diff --git a/src/library/library.cpp b/src/library/library.cpp index 4c93ed426..7c9df5f73 100644 --- a/src/library/library.cpp +++ b/src/library/library.cpp @@ -152,5 +152,6 @@ void Library::ResumeWatcher() { } void Library::ReloadSettings() { + backend_->ReloadSettingsAsync(); watcher_->ReloadSettingsAsync(); } diff --git a/src/library/librarybackend.cpp b/src/library/librarybackend.cpp index 82f3b4928..7457a6d75 100644 --- a/src/library/librarybackend.cpp +++ b/src/library/librarybackend.cpp @@ -31,13 +31,16 @@ #include #include +const char* LibraryBackend::kSettingsGroup = "LibraryBackend"; + const char* LibraryBackend::kNewScoreSql = "case when playcount <= 0 then (%1 * 100 + score) / 2" " else (score * (playcount + skipcount) + %1 * 100) / (playcount + skipcount + 1)" " end"; LibraryBackend::LibraryBackend(QObject *parent) - : LibraryBackendInterface(parent) + : LibraryBackendInterface(parent), + save_statistics_in_file_(false) { } @@ -49,8 +52,7 @@ void LibraryBackend::Init(Database* db, const QString& songs_table, dirs_table_ = dirs_table; subdirs_table_ = subdirs_table; fts_table_ = fts_table; - connect(this, SIGNAL(SongsStatisticsChanged(SongList)), - TagReaderClient::Instance(), SLOT(UpdateSongsStatistics(SongList))); + ReloadSettings(); } void LibraryBackend::LoadDirectoriesAsync() { @@ -1063,3 +1065,23 @@ void LibraryBackend::DeleteAll() { emit DatabaseReset(); } + +void LibraryBackend::ReloadSettingsAsync() { + QMetaObject::invokeMethod(this, "ReloadSettings", Qt::QueuedConnection); +} + +void LibraryBackend::ReloadSettings() { + QSettings s; + s.beginGroup(kSettingsGroup); + bool save_statistics_in_file = s.value("save_statistics_in_file", false).toBool(); + // Compare with previous value to know if we should connect, disconnect or nothing + if (save_statistics_in_file_ && !save_statistics_in_file) { + disconnect(this, SIGNAL(SongsStatisticsChanged(SongList)), + TagReaderClient::Instance(), SLOT(UpdateSongsStatistics(SongList))); + } else if (!save_statistics_in_file_ && save_statistics_in_file) { + connect(this, SIGNAL(SongsStatisticsChanged(SongList)), + TagReaderClient::Instance(), SLOT(UpdateSongsStatistics(SongList))); + } + // Save old value + save_statistics_in_file_ = save_statistics_in_file; +} diff --git a/src/library/librarybackend.h b/src/library/librarybackend.h index 3db6b4288..0ba3164dc 100644 --- a/src/library/librarybackend.h +++ b/src/library/librarybackend.h @@ -103,6 +103,8 @@ class LibraryBackend : public LibraryBackendInterface { Q_OBJECT public: + static const char* kSettingsGroup; + Q_INVOKABLE LibraryBackend(QObject* parent = 0); void Init(Database* db, const QString& songs_table, const QString& dirs_table, const QString& subdirs_table, @@ -163,6 +165,8 @@ class LibraryBackend : public LibraryBackendInterface { void DeleteAll(); + void ReloadSettingsAsync(); + public slots: void LoadDirectories(); void UpdateTotalSongCount(); @@ -178,6 +182,7 @@ class LibraryBackend : public LibraryBackendInterface { void IncrementSkipCount(int id, float progress); void ResetStatistics(int id); void UpdateSongRating(int id, float rating); + void ReloadSettings(); signals: void DirectoryDiscovered(const Directory& dir, const SubdirectoryList& subdirs); @@ -220,6 +225,7 @@ class LibraryBackend : public LibraryBackendInterface { QString dirs_table_; QString subdirs_table_; QString fts_table_; + bool save_statistics_in_file_; }; #endif // LIBRARYBACKEND_H diff --git a/src/library/librarysettingspage.cpp b/src/library/librarysettingspage.cpp index 9885c33c1..c64ec737b 100644 --- a/src/library/librarysettingspage.cpp +++ b/src/library/librarysettingspage.cpp @@ -16,6 +16,8 @@ */ #include "librarysettingspage.h" + +#include "librarybackend.h" #include "librarydirectorymodel.h" #include "librarymodel.h" #include "libraryview.h" @@ -93,6 +95,10 @@ void LibrarySettingsPage::Save() { s.setValue("cover_art_patterns", filters); s.endGroup(); + + s.beginGroup(LibraryBackend::kSettingsGroup); + s.setValue("save_statistics_in_file", ui_->save_statistics_in_file->isChecked()); + s.endGroup(); } void LibrarySettingsPage::Load() { @@ -127,4 +133,8 @@ void LibrarySettingsPage::Load() { ui_->cover_art_patterns->setText(filters.join(",")); s.endGroup(); + + s.beginGroup(LibraryBackend::kSettingsGroup); + ui_->save_statistics_in_file->setChecked(s.value("save_statistics_in_file", false).toBool()); + s.endGroup(); } diff --git a/src/library/librarysettingspage.ui b/src/library/librarysettingspage.ui index f48ff0448..4cf4b6cfb 100644 --- a/src/library/librarysettingspage.ui +++ b/src/library/librarysettingspage.ui @@ -92,6 +92,16 @@ + + + + <html><head/><body><p>If not checked, Clementine will try to save your ratings and other statistics only in a separate database and don't modify your files.</p><p>If checked, it will save statistics both in database and directly into the file each time they changed.</p><p>Please note it might not work for every format and, as there is no standard for doing so, other music players might not be able to read them.</p></body></html> + + + Save ratings and statistics in file tags when possible + + +