From 457c31fbaff94499276a6052108b7da65da63bc7 Mon Sep 17 00:00:00 2001 From: sithlord48 Date: Mon, 16 Feb 2026 15:34:04 -0500 Subject: [PATCH] refactor: SettingsDialog only allow save if modified --- src/lib/gui/dialogs/SettingsDialog.cpp | 58 ++++++++++++++++++++++++++ src/lib/gui/dialogs/SettingsDialog.h | 12 ++++++ 2 files changed, 70 insertions(+) diff --git a/src/lib/gui/dialogs/SettingsDialog.cpp b/src/lib/gui/dialogs/SettingsDialog.cpp index 534f299c0..a6f8bcafe 100644 --- a/src/lib/gui/dialogs/SettingsDialog.cpp +++ b/src/lib/gui/dialogs/SettingsDialog.cpp @@ -65,6 +65,7 @@ SettingsDialog::SettingsDialog(QWidget *parent, const IServerConfig &serverConfi setFixedHeight(height()); setWindowFlags((windowFlags() | Qt::CustomizeWindowHint) & ~Qt::WindowMinMaxButtonsHint); + setButtonBoxEnabledButtons(); initConnections(); } @@ -96,6 +97,28 @@ void SettingsDialog::initConnections() const const auto shortName = I18N::nativeTo639Name(lang); I18N::setLanguage(shortName); }); + + // Connect modifiable controls + connect(ui->rbIconMono, &QRadioButton::toggled, this, &SettingsDialog::setButtonBoxEnabledButtons); + connect(ui->sbPort, &QSpinBox::valueChanged, this, &SettingsDialog::setButtonBoxEnabledButtons); + connect(ui->comboLogLevel, &QComboBox::currentIndexChanged, this, &SettingsDialog::setButtonBoxEnabledButtons); + connect(ui->comboInterface, &QComboBox::currentIndexChanged, this, &SettingsDialog::setButtonBoxEnabledButtons); + connect(ui->comboTlsKeyLength, &QComboBox::currentIndexChanged, this, &SettingsDialog::setButtonBoxEnabledButtons); + connect(ui->comboLanguage, &QComboBox::currentIndexChanged, this, &SettingsDialog::setButtonBoxEnabledButtons); + connect(ui->cbLogToFile, &QCheckBox::toggled, this, &SettingsDialog::setButtonBoxEnabledButtons); + connect(ui->cbAutoHide, &QCheckBox::toggled, this, &SettingsDialog::setButtonBoxEnabledButtons); + connect(ui->cbPreventSleep, &QCheckBox::toggled, this, &SettingsDialog::setButtonBoxEnabledButtons); + connect(ui->cbCloseToTray, &QCheckBox::toggled, this, &SettingsDialog::setButtonBoxEnabledButtons); + connect(ui->cbElevateDaemon, &QCheckBox::toggled, this, &SettingsDialog::setButtonBoxEnabledButtons); + connect(ui->cbAutoUpdate, &QCheckBox::toggled, this, &SettingsDialog::setButtonBoxEnabledButtons); + connect(ui->cbGuiDebug, &QCheckBox::toggled, this, &SettingsDialog::setButtonBoxEnabledButtons); + connect(ui->cbUseWlClipboard, &QCheckBox::toggled, this, &SettingsDialog::setButtonBoxEnabledButtons); + connect(ui->cbShowVersion, &QCheckBox::toggled, this, &SettingsDialog::setButtonBoxEnabledButtons); + connect(ui->cbRequireClientCert, &QCheckBox::toggled, this, &SettingsDialog::setButtonBoxEnabledButtons); + connect(ui->groupService, &QGroupBox::toggled, this, &SettingsDialog::setButtonBoxEnabledButtons); + connect(ui->groupSecurity, &QGroupBox::toggled, this, &SettingsDialog::setButtonBoxEnabledButtons); + connect(ui->lineLogFilename, &QLineEdit::textChanged, this, &SettingsDialog::setButtonBoxEnabledButtons); + connect(ui->lineTlsCertPath, &QLineEdit::textChanged, this, &SettingsDialog::setButtonBoxEnabledButtons); } void SettingsDialog::regenCertificates() @@ -341,4 +364,39 @@ void SettingsDialog::logLevelChanged() ui->lblDebugWarning->setVisible(ui->comboLogLevel->currentIndex() > 4); } +bool SettingsDialog::isModified() const +{ + const auto processMode = Settings::value(Settings::Core::ProcessMode).value(); + const auto interfaceSet = ui->comboInterface->currentIndex(); + + return ( + (ui->sbPort->value() != Settings::value(Settings::Core::Port).toInt()) || + (ui->comboLogLevel->currentIndex() != Settings::value(Settings::Log::Level).toInt()) || + (ui->cbLogToFile->isChecked() != Settings::value(Settings::Log::ToFile).toBool()) || + (ui->lineLogFilename->text() != Settings::value(Settings::Log::File).toString()) || + (ui->cbAutoHide->isChecked() != Settings::value(Settings::Gui::Autohide).toBool()) || + (ui->cbPreventSleep->isChecked() != Settings::value(Settings::Core::PreventSleep).toBool()) || + (ui->cbCloseToTray->isChecked() != Settings::value(Settings::Gui::CloseToTray).toBool()) || + (ui->cbElevateDaemon->isChecked() != Settings::value(Settings::Daemon::Elevate).toBool()) || + (ui->cbAutoUpdate->isChecked() != Settings::value(Settings::Gui::AutoUpdateCheck).toBool()) || + (ui->cbGuiDebug->isChecked() != Settings::value(Settings::Log::GuiDebug).toBool()) || + (ui->cbUseWlClipboard->isChecked() != Settings::value(Settings::Core::UseWlClipboard).toBool()) || + (ui->cbShowVersion->isChecked() != Settings::value(Settings::Gui::ShowVersionInTitle).toBool()) || + (ui->rbIconMono->isChecked() != Settings::value(Settings::Gui::SymbolicTrayIcon).toBool()) || + (ui->groupService->isChecked() != (processMode == Settings::ProcessMode::Service)) || + ((ui->comboInterface->currentText() != Settings::value(Settings::Core::Interface).toString()) && interfaceSet) || + (ui->lineTlsCertPath->text() != Settings::value(Settings::Security::Certificate).toString()) || + (ui->comboTlsKeyLength->currentText() != Settings::value(Settings::Security::KeySize).toString()) || + (ui->groupSecurity->isChecked() != Settings::value(Settings::Security::TlsEnabled).toBool()) || + (ui->cbRequireClientCert->isChecked() != Settings::value(Settings::Security::CheckPeers).toBool()) || + (I18N::nativeTo639Name(ui->comboLanguage->currentText()) != Settings::value(Settings::Core::Language).toString()) + ); +} + +void SettingsDialog::setButtonBoxEnabledButtons() const +{ + const bool modified = isModified(); + ui->buttonBox->button(QDialogButtonBox::Save)->setEnabled(modified); +} + SettingsDialog::~SettingsDialog() = default; diff --git a/src/lib/gui/dialogs/SettingsDialog.h b/src/lib/gui/dialogs/SettingsDialog.h index 4e81da8d9..29dcedc0d 100644 --- a/src/lib/gui/dialogs/SettingsDialog.h +++ b/src/lib/gui/dialogs/SettingsDialog.h @@ -61,6 +61,18 @@ private: /// @brief update if the log level warning is shown void logLevelChanged(); + /** + * @brief isModified + * @return true when any client settings in the gui do not match the stored settings values. + */ + bool isModified() const; + + /** + * @brief setButtonBoxEnabledButtons + * Enable / Disable the button box buttons based on the state of the gui + */ + void setButtonBoxEnabledButtons() const; + std::unique_ptr ui; const IServerConfig &m_serverConfig; };