Fix bug caused by adding Various Artists for albumartist, where nodes would sometimes not move under Various Artists due to album node never being empty (Issue 509)
This commit is contained in:
parent
360aaabd0d
commit
2cf6875c6d
|
@ -878,52 +878,53 @@ void LibraryBackend::UpdateManualAlbumArt(const QString &artist,
|
|||
}
|
||||
}
|
||||
|
||||
void LibraryBackend::ForceCompilation(const QString& artist, const QString& album, bool on) {
|
||||
void LibraryBackend::ForceCompilation(const QString& album, const QList<QString>& artists, bool on) {
|
||||
QMutexLocker l(db_->Mutex());
|
||||
QSqlDatabase db(db_->Connect());
|
||||
SongList deleted_songs, added_songs;
|
||||
|
||||
// Get the songs before they're updated
|
||||
LibraryQuery query;
|
||||
query.SetColumnSpec("ROWID, " + Song::kColumnSpec);
|
||||
query.AddWhere("album", album);
|
||||
if (!artist.isNull())
|
||||
query.AddWhere("artist", artist);
|
||||
foreach(const QString &artist, artists) {
|
||||
// Get the songs before they're updated
|
||||
LibraryQuery query;
|
||||
query.SetColumnSpec("ROWID, " + Song::kColumnSpec);
|
||||
query.AddWhere("album", album);
|
||||
if (!artist.isNull())
|
||||
query.AddWhere("artist", artist);
|
||||
|
||||
if (!ExecQuery(&query)) return;
|
||||
if (!ExecQuery(&query)) return;
|
||||
|
||||
SongList deleted_songs;
|
||||
while (query.Next()) {
|
||||
Song song;
|
||||
song.InitFromQuery(query, true);
|
||||
deleted_songs << song;
|
||||
}
|
||||
while (query.Next()) {
|
||||
Song song;
|
||||
song.InitFromQuery(query, true);
|
||||
deleted_songs << song;
|
||||
}
|
||||
|
||||
// Update the songs
|
||||
QString sql(QString("UPDATE %1 SET forced_compilation_on = :forced_compilation_on,"
|
||||
" forced_compilation_off = :forced_compilation_off,"
|
||||
" effective_compilation = ((compilation OR sampler OR :forced_compilation_on) AND NOT :forced_compilation_off) + 0"
|
||||
" WHERE album = :album AND unavailable = 0").arg(songs_table_));
|
||||
if (!artist.isEmpty())
|
||||
sql += " AND artist = :artist";
|
||||
// Update the songs
|
||||
QString sql(QString("UPDATE %1 SET forced_compilation_on = :forced_compilation_on,"
|
||||
" forced_compilation_off = :forced_compilation_off,"
|
||||
" effective_compilation = ((compilation OR sampler OR :forced_compilation_on) AND NOT :forced_compilation_off) + 0"
|
||||
" WHERE album = :album AND unavailable = 0").arg(songs_table_));
|
||||
if (!artist.isEmpty())
|
||||
sql += " AND artist = :artist";
|
||||
|
||||
QSqlQuery q(sql, db);
|
||||
q.bindValue(":forced_compilation_on", on ? 1 : 0);
|
||||
q.bindValue(":forced_compilation_off", on ? 0 : 1);
|
||||
q.bindValue(":album", album);
|
||||
if (!artist.isEmpty())
|
||||
q.bindValue(":artist", artist);
|
||||
QSqlQuery q(sql, db);
|
||||
q.bindValue(":forced_compilation_on", on ? 1 : 0);
|
||||
q.bindValue(":forced_compilation_off", on ? 0 : 1);
|
||||
q.bindValue(":album", album);
|
||||
if (!artist.isEmpty())
|
||||
q.bindValue(":artist", artist);
|
||||
|
||||
q.exec();
|
||||
db_->CheckErrors(q);
|
||||
q.exec();
|
||||
db_->CheckErrors(q);
|
||||
|
||||
// Now get the updated songs
|
||||
if (!ExecQuery(&query)) return;
|
||||
// Now get the updated songs
|
||||
if (!ExecQuery(&query)) return;
|
||||
|
||||
SongList added_songs;
|
||||
while (query.Next()) {
|
||||
Song song;
|
||||
song.InitFromQuery(query, true);
|
||||
added_songs << song;
|
||||
while (query.Next()) {
|
||||
Song song;
|
||||
song.InitFromQuery(query, true);
|
||||
added_songs << song;
|
||||
}
|
||||
}
|
||||
|
||||
if (!added_songs.isEmpty() || !deleted_songs.isEmpty()) {
|
||||
|
|
|
@ -173,7 +173,7 @@ class LibraryBackend : public LibraryBackendInterface {
|
|||
void AddOrUpdateSubdirs(const SubdirectoryList& subdirs);
|
||||
void UpdateCompilations();
|
||||
void UpdateManualAlbumArt(const QString& artist, const QString& album, const QString& art);
|
||||
void ForceCompilation(const QString& artist, const QString& album, bool on);
|
||||
void ForceCompilation(const QString& album, const QList<QString>& artists, bool on);
|
||||
void IncrementPlayCount(int id);
|
||||
void IncrementSkipCount(int id, float progress);
|
||||
void ResetStatistics(int id);
|
||||
|
|
|
@ -380,16 +380,17 @@ void LibraryView::ShowInVarious(bool on) {
|
|||
if (!context_menu_index_.isValid())
|
||||
return;
|
||||
|
||||
// Build a list of the selected unique album/artist combos
|
||||
typedef QPair<QString, QString> AlbumArtist;
|
||||
QSet<AlbumArtist> selected;
|
||||
// Map is from album name -> all artists sharing that album name, built from each selected
|
||||
// song. We put through "Various Artists" changes one album at a time, to make sure the old album
|
||||
// node gets removed (due to all children removed), before the new one gets added
|
||||
QMultiMap<QString, QString> albums;
|
||||
foreach (const Song& song, GetSelectedSongs()) {
|
||||
selected << AlbumArtist(song.album(), song.artist());
|
||||
if (albums.find(song.album(), song.artist()) == albums.end())
|
||||
albums.insert( song.album(), song.artist() );
|
||||
}
|
||||
|
||||
foreach (const AlbumArtist& albumartist, selected.values()) {
|
||||
library_->backend()->ForceCompilation(
|
||||
albumartist.second, albumartist.first, on);
|
||||
foreach (const QString& album, QSet<QString>::fromList(albums.keys())) {
|
||||
library_->backend()->ForceCompilation(album, albums.values(album), on);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue