AlbumCoverChoiceController: Clear manually set cover when setting embedded cover

Possible fix for #858
This commit is contained in:
Jonas Kvinge 2022-01-06 02:13:24 +01:00
parent df359ba0fa
commit 2f3e8986ab
3 changed files with 16 additions and 9 deletions

View File

@ -1574,7 +1574,7 @@ void CollectionBackend::UpdateManualAlbumArt(const QString &effective_albumartis
}
// Update the songs
QString sql(QString("UPDATE %1 SET art_manual = :cover").arg(songs_table_));
QString sql = QString("UPDATE %1 SET art_manual = :cover").arg(songs_table_);
if (clear_art_automatic) {
sql += ", art_automatic = ''";
}
@ -1611,13 +1611,13 @@ void CollectionBackend::UpdateManualAlbumArt(const QString &effective_albumartis
}
void CollectionBackend::UpdateAutomaticAlbumArtAsync(const QString &effective_albumartist, const QString &album, const QUrl &cover_url) {
void CollectionBackend::UpdateAutomaticAlbumArtAsync(const QString &effective_albumartist, const QString &album, const QUrl &cover_url, const bool clear_art_manual) {
QMetaObject::invokeMethod(this, "UpdateAutomaticAlbumArt", Qt::QueuedConnection, Q_ARG(QString, effective_albumartist), Q_ARG(QString, album), Q_ARG(QUrl, cover_url));
QMetaObject::invokeMethod(this, "UpdateAutomaticAlbumArt", Qt::QueuedConnection, Q_ARG(QString, effective_albumartist), Q_ARG(QString, album), Q_ARG(QUrl, cover_url), Q_ARG(bool, clear_art_manual));
}
void CollectionBackend::UpdateAutomaticAlbumArt(const QString &effective_albumartist, const QString &album, const QUrl &cover_url) {
void CollectionBackend::UpdateAutomaticAlbumArt(const QString &effective_albumartist, const QString &album, const QUrl &cover_url, const bool clear_art_manual) {
QMutexLocker l(db_->Mutex());
QSqlDatabase db(db_->Connect());
@ -1641,7 +1641,11 @@ void CollectionBackend::UpdateAutomaticAlbumArt(const QString &effective_albumar
}
// Update the songs
QString sql(QString("UPDATE %1 SET art_automatic = :cover WHERE effective_albumartist = :effective_albumartist AND album = :album AND unavailable = 0").arg(songs_table_));
QString sql = QString("UPDATE %1 SET art_automatic = :cover").arg(songs_table_);
if (clear_art_manual) {
sql += ", art_manual = ''";
}
sql += " WHERE effective_albumartist = :effective_albumartist AND album = :album AND unavailable = 0";
SqlQuery q(db);
q.prepare(sql);

View File

@ -107,7 +107,7 @@ class CollectionBackendInterface : public QObject {
virtual AlbumList GetCompilationAlbums(const QueryOptions &opt = QueryOptions()) = 0;
virtual void UpdateManualAlbumArtAsync(const QString &effective_albumartist, const QString &album, const QUrl &cover_url, const bool clear_art_automatic = false) = 0;
virtual void UpdateAutomaticAlbumArtAsync(const QString &effective_albumartist, const QString &album, const QUrl &cover_url) = 0;
virtual void UpdateAutomaticAlbumArtAsync(const QString &effective_albumartist, const QString &album, const QUrl &cover_url, const bool clear_art_manual = false) = 0;
virtual Album GetAlbumArt(const QString &effective_albumartist, const QString &album) = 0;
@ -175,7 +175,7 @@ class CollectionBackend : public CollectionBackendInterface {
AlbumList GetAlbumsByArtist(const QString &artist, const QueryOptions &opt = QueryOptions()) override;
void UpdateManualAlbumArtAsync(const QString &effective_albumartist, const QString &album, const QUrl &cover_url, const bool clear_art_automatic = false) override;
void UpdateAutomaticAlbumArtAsync(const QString &effective_albumartist, const QString &album, const QUrl &cover_url) override;
void UpdateAutomaticAlbumArtAsync(const QString &effective_albumartist, const QString &album, const QUrl &cover_url, const bool clear_art_manual = false) override;
Album GetAlbumArt(const QString &effective_albumartist, const QString &album) override;
@ -229,7 +229,7 @@ class CollectionBackend : public CollectionBackendInterface {
void AddOrUpdateSubdirs(const SubdirectoryList &subdirs);
void CompilationsNeedUpdating();
void UpdateManualAlbumArt(const QString &effective_albumartist, const QString &album, const QUrl &cover_url, const bool clear_art_automatic = false);
void UpdateAutomaticAlbumArt(const QString &effective_albumartist, const QString &album, const QUrl &cover_url);
void UpdateAutomaticAlbumArt(const QString &effective_albumartist, const QString &album, const QUrl &cover_url, const bool clear_art_manual = false);
void ForceCompilation(const QString &album, const QList<QString> &artists, const bool on);
void IncrementPlayCount(const int id);
void IncrementSkipCount(const int id, const float progress);

View File

@ -534,9 +534,12 @@ void AlbumCoverChoiceController::SaveArtAutomaticToSong(Song *song, const QUrl &
if (!song->is_valid()) return;
song->set_art_automatic(art_automatic);
if (song->has_embedded_cover()) {
song->clear_art_manual();
}
if (song->source() == Song::Source_Collection) {
app_->collection_backend()->UpdateAutomaticAlbumArtAsync(song->effective_albumartist(), song->album(), art_automatic);
app_->collection_backend()->UpdateAutomaticAlbumArtAsync(song->effective_albumartist(), song->album(), art_automatic, song->has_embedded_cover());
}
if (*song == app_->current_albumcover_loader()->last_song()) {