Save embedded cover in the same process as tags

Possible fix for #1158
This commit is contained in:
Jonas Kvinge
2023-03-18 20:03:07 +01:00
parent 394955a03f
commit e20cbe4170
42 changed files with 1205 additions and 723 deletions

View File

@@ -140,8 +140,12 @@ void CollectionBackend::IncrementSkipCountAsync(const int id, const float progre
QMetaObject::invokeMethod(this, "IncrementSkipCount", Qt::QueuedConnection, Q_ARG(int, id), Q_ARG(float, progress));
}
void CollectionBackend::ResetStatisticsAsync(const int id, const bool save_tags) {
QMetaObject::invokeMethod(this, "ResetStatistics", Qt::QueuedConnection, Q_ARG(int, id), Q_ARG(bool, save_tags));
void CollectionBackend::ResetPlayStatisticsAsync(const int id, const bool save_tags) {
QMetaObject::invokeMethod(this, "ResetPlayStatistics", Qt::QueuedConnection, Q_ARG(int, id), Q_ARG(bool, save_tags));
}
void CollectionBackend::ResetPlayStatisticsAsync(const QList<int> &id_list, const bool save_tags) {
QMetaObject::invokeMethod(this, "ResetPlayStatistics", Qt::QueuedConnection, Q_ARG(QList<int>, id_list), Q_ARG(bool, save_tags));
}
void CollectionBackend::LoadDirectories() {
@@ -1776,23 +1780,48 @@ void CollectionBackend::IncrementSkipCount(const int id, const float progress) {
}
void CollectionBackend::ResetStatistics(const int id, const bool save_tags) {
void CollectionBackend::ResetPlayStatistics(const int id, const bool save_tags) {
if (id == -1) return;
ResetPlayStatistics(QList<int>() << id, save_tags);
}
void CollectionBackend::ResetPlayStatistics(const QList<int> &id_list, const bool save_tags) {
if (id_list.isEmpty()) return;
QStringList id_str_list;
id_str_list.reserve(id_list.count());
for (const int id : id_list) {
id_str_list << QString::number(id);
}
const bool success = ResetPlayStatistics(id_str_list);
if (success) {
const SongList songs = GetSongsById(id_list);
emit SongsStatisticsChanged(songs, save_tags);
}
}
bool CollectionBackend::ResetPlayStatistics(const QStringList &id_str_list) {
if (id_str_list.isEmpty()) return false;
QMutexLocker l(db_->Mutex());
QSqlDatabase db(db_->Connect());
SqlQuery q(db);
q.prepare(QString("UPDATE %1 SET playcount = 0, skipcount = 0, lastplayed = -1 WHERE ROWID = :id").arg(songs_table_));
q.BindValue(":id", id);
q.prepare(QString("UPDATE %1 SET playcount = 0, skipcount = 0, lastplayed = -1 WHERE ROWID IN (:ids)").arg(songs_table_));
q.BindValue(":ids", id_str_list.join(","));
if (!q.Exec()) {
db_->ReportErrors(q);
return;
return false;
}
Song new_song = GetSongById(id, db);
emit SongsStatisticsChanged(SongList() << new_song, save_tags);
return true;
}

View File

@@ -200,7 +200,8 @@ class CollectionBackend : public CollectionBackendInterface {
void IncrementPlayCountAsync(const int id);
void IncrementSkipCountAsync(const int id, const float progress);
void ResetStatisticsAsync(const int id, const bool save_tags = false);
void ResetPlayStatisticsAsync(const int id, const bool save_tags = false);
void ResetPlayStatisticsAsync(const QList<int> &id_list, const bool save_tags = false);
void DeleteAllAsync();
@@ -236,7 +237,9 @@ class CollectionBackend : public CollectionBackendInterface {
void ForceCompilation(const QString &album, const QList<QString> &artists, const bool on);
void IncrementPlayCount(const int id);
void IncrementSkipCount(const int id, const float progress);
void ResetStatistics(const int id, const bool save_tags = false);
void ResetPlayStatistics(const int id, const bool save_tags = false);
void ResetPlayStatistics(const QList<int> &id_list, const bool save_tags = false);
bool ResetPlayStatistics(const QStringList &id_str_list);
void DeleteAll();
void SongPathChanged(const Song &song, const QFileInfo &new_file, const std::optional<int> new_collection_directory_id);

View File

@@ -855,8 +855,8 @@ void CollectionWatcher::AddChangedSong(const QString &file, const Song &matching
changes << "metadata";
notify_new = true;
}
if (!matching_song.IsStatisticsEqual(new_song)) {
changes << "statistics";
if (!matching_song.IsPlayStatisticsEqual(new_song)) {
changes << "play statistics";
notify_new = true;
}
if (!matching_song.IsRatingEqual(new_song)) {