mirror of
https://github.com/clementine-player/Clementine
synced 2024-12-16 11:19:18 +01:00
Add a random smart playlist to Jamendo
This commit is contained in:
parent
b1bf95a668
commit
f11c494c44
@ -28,21 +28,6 @@ const char* Library::kDirsTable = "directories";
|
||||
const char* Library::kSubdirsTable = "subdirectories";
|
||||
const char* Library::kFtsTable = "songs_fts";
|
||||
|
||||
using smart_playlists::Generator;
|
||||
using smart_playlists::GeneratorPtr;
|
||||
using smart_playlists::QueryGenerator;
|
||||
using smart_playlists::Search;
|
||||
using smart_playlists::SearchTerm;
|
||||
|
||||
static GeneratorPtr NewQuery(
|
||||
const QString& name, const smart_playlists::Search& search, bool dynamic = false) {
|
||||
boost::shared_ptr<QueryGenerator> gen(new QueryGenerator);
|
||||
gen->Load(search);
|
||||
gen->set_name(name);
|
||||
gen->set_dynamic(dynamic);
|
||||
return boost::static_pointer_cast<Generator>(gen);
|
||||
}
|
||||
|
||||
Library::Library(BackgroundThread<Database>* db_thread, TaskManager* task_manager,
|
||||
QObject *parent)
|
||||
: QObject(parent),
|
||||
@ -57,46 +42,52 @@ Library::Library(BackgroundThread<Database>* db_thread, TaskManager* task_manage
|
||||
|
||||
backend_->Init(db_thread->Worker(), kSongsTable, kDirsTable, kSubdirsTable, kFtsTable);
|
||||
|
||||
using smart_playlists::Generator;
|
||||
using smart_playlists::GeneratorPtr;
|
||||
using smart_playlists::QueryGenerator;
|
||||
using smart_playlists::Search;
|
||||
using smart_playlists::SearchTerm;
|
||||
|
||||
model_ = new LibraryModel(backend_, this);
|
||||
model_->set_show_smart_playlists(true);
|
||||
model_->set_default_smart_playlists(LibraryModel::DefaultGenerators()
|
||||
<< (LibraryModel::GeneratorList()
|
||||
<< NewQuery(tr("50 random tracks"), Search(
|
||||
<< GeneratorPtr(new QueryGenerator(tr("50 random tracks"), Search(
|
||||
Search::Type_All, Search::TermList(),
|
||||
Search::Sort_Random, SearchTerm::Field_Title, 50))
|
||||
<< NewQuery(tr("Ever played"), Search(
|
||||
Search::Sort_Random, SearchTerm::Field_Title, 50)))
|
||||
<< GeneratorPtr(new QueryGenerator(tr("Ever played"), Search(
|
||||
Search::Type_And, Search::TermList()
|
||||
<< SearchTerm(SearchTerm::Field_PlayCount, SearchTerm::Op_GreaterThan, 0),
|
||||
Search::Sort_Random, SearchTerm::Field_Title))
|
||||
<< NewQuery(tr("Never played"), Search(
|
||||
Search::Sort_Random, SearchTerm::Field_Title)))
|
||||
<< GeneratorPtr(new QueryGenerator(tr("Never played"), Search(
|
||||
Search::Type_And, Search::TermList()
|
||||
<< SearchTerm(SearchTerm::Field_PlayCount, SearchTerm::Op_Equals, 0),
|
||||
Search::Sort_Random, SearchTerm::Field_Title))
|
||||
<< NewQuery(tr("Last played"), Search(
|
||||
Search::Sort_Random, SearchTerm::Field_Title)))
|
||||
<< GeneratorPtr(new QueryGenerator(tr("Last played"), Search(
|
||||
Search::Type_All, Search::TermList(),
|
||||
Search::Sort_FieldDesc, SearchTerm::Field_LastPlayed))
|
||||
<< NewQuery(tr("Most played"), Search(
|
||||
Search::Sort_FieldDesc, SearchTerm::Field_LastPlayed)))
|
||||
<< GeneratorPtr(new QueryGenerator(tr("Most played"), Search(
|
||||
Search::Type_All, Search::TermList(),
|
||||
Search::Sort_FieldDesc, SearchTerm::Field_PlayCount))
|
||||
<< NewQuery(tr("Favourite tracks"), Search(
|
||||
Search::Sort_FieldDesc, SearchTerm::Field_PlayCount)))
|
||||
<< GeneratorPtr(new QueryGenerator(tr("Favourite tracks"), Search(
|
||||
Search::Type_All, Search::TermList(),
|
||||
Search::Sort_FieldDesc, SearchTerm::Field_Score))
|
||||
<< NewQuery(tr("Newest tracks"), Search(
|
||||
Search::Sort_FieldDesc, SearchTerm::Field_Score)))
|
||||
<< GeneratorPtr(new QueryGenerator(tr("Newest tracks"), Search(
|
||||
Search::Type_All, Search::TermList(),
|
||||
Search::Sort_FieldDesc, SearchTerm::Field_DateCreated))
|
||||
Search::Sort_FieldDesc, SearchTerm::Field_DateCreated)))
|
||||
) << (LibraryModel::GeneratorList()
|
||||
<< NewQuery(tr("All tracks"), Search(
|
||||
<< GeneratorPtr(new QueryGenerator(tr("All tracks"), Search(
|
||||
Search::Type_All, Search::TermList(),
|
||||
Search::Sort_FieldAsc, SearchTerm::Field_Artist, -1))
|
||||
<< NewQuery(tr("Least favourite tracks"), Search(
|
||||
Search::Sort_FieldAsc, SearchTerm::Field_Artist, -1)))
|
||||
<< GeneratorPtr(new QueryGenerator(tr("Least favourite tracks"), Search(
|
||||
Search::Type_Or, Search::TermList()
|
||||
<< SearchTerm(SearchTerm::Field_Rating, SearchTerm::Op_LessThan, 0.6)
|
||||
<< SearchTerm(SearchTerm::Field_SkipCount, SearchTerm::Op_GreaterThan, 4),
|
||||
Search::Sort_FieldDesc, SearchTerm::Field_SkipCount))
|
||||
Search::Sort_FieldDesc, SearchTerm::Field_SkipCount)))
|
||||
) << (LibraryModel::GeneratorList()
|
||||
<< NewQuery(tr("Dynamic random mix"), Search(
|
||||
<< GeneratorPtr(new QueryGenerator(tr("Dynamic random mix"), Search(
|
||||
Search::Type_All, Search::TermList(),
|
||||
Search::Sort_Random, SearchTerm::Field_Title), true)
|
||||
Search::Sort_Random, SearchTerm::Field_Title), true))
|
||||
)
|
||||
);
|
||||
}
|
||||
|
@ -38,6 +38,7 @@
|
||||
#include "radio/jamendodynamicplaylist.h"
|
||||
#include "radio/jamendoplaylistitem.h"
|
||||
#include "smartplaylists/generator.h"
|
||||
#include "smartplaylists/querygenerator.h"
|
||||
#include "ui/iconloader.h"
|
||||
|
||||
const char* JamendoService::kServiceName = "Jamendo";
|
||||
@ -63,9 +64,6 @@ const char* JamendoService::kSettingsGroup = "Jamendo";
|
||||
const int JamendoService::kBatchSize = 10000;
|
||||
const int JamendoService::kApproxDatabaseSize = 300000;
|
||||
|
||||
using smart_playlists::Generator;
|
||||
using smart_playlists::GeneratorPtr;
|
||||
|
||||
JamendoService::JamendoService(RadioModel* parent)
|
||||
: RadioService(kServiceName, parent),
|
||||
network_(new NetworkAccessManager(this)),
|
||||
@ -84,6 +82,12 @@ JamendoService::JamendoService(RadioModel* parent)
|
||||
connect(library_backend_, SIGNAL(TotalSongCountUpdated(int)),
|
||||
SLOT(UpdateTotalSongCount(int)));
|
||||
|
||||
using smart_playlists::Generator;
|
||||
using smart_playlists::GeneratorPtr;
|
||||
using smart_playlists::QueryGenerator;
|
||||
using smart_playlists::Search;
|
||||
using smart_playlists::SearchTerm;
|
||||
|
||||
library_model_ = new LibraryModel(library_backend_, this);
|
||||
library_model_->set_show_smart_playlists(true);
|
||||
library_model_->set_default_smart_playlists(LibraryModel::DefaultGenerators()
|
||||
@ -97,6 +101,11 @@ JamendoService::JamendoService(RadioModel* parent)
|
||||
<< GeneratorPtr(new JamendoDynamicPlaylist(tr("Jamendo Most Listened Tracks"),
|
||||
JamendoDynamicPlaylist::OrderBy_Listened))
|
||||
)
|
||||
<< (LibraryModel::GeneratorList()
|
||||
<< GeneratorPtr(new QueryGenerator(tr("Dynamic random mix"), Search(
|
||||
Search::Type_All, Search::TermList(),
|
||||
Search::Sort_Random, SearchTerm::Field_Title), true))
|
||||
)
|
||||
);
|
||||
|
||||
library_sort_model_->setSourceModel(library_model_);
|
||||
|
@ -29,6 +29,14 @@ QueryGenerator::QueryGenerator()
|
||||
{
|
||||
}
|
||||
|
||||
QueryGenerator::QueryGenerator(const QString& name, const Search& search, bool dynamic)
|
||||
: search_(search),
|
||||
dynamic_(dynamic),
|
||||
current_pos_(0)
|
||||
{
|
||||
set_name(name);
|
||||
}
|
||||
|
||||
void QueryGenerator::Load(const Search& search) {
|
||||
search_ = search;
|
||||
dynamic_ = false;
|
||||
|
@ -26,6 +26,7 @@ namespace smart_playlists {
|
||||
class QueryGenerator : public Generator {
|
||||
public:
|
||||
QueryGenerator();
|
||||
QueryGenerator(const QString& name, const Search& search, bool dynamic = false);
|
||||
|
||||
QString type() const { return "Query"; }
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user