From daaaf9b4ee3fffc566b0d2b152e5c7f2fa82ed1e Mon Sep 17 00:00:00 2001 From: Nick Bolton Date: Thu, 8 Aug 2024 11:38:34 +0100 Subject: [PATCH] Fixed bugs in config dialog related to service checkbox --- src/gui/src/MainWindow.cpp | 8 +- src/gui/src/ScreenSettingsDialog.cpp | 5 +- src/gui/src/ScreenSetupModel.cpp | 5 +- src/gui/src/ScreenSetupModel.h | 10 +- src/gui/src/ScreenSetupView.cpp | 3 +- src/gui/src/ScreenSetupView.h | 10 +- src/gui/src/ServerConfig.h | 30 +- src/gui/src/SettingsDialog.cpp | 319 +++++++++--------- src/gui/src/SettingsDialog.h | 48 +-- .../ScreenDuplicationsValidator.cpp | 4 +- .../validators/ScreenDuplicationsValidator.h | 12 +- .../src/validators/ScreenNameValidator.cpp | 3 +- src/gui/src/validators/ScreenNameValidator.h | 2 +- src/lib/gui/config/IServerConfig.h | 3 + src/lib/gui/config/ScreenList.h | 9 +- .../unittests/gui/core/CoreProcessTests.cpp | 1 + 16 files changed, 249 insertions(+), 223 deletions(-) diff --git a/src/gui/src/MainWindow.cpp b/src/gui/src/MainWindow.cpp index 0f56408089..7d80860674 100644 --- a/src/gui/src/MainWindow.cpp +++ b/src/gui/src/MainWindow.cpp @@ -408,9 +408,11 @@ void MainWindow::on_m_pActionHelp_triggered() { } void MainWindow::on_m_pActionSettings_triggered() { - auto result = - SettingsDialog(this, m_AppConfig, m_LicenseHandler.license()).exec(); - if (result == QDialog::Accepted) { + auto dialog = SettingsDialog( + this, m_AppConfig, m_ServerConfig, m_LicenseHandler.license(), + m_CoreProcess); + + if (dialog.exec() == QDialog::Accepted) { m_ConfigScopes.save(); applyConfig(); diff --git a/src/gui/src/ScreenSettingsDialog.cpp b/src/gui/src/ScreenSettingsDialog.cpp index bc0807485a..207126c063 100644 --- a/src/gui/src/ScreenSettingsDialog.cpp +++ b/src/gui/src/ScreenSettingsDialog.cpp @@ -1,6 +1,6 @@ /* * synergy -- mouse and keyboard sharing utility - * Copyright (C) 2012-2016 Symless Ltd. + * Copyright (C) 2012 Symless Ltd. * Copyright (C) 2008 Volker Lanz (vl@fidra.de) * * This package is free software; you can redistribute it and/or @@ -17,7 +17,8 @@ */ #include "ScreenSettingsDialog.h" -#include "Screen.h" + +#include "gui/config/Screen.h" #include "gui/styles.h" #include "validators/AliasValidator.h" #include "validators/ScreenNameValidator.h" diff --git a/src/gui/src/ScreenSetupModel.cpp b/src/gui/src/ScreenSetupModel.cpp index b68021b1c5..317c3ee838 100644 --- a/src/gui/src/ScreenSetupModel.cpp +++ b/src/gui/src/ScreenSetupModel.cpp @@ -1,6 +1,6 @@ /* * synergy -- mouse and keyboard sharing utility - * Copyright (C) 2012-2016 Symless Ltd. + * Copyright (C) 2012 Symless Ltd. * Copyright (C) 2008 Volker Lanz (vl@fidra.de) * * This package is free software; you can redistribute it and/or @@ -17,7 +17,8 @@ */ #include "ScreenSetupModel.h" -#include "Screen.h" + +#include "gui/config/Screen.h" #include #include diff --git a/src/gui/src/ScreenSetupModel.h b/src/gui/src/ScreenSetupModel.h index 1b54a4e984..24121df6d5 100644 --- a/src/gui/src/ScreenSetupModel.h +++ b/src/gui/src/ScreenSetupModel.h @@ -1,6 +1,6 @@ /* * synergy -- mouse and keyboard sharing utility - * Copyright (C) 2012-2016 Symless Ltd. + * Copyright (C) 2012 Symless Ltd. * Copyright (C) 2008 Volker Lanz (vl@fidra.de) * * This package is free software; you can redistribute it and/or @@ -16,16 +16,14 @@ * along with this program. If not, see . */ -#if !defined(SCREENSETUPMODEL__H) - -#define SCREENSETUPMODEL__H +#pragma once #include #include #include #include -#include "ScreenList.h" +#include "gui/config/ScreenList.h" class ScreenSetupView; class ServerConfigDialog; @@ -80,5 +78,3 @@ private: static const QString m_MimeType; }; - -#endif diff --git a/src/gui/src/ScreenSetupView.cpp b/src/gui/src/ScreenSetupView.cpp index 6821c826c6..660e6a8f0b 100644 --- a/src/gui/src/ScreenSetupView.cpp +++ b/src/gui/src/ScreenSetupView.cpp @@ -1,6 +1,6 @@ /* * synergy -- mouse and keyboard sharing utility - * Copyright (C) 2012-2016 Symless Ltd. + * Copyright (C) 2012 Symless Ltd. * Copyright (C) 2008 Volker Lanz (vl@fidra.de) * * This package is free software; you can redistribute it and/or @@ -17,6 +17,7 @@ */ #include "ScreenSetupView.h" + #include "ScreenSettingsDialog.h" #include "ScreenSetupModel.h" diff --git a/src/gui/src/ScreenSetupView.h b/src/gui/src/ScreenSetupView.h index bd77d4becf..b6b1e40ea8 100644 --- a/src/gui/src/ScreenSetupView.h +++ b/src/gui/src/ScreenSetupView.h @@ -1,6 +1,6 @@ /* * synergy -- mouse and keyboard sharing utility - * Copyright (C) 2012-2016 Symless Ltd. + * Copyright (C) 2012 Symless Ltd. * Copyright (C) 2008 Volker Lanz (vl@fidra.de) * * This package is free software; you can redistribute it and/or @@ -16,14 +16,12 @@ * along with this program. If not, see . */ -#if !defined(SCREENSETUPVIEW__H) - -#define SCREENSETUPVIEW__H +#pragma once #include #include -#include "Screen.h" +#include "gui/config/Screen.h" class QWidget; class QMouseEvent; @@ -51,5 +49,3 @@ protected: void initViewItemOption(QStyleOptionViewItem *option) const override; void scrollTo(const QModelIndex &, ScrollHint) override {} }; - -#endif diff --git a/src/gui/src/ServerConfig.h b/src/gui/src/ServerConfig.h index f4764c5675..f99c6bf3ee 100644 --- a/src/gui/src/ServerConfig.h +++ b/src/gui/src/ServerConfig.h @@ -1,6 +1,6 @@ /* * synergy -- mouse and keyboard sharing utility - * Copyright (C) 2012-2016 Symless Ltd. + * Copyright (C) 2012 Symless Ltd. * Copyright (C) 2008 Volker Lanz (vl@fidra.de) * * This package is free software; you can redistribute it and/or @@ -19,9 +19,9 @@ #pragma once #include "Hotkey.h" -#include "ScreenConfig.h" -#include "ScreenList.h" #include "gui/config/IServerConfig.h" +#include "gui/config/ScreenConfig.h" +#include "gui/config/ScreenList.h" #include @@ -49,7 +49,15 @@ public: bool operator==(const ServerConfig &sc) const; - const ScreenList &screens() const { return m_Screens; } + // + // Overrides + // + const ScreenList &screens() const override { return m_Screens; } + bool enableDragAndDrop() const override { return m_EnableDragAndDrop; } + + // + // New methods + // int numColumns() const { return m_Columns; } int numRows() const { return m_Rows; } bool hasHeartbeat() const { return m_HasHeartbeat; } @@ -64,23 +72,29 @@ public: int switchCornerSize() const { return m_SwitchCornerSize; } const QList &switchCorners() const { return m_SwitchCorners; } const HotkeyList &hotkeys() const { return m_Hotkeys; } - bool enableDragAndDrop() const override { return m_EnableDragAndDrop; } bool disableLockToScreen() const { return m_DisableLockToScreen; } bool clipboardSharing() const { return m_ClipboardSharing; } size_t clipboardSharingSize() const { return m_ClipboardSharingSize; } static size_t defaultClipboardSharingSize(); - void commit(); + // + // Overrides + // bool save(const QString &fileName) const override; + bool screenExists(const QString &screenName) const override; void save(QFile &file) const override; + bool isFull() const override; + + // + // New methods + // + void commit(); int numScreens() const; int autoAddScreen(const QString name); const QString &getServerName() const; void updateServerName(); const QString &configFile() const; bool useExternalConfig() const; - bool isFull() const override; - bool screenExists(const QString &screenName) const override; void addClient(const QString &clientName); QString getClientAddress() const; void setClientAddress(const QString &address); diff --git a/src/gui/src/SettingsDialog.cpp b/src/gui/src/SettingsDialog.cpp index 637031c86e..4c50ea3d7b 100644 --- a/src/gui/src/SettingsDialog.cpp +++ b/src/gui/src/SettingsDialog.cpp @@ -22,6 +22,7 @@ #include "UpgradeDialog.h" #include "gui/config/AppConfig.h" #include "gui/constants.h" +#include "gui/core/CoreProcess.h" #include "gui/tls/TlsCertificate.h" #include "gui/tls/TlsUtility.h" #include "validators/ScreenNameValidator.h" @@ -40,12 +41,15 @@ using namespace synergy::gui; const char *const kProProductName = "Synergy 1 Pro"; SettingsDialog::SettingsDialog( - QWidget *parent, AppConfig &config, const License &license) + MainWindow *parent, AppConfig &appConfig, const IServerConfig &serverConfig, + const License &license, const CoreProcess &coreProcess) : QDialog(parent, Qt::WindowTitleHint | Qt::WindowSystemMenuHint), Ui::SettingsDialogBase(), - m_appConfig(config), + m_appConfig(appConfig), + m_serverConfig(serverConfig), m_license(license), - m_tlsUtility(config, license) { + m_coreProcess(coreProcess), + m_tlsUtility(appConfig, license) { setupUi(this); @@ -53,124 +57,18 @@ SettingsDialog::SettingsDialog( // the developer was looking at, and it's easy to accidentally save that. m_pTabWidget->setCurrentIndex(0); - m_pMainWindow = dynamic_cast(parent); - loadFromConfig(); - m_wasOriginallySystemScope = appConfig().isActiveScopeSystem(); - updateControlsEnabled(); - - const auto &serveConfig = m_pMainWindow->serverConfig(); + m_wasOriginallySystemScope = m_appConfig.isActiveScopeSystem(); + updateControls(); m_pScreenNameError = new validators::ValidationError(this); m_pLineEditScreenName->setValidator(new validators::ScreenNameValidator( - m_pLineEditScreenName, m_pScreenNameError, &serveConfig.screens())); + m_pLineEditScreenName, m_pScreenNameError, &serverConfig.screens())); } -void SettingsDialog::accept() { - if (!m_pLineEditScreenName->hasAcceptableInput()) { - QMessageBox::warning( - this, tr("Invalid screen name"), m_pScreenNameError->message()); - return; - } - - appConfig().setLoadFromSystemScope(m_pRadioSystemScope->isChecked()); - appConfig().setScreenName(m_pLineEditScreenName->text()); - appConfig().setPort(m_pSpinBoxPort->value()); - appConfig().setNetworkInterface(m_pLineEditInterface->text()); - appConfig().setLogLevel(m_pComboLogLevel->currentIndex()); - appConfig().setLogToFile(m_pCheckBoxLogToFile->isChecked()); - appConfig().setLogFilename(m_pLineEditLogFilename->text()); - appConfig().setElevateMode( - static_cast(m_pComboElevate->currentIndex())); - appConfig().setAutoHide(m_pCheckBoxAutoHide->isChecked()); - appConfig().setPreventSleep(m_pCheckBoxPreventSleep->isChecked()); - appConfig().setTlsCertPath(m_pLineEditCertificatePath->text()); - appConfig().setTlsKeyLength(m_pComboBoxKeyLength->currentText().toInt()); - appConfig().setTlsEnabled(m_pCheckBoxEnableCrypto->isChecked()); - appConfig().setLanguageSync(m_pCheckBoxLanguageSync->isChecked()); - appConfig().setInvertScrollDirection(m_pCheckBoxScrollDirection->isChecked()); - appConfig().setEnableService(m_pCheckBoxServiceEnabled->isChecked()); - appConfig().setCloseToTray(m_pCheckBoxCloseToTray->isChecked()); - appConfig().setInvertConnection(m_pInvertConnection->isChecked()); - - QDialog::accept(); -} - -void SettingsDialog::reject() { - // restore original system scope value on reject. - if (appConfig().isActiveScopeSystem() != m_wasOriginallySystemScope) { - appConfig().setLoadFromSystemScope(m_wasOriginallySystemScope); - } - - QDialog::reject(); -} - -void SettingsDialog::loadFromConfig() { - - m_pLineEditScreenName->setText(appConfig().screenName()); - m_pSpinBoxPort->setValue(appConfig().port()); - m_pLineEditInterface->setText(appConfig().networkInterface()); - m_pComboLogLevel->setCurrentIndex(appConfig().logLevel()); - m_pCheckBoxLogToFile->setChecked(appConfig().logToFile()); - m_pLineEditLogFilename->setText(appConfig().logFilename()); - m_pCheckBoxAutoHide->setChecked(appConfig().autoHide()); - m_pCheckBoxPreventSleep->setChecked(appConfig().preventSleep()); - m_pLineEditCertificatePath->setText(appConfig().tlsCertPath()); - m_pCheckBoxEnableCrypto->setChecked(m_appConfig.tlsEnabled()); - m_pCheckBoxLanguageSync->setChecked(m_appConfig.languageSync()); - m_pCheckBoxScrollDirection->setChecked(m_appConfig.invertScrollDirection()); - m_pCheckBoxServiceEnabled->setChecked(m_appConfig.enableService()); - m_pCheckBoxCloseToTray->setChecked(m_appConfig.closeToTray()); - - if (m_appConfig.isActiveScopeSystem()) { - m_pRadioSystemScope->setChecked(true); - } else { - m_pRadioUserScope->setChecked(true); - } - - m_pInvertConnection->setChecked(m_appConfig.invertConnection()); - m_pInvertConnection->setEnabled( - m_license.productEdition() == Edition::kBusiness); - - updateTlsControls(); -} - -void SettingsDialog::updateTlsControls() { - if (QFile(appConfig().tlsCertPath()).exists()) { - updateKeyLengthOnFile(appConfig().tlsCertPath()); - } else { - const auto keyLengthText = QString::number(appConfig().tlsKeyLength()); - m_pComboBoxKeyLength->setCurrentIndex( - m_pComboBoxKeyLength->findText(keyLengthText)); - } - - m_pCheckBoxEnableCrypto->setChecked(m_appConfig.tlsEnabled()); - - updateTlsControlsEnabled(); -} - -void SettingsDialog::updateTlsControlsEnabled() { - bool writable = appConfig().isActiveScopeWritable(); - auto clientMode = appConfig().clientGroupChecked(); - auto tlsAvailable = m_tlsUtility.isAvailableAndEnabled(); - auto tlsChecked = m_pCheckBoxEnableCrypto->isChecked(); - auto enabled = writable && !clientMode && tlsAvailable && tlsChecked; - - qDebug( - "tls enabled=%d, writable=%d, client=%d, available=%d, checked=%d", - enabled, writable, clientMode, tlsAvailable, tlsChecked); - - m_pLabelKeyLength->setEnabled(enabled); - m_pComboBoxKeyLength->setEnabled(enabled); - m_pLabelCertificate->setEnabled(enabled); - m_pLineEditCertificatePath->setEnabled(enabled); - m_pPushButtonBrowseCert->setEnabled(enabled); - m_pPushButtonRegenCert->setEnabled(enabled); -} - -bool SettingsDialog::isClientMode() const { - return m_pMainWindow->coreMode() == MainWindow::CoreMode::Client; -} +// +// Auto-connect slots +// void SettingsDialog::on_m_pCheckBoxLogToFile_stateChanged(int i) { bool checked = i == 2; @@ -206,9 +104,9 @@ void SettingsDialog::on_m_pCheckBoxEnableCrypto_clicked(bool) { void SettingsDialog::on_m_pRadioSystemScope_toggled(bool checked) { // We only need to test the System scoped Radio as they are connected - appConfig().setLoadFromSystemScope(checked); + m_appConfig.setLoadFromSystemScope(checked); loadFromConfig(); - updateControlsEnabled(); + updateControls(); } void SettingsDialog::on_m_pPushButtonBrowseCert_clicked() { @@ -233,18 +131,6 @@ void SettingsDialog::on_m_pComboBoxKeyLength_currentIndexChanged(int index) { updateTlsRegenerateButton(); } -void SettingsDialog::updateTlsRegenerateButton() { - const auto keyLength = m_pComboBoxKeyLength->currentText().toInt(); - auto keyChanged = appConfig().tlsKeyLength() != keyLength; - auto pathChanged = - appConfig().tlsCertPath() != m_pLineEditCertificatePath->text(); - // NOR the above bools, if any have changed regen should be disabled as it - // will be done on save - auto nor = !(keyChanged || pathChanged); - m_pPushButtonRegenCert->setEnabled( - nor && m_pCheckBoxEnableCrypto->isChecked()); -} - void SettingsDialog::on_m_pPushButtonRegenCert_clicked() { if (m_tlsUtility.generateCertificate()) { QMessageBox::information( @@ -253,6 +139,134 @@ void SettingsDialog::on_m_pPushButtonRegenCert_clicked() { } } +void SettingsDialog::on_m_pCheckBoxServiceEnabled_toggled(bool checked) { + updateControls(); +} + +// +// End of auto-connect slots +// + +void SettingsDialog::accept() { + if (!m_pLineEditScreenName->hasAcceptableInput()) { + QMessageBox::warning( + this, tr("Invalid screen name"), m_pScreenNameError->message()); + return; + } + + m_appConfig.setLoadFromSystemScope(m_pRadioSystemScope->isChecked()); + m_appConfig.setScreenName(m_pLineEditScreenName->text()); + m_appConfig.setPort(m_pSpinBoxPort->value()); + m_appConfig.setNetworkInterface(m_pLineEditInterface->text()); + m_appConfig.setLogLevel(m_pComboLogLevel->currentIndex()); + m_appConfig.setLogToFile(m_pCheckBoxLogToFile->isChecked()); + m_appConfig.setLogFilename(m_pLineEditLogFilename->text()); + m_appConfig.setElevateMode( + static_cast(m_pComboElevate->currentIndex())); + m_appConfig.setAutoHide(m_pCheckBoxAutoHide->isChecked()); + m_appConfig.setPreventSleep(m_pCheckBoxPreventSleep->isChecked()); + m_appConfig.setTlsCertPath(m_pLineEditCertificatePath->text()); + m_appConfig.setTlsKeyLength(m_pComboBoxKeyLength->currentText().toInt()); + m_appConfig.setTlsEnabled(m_pCheckBoxEnableCrypto->isChecked()); + m_appConfig.setLanguageSync(m_pCheckBoxLanguageSync->isChecked()); + m_appConfig.setInvertScrollDirection(m_pCheckBoxScrollDirection->isChecked()); + m_appConfig.setEnableService(m_pCheckBoxServiceEnabled->isChecked()); + m_appConfig.setCloseToTray(m_pCheckBoxCloseToTray->isChecked()); + m_appConfig.setInvertConnection(m_pInvertConnection->isChecked()); + + QDialog::accept(); +} + +void SettingsDialog::reject() { + // restore original system scope value on reject. + if (m_appConfig.isActiveScopeSystem() != m_wasOriginallySystemScope) { + m_appConfig.setLoadFromSystemScope(m_wasOriginallySystemScope); + } + + QDialog::reject(); +} + +void SettingsDialog::loadFromConfig() { + + m_pLineEditScreenName->setText(m_appConfig.screenName()); + m_pSpinBoxPort->setValue(m_appConfig.port()); + m_pLineEditInterface->setText(m_appConfig.networkInterface()); + m_pComboLogLevel->setCurrentIndex(m_appConfig.logLevel()); + m_pCheckBoxLogToFile->setChecked(m_appConfig.logToFile()); + m_pLineEditLogFilename->setText(m_appConfig.logFilename()); + m_pCheckBoxAutoHide->setChecked(m_appConfig.autoHide()); + m_pCheckBoxPreventSleep->setChecked(m_appConfig.preventSleep()); + m_pLineEditCertificatePath->setText(m_appConfig.tlsCertPath()); + m_pCheckBoxEnableCrypto->setChecked(m_appConfig.tlsEnabled()); + m_pCheckBoxLanguageSync->setChecked(m_appConfig.languageSync()); + m_pCheckBoxScrollDirection->setChecked(m_appConfig.invertScrollDirection()); + m_pCheckBoxServiceEnabled->setChecked(m_appConfig.enableService()); + m_pCheckBoxCloseToTray->setChecked(m_appConfig.closeToTray()); + m_pComboElevate->setCurrentIndex(static_cast(m_appConfig.elevateMode())); + + if (m_appConfig.isActiveScopeSystem()) { + m_pRadioSystemScope->setChecked(true); + } else { + m_pRadioUserScope->setChecked(true); + } + + m_pInvertConnection->setChecked(m_appConfig.invertConnection()); + m_pInvertConnection->setEnabled( + m_license.productEdition() == Edition::kBusiness); + + updateTlsControls(); +} + +void SettingsDialog::updateTlsControls() { + if (QFile(m_appConfig.tlsCertPath()).exists()) { + updateKeyLengthOnFile(m_appConfig.tlsCertPath()); + } else { + const auto keyLengthText = QString::number(m_appConfig.tlsKeyLength()); + m_pComboBoxKeyLength->setCurrentIndex( + m_pComboBoxKeyLength->findText(keyLengthText)); + } + + m_pCheckBoxEnableCrypto->setChecked(m_appConfig.tlsEnabled()); + + updateTlsControlsEnabled(); +} + +void SettingsDialog::updateTlsControlsEnabled() { + const auto writable = m_appConfig.isActiveScopeWritable(); + const auto clientMode = m_appConfig.clientGroupChecked(); + const auto tlsAvailable = m_tlsUtility.isAvailableAndEnabled(); + const auto tlsChecked = m_pCheckBoxEnableCrypto->isChecked(); + + auto enabled = writable && !clientMode && tlsAvailable && tlsChecked; + + qDebug( + "tls enabled=%d, writable=%d, client=%d, available=%d, checked=%d", + enabled, writable, clientMode, tlsAvailable, tlsChecked); + + m_pLabelKeyLength->setEnabled(enabled); + m_pComboBoxKeyLength->setEnabled(enabled); + m_pLabelCertificate->setEnabled(enabled); + m_pLineEditCertificatePath->setEnabled(enabled); + m_pPushButtonBrowseCert->setEnabled(enabled); + m_pPushButtonRegenCert->setEnabled(enabled); +} + +bool SettingsDialog::isClientMode() const { + return m_coreProcess.mode() == MainWindow::CoreMode::Client; +} + +void SettingsDialog::updateTlsRegenerateButton() { + const auto writable = m_appConfig.isActiveScopeWritable(); + const auto keyLength = m_pComboBoxKeyLength->currentText().toInt(); + const auto path = m_pLineEditCertificatePath->text(); + const auto keyChanged = m_appConfig.tlsKeyLength() != keyLength; + const auto pathChanged = m_appConfig.tlsCertPath() != path; + const auto tlsEnabled = m_pCheckBoxEnableCrypto->isChecked(); + + m_pPushButtonRegenCert->setEnabled( + writable && tlsEnabled && (keyChanged || pathChanged)); +} + void SettingsDialog::updateKeyLengthOnFile(const QString &path) { TlsCertificate ssl; if (!QFile(path).exists()) { @@ -262,52 +276,47 @@ void SettingsDialog::updateKeyLengthOnFile(const QString &path) { auto length = ssl.getCertKeyLength(path); auto index = m_pComboBoxKeyLength->findText(QString::number(length)); m_pComboBoxKeyLength->setCurrentIndex(index); - appConfig().setTlsKeyLength(length); + m_appConfig.setTlsKeyLength(length); } -void SettingsDialog::updateControlsEnabled() { - bool writable = appConfig().isActiveScopeWritable(); +void SettingsDialog::updateControls() { + +#if defined(Q_OS_WIN) + const auto serviceAvailable = true; +#else + // service not supported on unix yet, so always disable. + const auto serviceAvailable = false; +#endif + + const bool writable = m_appConfig.isActiveScopeWritable(); + const bool serviceChecked = m_pCheckBoxServiceEnabled->isChecked(); + const bool logToFile = m_pCheckBoxLogToFile->isChecked(); m_pLineEditScreenName->setEnabled(writable); m_pSpinBoxPort->setEnabled(writable); m_pLineEditInterface->setEnabled(writable); m_pComboLogLevel->setEnabled(writable); m_pCheckBoxLogToFile->setEnabled(writable); - m_pComboElevate->setEnabled(writable); m_pCheckBoxAutoHide->setEnabled(writable); m_pCheckBoxPreventSleep->setEnabled(writable); m_pLineEditCertificatePath->setEnabled(writable); m_pComboBoxKeyLength->setEnabled(writable); m_pPushButtonBrowseCert->setEnabled(writable); m_pCheckBoxEnableCrypto->setEnabled(writable); - m_pCheckBoxServiceEnabled->setEnabled(writable); m_pCheckBoxCloseToTray->setEnabled(writable); + m_pCheckBoxServiceEnabled->setEnabled(writable & serviceAvailable); + m_pLabelElevate->setEnabled(writable & serviceAvailable && serviceChecked); + m_pComboElevate->setEnabled(writable & serviceAvailable && serviceChecked); + m_pCheckBoxLanguageSync->setEnabled(writable && isClientMode()); m_pCheckBoxScrollDirection->setEnabled(writable && isClientMode()); -#if !defined(Q_OS_WIN) - m_pCheckBoxServiceEnabled->setEnabled(false); -#endif - - m_pLabelLogPath->setEnabled(writable && m_pCheckBoxLogToFile->isChecked()); - m_pLineEditLogFilename->setEnabled( - writable && m_pCheckBoxLogToFile->isChecked()); - m_pButtonBrowseLog->setEnabled(writable && m_pCheckBoxLogToFile->isChecked()); + m_pLabelLogPath->setEnabled(writable && logToFile); + m_pLineEditLogFilename->setEnabled(writable && logToFile); + m_pButtonBrowseLog->setEnabled(writable && logToFile); updateTlsControlsEnabled(); - - if (writable) { - updateTlsRegenerateButton(); - } - -#if defined(Q_OS_WIN) - m_pComboElevate->setCurrentIndex(static_cast(appConfig().elevateMode())); -#else - // elevate checkbox is only usable on ms windows. - m_pLabelElevate->setEnabled(false); - m_pComboElevate->setEnabled(false); -#endif - + updateTlsRegenerateButton(); updateTlsControls(); } diff --git a/src/gui/src/SettingsDialog.h b/src/gui/src/SettingsDialog.h index aa0e060aaa..0f6a3d51b2 100644 --- a/src/gui/src/SettingsDialog.h +++ b/src/gui/src/SettingsDialog.h @@ -20,6 +20,9 @@ #include "ui_SettingsDialogBase.h" +#include "gui/config/AppConfig.h" +#include "gui/config/IServerConfig.h" +#include "gui/core/CoreProcess.h" #include "gui/core/CoreTool.h" #include "gui/tls/TlsUtility.h" #include "license/License.h" @@ -28,15 +31,19 @@ #include class MainWindow; -class AppConfig; class SettingsDialog : public QDialog, public Ui::SettingsDialogBase { + using IServerConfig = synergy::gui::IServerConfig; + using CoreProcess = synergy::gui::CoreProcess; + using License = synergy::license::License; + Q_OBJECT public: SettingsDialog( - QWidget *parent, AppConfig &config, - const synergy::license::License &license); + MainWindow *parent, AppConfig &appConfig, + const IServerConfig &serverConfig, const License &license, + const CoreProcess &coreProcess); static QString browseForSynergyc( QWidget *parent, const QString &programDir, const QString &coreClientName); @@ -44,10 +51,19 @@ public: QWidget *parent, const QString &programDir, const QString &coreServerName); -protected: +private slots: + void on_m_pCheckBoxEnableCrypto_clicked(bool checked); + void on_m_pCheckBoxLogToFile_stateChanged(int); + void on_m_pButtonBrowseLog_clicked(); + void on_m_pRadioSystemScope_toggled(bool checked); + void on_m_pPushButtonBrowseCert_clicked(); + void on_m_pComboBoxKeyLength_currentIndexChanged(int index); + void on_m_pPushButtonRegenCert_clicked(); + void on_m_pCheckBoxServiceEnabled_toggled(bool checked); + +private: void accept() override; void reject() override; - AppConfig &appConfig() { return m_appConfig; } /// @brief Load all settings. void loadFromConfig(); @@ -59,31 +75,23 @@ protected: void updateKeyLengthOnFile(const QString &path); /// @brief Enables controls when they should be. - void updateControlsEnabled(); + void updateControls(); bool isClientMode() const; void updateTlsControls(); void updateTlsControlsEnabled(); -private: - MainWindow *m_pMainWindow; - AppConfig &m_appConfig; [[no_unique_address]] CoreTool m_coreTool; - const synergy::license::License &m_license; - synergy::gui::TlsUtility m_tlsUtility; validators::ValidationError *m_pScreenNameError; /// @brief Stores settings scope at start of settings dialog - /// This is neccessary to restore state if user changes + /// This is necessary to restore state if user changes /// the scope and doesn't save changes bool m_wasOriginallySystemScope = false; -private slots: - void on_m_pCheckBoxEnableCrypto_clicked(bool checked); - void on_m_pCheckBoxLogToFile_stateChanged(int); - void on_m_pButtonBrowseLog_clicked(); - void on_m_pRadioSystemScope_toggled(bool checked); - void on_m_pPushButtonBrowseCert_clicked(); - void on_m_pComboBoxKeyLength_currentIndexChanged(int index); - void on_m_pPushButtonRegenCert_clicked(); + AppConfig &m_appConfig; + const IServerConfig &m_serverConfig; + const License &m_license; + const CoreProcess &m_coreProcess; + synergy::gui::TlsUtility m_tlsUtility; }; diff --git a/src/gui/src/validators/ScreenDuplicationsValidator.cpp b/src/gui/src/validators/ScreenDuplicationsValidator.cpp index 7e9545c1bd..168b335189 100644 --- a/src/gui/src/validators/ScreenDuplicationsValidator.cpp +++ b/src/gui/src/validators/ScreenDuplicationsValidator.cpp @@ -1,7 +1,6 @@ /* * synergy -- mouse and keyboard sharing utility - * Copyright (C) 2012-2021 Symless Ltd. - * Copyright (C) 2008 Volker Lanz (vl@fidra.de) + * Copyright (C) 2021 Symless Ltd. * * This package is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -15,6 +14,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ + #include "ScreenDuplicationsValidator.h" namespace validators { diff --git a/src/gui/src/validators/ScreenDuplicationsValidator.h b/src/gui/src/validators/ScreenDuplicationsValidator.h index 075048977b..d54ce635d5 100644 --- a/src/gui/src/validators/ScreenDuplicationsValidator.h +++ b/src/gui/src/validators/ScreenDuplicationsValidator.h @@ -1,7 +1,6 @@ /* * synergy -- mouse and keyboard sharing utility - * Copyright (C) 2012-2021 Symless Ltd. - * Copyright (C) 2008 Volker Lanz (vl@fidra.de) + * Copyright (C) 2021 Symless Ltd. * * This package is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -15,11 +14,12 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -#ifndef SCREENDUPLICATIONSVALIDATOR_H -#define SCREENDUPLICATIONSVALIDATOR_H + +#pragma once #include "IStringValidator.h" -#include "ScreenList.h" + +#include "gui/config/ScreenList.h" namespace validators { @@ -35,5 +35,3 @@ public: }; } // namespace validators - -#endif // SCREENDUPLICATIONSVALIDATOR_H diff --git a/src/gui/src/validators/ScreenNameValidator.cpp b/src/gui/src/validators/ScreenNameValidator.cpp index 74edf74dfc..faec86e568 100644 --- a/src/gui/src/validators/ScreenNameValidator.cpp +++ b/src/gui/src/validators/ScreenNameValidator.cpp @@ -1,7 +1,6 @@ /* * synergy -- mouse and keyboard sharing utility - * Copyright (C) 2012-2021 Symless Ltd. - * Copyright (C) 2008 Volker Lanz (vl@fidra.de) + * Copyright (C) 2021 Symless Ltd. * * This package is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License diff --git a/src/gui/src/validators/ScreenNameValidator.h b/src/gui/src/validators/ScreenNameValidator.h index 8728481069..3afdc0b4d6 100644 --- a/src/gui/src/validators/ScreenNameValidator.h +++ b/src/gui/src/validators/ScreenNameValidator.h @@ -18,7 +18,7 @@ #pragma once #include "LineEditValidator.h" -#include "ScreenList.h" +#include "gui/config/ScreenList.h" #include "validators/ValidationError.h" namespace validators { diff --git a/src/lib/gui/config/IServerConfig.h b/src/lib/gui/config/IServerConfig.h index 313dda7f99..1114c97d32 100644 --- a/src/lib/gui/config/IServerConfig.h +++ b/src/lib/gui/config/IServerConfig.h @@ -20,6 +20,8 @@ #include #include +#include "ScreenList.h" + namespace synergy::gui { class IServerConfig { @@ -30,6 +32,7 @@ public: virtual bool save(const QString &fileName) const = 0; virtual void save(QFile &file) const = 0; virtual bool enableDragAndDrop() const = 0; + virtual const ScreenList &screens() const = 0; }; } // namespace synergy::gui diff --git a/src/lib/gui/config/ScreenList.h b/src/lib/gui/config/ScreenList.h index f2c247b56e..c8bd89fcc9 100644 --- a/src/lib/gui/config/ScreenList.h +++ b/src/lib/gui/config/ScreenList.h @@ -1,7 +1,6 @@ /* * synergy -- mouse and keyboard sharing utility - * Copyright (C) 2012-2021 Symless Ltd. - * Copyright (C) 2008 Volker Lanz (vl@fidra.de) + * Copyright (C) 2021 Symless Ltd. * * This package is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -15,8 +14,8 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -#ifndef SCREENLIST_H -#define SCREENLIST_H + +#pragma once #include "Screen.h" @@ -51,5 +50,3 @@ public: */ bool operator==(const ScreenList &sc) const; }; - -#endif // SCREENLIST_H diff --git a/src/test/unittests/gui/core/CoreProcessTests.cpp b/src/test/unittests/gui/core/CoreProcessTests.cpp index 73ab3aa917..35a5f3d512 100644 --- a/src/test/unittests/gui/core/CoreProcessTests.cpp +++ b/src/test/unittests/gui/core/CoreProcessTests.cpp @@ -75,6 +75,7 @@ public: MOCK_METHOD(bool, save, (const QString &fileName), (const, override)); MOCK_METHOD(void, save, (QFile & file), (const, override)); MOCK_METHOD(bool, enableDragAndDrop, (), (const, override)); + MOCK_METHOD(const ScreenList &, screens, (), (const, override)); }; class MockQProcessProxy : public proxy::QProcessProxy {