Update issue 1175:

Add an option in preferences to save all ratings/statistics into files, for all songs
This commit is contained in:
Arnaud Bienner 2013-03-26 23:56:46 +01:00
parent 84b4b93b46
commit db5fbe2059
9 changed files with 88 additions and 3 deletions

View File

@ -147,6 +147,20 @@ bool TagReaderClient::SaveFileBlocking(const QString& filename, const Song& meta
return ret;
}
bool TagReaderClient::UpdateSongStatisticsBlocking(const Song& metadata) {
Q_ASSERT(QThread::currentThread() != thread());
bool ret = false;
TagReaderReply* reply = UpdateSongStatistics(metadata);
if (reply->WaitForFinished()) {
ret = reply->message().save_song_statistics_to_file_response().success();
}
reply->deleteLater();
return ret;
}
bool TagReaderClient::IsMediaFileBlocking(const QString& filename) {
Q_ASSERT(QThread::currentThread() != thread());

View File

@ -57,6 +57,7 @@ public:
// be called from the TagReaderClient's thread.
void ReadFileBlocking(const QString& filename, Song* song);
bool SaveFileBlocking(const QString& filename, const Song& metadata);
bool UpdateSongStatisticsBlocking(const Song& metadata);
bool IsMediaFileBlocking(const QString& filename);
QImage LoadEmbeddedArtBlocking(const QString& filename);

View File

@ -21,6 +21,8 @@
#include "librarybackend.h"
#include "core/application.h"
#include "core/database.h"
#include "core/tagreaderclient.h"
#include "core/taskmanager.h"
#include "smartplaylists/generator.h"
#include "smartplaylists/querygenerator.h"
#include "smartplaylists/search.h"
@ -155,3 +157,18 @@ void Library::ReloadSettings() {
backend_->ReloadSettingsAsync();
watcher_->ReloadSettingsAsync();
}
void Library::WriteAllSongsStatisticsToFiles() {
const SongList all_songs = backend_->GetAllSongs();
const int task_id = app_->task_manager()->StartTask(tr("Saving songs statistics into songs files"));
app_->task_manager()->SetTaskBlocksLibraryScans(task_id);
const int nb_songs = all_songs.size();
int i = 0;
foreach (const Song& song, all_songs) {
TagReaderClient::Instance()->UpdateSongStatisticsBlocking(song);
app_->task_manager()->SetTaskProgress(task_id, ++i, nb_songs);
}
app_->task_manager()->SetTaskFinished(task_id);
}

View File

@ -49,6 +49,8 @@ class Library : public QObject {
QString full_rescan_reason(int schema_version) const { return full_rescan_revisions_.value(schema_version, QString()); }
void WriteAllSongsStatisticsToFiles();
public slots:
void ReloadSettings();

View File

@ -964,6 +964,13 @@ SongList LibraryBackend::FindSongs(const smart_playlists::Search& search) {
return ret;
}
SongList LibraryBackend::GetAllSongs() {
// Get all the songs!
return FindSongs(smart_playlists::Search(
smart_playlists::Search::Type_All, smart_playlists::Search::TermList(),
smart_playlists::Search::Sort_FieldAsc, smart_playlists::SearchTerm::Field_Artist, -1));
}
void LibraryBackend::IncrementPlayCount(int id) {
if (id == -1)
return;

View File

@ -157,6 +157,7 @@ class LibraryBackend : public LibraryBackendInterface {
bool ExecQuery(LibraryQuery* q);
SongList ExecLibraryQuery(LibraryQuery* query);
SongList FindSongs(const smart_playlists::Search& search);
SongList GetAllSongs();
void IncrementPlayCountAsync(int id);
void IncrementSkipCountAsync(int id, float progress);

View File

@ -28,9 +28,11 @@
#include "ui/iconloader.h"
#include "ui/settingsdialog.h"
#include <QFileDialog>
#include <QSettings>
#include <QDir>
#include <QFileDialog>
#include <QMessageBox>
#include <QSettings>
#include <QtConcurrentRun>
const char* LibrarySettingsPage::kSettingsGroup = "LibraryConfig";
@ -49,6 +51,7 @@ LibrarySettingsPage::LibrarySettingsPage(SettingsDialog* dialog)
connect(ui_->add, SIGNAL(clicked()), SLOT(Add()));
connect(ui_->remove, SIGNAL(clicked()), SLOT(Remove()));
connect(ui_->sync_stats_button, SIGNAL(clicked()), SLOT(WriteAllSongsStatisticsToFiles()));
}
LibrarySettingsPage::~LibrarySettingsPage() {
@ -138,3 +141,15 @@ void LibrarySettingsPage::Load() {
ui_->save_statistics_in_file->setChecked(s.value("save_statistics_in_file", false).toBool());
s.endGroup();
}
void LibrarySettingsPage::WriteAllSongsStatisticsToFiles() {
QMessageBox confirmation_dialog(
QMessageBox::Question,
tr("Write all songs statistics into songs' files"),
tr("Are you sure you want to write song's statistics into song's file for all the songs of your library?"),
QMessageBox::Yes | QMessageBox::Cancel);
if (confirmation_dialog.exec() != QMessageBox::Yes) {
return;
}
QtConcurrent::run(dialog()->app()->library(), &Library::WriteAllSongsStatisticsToFiles);
}

View File

@ -40,6 +40,7 @@ public:
private slots:
void Add();
void Remove();
void WriteAllSongsStatisticsToFiles();
void CurrentRowChanged(const QModelIndex& index);

View File

@ -7,7 +7,7 @@
<x>0</x>
<y>0</y>
<width>509</width>
<height>395</height>
<height>452</height>
</rect>
</property>
<property name="windowTitle">
@ -102,6 +102,33 @@
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_5">
<item>
<widget class="QPushButton" name="sync_stats_button">
<property name="toolTip">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;This will write songs' ratings and statistics into files tags for all your library's songs.&lt;/p&gt;&lt;p&gt;This is not needed if the &amp;quot;Save ratings and statistics in file tags&amp;quot; option has always been activated.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="text">
<string>Synchronize statistics to files now</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item>
<widget class="QLabel" name="label_2">
<property name="text">