Fix deleting multiple covers in album cover manager

This commit is contained in:
Jonas Kvinge 2021-03-07 03:43:49 +01:00
parent bbcd6a3261
commit 04bbff338d
4 changed files with 23 additions and 23 deletions

View File

@ -2938,7 +2938,7 @@ void MainWindow::ClearCover() {
}
void MainWindow::DeleteCover() {
album_cover_choice_controller_->DeleteCover(&song_);
album_cover_choice_controller_->DeleteCover(&song_, true);
}
void MainWindow::ShowCover() {

View File

@ -347,16 +347,16 @@ QUrl AlbumCoverChoiceController::UnsetCover(Song *song) {
}
void AlbumCoverChoiceController::ClearCover(Song *song) {
void AlbumCoverChoiceController::ClearCover(Song *song, const bool clear_art_automatic) {
if (!song->url().isLocalFile() || song->effective_albumartist().isEmpty() || song->album().isEmpty()) return;
song->clear_art_manual();
SaveArtManualToSong(song, QUrl());
SaveArtManualToSong(song, QUrl(), clear_art_automatic);
}
bool AlbumCoverChoiceController::DeleteCover(Song *song) {
bool AlbumCoverChoiceController::DeleteCover(Song *song, const bool manually_unset) {
if (!song->url().isLocalFile() || song->effective_albumartist().isEmpty() || song->album().isEmpty()) return false;
@ -399,7 +399,10 @@ bool AlbumCoverChoiceController::DeleteCover(Song *song) {
}
else song->clear_art_manual();
if (success) UnsetCover(song);
if (success) {
if (manually_unset) UnsetCover(song);
else ClearCover(song, true);
}
return success;

View File

@ -119,10 +119,10 @@ class AlbumCoverChoiceController : public QWidget {
QUrl UnsetCover(Song *song);
// Clears any album cover art associated with the song.
void ClearCover(Song *song);
void ClearCover(Song *song, const bool clear_art_automatic = false);
// Physically deletes associated album covers from disk.
bool DeleteCover(Song *song);
bool DeleteCover(Song *song, const bool manually_unset = false);
// Shows the cover of given song in it's original size.
void ShowCover(const Song &song, const QImage &image = QImage());

View File

@ -595,10 +595,18 @@ bool AlbumCoverManager::eventFilter(QObject *obj, QEvent *e) {
if (context_menu_items_.isEmpty()) return false;
bool some_with_covers = false;
bool some_unset = false;
bool some_clear = false;
for (QListWidgetItem *item : context_menu_items_) {
AlbumItem *album_item = static_cast<AlbumItem*>(item);
if (ItemHasCover(*album_item)) some_with_covers = true;
if (album_item->data(Role_PathManual).toUrl().path() == Song::kManuallyUnsetCover) {
some_unset = true;
}
else if (album_item->data(Role_PathAutomatic).toUrl().isEmpty() && album_item->data(Role_PathManual).toUrl().isEmpty()) {
some_clear = true;
}
}
album_cover_choice_controller_->show_cover_action()->setEnabled(some_with_covers && context_menu_items_.size() == 1);
@ -606,8 +614,8 @@ bool AlbumCoverManager::eventFilter(QObject *obj, QEvent *e) {
album_cover_choice_controller_->cover_from_file_action()->setEnabled(context_menu_items_.size() == 1);
album_cover_choice_controller_->cover_from_url_action()->setEnabled(context_menu_items_.size() == 1);
album_cover_choice_controller_->search_for_cover_action()->setEnabled(app_->cover_providers()->HasAnyProviders());
album_cover_choice_controller_->unset_cover_action()->setEnabled(some_with_covers);
album_cover_choice_controller_->clear_cover_action()->setEnabled(some_with_covers);
album_cover_choice_controller_->unset_cover_action()->setEnabled(some_with_covers || some_clear);
album_cover_choice_controller_->clear_cover_action()->setEnabled(some_with_covers || some_unset);
album_cover_choice_controller_->delete_cover_action()->setEnabled(some_with_covers);
QContextMenuEvent *context_menu_event = static_cast<QContextMenuEvent*>(e);
@ -862,24 +870,13 @@ void AlbumCoverManager::ClearCover() {
void AlbumCoverManager::DeleteCover() {
Song song = GetFirstSelectedAsSong();
if (!song.is_valid()) return;
AlbumItem *first_album_item = static_cast<AlbumItem*>(context_menu_items_[0]);
album_cover_choice_controller_->DeleteCover(&song);
// Force the 'none' cover on all of the selected items
for (QListWidgetItem *item : context_menu_items_) {
AlbumItem *album_item = static_cast<AlbumItem*>(item);
Song song = ItemAsSong(album_item);
album_cover_choice_controller_->DeleteCover(&song);
album_item->setIcon(icon_nocover_item_);
album_item->setData(Role_PathManual, QUrl());
// Don't save the first one twice
if (album_item != first_album_item) {
Song current_song = ItemAsSong(album_item);
album_cover_choice_controller_->SaveArtManualToSong(&current_song, QUrl(), true);
}
album_item->setData(Role_PathAutomatic, QUrl());
}
}