Preserve user stats like play/skip counts when reloading song metadata when opening the edit tag dialog. Fixes issue 3359.

This commit is contained in:
David Sansome 2012-12-26 00:48:16 +11:00
parent 9e9b7f7fa6
commit e3c8caa613
4 changed files with 18 additions and 7 deletions

View File

@ -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());
}

View File

@ -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

View File

@ -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.

View File

@ -216,8 +216,10 @@ QList<EditTagDialog::Data> EditTagDialog::LoadData(const SongList& songs) const
Song copy(song);
TagReaderClient::Instance()->ReadFileBlocking(copy.url().toLocalFile(), &copy);
if (copy.is_valid())
if (copy.is_valid()) {
copy.MergeUserSetData(song);
ret << Data(copy);
}
}
}