Add support for 'album artist' field in the LibraryBackendInterface

This commit is contained in:
santigl 2017-03-03 20:18:16 -03:00 committed by John Maguire
parent 58b7c62f25
commit deb7c33c64
3 changed files with 78 additions and 29 deletions

View File

@ -554,12 +554,17 @@ QStringList LibraryBackend::GetAllArtistsWithAlbums(const QueryOptions& opt) {
LibraryBackend::AlbumList LibraryBackend::GetAllAlbums(
const QueryOptions& opt) {
return GetAlbums(QString(), false, opt);
return GetAlbums(QString(), QString(), false, opt);
}
LibraryBackend::AlbumList LibraryBackend::GetAlbumsByArtist(
const QString& artist, const QueryOptions& opt) {
return GetAlbums(artist, false, opt);
return GetAlbums(artist, QString(), false, opt);
}
LibraryBackend::AlbumList LibraryBackend::GetAlbumsByAlbumArtist(
const QString& album_artist, const QueryOptions& opt) {
return GetAlbums(QString(), album_artist, false, opt);
}
SongList LibraryBackend::GetSongsByAlbum(const QString& album,
@ -706,7 +711,7 @@ SongList LibraryBackend::GetSongsByUrl(const QUrl& url) {
LibraryBackend::AlbumList LibraryBackend::GetCompilationAlbums(
const QueryOptions& opt) {
return GetAlbums(QString(), true, opt);
return GetAlbums(QString(), QString(), true, opt);
}
SongList LibraryBackend::GetCompilationSongs(const QString& album,
@ -844,18 +849,22 @@ void LibraryBackend::UpdateCompilations(QSqlQuery& find_songs,
}
LibraryBackend::AlbumList LibraryBackend::GetAlbums(const QString& artist,
const QString& album_artist,
bool compilation,
const QueryOptions& opt) {
AlbumList ret;
LibraryQuery query(opt);
query.SetColumnSpec(
"album, artist, compilation, sampler, art_automatic, "
"album, artist, albumartist, compilation, sampler, art_automatic, "
"art_manual, filename");
query.SetOrderBy("album");
if (compilation) {
query.AddCompilationRequirement(true);
} else if (!album_artist.isNull()) {
query.AddCompilationRequirement(false);
query.AddWhere("albumartist", album_artist);
} else if (!artist.isNull()) {
query.AddCompilationRequirement(false);
query.AddWhere("artist", artist);
@ -863,39 +872,51 @@ LibraryBackend::AlbumList LibraryBackend::GetAlbums(const QString& artist,
QMutexLocker l(db_->Mutex());
if (!ExecQuery(&query)) return ret;
l.unlock();
QString last_album;
QString last_artist;
QString last_artist, last_album_artist;
while (query.Next()) {
bool compilation = query.Value(2).toBool() | query.Value(3).toBool();
bool compilation = query.Value(3).toBool() | query.Value(4).toBool();
Album info;
info.artist = compilation ? QString() : query.Value(1).toString();
info.album_artist = compilation ? QString() : query.Value(2).toString();
info.album_name = query.Value(0).toString();
info.art_automatic = query.Value(4).toString();
info.art_manual = query.Value(5).toString();
info.first_url = QUrl::fromEncoded(query.Value(6).toByteArray());
info.art_automatic = query.Value(5).toString();
info.art_manual = query.Value(6).toString();
info.first_url = QUrl::fromEncoded(query.Value(7).toByteArray());
if (info.artist == last_artist && info.album_name == last_album) continue;
if ((info.artist == last_artist ||
info.album_artist == last_album_artist) &&
info.album_name == last_album)
continue;
ret << info;
last_album = info.album_name;
last_artist = info.artist;
last_album_artist = info.album_artist;
}
return ret;
}
LibraryBackend::Album LibraryBackend::GetAlbumArt(const QString& artist,
const QString& albumartist,
const QString& album) {
Album ret;
ret.album_name = album;
ret.artist = artist;
ret.album_artist = albumartist;
LibraryQuery query = LibraryQuery(QueryOptions());
query.SetColumnSpec("art_automatic, art_manual, filename");
query.AddWhere("artist", artist);
if (!albumartist.isEmpty()) {
query.AddWhere("albumartist", albumartist);
} else if (!artist.isEmpty()) {
query.AddWhere("artist", artist);
}
query.AddWhere("album", album);
QMutexLocker l(db_->Mutex());
@ -911,14 +932,17 @@ LibraryBackend::Album LibraryBackend::GetAlbumArt(const QString& artist,
}
void LibraryBackend::UpdateManualAlbumArtAsync(const QString& artist,
const QString& albumartist,
const QString& album,
const QString& art) {
metaObject()->invokeMethod(this, "UpdateManualAlbumArt", Qt::QueuedConnection,
Q_ARG(QString, artist), Q_ARG(QString, album),
Q_ARG(QString, artist),
Q_ARG(QString, albumartist), Q_ARG(QString, album),
Q_ARG(QString, art));
}
void LibraryBackend::UpdateManualAlbumArt(const QString& artist,
const QString& albumartist,
const QString& album,
const QString& art) {
QMutexLocker l(db_->Mutex());
@ -928,7 +952,12 @@ void LibraryBackend::UpdateManualAlbumArt(const QString& artist,
LibraryQuery query;
query.SetColumnSpec("ROWID, " + Song::kColumnSpec);
query.AddWhere("album", album);
if (!artist.isNull()) query.AddWhere("artist", artist);
if (!albumartist.isNull()) {
query.AddWhere("albumartist", albumartist);
} else if (!artist.isNull()) {
query.AddWhere("artist", artist);
}
if (!ExecQuery(&query)) return;
@ -944,12 +973,20 @@ void LibraryBackend::UpdateManualAlbumArt(const QString& artist,
QString(
"UPDATE %1 SET art_manual = :art"
" WHERE album = :album AND unavailable = 0").arg(songs_table_));
if (!artist.isNull()) sql += " AND artist = :artist";
if (!albumartist.isNull()) {
sql += " AND albumartist = :albumartist";
} else if (!artist.isNull()) {
sql += " AND artist = :artist";
}
QSqlQuery q(sql, db);
q.bindValue(":art", art);
q.bindValue(":album", album);
if (!artist.isNull()) q.bindValue(":artist", artist);
if (!albumartist.isNull()) {
q.bindValue(":albumartist", albumartist);
} else if (!artist.isNull()) {
q.bindValue(":artist", artist);
}
q.exec();
db_->CheckErrors(q);

View File

@ -41,16 +41,22 @@ class LibraryBackendInterface : public QObject {
struct Album {
Album() {}
Album(const QString& _artist, const QString& _album_name,
const QString& _art_automatic, const QString& _art_manual,
const QUrl& _first_url)
Album(const QString& _artist, const QString& _album_artist,
const QString& _album_name, const QString& _art_automatic,
const QString& _art_manual, const QUrl& _first_url)
: artist(_artist),
album_artist(_album_artist),
album_name(_album_name),
art_automatic(_art_automatic),
art_manual(_art_manual),
first_url(_first_url) {}
const QString& effective_albumartist() const {
return album_artist.isEmpty() ? artist : album_artist;
}
QString artist;
QString album_artist;
QString album_name;
QString art_automatic;
@ -92,9 +98,11 @@ class LibraryBackendInterface : public QObject {
const QueryOptions& opt = QueryOptions()) = 0;
virtual void UpdateManualAlbumArtAsync(const QString& artist,
const QString& albumartist,
const QString& album,
const QString& art) = 0;
virtual Album GetAlbumArt(const QString& artist, const QString& album) = 0;
virtual Album GetAlbumArt(const QString& artist, const QString& albumartist,
const QString& album) = 0;
virtual Song GetSongById(int id) = 0;
@ -157,11 +165,15 @@ class LibraryBackend : public LibraryBackendInterface {
AlbumList GetAllAlbums(const QueryOptions& opt = QueryOptions());
AlbumList GetAlbumsByArtist(const QString& artist,
const QueryOptions& opt = QueryOptions());
AlbumList GetAlbumsByAlbumArtist(const QString& albumartist,
const QueryOptions& opt = QueryOptions());
AlbumList GetCompilationAlbums(const QueryOptions& opt = QueryOptions());
void UpdateManualAlbumArtAsync(const QString& artist, const QString& album,
const QString& art);
Album GetAlbumArt(const QString& artist, const QString& album);
void UpdateManualAlbumArtAsync(const QString& artist,
const QString& albumartist,
const QString& album, const QString& art);
Album GetAlbumArt(const QString& artist, const QString& albumartist,
const QString& album);
Song GetSongById(int id);
SongList GetSongsById(const QList<int>& ids);
@ -197,8 +209,8 @@ class LibraryBackend : public LibraryBackendInterface {
void MarkSongsUnavailable(const SongList& songs, bool unavailable = true);
void AddOrUpdateSubdirs(const SubdirectoryList& subdirs);
void UpdateCompilations();
void UpdateManualAlbumArt(const QString& artist, const QString& album,
const QString& art);
void UpdateManualAlbumArt(const QString& artist, const QString& albumartist,
const QString& album, const QString& art);
void ForceCompilation(const QString& album, const QList<QString>& artists,
bool on);
void IncrementPlayCount(int id);
@ -236,7 +248,8 @@ signals:
void UpdateCompilations(QSqlQuery& find_songs, QSqlQuery& update,
SongList& deleted_songs, SongList& added_songs,
const QString& album, int sampler);
AlbumList GetAlbums(const QString& artist, bool compilation = false,
AlbumList GetAlbums(const QString& artist, const QString& album_artist,
bool compilation = false,
const QueryOptions& opt = QueryOptions());
SubdirectoryList SubdirsInDirectory(int id, QSqlDatabase& db);

View File

@ -424,8 +424,8 @@ bool AlbumCoverManager::ShouldHide(const QListWidgetItem& item,
QStringList query = filter.split(' ');
for (const QString& s : query) {
if (!item.text().contains(s, Qt::CaseInsensitive) &&
!item.data(Role_ArtistName).toString().contains(
s, Qt::CaseInsensitive),
!item.data(Role_ArtistName).toString().contains(
s, Qt::CaseInsensitive) &&
!item.data(Role_AlbumArtistName).toString().contains(
s, Qt::CaseInsensitive)) {
return true;
@ -578,9 +578,8 @@ void AlbumCoverManager::ShowCover() {
void AlbumCoverManager::FetchSingleCover() {
for (QListWidgetItem* item : context_menu_items_) {
QString artist_name = EffectiveAlbumArtistName(item);
quint64 id = cover_fetcher_->FetchAlbumCover(
artist_name, item->data(Role_AlbumName).toString());
EffectiveAlbumArtistName(item), item->data(Role_AlbumName).toString());
cover_fetching_tasks_[id] = item;
jobs_++;
}