Write statistics and ratings in Library, not LibraryBackend.
This commit is contained in:
parent
c8625deffb
commit
f6a72828a9
|
@ -40,7 +40,9 @@ Library::Library(Application* app, QObject* parent)
|
|||
backend_(nullptr),
|
||||
model_(nullptr),
|
||||
watcher_(nullptr),
|
||||
watcher_thread_(nullptr) {
|
||||
watcher_thread_(nullptr),
|
||||
save_statistics_in_files_(false),
|
||||
save_ratings_in_files_(false) {
|
||||
backend_ = new LibraryBackend;
|
||||
backend()->moveToThread(app->database()->thread());
|
||||
|
||||
|
@ -116,6 +118,8 @@ Library::Library(Application* app, QObject* parent)
|
|||
|
||||
// full rescan revisions
|
||||
full_rescan_revisions_[26] = tr("CUE sheet support");
|
||||
|
||||
ReloadSettings();
|
||||
}
|
||||
|
||||
Library::~Library() {
|
||||
|
@ -138,6 +142,10 @@ void Library::Init() {
|
|||
watcher_, SLOT(AddDirectory(Directory, SubdirectoryList)));
|
||||
connect(backend_, SIGNAL(DirectoryDeleted(Directory)), watcher_,
|
||||
SLOT(RemoveDirectory(Directory)));
|
||||
connect(backend_, SIGNAL(SongsRatingChanged(SongList)),
|
||||
SLOT(SongsRatingChanged(SongList)));
|
||||
connect(backend_, SIGNAL(SongsStatisticsChanged(SongList)),
|
||||
SLOT(SongsStatisticsChanged(SongList)));
|
||||
connect(watcher_, SIGNAL(NewOrUpdatedSongs(SongList)), backend_,
|
||||
SLOT(AddOrUpdateSongs(SongList)));
|
||||
connect(watcher_, SIGNAL(SongsMTimeUpdated(SongList)), backend_,
|
||||
|
@ -166,8 +174,15 @@ void Library::PauseWatcher() { watcher_->SetRescanPausedAsync(true); }
|
|||
void Library::ResumeWatcher() { watcher_->SetRescanPausedAsync(false); }
|
||||
|
||||
void Library::ReloadSettings() {
|
||||
backend_->ReloadSettingsAsync();
|
||||
watcher_->ReloadSettingsAsync();
|
||||
|
||||
// These don't belong in LibraryBackend's group but it's too late to change
|
||||
// now.
|
||||
QSettings s;
|
||||
s.beginGroup(LibraryBackend::kSettingsGroup);
|
||||
save_statistics_in_files_ =
|
||||
s.value("save_statistics_in_file", false).toBool();
|
||||
save_ratings_in_files_ = s.value("save_ratings_in_file", false).toBool();
|
||||
}
|
||||
|
||||
void Library::WriteAllSongsStatisticsToFiles() {
|
||||
|
@ -186,3 +201,15 @@ void Library::WriteAllSongsStatisticsToFiles() {
|
|||
}
|
||||
app_->task_manager()->SetTaskFinished(task_id);
|
||||
}
|
||||
|
||||
void Library::SongsRatingChanged(const SongList& songs) {
|
||||
if (save_ratings_in_files_) {
|
||||
app_->tag_reader_client()->UpdateSongsRating(songs);
|
||||
}
|
||||
}
|
||||
|
||||
void Library::SongsStatisticsChanged(const SongList& songs) {
|
||||
if (save_statistics_in_files_) {
|
||||
app_->tag_reader_client()->UpdateSongsStatistics(songs);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,6 +21,8 @@
|
|||
#include <QHash>
|
||||
#include <QObject>
|
||||
|
||||
#include "core/song.h"
|
||||
|
||||
class Application;
|
||||
class Database;
|
||||
class LibraryBackend;
|
||||
|
@ -62,6 +64,9 @@ class Library : public QObject {
|
|||
private slots:
|
||||
void IncrementalScan();
|
||||
|
||||
void SongsStatisticsChanged(const SongList& songs);
|
||||
void SongsRatingChanged(const SongList& songs);
|
||||
|
||||
private:
|
||||
Application* app_;
|
||||
LibraryBackend* backend_;
|
||||
|
@ -70,9 +75,11 @@ class Library : public QObject {
|
|||
LibraryWatcher* watcher_;
|
||||
QThread* watcher_thread_;
|
||||
|
||||
bool save_statistics_in_files_;
|
||||
bool save_ratings_in_files_;
|
||||
|
||||
// DB schema versions which should trigger a full library rescan (each of
|
||||
// those with
|
||||
// a short reason why).
|
||||
// those with a short reason why).
|
||||
QHash<int, QString> full_rescan_revisions_;
|
||||
};
|
||||
|
||||
|
|
|
@ -55,7 +55,6 @@ void LibraryBackend::Init(Database* db, const QString& songs_table,
|
|||
dirs_table_ = dirs_table;
|
||||
subdirs_table_ = subdirs_table;
|
||||
fts_table_ = fts_table;
|
||||
ReloadSettings();
|
||||
}
|
||||
|
||||
void LibraryBackend::LoadDirectoriesAsync() {
|
||||
|
@ -1159,48 +1158,3 @@ void LibraryBackend::DeleteAll() {
|
|||
|
||||
emit DatabaseReset();
|
||||
}
|
||||
|
||||
void LibraryBackend::ReloadSettingsAsync() {
|
||||
QMetaObject::invokeMethod(this, "ReloadSettings", Qt::QueuedConnection);
|
||||
}
|
||||
|
||||
void LibraryBackend::ReloadSettings() {
|
||||
QSettings s;
|
||||
s.beginGroup(kSettingsGroup);
|
||||
|
||||
// Statistics
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
// Rating
|
||||
{
|
||||
bool save_ratings_in_file = s.value("save_ratings_in_file", false).toBool();
|
||||
// Compare with previous value to know if we should connect, disconnect or
|
||||
// nothing
|
||||
if (save_ratings_in_file_ && !save_ratings_in_file) {
|
||||
disconnect(this, SIGNAL(SongsRatingChanged(SongList)),
|
||||
TagReaderClient::Instance(),
|
||||
SLOT(UpdateSongsRating(SongList)));
|
||||
} else if (!save_ratings_in_file_ && save_ratings_in_file) {
|
||||
connect(this, SIGNAL(SongsRatingChanged(SongList)),
|
||||
TagReaderClient::Instance(), SLOT(UpdateSongsRating(SongList)));
|
||||
}
|
||||
// Save old value
|
||||
save_ratings_in_file_ = save_ratings_in_file;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -188,8 +188,6 @@ class LibraryBackend : public LibraryBackendInterface {
|
|||
|
||||
void DeleteAll();
|
||||
|
||||
void ReloadSettingsAsync();
|
||||
|
||||
public slots:
|
||||
void LoadDirectories();
|
||||
void UpdateTotalSongCount();
|
||||
|
@ -208,7 +206,6 @@ class LibraryBackend : public LibraryBackendInterface {
|
|||
void ResetStatistics(int id);
|
||||
void UpdateSongRating(int id, float rating);
|
||||
void UpdateSongsRating(const QList<int>& id_list, float rating);
|
||||
void ReloadSettings();
|
||||
|
||||
signals:
|
||||
void DirectoryDiscovered(const Directory& dir,
|
||||
|
|
Loading…
Reference in New Issue