Add support for saving playcounts and ratings to tags

This commit is contained in:
Jonas Kvinge
2021-10-24 16:08:17 +02:00
parent ce7926cfa4
commit 3ab86543ad
22 changed files with 1230 additions and 286 deletions

View File

@@ -40,10 +40,12 @@
#include <QRadioButton>
#include <QSpinBox>
#include <QSettings>
#include <QMessageBox>
#include "core/application.h"
#include "core/iconloader.h"
#include "core/utilities.h"
#include "collection/collection.h"
#include "collection/collectionmodel.h"
#include "collection/collectiondirectorymodel.h"
#include "collectionsettingspage.h"
@@ -94,6 +96,8 @@ CollectionSettingsPage::CollectionSettingsPage(SettingsDialog *dialog, QWidget *
QObject::connect(ui_->combobox_cache_size, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &CollectionSettingsPage::CacheSizeUnitChanged);
QObject::connect(ui_->combobox_disk_cache_size, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &CollectionSettingsPage::DiskCacheSizeUnitChanged);
QObject::connect(ui_->button_save_stats, &QPushButton::clicked, this, &CollectionSettingsPage::WriteAllSongsStatisticsToFiles);
#ifndef HAVE_SONGFINGERPRINTING
ui_->song_tracking->hide();
#endif
@@ -110,7 +114,7 @@ void CollectionSettingsPage::Add() {
QString path(s.value("last_path", QStandardPaths::writableLocation(QStandardPaths::MusicLocation)).toString());
path = QFileDialog::getExistingDirectory(this, tr("Add directory..."), path);
if (!path.isNull()) {
if (!path.isEmpty()) {
dialog()->collection_directory_model()->AddDirectory(path);
}
@@ -206,6 +210,9 @@ void CollectionSettingsPage::Load() {
ui_->combobox_disk_cache_size->setCurrentIndex(s.value(kSettingsDiskCacheSizeUnit, static_cast<int>(CacheSizeUnit_MB)).toInt());
if (ui_->combobox_disk_cache_size->currentIndex() == -1) ui_->combobox_cache_size->setCurrentIndex(static_cast<int>(CacheSizeUnit_MB));
ui_->checkbox_save_playcounts->setChecked(s.value("save_playcounts", false).toBool());
ui_->checkbox_save_ratings->setChecked(s.value("save_ratings", false).toBool());
#if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0)
ui_->checkbox_delete_files->setChecked(s.value("delete_files", false).toBool());
#else
@@ -270,6 +277,9 @@ void CollectionSettingsPage::Save() {
s.setValue(kSettingsDiskCacheSize, ui_->spinbox_disk_cache_size->value());
s.setValue(kSettingsDiskCacheSizeUnit, ui_->combobox_disk_cache_size->currentIndex());
s.setValue("save_playcounts", ui_->checkbox_save_playcounts->isChecked());
s.setValue("save_ratings", ui_->checkbox_save_ratings->isChecked());
s.setValue("delete_files", ui_->checkbox_delete_files->isChecked());
s.endGroup();
@@ -334,3 +344,14 @@ void CollectionSettingsPage::DiskCacheSizeUnitChanged(int index) {
}
}
void CollectionSettingsPage::WriteAllSongsStatisticsToFiles() {
QMessageBox confirmation_dialog(QMessageBox::Question, tr("Write all playcounts and ratings to files"), tr("Are you sure you want to write song playcounts and ratings to file for all songs in your collection?"), QMessageBox::Yes | QMessageBox::Cancel);
if (confirmation_dialog.exec() != QMessageBox::Yes) {
return;
}
dialog()->app()->collection()->SyncPlaycountAndRatingToFilesAsync();
}

View File

@@ -82,6 +82,7 @@ class CollectionSettingsPage : public SettingsPage {
void ClearPixmapDiskCache();
void CacheSizeUnitChanged(int index);
void DiskCacheSizeUnitChanged(int index);
void WriteAllSongsStatisticsToFiles();
private:
Ui_CollectionSettingsPage *ui_;

View File

@@ -7,7 +7,7 @@
<x>0</x>
<y>0</y>
<width>516</width>
<height>1167</height>
<height>1339</height>
</rect>
</property>
<property name="windowTitle">
@@ -540,6 +540,53 @@ If there are no matches then it will use the largest image in the directory.</st
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="groupbox_song_playcounts_and_ratings">
<property name="title">
<string>Song playcounts and ratings</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_3">
<item>
<widget class="QCheckBox" name="checkbox_save_playcounts">
<property name="text">
<string>Save playcounts to song tags when possible</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="checkbox_save_ratings">
<property name="text">
<string>Save ratings to song tags when possible</string>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="layout_statistics_button">
<item>
<widget class="QPushButton" name="button_save_stats">
<property name="text">
<string>Save playcounts and ratings to files now</string>
</property>
</widget>
</item>
<item>
<spacer name="spacer_save_stats">
<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>
</layout>
</widget>
</item>
<item>
<widget class="QCheckBox" name="checkbox_delete_files">
<property name="text">