feat: settingsdialog remove need for appconfig

This commit is contained in:
sithlord48 2025-03-09 23:07:01 -04:00 committed by Nick Bolton
parent 8606dc8618
commit 8bb325a2d2
3 changed files with 15 additions and 23 deletions

View file

@ -502,7 +502,7 @@ void MainWindow::openGetNewVersionUrl() const
void MainWindow::openSettings() void MainWindow::openSettings()
{ {
auto dialog = SettingsDialog(this, m_appConfig, m_serverConfig, m_coreProcess); auto dialog = SettingsDialog(this, m_serverConfig, m_coreProcess);
if (dialog.exec() == QDialog::Accepted) { if (dialog.exec() == QDialog::Accepted) {
m_configScopes.save(); m_configScopes.save();

View file

@ -21,12 +21,9 @@
using namespace deskflow::gui; using namespace deskflow::gui;
SettingsDialog::SettingsDialog( SettingsDialog::SettingsDialog(QWidget *parent, const IServerConfig &serverConfig, const CoreProcess &coreProcess)
QWidget *parent, AppConfig &appConfig, const IServerConfig &serverConfig, const CoreProcess &coreProcess
)
: QDialog(parent), : QDialog(parent),
ui{std::make_unique<Ui::SettingsDialog>()}, ui{std::make_unique<Ui::SettingsDialog>()},
m_appConfig(appConfig),
m_serverConfig(serverConfig), m_serverConfig(serverConfig),
m_coreProcess(coreProcess), m_coreProcess(coreProcess),
m_tlsUtility(this) m_tlsUtility(this)
@ -46,7 +43,7 @@ SettingsDialog::SettingsDialog(
ui->tabWidget->setCurrentIndex(0); ui->tabWidget->setCurrentIndex(0);
loadFromConfig(); loadFromConfig();
m_wasOriginallySystemScope = m_appConfig.isActiveScopeSystem(); m_wasOriginallySystemScope = Settings::isSystemScope();
updateControls(); updateControls();
adjustSize(); adjustSize();
@ -117,11 +114,11 @@ void SettingsDialog::setLogToFile(bool logToFile)
void SettingsDialog::setSystemScope(bool systemScope) void SettingsDialog::setSystemScope(bool systemScope)
{ {
m_appConfig.setLoadFromSystemScope(systemScope); Settings::setScope(systemScope);
loadFromConfig(); loadFromConfig();
updateControls(); updateControls();
if (isVisible() && !m_appConfig.isActiveScopeWritable()) { if (isVisible() && Settings::isWritable()) {
showReadOnlyMessage(); showReadOnlyMessage();
} }
} }
@ -134,15 +131,14 @@ void SettingsDialog::showEvent(QShowEvent *event)
void SettingsDialog::showReadOnlyMessage() void SettingsDialog::showReadOnlyMessage()
{ {
if (m_appConfig.isActiveScopeWritable()) if (Settings::isWritable())
return; return;
const auto activeScopeFilename = m_appConfig.scopes().activeFilePath(); messages::showReadOnlySettings(this, Settings::settingsFile());
messages::showReadOnlySettings(this, activeScopeFilename);
} }
void SettingsDialog::accept() void SettingsDialog::accept()
{ {
m_appConfig.setLoadFromSystemScope(ui->rbScopeSystem->isChecked()); Settings::setScope(ui->rbScopeSystem->isChecked());
Settings::setValue(Settings::Core::Port, ui->sbPort->value()); Settings::setValue(Settings::Core::Port, ui->sbPort->value());
Settings::setValue(Settings::Core::Interface, ui->lineInterface->text()); Settings::setValue(Settings::Core::Interface, ui->lineInterface->text());
Settings::setValue(Settings::Log::Level, ui->comboLogLevel->currentIndex()); Settings::setValue(Settings::Log::Level, ui->comboLogLevel->currentIndex());
@ -174,8 +170,8 @@ void SettingsDialog::accept()
void SettingsDialog::reject() void SettingsDialog::reject()
{ {
// restore original system scope value on reject. // restore original system scope value on reject.
if (m_appConfig.isActiveScopeSystem() != m_wasOriginallySystemScope) { if (Settings::isSystemScope() != m_wasOriginallySystemScope) {
m_appConfig.setLoadFromSystemScope(m_wasOriginallySystemScope); Settings::setScope(m_wasOriginallySystemScope);
} }
QDialog::reject(); QDialog::reject();
@ -197,7 +193,7 @@ void SettingsDialog::loadFromConfig()
ui->comboElevate->setCurrentIndex(Settings::value(Settings::Core::ElevateMode).toInt()); ui->comboElevate->setCurrentIndex(Settings::value(Settings::Core::ElevateMode).toInt());
ui->cbAutoUpdate->setChecked(Settings::value(Settings::Gui::Autohide).toBool()); ui->cbAutoUpdate->setChecked(Settings::value(Settings::Gui::Autohide).toBool());
if (m_appConfig.isActiveScopeSystem()) { if (Settings::isSystemScope()) {
ui->rbScopeSystem->setChecked(true); ui->rbScopeSystem->setChecked(true);
} else { } else {
ui->rbScopeUser->setChecked(true); ui->rbScopeUser->setChecked(true);
@ -226,7 +222,7 @@ void SettingsDialog::updateTlsControls()
} }
const auto tlsEnabled = Settings::value(Settings::Security::TlsEnabled).toBool(); const auto tlsEnabled = Settings::value(Settings::Security::TlsEnabled).toBool();
const auto writable = m_appConfig.isActiveScopeWritable(); const auto writable = Settings::isWritable();
const auto enabled = writable && tlsEnabled; const auto enabled = writable && tlsEnabled;
ui->lineTlsCertPath->setText(certificate); ui->lineTlsCertPath->setText(certificate);
@ -243,7 +239,7 @@ void SettingsDialog::updateTlsControls()
void SettingsDialog::updateTlsControlsEnabled() void SettingsDialog::updateTlsControlsEnabled()
{ {
const auto writable = m_appConfig.isActiveScopeWritable(); const auto writable = Settings::isWritable();
const auto clientMode = const auto clientMode =
Settings::value(Settings::Core::CoreMode).value<Settings::CoreMode>() == Settings::CoreMode::Client; Settings::value(Settings::Core::CoreMode).value<Settings::CoreMode>() == Settings::CoreMode::Client;
const auto tlsChecked = ui->groupSecurity->isChecked(); const auto tlsChecked = ui->groupSecurity->isChecked();
@ -285,7 +281,7 @@ void SettingsDialog::updateControls()
ui->groupService->setTitle("Service (Windows only)"); ui->groupService->setTitle("Service (Windows only)");
#endif #endif
const bool writable = m_appConfig.isActiveScopeWritable(); const bool writable = Settings::isWritable();
const bool serviceChecked = ui->cbServiceEnabled->isChecked(); const bool serviceChecked = ui->cbServiceEnabled->isChecked();
const bool logToFile = ui->cbLogToFile->isChecked(); const bool logToFile = ui->cbLogToFile->isChecked();

View file

@ -9,7 +9,6 @@
#pragma once #pragma once
#include <QDialog> #include <QDialog>
#include "gui/config/AppConfig.h"
#include "gui/config/IServerConfig.h" #include "gui/config/IServerConfig.h"
#include "gui/core/CoreProcess.h" #include "gui/core/CoreProcess.h"
#include "gui/tls/TlsUtility.h" #include "gui/tls/TlsUtility.h"
@ -28,9 +27,7 @@ class SettingsDialog : public QDialog
public: public:
void extracted(); void extracted();
SettingsDialog( SettingsDialog(QWidget *parent, const IServerConfig &serverConfig, const CoreProcess &coreProcess);
QWidget *parent, AppConfig &appConfig, const IServerConfig &serverConfig, const CoreProcess &coreProcess
);
~SettingsDialog() override; ~SettingsDialog() override;
signals: signals:
@ -69,7 +66,6 @@ private:
bool m_wasOriginallySystemScope = false; bool m_wasOriginallySystemScope = false;
std::unique_ptr<Ui::SettingsDialog> ui; std::unique_ptr<Ui::SettingsDialog> ui;
AppConfig &m_appConfig;
const IServerConfig &m_serverConfig; const IServerConfig &m_serverConfig;
const CoreProcess &m_coreProcess; const CoreProcess &m_coreProcess;
deskflow::gui::TlsUtility m_tlsUtility; deskflow::gui::TlsUtility m_tlsUtility;