1
0
mirror of https://github.com/clementine-player/Clementine synced 2024-12-18 04:19:55 +01:00

HasCompilations() implementation local to the LibraryModel

Instead of relying on the backend to provide us with the information
of whether there are compilations in the whole of the library, we instead
look into the query we are currently working with for compilations. This
way we can be as granular as we want in the future.

This also means we now have to add the Various artists node at the time we
do the query with RunQuery() instead at BeginReset().
This commit is contained in:
Tony Motakis 2012-10-25 03:47:14 +02:00 committed by David Sansome
parent 14eca258a2
commit 207225d620
5 changed files with 17 additions and 22 deletions

View File

@ -628,18 +628,6 @@ SongList LibraryBackend::GetSongsByUrl(const QUrl& url) {
return songlist;
}
bool LibraryBackend::HasCompilations(const QueryOptions& opt) {
LibraryQuery query(opt);
query.SetColumnSpec("%songs_table.ROWID");
query.AddCompilationRequirement(true);
query.SetLimit(1);
QMutexLocker l(db_->Mutex());
if (!ExecQuery(&query)) return false;
return query.Next();
}
LibraryBackend::AlbumList LibraryBackend::GetCompilationAlbums(const QueryOptions& opt) {
return GetAlbums(QString(), true, opt);
}

View File

@ -74,7 +74,6 @@ public:
virtual SongList GetSongs(
const QString& artist, const QString& album, const QueryOptions& opt = QueryOptions()) = 0;
virtual bool HasCompilations(const QueryOptions& opt = QueryOptions()) = 0;
virtual SongList GetCompilationSongs(const QString& album, const QueryOptions& opt = QueryOptions()) = 0;
virtual AlbumList GetAllAlbums(const QueryOptions& opt = QueryOptions()) = 0;
@ -132,7 +131,6 @@ class LibraryBackend : public LibraryBackendInterface {
SongList GetSongsByAlbum(const QString& album, const QueryOptions& opt = QueryOptions());
SongList GetSongs(const QString& artist, const QString& album, const QueryOptions& opt = QueryOptions());
bool HasCompilations(const QueryOptions& opt = QueryOptions());
SongList GetCompilationSongs(const QString& album, const QueryOptions& opt = QueryOptions());
AlbumList GetAllAlbums(const QueryOptions& opt = QueryOptions());

View File

@ -554,6 +554,17 @@ QVariant LibraryModel::data(const LibraryItem* item, int role) const {
return QVariant();
}
bool LibraryModel::HasCompilations(const LibraryQuery query) {
LibraryQuery q = query;
q.AddCompilationRequirement(true);
q.SetLimit(1);
QMutexLocker l(backend_->db()->Mutex());
if (!backend_->ExecQuery(&q)) return false;
return q.Next();
}
SqlRowList LibraryModel::RunQuery(LibraryItem* parent, bool signal) {
// Information about what we want the children to be
int child_level = parent == root_ ? 0 : parent->container_level + 1;
@ -573,6 +584,10 @@ SqlRowList LibraryModel::RunQuery(LibraryItem* parent, bool signal) {
// Top-level artists is special - we don't want compilation albums appearing
if (child_level == 0 && IsArtistGroupBy(child_type)) {
// Various artists?
if (show_various_artists_ && HasCompilations(q))
CreateCompilationArtistNode(signal, parent);
q.AddCompilationRequirement(false);
}
@ -661,13 +676,6 @@ void LibraryModel::BeginReset() {
root_ = new LibraryItem(this);
root_->lazy_loaded = false;
if (show_various_artists_) {
// Various artists?
if (IsArtistGroupBy(group_by_[0]) &&
backend_->HasCompilations(query_options_))
CreateCompilationArtistNode(false, root_);
}
// Smart playlists?
if (show_smart_playlists_ && query_options_.filter().isEmpty())
CreateSmartPlaylists();

View File

@ -189,6 +189,8 @@ class LibraryModel : public SimpleTreeModel<LibraryItem> {
SqlRowList RunQuery(LibraryItem* parent, bool signal);
void PostQuery(LibraryItem* parent, SqlRowList rows, bool signal);
bool HasCompilations(const LibraryQuery query);
void BeginReset();
// Functions for working with queries and creating items.

View File

@ -41,7 +41,6 @@ class MockLibraryBackend : public LibraryBackendInterface {
MOCK_METHOD1(GetAllArtistsWithAlbums, QStringList(const QueryOptions&));
MOCK_METHOD3(GetSongs, SongList(const QString&, const QString&, const QueryOptions&));
MOCK_METHOD1(HasCompilations, bool(const QueryOptions&));
MOCK_METHOD2(GetCompilationSongs, SongList(const QString&, const QueryOptions&));
MOCK_METHOD1(GetAllAlbums, AlbumList(const QueryOptions&));