From 2f3e8986ab21d493cd3297e613159f4da8545b86 Mon Sep 17 00:00:00 2001 From: Jonas Kvinge Date: Thu, 6 Jan 2022 02:13:24 +0100 Subject: [PATCH] AlbumCoverChoiceController: Clear manually set cover when setting embedded cover Possible fix for #858 --- src/collection/collectionbackend.cpp | 14 +++++++++----- src/collection/collectionbackend.h | 6 +++--- src/covermanager/albumcoverchoicecontroller.cpp | 5 ++++- 3 files changed, 16 insertions(+), 9 deletions(-) diff --git a/src/collection/collectionbackend.cpp b/src/collection/collectionbackend.cpp index 8bfbbb376..fa42d0e61 100644 --- a/src/collection/collectionbackend.cpp +++ b/src/collection/collectionbackend.cpp @@ -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); diff --git a/src/collection/collectionbackend.h b/src/collection/collectionbackend.h index 00e24153d..e64a69588 100644 --- a/src/collection/collectionbackend.h +++ b/src/collection/collectionbackend.h @@ -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 &artists, const bool on); void IncrementPlayCount(const int id); void IncrementSkipCount(const int id, const float progress); diff --git a/src/covermanager/albumcoverchoicecontroller.cpp b/src/covermanager/albumcoverchoicecontroller.cpp index cf556638a..d8004e6ca 100644 --- a/src/covermanager/albumcoverchoicecontroller.cpp +++ b/src/covermanager/albumcoverchoicecontroller.cpp @@ -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()) {