From c75f046c10ee55e462b9bbc7ceb93180b06a8f32 Mon Sep 17 00:00:00 2001 From: terrorfisch Date: Fri, 30 Oct 2015 12:44:12 +0100 Subject: [PATCH] FIX: Tag fetcher applies incorrect tags for songs without any results Before this fix the fetched data of the first title was applied to all selected titles. If the other titles hat correctly fetched tags, this information was overridden by the correct data. So the error only occured in case of failure during fetching. --- src/ui/edittagdialog.cpp | 46 +++++++++++++++++++++++----------------- 1 file changed, 26 insertions(+), 20 deletions(-) diff --git a/src/ui/edittagdialog.cpp b/src/ui/edittagdialog.cpp index 20ac4ab9d..9b2f11d5d 100644 --- a/src/ui/edittagdialog.cpp +++ b/src/ui/edittagdialog.cpp @@ -842,26 +842,32 @@ void EditTagDialog::FetchTagSongChosen(const Song& original_song, const QString filename = original_song.url().toLocalFile(); // Find the song with this filename - for (int i = 0; i < data_.count(); ++i) { - Data* data = &data_[i]; - if (data->original_.url().toLocalFile() != filename) continue; - - // Is it currently being displayed in the UI? - if (ui_->song_list->currentRow() == i) { - // Yes! We can just set the fields in the UI - ui_->title->set_text(new_metadata.title()); - ui_->artist->set_text(new_metadata.artist()); - ui_->album->set_text(new_metadata.album()); - ui_->track->setValue(new_metadata.track()); - ui_->year->setValue(new_metadata.year()); - } else { - data->current_.set_title(new_metadata.title()); - data->current_.set_artist(new_metadata.artist()); - data->current_.set_album(new_metadata.album()); - data->current_.set_track(new_metadata.track()); - data->current_.set_year(new_metadata.year()); + int id; + for (id = 0; id < data_.count(); ++id) + if (data_[id].original_.url().toLocalFile() == filename) + break; + + if( id == data_.count() ) { + qLog(Warning) << "Could not find song to filename: " << filename; + return; + } + + Data& data = data_[id]; + data.current_.set_title(new_metadata.title()); + data.current_.set_artist(new_metadata.artist()); + data.current_.set_album(new_metadata.album()); + data.current_.set_track(new_metadata.track()); + data.current_.set_year(new_metadata.year()); + + // Is it currently selected in the UI? + QModelIndexList selection = + ui_->song_list->selectionModel()->selectedRows(); + for( const QModelIndex& i : selection ) { + if ( i.row() == id ) { + // We need to update view + for (const FieldData& field : fields_) + InitFieldValue(field, selection); + break; } - - break; } }