Add preference to save ratings and statistics in files
This commit is contained in:
parent
08d40f5fca
commit
b157c307e7
|
@ -152,5 +152,6 @@ void Library::ResumeWatcher() {
|
|||
}
|
||||
|
||||
void Library::ReloadSettings() {
|
||||
backend_->ReloadSettingsAsync();
|
||||
watcher_->ReloadSettingsAsync();
|
||||
}
|
||||
|
|
|
@ -31,13 +31,16 @@
|
|||
#include <QVariant>
|
||||
#include <QtDebug>
|
||||
|
||||
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;
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
|
|
@ -92,6 +92,16 @@
|
|||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QCheckBox" name="save_statistics_in_file">
|
||||
<property name="toolTip">
|
||||
<string><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></string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Save ratings and statistics in file tags when possible</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="label_2">
|
||||
<property name="text">
|
||||
|
|
Loading…
Reference in New Issue