Clear art automatic when embedded cover is deleted

This commit is contained in:
Jonas Kvinge
2021-03-07 05:43:56 +01:00
parent 89f1f8e6dc
commit 3e6029d33c
4 changed files with 20 additions and 15 deletions

View File

@@ -336,12 +336,12 @@ AlbumCoverImageResult AlbumCoverChoiceController::SearchForImage(Song *song) {
} }
QUrl AlbumCoverChoiceController::UnsetCover(Song *song) { QUrl AlbumCoverChoiceController::UnsetCover(Song *song, const bool clear_art_automatic) {
if (!song->url().isLocalFile() || song->effective_albumartist().isEmpty() || song->album().isEmpty()) return QUrl(); if (!song->url().isLocalFile() || song->effective_albumartist().isEmpty() || song->album().isEmpty()) return QUrl();
QUrl cover_url = QUrl::fromLocalFile(Song::kManuallyUnsetCover); QUrl cover_url = QUrl::fromLocalFile(Song::kManuallyUnsetCover);
SaveArtManualToSong(song, cover_url); SaveArtManualToSong(song, cover_url, clear_art_automatic);
return cover_url; return cover_url;
@@ -352,6 +352,7 @@ void AlbumCoverChoiceController::ClearCover(Song *song, const bool clear_art_aut
if (!song->url().isLocalFile() || song->effective_albumartist().isEmpty() || song->album().isEmpty()) return; if (!song->url().isLocalFile() || song->effective_albumartist().isEmpty() || song->album().isEmpty()) return;
song->clear_art_manual(); song->clear_art_manual();
if (clear_art_automatic) song->clear_art_automatic();
SaveArtManualToSong(song, QUrl(), clear_art_automatic); SaveArtManualToSong(song, QUrl(), clear_art_automatic);
} }
@@ -400,7 +401,7 @@ bool AlbumCoverChoiceController::DeleteCover(Song *song, const bool manually_uns
else song->clear_art_manual(); else song->clear_art_manual();
if (success) { if (success) {
if (manually_unset) UnsetCover(song); if (manually_unset) UnsetCover(song, true);
else ClearCover(song, true); else ClearCover(song, true);
} }
@@ -758,11 +759,14 @@ QUrl AlbumCoverChoiceController::SaveCoverAutomatic(Song *song, const AlbumCover
} }
void AlbumCoverChoiceController::SaveEmbeddedCoverAsyncFinished(quint64 id, const bool success) { void AlbumCoverChoiceController::SaveEmbeddedCoverAsyncFinished(quint64 id, const bool success, const bool cleared) {
if (!cover_save_tasks_.contains(id)) return; if (!cover_save_tasks_.contains(id)) return;
Song song = cover_save_tasks_.take(id); Song song = cover_save_tasks_.take(id);
if (success) SaveArtAutomaticToSong(&song, QUrl::fromLocalFile(Song::kEmbeddedCover)); if (success) {
if (cleared) SaveArtAutomaticToSong(&song, QUrl());
else SaveArtAutomaticToSong(&song, QUrl::fromLocalFile(Song::kEmbeddedCover));
}
} }

View File

@@ -116,7 +116,7 @@ class AlbumCoverChoiceController : public QWidget {
AlbumCoverImageResult SearchForImage(Song *song); AlbumCoverImageResult SearchForImage(Song *song);
// Returns a path which indicates that the cover has been unset manually. // Returns a path which indicates that the cover has been unset manually.
QUrl UnsetCover(Song *song); QUrl UnsetCover(Song *song, const bool clear_art_automatic = false);
// Clears any album cover art associated with the song. // Clears any album cover art associated with the song.
void ClearCover(Song *song, const bool clear_art_automatic = false); void ClearCover(Song *song, const bool clear_art_automatic = false);
@@ -154,7 +154,7 @@ class AlbumCoverChoiceController : public QWidget {
private slots: private slots:
void AlbumCoverFetched(const quint64 id, const AlbumCoverImageResult &result, const CoverSearchStatistics &statistics); void AlbumCoverFetched(const quint64 id, const AlbumCoverImageResult &result, const CoverSearchStatistics &statistics);
void SaveEmbeddedCoverAsyncFinished(quint64 id, const bool success); void SaveEmbeddedCoverAsyncFinished(quint64 id, const bool success, const bool cleared);
signals: signals:
void AutomaticCoverSearchDone(); void AutomaticCoverSearchDone();

View File

@@ -595,7 +595,8 @@ void AlbumCoverLoader::SaveEmbeddedCover(const qint64 id, const QString song_fil
TagReaderReply *reply = TagReaderClient::Instance()->SaveEmbeddedArt(song_filename, image_data); TagReaderReply *reply = TagReaderClient::Instance()->SaveEmbeddedArt(song_filename, image_data);
tagreader_save_embedded_art_requests_.insert(id, reply); tagreader_save_embedded_art_requests_.insert(id, reply);
QObject::connect(reply, &TagReaderReply::Finished, this, [this, id, reply]() { SaveEmbeddedArtFinished(id, reply); }, Qt::QueuedConnection); const bool clear = image_data.isEmpty();
QObject::connect(reply, &TagReaderReply::Finished, this, [this, id, reply, clear]() { SaveEmbeddedArtFinished(id, reply, clear); }, Qt::QueuedConnection);
} }
@@ -620,7 +621,7 @@ void AlbumCoverLoader::SaveEmbeddedCover(const qint64 id, const QString song_fil
QFile file(cover_filename); QFile file(cover_filename);
if (file.size() >= 209715200 || !file.open(QIODevice::ReadOnly)) { // Max 200 MB. if (file.size() >= 209715200 || !file.open(QIODevice::ReadOnly)) { // Max 200 MB.
emit SaveEmbeddedCoverAsyncFinished(id, false); emit SaveEmbeddedCoverAsyncFinished(id, false, false);
return; return;
} }
@@ -652,7 +653,7 @@ void AlbumCoverLoader::SaveEmbeddedCover(const qint64 id, const QList<QUrl> urls
} }
} }
emit SaveEmbeddedCoverAsyncFinished(id, false); emit SaveEmbeddedCoverAsyncFinished(id, false, image.isNull());
} }
@@ -661,7 +662,7 @@ void AlbumCoverLoader::SaveEmbeddedCover(const qint64 id, const QList<QUrl> urls
QFile file(cover_filename); QFile file(cover_filename);
if (file.size() >= 209715200 || !file.open(QIODevice::ReadOnly)) { // Max 200 MB. if (file.size() >= 209715200 || !file.open(QIODevice::ReadOnly)) { // Max 200 MB.
emit SaveEmbeddedCoverAsyncFinished(id, false); emit SaveEmbeddedCoverAsyncFinished(id, false, false);
return; return;
} }
@@ -679,14 +680,14 @@ void AlbumCoverLoader::SaveEmbeddedCover(const qint64 id, const QList<QUrl> urls
} }
void AlbumCoverLoader::SaveEmbeddedArtFinished(const qint64 id, TagReaderReply *reply) { void AlbumCoverLoader::SaveEmbeddedArtFinished(const qint64 id, TagReaderReply *reply, const bool cleared) {
if (tagreader_save_embedded_art_requests_.contains(id)) { if (tagreader_save_embedded_art_requests_.contains(id)) {
tagreader_save_embedded_art_requests_.remove(id, reply); tagreader_save_embedded_art_requests_.remove(id, reply);
} }
if (!tagreader_save_embedded_art_requests_.contains(id)) { if (!tagreader_save_embedded_art_requests_.contains(id)) {
emit SaveEmbeddedCoverAsyncFinished(id, reply->is_successful()); emit SaveEmbeddedCoverAsyncFinished(id, reply->is_successful(), cleared);
} }
metaObject()->invokeMethod(reply, "deleteLater", Qt::QueuedConnection); metaObject()->invokeMethod(reply, "deleteLater", Qt::QueuedConnection);

View File

@@ -91,7 +91,7 @@ class AlbumCoverLoader : public QObject {
signals: signals:
void ExitFinished(); void ExitFinished();
void AlbumCoverLoaded(quint64 id, AlbumCoverLoaderResult result); void AlbumCoverLoaded(quint64 id, AlbumCoverLoaderResult result);
void SaveEmbeddedCoverAsyncFinished(quint64 id, bool success); void SaveEmbeddedCoverAsyncFinished(quint64 id, bool success, bool cleared);
protected slots: protected slots:
void Exit(); void Exit();
@@ -105,7 +105,7 @@ class AlbumCoverLoader : public QObject {
void SaveEmbeddedCover(const qint64 id, const QList<QUrl> urls, const QString &cover_filename); void SaveEmbeddedCover(const qint64 id, const QList<QUrl> urls, const QString &cover_filename);
void SaveEmbeddedCover(const qint64 id, const QList<QUrl> urls, const QByteArray &image_data); void SaveEmbeddedCover(const qint64 id, const QList<QUrl> urls, const QByteArray &image_data);
void SaveEmbeddedArtFinished(const qint64 id, TagReaderReply *reply); void SaveEmbeddedArtFinished(const qint64 id, TagReaderReply *reply, const bool cleared);
protected: protected: