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:
parent
14eca258a2
commit
207225d620
|
@ -628,18 +628,6 @@ SongList LibraryBackend::GetSongsByUrl(const QUrl& url) {
|
||||||
return songlist;
|
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) {
|
LibraryBackend::AlbumList LibraryBackend::GetCompilationAlbums(const QueryOptions& opt) {
|
||||||
return GetAlbums(QString(), true, opt);
|
return GetAlbums(QString(), true, opt);
|
||||||
}
|
}
|
||||||
|
|
|
@ -74,7 +74,6 @@ public:
|
||||||
virtual SongList GetSongs(
|
virtual SongList GetSongs(
|
||||||
const QString& artist, const QString& album, const QueryOptions& opt = QueryOptions()) = 0;
|
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 SongList GetCompilationSongs(const QString& album, const QueryOptions& opt = QueryOptions()) = 0;
|
||||||
|
|
||||||
virtual AlbumList GetAllAlbums(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 GetSongsByAlbum(const QString& album, const QueryOptions& opt = QueryOptions());
|
||||||
SongList GetSongs(const QString& artist, 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());
|
SongList GetCompilationSongs(const QString& album, const QueryOptions& opt = QueryOptions());
|
||||||
|
|
||||||
AlbumList GetAllAlbums(const QueryOptions& opt = QueryOptions());
|
AlbumList GetAllAlbums(const QueryOptions& opt = QueryOptions());
|
||||||
|
|
|
@ -554,6 +554,17 @@ QVariant LibraryModel::data(const LibraryItem* item, int role) const {
|
||||||
return QVariant();
|
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) {
|
SqlRowList LibraryModel::RunQuery(LibraryItem* parent, bool signal) {
|
||||||
// Information about what we want the children to be
|
// Information about what we want the children to be
|
||||||
int child_level = parent == root_ ? 0 : parent->container_level + 1;
|
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
|
// Top-level artists is special - we don't want compilation albums appearing
|
||||||
if (child_level == 0 && IsArtistGroupBy(child_type)) {
|
if (child_level == 0 && IsArtistGroupBy(child_type)) {
|
||||||
|
// Various artists?
|
||||||
|
if (show_various_artists_ && HasCompilations(q))
|
||||||
|
CreateCompilationArtistNode(signal, parent);
|
||||||
|
|
||||||
q.AddCompilationRequirement(false);
|
q.AddCompilationRequirement(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -661,13 +676,6 @@ void LibraryModel::BeginReset() {
|
||||||
root_ = new LibraryItem(this);
|
root_ = new LibraryItem(this);
|
||||||
root_->lazy_loaded = false;
|
root_->lazy_loaded = false;
|
||||||
|
|
||||||
if (show_various_artists_) {
|
|
||||||
// Various artists?
|
|
||||||
if (IsArtistGroupBy(group_by_[0]) &&
|
|
||||||
backend_->HasCompilations(query_options_))
|
|
||||||
CreateCompilationArtistNode(false, root_);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Smart playlists?
|
// Smart playlists?
|
||||||
if (show_smart_playlists_ && query_options_.filter().isEmpty())
|
if (show_smart_playlists_ && query_options_.filter().isEmpty())
|
||||||
CreateSmartPlaylists();
|
CreateSmartPlaylists();
|
||||||
|
|
|
@ -189,6 +189,8 @@ class LibraryModel : public SimpleTreeModel<LibraryItem> {
|
||||||
SqlRowList RunQuery(LibraryItem* parent, bool signal);
|
SqlRowList RunQuery(LibraryItem* parent, bool signal);
|
||||||
void PostQuery(LibraryItem* parent, SqlRowList rows, bool signal);
|
void PostQuery(LibraryItem* parent, SqlRowList rows, bool signal);
|
||||||
|
|
||||||
|
bool HasCompilations(const LibraryQuery query);
|
||||||
|
|
||||||
void BeginReset();
|
void BeginReset();
|
||||||
|
|
||||||
// Functions for working with queries and creating items.
|
// Functions for working with queries and creating items.
|
||||||
|
|
|
@ -41,7 +41,6 @@ class MockLibraryBackend : public LibraryBackendInterface {
|
||||||
MOCK_METHOD1(GetAllArtistsWithAlbums, QStringList(const QueryOptions&));
|
MOCK_METHOD1(GetAllArtistsWithAlbums, QStringList(const QueryOptions&));
|
||||||
MOCK_METHOD3(GetSongs, SongList(const QString&, const QString&, 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_METHOD2(GetCompilationSongs, SongList(const QString&, const QueryOptions&));
|
||||||
|
|
||||||
MOCK_METHOD1(GetAllAlbums, AlbumList(const QueryOptions&));
|
MOCK_METHOD1(GetAllAlbums, AlbumList(const QueryOptions&));
|
||||||
|
|
Loading…
Reference in New Issue