Save initial settings

This commit is contained in:
Jonas Kvinge 2020-10-01 22:04:38 +02:00
parent 48ee471def
commit 390fd64a74
19 changed files with 107 additions and 71 deletions

View File

@ -138,6 +138,8 @@ AppearanceSettingsPage::~AppearanceSettingsPage() {
void AppearanceSettingsPage::Load() {
QSettings s;
if (!s.contains(kSettingsGroup)) set_changed();
s.beginGroup(kSettingsGroup);
QPalette p = QApplication::palette();

View File

@ -71,13 +71,10 @@ BackendSettingsPage::BackendSettingsPage(SettingsDialog *dialog) : SettingsPage(
ui_->label_replaygainpreamp->setMinimumWidth(QFontMetrics(ui_->label_replaygainpreamp->font()).width("-WW.W dB"));
#endif
s_.beginGroup(BackendSettingsPage::kSettingsGroup);
}
BackendSettingsPage::~BackendSettingsPage() {
s_.endGroup();
delete ui_;
}
@ -87,7 +84,12 @@ void BackendSettingsPage::Load() {
configloaded_ = false;
engineloaded_ = false;
Engine::EngineType enginetype = Engine::EngineTypeFromName(s_.value("engine", EngineName(Engine::None)).toString());
QSettings s;
if (!s.contains(kSettingsGroup)) set_changed();
s.beginGroup(kSettingsGroup);
Engine::EngineType enginetype = Engine::EngineTypeFromName(s.value("engine", EngineName(Engine::None)).toString());
if (enginetype == Engine::None && engine()) enginetype = engine()->type();
ui_->combobox_engine->clear();
@ -99,21 +101,21 @@ void BackendSettingsPage::Load() {
#endif
enginetype_current_ = enginetype;
output_current_ = s_.value("output", QString()).toString();
device_current_ = s_.value("device", QVariant());
output_current_ = s.value("output", QString()).toString();
device_current_ = s.value("device", QVariant());
ui_->combobox_engine->setCurrentIndex(ui_->combobox_engine->findData(static_cast<int>(enginetype)));
if (EngineInitialised()) Load_Engine(enginetype);
ui_->checkbox_volume_control->setChecked(s_.value("volume_control", true).toBool());
ui_->checkbox_volume_control->setChecked(s.value("volume_control", true).toBool());
ui_->spinbox_bufferduration->setValue(s_.value("bufferduration", 4000).toInt());
ui_->slider_bufferminfill->setValue(s_.value("bufferminfill", 33).toInt());
ui_->spinbox_bufferduration->setValue(s.value("bufferduration", 4000).toInt());
ui_->slider_bufferminfill->setValue(s.value("bufferminfill", 33).toInt());
ui_->checkbox_replaygain->setChecked(s_.value("rgenabled", false).toBool());
ui_->combobox_replaygainmode->setCurrentIndex(s_.value("rgmode", 0).toInt());
ui_->stickslider_replaygainpreamp->setValue(s_.value("rgpreamp", 0.0).toDouble() * 10 + 150);
ui_->checkbox_replaygaincompression->setChecked(s_.value("rgcompression", true).toBool());
ui_->checkbox_replaygain->setChecked(s.value("rgenabled", false).toBool());
ui_->combobox_replaygainmode->setCurrentIndex(s.value("rgmode", 0).toInt());
ui_->stickslider_replaygainpreamp->setValue(s.value("rgpreamp", 0.0).toDouble() * 10 + 150);
ui_->checkbox_replaygaincompression->setChecked(s.value("rgcompression", true).toBool());
#if defined(HAVE_ALSA)
bool fade_default = false;
@ -121,18 +123,18 @@ void BackendSettingsPage::Load() {
bool fade_default = true;
#endif
ui_->checkbox_fadeout_stop->setChecked(s_.value("FadeoutEnabled", fade_default).toBool());
ui_->checkbox_fadeout_cross->setChecked(s_.value("CrossfadeEnabled", fade_default).toBool());
ui_->checkbox_fadeout_auto->setChecked(s_.value("AutoCrossfadeEnabled", false).toBool());
ui_->checkbox_fadeout_samealbum->setChecked(s_.value("NoCrossfadeSameAlbum", true).toBool());
ui_->checkbox_fadeout_pauseresume->setChecked(s_.value("FadeoutPauseEnabled", false).toBool());
ui_->spinbox_fadeduration->setValue(s_.value("FadeoutDuration", 2000).toInt());
ui_->spinbox_fadeduration_pauseresume->setValue(s_.value("FadeoutPauseDuration", 250).toInt());
ui_->checkbox_fadeout_stop->setChecked(s.value("FadeoutEnabled", fade_default).toBool());
ui_->checkbox_fadeout_cross->setChecked(s.value("CrossfadeEnabled", fade_default).toBool());
ui_->checkbox_fadeout_auto->setChecked(s.value("AutoCrossfadeEnabled", false).toBool());
ui_->checkbox_fadeout_samealbum->setChecked(s.value("NoCrossfadeSameAlbum", true).toBool());
ui_->checkbox_fadeout_pauseresume->setChecked(s.value("FadeoutPauseEnabled", false).toBool());
ui_->spinbox_fadeduration->setValue(s.value("FadeoutDuration", 2000).toInt());
ui_->spinbox_fadeduration_pauseresume->setValue(s.value("FadeoutPauseDuration", 250).toInt());
#if defined(HAVE_ALSA)
ui_->lineedit_device->show();
ui_->widget_alsa_plugin->show();
int alsaplug_int = alsa_plugin(s_.value("alsaplugin", 0).toInt());
int alsaplug_int = alsa_plugin(s.value("alsaplugin", 0).toInt());
if (alsa_plugin(alsaplug_int)) {
alsa_plugin alsaplugin = alsa_plugin(alsaplug_int);
switch (alsaplugin) {
@ -199,6 +201,8 @@ void BackendSettingsPage::Load() {
set_changed();
}
s.endGroup();
}
bool BackendSettingsPage::EngineInitialised() {
@ -396,33 +400,38 @@ void BackendSettingsPage::Save() {
else if (ui_->combobox_device->currentText() == "Custom") device_value = ui_->lineedit_device->text();
else device_value = ui_->combobox_device->itemData(ui_->combobox_device->currentIndex()).value<QVariant>();
s_.setValue("engine", EngineName(enginetype));
s_.setValue("output", output_name);
s_.setValue("device", device_value);
QSettings s;
s.beginGroup(kSettingsGroup);
s_.setValue("bufferduration", ui_->spinbox_bufferduration->value());
s_.setValue("bufferminfill", ui_->slider_bufferminfill->value());
s.setValue("engine", EngineName(enginetype));
s.setValue("output", output_name);
s.setValue("device", device_value);
s_.setValue("rgenabled", ui_->checkbox_replaygain->isChecked());
s_.setValue("rgmode", ui_->combobox_replaygainmode->currentIndex());
s_.setValue("rgpreamp", float(ui_->stickslider_replaygainpreamp->value()) / 10 - 15);
s_.setValue("rgcompression", ui_->checkbox_replaygaincompression->isChecked());
s.setValue("bufferduration", ui_->spinbox_bufferduration->value());
s.setValue("bufferminfill", ui_->slider_bufferminfill->value());
s_.setValue("FadeoutEnabled", ui_->checkbox_fadeout_stop->isChecked());
s_.setValue("CrossfadeEnabled", ui_->checkbox_fadeout_cross->isChecked());
s_.setValue("AutoCrossfadeEnabled", ui_->checkbox_fadeout_auto->isChecked());
s_.setValue("NoCrossfadeSameAlbum", ui_->checkbox_fadeout_samealbum->isChecked());
s_.setValue("FadeoutPauseEnabled", ui_->checkbox_fadeout_pauseresume->isChecked());
s_.setValue("FadeoutDuration", ui_->spinbox_fadeduration->value());
s_.setValue("FadeoutPauseDuration", ui_->spinbox_fadeduration_pauseresume->value());
s.setValue("rgenabled", ui_->checkbox_replaygain->isChecked());
s.setValue("rgmode", ui_->combobox_replaygainmode->currentIndex());
s.setValue("rgpreamp", float(ui_->stickslider_replaygainpreamp->value()) / 10 - 15);
s.setValue("rgcompression", ui_->checkbox_replaygaincompression->isChecked());
s.setValue("FadeoutEnabled", ui_->checkbox_fadeout_stop->isChecked());
s.setValue("CrossfadeEnabled", ui_->checkbox_fadeout_cross->isChecked());
s.setValue("AutoCrossfadeEnabled", ui_->checkbox_fadeout_auto->isChecked());
s.setValue("NoCrossfadeSameAlbum", ui_->checkbox_fadeout_samealbum->isChecked());
s.setValue("FadeoutPauseEnabled", ui_->checkbox_fadeout_pauseresume->isChecked());
s.setValue("FadeoutDuration", ui_->spinbox_fadeduration->value());
s.setValue("FadeoutPauseDuration", ui_->spinbox_fadeduration_pauseresume->value());
#ifdef HAVE_ALSA
if (ui_->radiobutton_alsa_hw->isChecked()) s_.setValue("alsaplugin", static_cast<int>(alsa_plugin::alsa_hw));
else if (ui_->radiobutton_alsa_plughw->isChecked()) s_.setValue("alsaplugin", static_cast<int>(alsa_plugin::alsa_plughw));
else s_.remove("alsaplugin");
if (ui_->radiobutton_alsa_hw->isChecked()) s.setValue("alsaplugin", static_cast<int>(alsa_plugin::alsa_hw));
else if (ui_->radiobutton_alsa_plughw->isChecked()) s.setValue("alsaplugin", static_cast<int>(alsa_plugin::alsa_plughw));
else s.remove("alsaplugin");
#endif
s_.setValue("volume_control", ui_->checkbox_volume_control->isChecked());
s.setValue("volume_control", ui_->checkbox_volume_control->isChecked());
s.endGroup();
}

View File

@ -25,7 +25,6 @@
#include <QObject>
#include <QVariant>
#include <QString>
#include <QSettings>
#include "engine/enginetype.h"
#include "dialogs/errordialog.h"
@ -85,7 +84,6 @@ private:
void SwitchALSADevices(alsa_plugin alsaplugin);
#endif
QSettings s_;
bool configloaded_;
bool engineloaded_;
ErrorDialog errordialog_;

View File

@ -149,8 +149,9 @@ BehaviourSettingsPage::~BehaviourSettingsPage() {
void BehaviourSettingsPage::Load() {
QSettings s;
if (!s.contains(kSettingsGroup)) set_changed();
s.beginGroup(kSettingsGroup);
#ifndef Q_OS_MACOS
if (QSystemTrayIcon::isSystemTrayAvailable()) {
ui_->checkbox_showtrayicon->setEnabled(true);

View File

@ -96,17 +96,17 @@ CollectionSettingsPage::~CollectionSettingsPage() { delete ui_; }
void CollectionSettingsPage::Add() {
QSettings settings;
settings.beginGroup(kSettingsGroup);
QSettings s;
s.beginGroup(kSettingsGroup);
QString path(settings.value("last_path", QStandardPaths::writableLocation(QStandardPaths::MusicLocation)).toString());
QString path(s.value("last_path", QStandardPaths::writableLocation(QStandardPaths::MusicLocation)).toString());
path = QFileDialog::getExistingDirectory(this, tr("Add directory..."), path);
if (!path.isNull()) {
dialog()->collection_directory_model()->AddDirectory(path);
}
settings.setValue("last_path", path);
s.setValue("last_path", path);
set_changed();
@ -149,6 +149,7 @@ void CollectionSettingsPage::Load() {
}
QSettings s;
if (!s.contains(kSettingsGroup)) set_changed();
s.beginGroup(kSettingsGroup);
ui_->auto_open->setChecked(s.value("auto_open", true).toBool());

View File

@ -125,8 +125,9 @@ ContextSettingsPage::~ContextSettingsPage() { delete ui_; }
void ContextSettingsPage::Load() {
QSettings s;
if (!s.contains(kSettingsGroup)) set_changed();
s.beginGroup(ContextSettingsPage::kSettingsGroup);
s.beginGroup(kSettingsGroup);
ui_->context_custom_text1->setText(s.value(kSettingsTitleFmt, "%title% - %artist%").toString());
ui_->context_custom_text2->setText(s.value(kSettingsSummaryFmt, "%album%").toString());

View File

@ -73,6 +73,8 @@ CoversSettingsPage::~CoversSettingsPage() { delete ui_; }
void CoversSettingsPage::Load() {
if (!QSettings().contains(kSettingsGroup)) set_changed();
ui_->providers->clear();
QList<CoverProvider*> cover_providers_sorted = dialog()->app()->cover_providers()->List();

View File

@ -73,6 +73,8 @@ LyricsSettingsPage::~LyricsSettingsPage() { delete ui_; }
void LyricsSettingsPage::Load() {
if (!QSettings().contains(kSettingsGroup)) set_changed();
ui_->providers->clear();
QList<LyricsProvider*> lyrics_providers_sorted = dialog()->app()->lyrics_providers()->List();

View File

@ -66,6 +66,8 @@ MoodbarSettingsPage::~MoodbarSettingsPage() { delete ui_; }
void MoodbarSettingsPage::Load() {
QSettings s;
if (!s.contains(kSettingsGroup)) set_changed();
s.beginGroup(kSettingsGroup);
ui_->moodbar_enabled->setChecked(s.value("enabled", false).toBool());
ui_->moodbar_show->setChecked(s.value("show", false).toBool());

View File

@ -51,6 +51,7 @@ NetworkProxySettingsPage::~NetworkProxySettingsPage() { delete ui_; }
void NetworkProxySettingsPage::Load() {
QSettings s;
if (!s.contains(kSettingsGroup)) set_changed();
s.beginGroup(NetworkProxyFactory::kSettingsGroup);
NetworkProxyFactory::Mode mode = NetworkProxyFactory::Mode(s.value("mode", NetworkProxyFactory::Mode_System).toInt());

View File

@ -56,7 +56,7 @@
class QHideEvent;
class QShowEvent;
const char *NotificationsSettingsPage::kSettingsGroup = "Notifications";
//const char *NotificationsSettingsPage::kSettingsGroup = "Notifications";
NotificationsSettingsPage::NotificationsSettingsPage(SettingsDialog* dialog)
: SettingsPage(dialog), ui_(new Ui_NotificationsSettingsPage), pretty_popup_(new OSDPretty(OSDPretty::Mode_Draggable)) {
@ -142,6 +142,7 @@ void NotificationsSettingsPage::hideEvent(QHideEvent*) {
void NotificationsSettingsPage::Load() {
QSettings s;
if (!s.contains(OSDBase::kSettingsGroup)) set_changed();
s.beginGroup(OSDBase::kSettingsGroup);
OSDBase::Behaviour osd_behaviour = OSDBase::Behaviour(s.value("Behaviour", OSDBase::Native).toInt());

View File

@ -43,7 +43,7 @@ class NotificationsSettingsPage : public SettingsPage {
explicit NotificationsSettingsPage(SettingsDialog *dialog);
~NotificationsSettingsPage() override;
static const char *kSettingsGroup;
//static const char *kSettingsGroup;
void Load() override;
void Save() override;

View File

@ -49,6 +49,8 @@ PlaylistSettingsPage::~PlaylistSettingsPage() {
void PlaylistSettingsPage::Load() {
QSettings s;
if (!s.contains(kSettingsGroup)) set_changed();
s.beginGroup(kSettingsGroup);
#ifdef Q_OS_MACOS

View File

@ -73,6 +73,7 @@ QobuzSettingsPage::~QobuzSettingsPage() { delete ui_; }
void QobuzSettingsPage::Load() {
QSettings s;
if (!s.contains(kSettingsGroup)) set_changed();
s.beginGroup(kSettingsGroup);
ui_->enable->setChecked(s.value("enabled", false).toBool());

View File

@ -89,6 +89,9 @@ ScrobblerSettingsPage::~ScrobblerSettingsPage() { delete ui_; }
void ScrobblerSettingsPage::Load() {
QSettings s;
if (!s.contains(kSettingsGroup)) set_changed();
ui_->checkbox_enable->setChecked(scrobbler_->IsEnabled());
ui_->checkbox_scrobble_button->setChecked(scrobbler_->ScrobbleButton());
ui_->checkbox_love_button->setChecked(scrobbler_->LoveButton());

View File

@ -65,8 +65,6 @@ GlobalShortcutsSettingsPage::GlobalShortcutsSettingsPage(SettingsDialog *dialog)
ui_->list->header()->setSectionResizeMode(QHeaderView::ResizeToContents);
setWindowIcon(IconLoader::Load("keyboard"));
settings_.beginGroup(kSettingsGroup);
connect(ui_->list, SIGNAL(currentItemChanged(QTreeWidgetItem*, QTreeWidgetItem*)), SLOT(ItemClicked(QTreeWidgetItem*)));
connect(ui_->radio_none, SIGNAL(clicked()), SLOT(NoneClicked()));
connect(ui_->radio_default, SIGNAL(clicked()), SLOT(DefaultClicked()));
@ -102,6 +100,10 @@ bool GlobalShortcutsSettingsPage::IsEnabled() const {
void GlobalShortcutsSettingsPage::Load() {
QSettings s;
if (!s.contains(kSettingsGroup)) set_changed();
s.beginGroup(kSettingsGroup);
GlobalShortcuts *manager = dialog()->global_shortcuts_manager();
if (!initialised_) {
@ -128,32 +130,32 @@ void GlobalShortcutsSettingsPage::Load() {
else {
qLog(Debug) << "X11 backend is unavailable.";
ui_->widget_x11->hide();
settings_.setValue("use_x11", false);
s.setValue("use_x11", false);
}
for (const GlobalShortcuts::Shortcut &s : manager->shortcuts().values()) {
for (const GlobalShortcuts::Shortcut &i : manager->shortcuts().values()) {
Shortcut shortcut;
shortcut.s = s;
shortcut.key = s.action->shortcut();
shortcut.item = new QTreeWidgetItem(ui_->list, QStringList() << s.action->text() << s.action->shortcut().toString(QKeySequence::NativeText));
shortcut.item->setData(0, Qt::UserRole, s.id);
shortcuts_[s.id] = shortcut;
shortcut.s = i;
shortcut.key = i.action->shortcut();
shortcut.item = new QTreeWidgetItem(ui_->list, QStringList() << i.action->text() << i.action->shortcut().toString(QKeySequence::NativeText));
shortcut.item->setData(0, Qt::UserRole, i.id);
shortcuts_[i.id] = shortcut;
}
ui_->list->sortItems(0, Qt::AscendingOrder);
ItemClicked(ui_->list->topLevelItem(0));
}
for (const Shortcut &s : shortcuts_.values()) {
SetShortcut(s.s.id, s.s.action->shortcut());
for (const Shortcut &shortcut : shortcuts_.values()) {
SetShortcut(shortcut.s.id, shortcut.s.action->shortcut());
}
bool use_gsd = settings_.value("use_gsd", true).toBool();
bool use_gsd = s.value("use_gsd", true).toBool();
if (ui_->widget_gsd->isVisibleTo(this)) {
ui_->checkbox_gsd->setChecked(use_gsd);
}
bool use_x11 = settings_.value("use_x11", false).toBool();
bool use_x11 = s.value("use_x11", false).toBool();
if (ui_->widget_x11->isVisibleTo(this)) {
ui_->checkbox_x11->setChecked(use_x11);
}
@ -174,20 +176,27 @@ void GlobalShortcutsSettingsPage::Load() {
ui_->label_macos_mavericks->setVisible(macos_version >= 9);
#endif // Q_OS_MACOS
s.endGroup();
Init(ui_->layout_globalshortcutssettingspage->parentWidget());
}
void GlobalShortcutsSettingsPage::Save() {
for (const Shortcut &s : shortcuts_.values()) {
s.s.action->setShortcut(s.key);
s.s.shortcut->setKey(s.key);
settings_.setValue(s.s.id, s.key.toString());
QSettings s;
s.beginGroup(kSettingsGroup);
for (const Shortcut &shortcut : shortcuts_.values()) {
shortcut.s.action->setShortcut(shortcut.key);
shortcut.s.shortcut->setKey(shortcut.key);
s.setValue(shortcut.s.id, shortcut.key.toString());
}
settings_.setValue("use_gsd", ui_->checkbox_gsd->isChecked());
settings_.setValue("use_x11", ui_->checkbox_x11->isChecked());
s.setValue("use_gsd", ui_->checkbox_gsd->isChecked());
s.setValue("use_x11", ui_->checkbox_x11->isChecked());
s.endGroup();
dialog()->global_shortcuts_manager()->ReloadSettings();

View File

@ -81,7 +81,6 @@ class GlobalShortcutsSettingsPage : public SettingsPage {
bool initialised_;
std::unique_ptr<GlobalShortcutGrabber> grabber_;
QSettings settings_;
QMap<QString, Shortcut> shortcuts_;
QString current_id_;

View File

@ -65,6 +65,7 @@ SubsonicSettingsPage::~SubsonicSettingsPage() { delete ui_; }
void SubsonicSettingsPage::Load() {
QSettings s;
if (!s.contains(kSettingsGroup)) set_changed();
s.beginGroup(kSettingsGroup);
ui_->enable->setChecked(s.value("enabled", false).toBool());

View File

@ -85,6 +85,7 @@ TidalSettingsPage::~TidalSettingsPage() { delete ui_; }
void TidalSettingsPage::Load() {
QSettings s;
if (!s.contains(kSettingsGroup)) set_changed();
s.beginGroup(kSettingsGroup);
ui_->enable->setChecked(s.value("enabled", false).toBool());