diff --git a/src/core/song.cpp b/src/core/song.cpp index 9ef99d2c9..75fbff4dc 100644 --- a/src/core/song.cpp +++ b/src/core/song.cpp @@ -1180,3 +1180,12 @@ void Song::ToXesam(QVariantMap* map) const { AddMetadata("xesam:userRating", rating(), map); } } + +void Song::MergeUserSetData(const Song& other) { + set_playcount(other.playcount()); + set_skipcount(other.skipcount()); + set_lastplayed(other.lastplayed()); + set_rating(other.rating()); + set_score(other.score()); + set_art_manual(other.art_manual()); +} diff --git a/src/core/song.h b/src/core/song.h index 3163cc46b..91c28fe9b 100644 --- a/src/core/song.h +++ b/src/core/song.h @@ -130,6 +130,11 @@ class Song { void ToWmdm(IWMDMMetaData* metadata) const; #endif + // Copies important statistics from the other song to this one, overwriting + // any data that already exists. Useful when you want updated tags from disk + // but you want to keep user stats. + void MergeUserSetData(const Song& other); + static QString Decode(const QString& tag, const QTextCodec* codec = NULL); // Save diff --git a/src/library/librarywatcher.cpp b/src/library/librarywatcher.cpp index c78b20e51..4a421a840 100644 --- a/src/library/librarywatcher.cpp +++ b/src/library/librarywatcher.cpp @@ -514,12 +514,7 @@ void LibraryWatcher::PreserveUserSetData(const QString& file, const QString& ima if (!out->has_embedded_cover()) out->set_art_automatic(image); - out->set_playcount(matching_song.playcount()); - out->set_skipcount(matching_song.skipcount()); - out->set_lastplayed(matching_song.lastplayed()); - out->set_rating(matching_song.rating()); - out->set_score(matching_song.score()); - out->set_art_manual(matching_song.art_manual()); + out->MergeUserSetData(matching_song); // The song was deleted from the database (e.g. due to an unmounted // filesystem), but has been restored. diff --git a/src/ui/edittagdialog.cpp b/src/ui/edittagdialog.cpp index 3759de3e3..7e81d8c82 100644 --- a/src/ui/edittagdialog.cpp +++ b/src/ui/edittagdialog.cpp @@ -216,8 +216,10 @@ QList EditTagDialog::LoadData(const SongList& songs) const Song copy(song); TagReaderClient::Instance()->ReadFileBlocking(copy.url().toLocalFile(), ©); - if (copy.is_valid()) + if (copy.is_valid()) { + copy.MergeUserSetData(song); ret << Data(copy); + } } }