Skip to content

Commit

Permalink
HasCompilations() implementation local to the LibraryModel
Browse files Browse the repository at this point in the history
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().
  • Loading branch information
tvelocity authored and davidsansome committed Oct 27, 2012
1 parent 14eca25 commit 207225d
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 22 deletions.
12 changes: 0 additions & 12 deletions src/library/librarybackend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
2 changes: 0 additions & 2 deletions src/library/librarybackend.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ class LibraryBackendInterface : public QObject {
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;
Expand Down Expand Up @@ -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());
Expand Down
22 changes: 15 additions & 7 deletions src/library/librarymodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
}

Expand Down Expand Up @@ -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();
Expand Down
2 changes: 2 additions & 0 deletions src/library/librarymodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
1 change: 0 additions & 1 deletion tests/mock_librarybackend.h
Original file line number Diff line number Diff line change
Expand Up @@ -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&));
Expand Down

0 comments on commit 207225d

Please sign in to comment.