Prompt user if they are adding one part of a larger compilation to Various Artists. Fixes issue 2725

This commit is contained in:
Angus Gratton 2012-02-19 13:38:24 +00:00 committed by David Sansome
parent 089586ad07
commit f33d9b82d4
3 changed files with 44 additions and 4 deletions

View File

@ -493,20 +493,31 @@ LibraryBackend::AlbumList LibraryBackend::GetAlbumsByArtist(const QString& artis
return GetAlbums(artist, false, opt);
}
SongList LibraryBackend::GetSongsByAlbum(const QString& album, const QueryOptions& opt) {
LibraryQuery query(opt);
query.AddCompilationRequirement(false);
query.AddWhere("album", album);
return ExecLibraryQuery(&query);
}
SongList LibraryBackend::GetSongs(const QString& artist, const QString& album, const QueryOptions& opt) {
LibraryQuery query(opt);
query.SetColumnSpec("%songs_table.ROWID, " + Song::kColumnSpec);
query.AddCompilationRequirement(false);
query.AddWhere("artist", artist);
query.AddWhere("album", album);
return ExecLibraryQuery(&query);
}
SongList LibraryBackend::ExecLibraryQuery(LibraryQuery* query) {
query->SetColumnSpec("%songs_table.ROWID, " + Song::kColumnSpec);
QMutexLocker l(db_->Mutex());
if (!ExecQuery(&query)) return SongList();
if (!ExecQuery(query)) return SongList();
SongList ret;
while (query.Next()) {
while (query->Next()) {
Song song;
song.InitFromQuery(query, true);
song.InitFromQuery(*query, true);
ret << song;
}
return ret;

View File

@ -72,6 +72,7 @@ public:
virtual QStringList GetAllArtists(const QueryOptions& opt = QueryOptions()) = 0;
virtual QStringList GetAllArtistsWithAlbums(const QueryOptions& opt = QueryOptions()) = 0;
virtual SongList GetSongsByAlbum(const QString& album, const QueryOptions& opt = QueryOptions()) = 0;
virtual SongList GetSongs(
const QString& artist, const QString& album, const QueryOptions& opt = QueryOptions()) = 0;
@ -130,6 +131,7 @@ class LibraryBackend : public LibraryBackendInterface {
QStringList GetAll(const QString& column, const QueryOptions& opt = QueryOptions());
QStringList GetAllArtists(const QueryOptions& opt = QueryOptions());
QStringList GetAllArtistsWithAlbums(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());
bool HasCompilations(const QueryOptions& opt = QueryOptions());
@ -155,6 +157,7 @@ class LibraryBackend : public LibraryBackendInterface {
void RemoveDirectory(const Directory& dir);
bool ExecQuery(LibraryQuery* q);
SongList ExecLibraryQuery(LibraryQuery* query);
SongList FindSongs(const smart_playlists::Search& search);
void IncrementPlayCountAsync(int id);
@ -200,6 +203,7 @@ class LibraryBackend : public LibraryBackendInterface {
bool has_samplers;
bool has_not_samplers;
};
static const char* kNewScoreSql;

View File

@ -22,6 +22,7 @@
#include "libraryitem.h"
#include "librarybackend.h"
#include "core/deletefiles.h"
#include "core/logging.h"
#include "core/mimedata.h"
#include "core/musicstorage.h"
#include "core/utilities.h"
@ -389,6 +390,30 @@ void LibraryView::ShowInVarious(bool on) {
albums.insert( song.album(), song.artist() );
}
// If we have only one album and we are putting it into Various Artists, check to see
// if there are other Artists in this album and prompt the user if they'd like them moved, too
if(on && albums.keys().count() == 1) {
const QString album = albums.keys().first();
QList<Song> all_of_album = library_->backend()->GetSongsByAlbum(album);
QSet<QString> other_artists;
foreach (const Song& s, all_of_album) {
if(!albums.contains(album, s.artist()) && !other_artists.contains(s.artist())) {
other_artists.insert(s.artist());
}
}
if (other_artists.count() > 0) {
if (QMessageBox::question(this,
tr("There are other songs in this album"),
tr("Would you like to move the other songs in this album to Various Artists as well?"),
QMessageBox::Yes | QMessageBox::No,
QMessageBox::Yes) == QMessageBox::Yes) {
foreach (const QString& s, other_artists) {
albums.insert(album, s);
}
}
}
}
foreach (const QString& album, QSet<QString>::fromList(albums.keys())) {
library_->backend()->ForceCompilation(album, albums.values(album), on);
}