Add advanced settings for configuring collection watcher

This commit is contained in:
Jonas Kvinge
2022-01-30 04:24:33 +01:00
parent 78adc388df
commit e31c9d74fa
8 changed files with 154 additions and 8 deletions

View File

@@ -23,6 +23,7 @@
#include <limits>
#include <QThread>
#include <QStandardPaths>
#include <QAbstractItemModel>
#include <QItemSelectionModel>
@@ -78,6 +79,9 @@ CollectionSettingsPage::CollectionSettingsPage(SettingsDialog *dialog, QWidget *
ui_->combobox_cache_size->addItems({"KB", "MB"});
ui_->combobox_disk_cache_size->addItems({"KB", "MB", "GB"});
ui_->combobox_iopriority->addItems({"Auto", "Realtime", "Best effort", "Idle"});
ui_->combobox_threadpriority->addItems({"Idle", "Lowest", "Low", "Normal"});
QObject::connect(ui_->add, &QPushButton::clicked, this, &CollectionSettingsPage::Add);
QObject::connect(ui_->remove, &QPushButton::clicked, this, &CollectionSettingsPage::Remove);
@@ -102,6 +106,11 @@ CollectionSettingsPage::CollectionSettingsPage(SettingsDialog *dialog, QWidget *
ui_->song_tracking->hide();
#endif
#ifdef Q_OS_WIN32
ui_->label_iopriority->hide();
ui_->combobox_iopriority->hide();
#endif
}
CollectionSettingsPage::~CollectionSettingsPage() { delete ui_; }
@@ -221,6 +230,18 @@ void CollectionSettingsPage::Load() {
ui_->checkbox_delete_files->hide();
#endif
#ifndef Q_OS_WIN32
ComboBoxLoadFromSettingsByIndex(s, ui_->combobox_iopriority, "io_priority", Utilities::IOPRIO_CLASS_IDLE);
#endif
ComboBoxLoadFromSettingsByIndex(s, ui_->combobox_threadpriority, "thread_priority", QThread::Priority::IdlePriority);
int workers = s.value("tagreader_workers", qBound(1, QThread::idealThreadCount() / 2, 4)).toInt();
if (workers <= 0 || workers > 4) {
workers = 4;
}
ui_->spinbox_tagreaderworkers->setValue(workers);
s.endGroup();
DiskCacheEnable(ui_->checkbox_disk_cache->checkState());
@@ -284,6 +305,13 @@ void CollectionSettingsPage::Save() {
s.setValue("delete_files", ui_->checkbox_delete_files->isChecked());
#ifndef Q_OS_WIN32
s.setValue("io_priority", ui_->combobox_iopriority->currentIndex());
#endif
s.setValue("thread_priority", ui_->combobox_threadpriority->currentIndex());
s.setValue("tagreader_workers", ui_->spinbox_tagreaderworkers->value());
s.endGroup();
}

View File

@@ -7,7 +7,7 @@
<x>0</x>
<y>0</y>
<width>516</width>
<height>1339</height>
<height>1490</height>
</rect>
</property>
<property name="windowTitle">
@@ -601,6 +601,86 @@ If there are no matches then it will use the largest image in the directory.</st
</property>
</widget>
</item>
<item>
<widget class="QGroupBox" name="groupbox_advanced">
<property name="title">
<string>Advanced</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_4">
<item>
<layout class="QFormLayout" name="layout_advanced">
<item row="2" column="1">
<widget class="QComboBox" name="combobox_threadpriority">
<property name="maximumSize">
<size>
<width>100</width>
<height>16777215</height>
</size>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QComboBox" name="combobox_iopriority">
<property name="maximumSize">
<size>
<width>100</width>
<height>16777215</height>
</size>
</property>
<property name="currentIndex">
<number>-1</number>
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="QSpinBox" name="spinbox_tagreaderworkers">
<property name="maximumSize">
<size>
<width>60</width>
<height>16777215</height>
</size>
</property>
<property name="minimum">
<number>1</number>
</property>
<property name="maximum">
<number>4</number>
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QLabel" name="label_tagreaderworkers">
<property name="text">
<string>Tagreader workers</string>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label_threadpriority">
<property name="text">
<string>Thread priority</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_iopriority">
<property name="text">
<string>I/O priority</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QLabel" name="label_advanced">
<property name="text">
<string>Advanced settings require restart.</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
</layout>
</widget>
<tabstops>

View File

@@ -151,3 +151,13 @@ void SettingsPage::ComboBoxLoadFromSettings(const QSettings &s, QComboBox *combo
combobox->setCurrentIndex(i);
}
void SettingsPage::ComboBoxLoadFromSettingsByIndex(const QSettings &s, QComboBox *combobox, const QString &setting, const int default_value) {
if (combobox->count() == 0) return;
int i = s.value(setting, default_value).toInt();
if (i <= 0 || i >= combobox->count()) i = 0;
combobox->setCurrentIndex(i);
}

View File

@@ -69,6 +69,7 @@ class SettingsPage : public QWidget {
static void ComboBoxLoadFromSettings(const QSettings &s, QComboBox *combobox, const QString &setting, const QString &default_value);
static void ComboBoxLoadFromSettings(const QSettings &s, QComboBox *combobox, const QString &setting, const int default_value);
static void ComboBoxLoadFromSettingsByIndex(const QSettings &s, QComboBox *combobox, const QString &setting, const int default_value);
private:
virtual void Save() = 0;