From ef186d398d5f820f772922945dc3ece6121a0c47 Mon Sep 17 00:00:00 2001 From: Nick Bolton Date: Fri, 9 Aug 2024 09:08:29 +0100 Subject: [PATCH] Improve setting enable logic and test coverage (#7430) * Rename controls and improve setting enable logic * Move settings dialog to new lib * Rename dialog to dialogs * Include .ui files for GUI lib and include autogen headers in exe * Unit test settings dialog * Fix lint errors * Update ChangeLog * Fixed test name * Add debug messages * Tweak message * Logging for CI issue * Revert "Logging for CI issue" This reverts commit 124b2c1acd778f1e422057e203436582fe12d147. * Revert "Add debug messages" This reverts commit 39b6a06c716965e0a8199bf34b6652861874cb28. * Add Windows compiler error * Exclude test on Windows --- ChangeLog | 1 + cspell.json | 1 + src/gui/CMakeLists.txt | 5 ++ src/gui/src/MainWindow.cpp | 2 +- src/gui/src/MainWindowBase.ui | 12 +-- src/gui/src/ScreenSettingsDialog.cpp | 6 +- src/gui/src/SetupWizard.cpp | 4 +- src/lib/gui/CMakeLists.txt | 3 +- src/lib/gui/config/AppConfig.h | 57 +++++++------ src/lib/gui/config/IAppConfig.h | 35 ++++++++ src/lib/gui/constants.h | 2 + .../gui/dialogs}/SettingsDialog.cpp | 84 +++++++++---------- .../src => lib/gui/dialogs}/SettingsDialog.h | 28 +++---- .../gui/dialogs}/SettingsDialogBase.ui | 24 +++--- .../src => lib/gui/dialogs}/UpgradeDialog.cpp | 15 ++-- .../src => lib/gui/dialogs}/UpgradeDialog.h | 2 + .../gui}/validators/AliasValidator.cpp | 4 +- .../gui}/validators/AliasValidator.h | 2 +- .../gui}/validators/ComputerNameValidator.cpp | 4 +- .../gui}/validators/ComputerNameValidator.h | 5 +- .../gui}/validators/EmptyStringValidator.cpp | 4 +- .../gui}/validators/EmptyStringValidator.h | 9 +- .../gui}/validators/IStringValidator.cpp | 6 +- .../gui}/validators/IStringValidator.h | 9 +- .../gui}/validators/LineEditValidator.cpp | 0 .../gui}/validators/LineEditValidator.h | 0 .../ScreenDuplicationsValidator.cpp | 0 .../validators/ScreenDuplicationsValidator.h | 0 .../gui}/validators/ScreenNameValidator.cpp | 10 +-- .../gui}/validators/ScreenNameValidator.h | 2 +- .../gui}/validators/SpacesValidator.cpp | 4 +- .../gui}/validators/SpacesValidator.h | 8 +- .../gui}/validators/ValidationError.cpp | 0 .../gui}/validators/ValidationError.h | 2 +- .../gui}/widgets/ClientStateLabel.cpp | 8 +- .../gui}/widgets/ClientStateLabel.h | 12 +-- .../gui}/widgets/ServerStateLabel.cpp | 7 +- .../gui}/widgets/ServerStateLabel.h | 12 +-- src/test/CMakeLists.txt | 4 + src/test/shared/gui/TestQtCoreApp.h | 4 +- src/test/shared/gui/TestQtFullApp.h | 10 ++- src/test/shared/gui/mocks/AppConfigMock.h | 52 ++++++++++-- src/test/shared/gui/mocks/ServerConfigMock.h | 7 ++ .../gui/dialogs/SettingsDialogTests.cpp | 50 +++++++++++ src/test/unittests/main.cpp | 2 +- 45 files changed, 321 insertions(+), 197 deletions(-) rename src/{gui/src => lib/gui/dialogs}/SettingsDialog.cpp (79%) rename src/{gui/src => lib/gui/dialogs}/SettingsDialog.h (76%) rename src/{gui/src => lib/gui/dialogs}/SettingsDialogBase.ui (97%) rename src/{gui/src => lib/gui/dialogs}/UpgradeDialog.cpp (71%) rename src/{gui/src => lib/gui/dialogs}/UpgradeDialog.h (99%) rename src/{gui/src => lib/gui}/validators/AliasValidator.cpp (92%) rename src/{gui/src => lib/gui}/validators/AliasValidator.h (95%) rename src/{gui/src => lib/gui}/validators/ComputerNameValidator.cpp (92%) rename src/{gui/src => lib/gui}/validators/ComputerNameValidator.h (86%) rename src/{gui/src => lib/gui}/validators/EmptyStringValidator.cpp (91%) rename src/{gui/src => lib/gui}/validators/EmptyStringValidator.h (83%) rename src/{gui/src => lib/gui}/validators/IStringValidator.cpp (87%) rename src/{gui/src => lib/gui}/validators/IStringValidator.h (86%) rename src/{gui/src => lib/gui}/validators/LineEditValidator.cpp (100%) rename src/{gui/src => lib/gui}/validators/LineEditValidator.h (100%) rename src/{gui/src => lib/gui}/validators/ScreenDuplicationsValidator.cpp (100%) rename src/{gui/src => lib/gui}/validators/ScreenDuplicationsValidator.h (100%) rename src/{gui/src => lib/gui}/validators/ScreenNameValidator.cpp (85%) rename src/{gui/src => lib/gui}/validators/ScreenNameValidator.h (95%) rename src/{gui/src => lib/gui}/validators/SpacesValidator.cpp (91%) rename src/{gui/src => lib/gui}/validators/SpacesValidator.h (84%) rename src/{gui/src => lib/gui}/validators/ValidationError.cpp (100%) rename src/{gui/src => lib/gui}/validators/ValidationError.h (96%) rename src/{gui/src => lib/gui}/widgets/ClientStateLabel.cpp (87%) rename src/{gui/src => lib/gui}/widgets/ClientStateLabel.h (78%) rename src/{gui/src => lib/gui}/widgets/ServerStateLabel.cpp (92%) rename src/{gui/src => lib/gui}/widgets/ServerStateLabel.h (79%) create mode 100644 src/test/unittests/gui/dialogs/SettingsDialogTests.cpp diff --git a/ChangeLog b/ChangeLog index 4ead106de..025f8dd74 100644 --- a/ChangeLog +++ b/ChangeLog @@ -73,6 +73,7 @@ Enhancements: - #7427 More reliable button click detection for add client dialog - #7428 Refactor settings dialog to simplify enable/disable logic - #7429 Parse date numbers as long instead of int +- #7430 Improve setting enable logic and test coverage # 1.14.6 diff --git a/cspell.json b/cspell.json index 5385c2b75..d1b4f36aa 100644 --- a/cspell.json +++ b/cspell.json @@ -37,6 +37,7 @@ "Pixmap", "Poschta", "Priddy", + "Regen", "runas", "Sbârnea", "Schoeneman", diff --git a/src/gui/CMakeLists.txt b/src/gui/CMakeLists.txt index 9bffab945..f795fa28e 100644 --- a/src/gui/CMakeLists.txt +++ b/src/gui/CMakeLists.txt @@ -41,8 +41,13 @@ add_executable( res/Synergy.qrc ${QM_FILES}) +# regular exe headers include_directories(./src) +# gui library autogen headers: +# qt doesn't seem to auto include the autogen headers for libraries. +include_directories(${CMAKE_BINARY_DIR}/src/lib/gui/gui_autogen/include) + target_link_libraries( ${target} gui diff --git a/src/gui/src/MainWindow.cpp b/src/gui/src/MainWindow.cpp index 7ca0627bd..96e5af512 100644 --- a/src/gui/src/MainWindow.cpp +++ b/src/gui/src/MainWindow.cpp @@ -21,13 +21,13 @@ #include "AboutDialog.h" #include "ActivationDialog.h" #include "ServerConfigDialog.h" -#include "SettingsDialog.h" #include "gui/Logger.h" #include "gui/TrayIcon.h" #include "gui/VersionChecker.h" #include "gui/config/ConfigScopes.h" #include "gui/constants.h" #include "gui/core/CoreProcess.h" +#include "gui/dialogs/SettingsDialog.h" #include "gui/license/LicenseHandler.h" #include "gui/license/license_notices.h" #include "gui/messages.h" diff --git a/src/gui/src/MainWindowBase.ui b/src/gui/src/MainWindowBase.ui index e94472853..01116ab7e 100644 --- a/src/gui/src/MainWindowBase.ui +++ b/src/gui/src/MainWindowBase.ui @@ -201,7 +201,7 @@ - + No clients connected @@ -358,7 +358,7 @@ - + Connected to server @@ -662,14 +662,14 @@ - synergy_widgets::ServerStateLabel + synergy::gui::widgets::ServerStateLabel QLabel -
widgets/ServerStateLabel.h
+
gui/widgets/ServerStateLabel.h
- synergy_widgets::ClientStateLabel + synergy::gui::widgets::ClientStateLabel QLabel -
widgets/ClientStateLabel.h
+
gui/widgets/ClientStateLabel.h
diff --git a/src/gui/src/ScreenSettingsDialog.cpp b/src/gui/src/ScreenSettingsDialog.cpp index 4e58f601e..742435485 100644 --- a/src/gui/src/ScreenSettingsDialog.cpp +++ b/src/gui/src/ScreenSettingsDialog.cpp @@ -20,9 +20,9 @@ #include "gui/config/Screen.h" #include "gui/styles.h" -#include "validators/AliasValidator.h" -#include "validators/ScreenNameValidator.h" -#include "validators/ValidationError.h" +#include "gui/validators/AliasValidator.h" +#include "gui/validators/ScreenNameValidator.h" +#include "gui/validators/ValidationError.h" #include #include diff --git a/src/gui/src/SetupWizard.cpp b/src/gui/src/SetupWizard.cpp index 405bc9c24..94f9281d9 100644 --- a/src/gui/src/SetupWizard.cpp +++ b/src/gui/src/SetupWizard.cpp @@ -18,8 +18,8 @@ #include "SetupWizard.h" #include "gui/styles.h" -#include "validators/ScreenNameValidator.h" -#include "validators/ValidationError.h" +#include "gui/validators/ScreenNameValidator.h" +#include "gui/validators/ValidationError.h" using namespace synergy::gui; diff --git a/src/lib/gui/CMakeLists.txt b/src/lib/gui/CMakeLists.txt index 6952269a0..47f712198 100644 --- a/src/lib/gui/CMakeLists.txt +++ b/src/lib/gui/CMakeLists.txt @@ -22,6 +22,7 @@ set(CMAKE_INCLUDE_CURRENT_DIR ON) file(GLOB_RECURSE sources *.cpp) file(GLOB_RECURSE headers *.h) +file(GLOB_RECURSE ui_files *.ui) if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin") file(GLOB mac_sources *.mm) @@ -32,7 +33,7 @@ if(ADD_HEADERS_TO_SOURCES) list(APPEND sources ${headers}) endif() -add_library(${target} STATIC ${sources}) +add_library(${target} STATIC ${sources} ${ui_files}) target_link_libraries( ${target} global diff --git a/src/lib/gui/config/AppConfig.h b/src/lib/gui/config/AppConfig.h index ebe7e9506..07503c17b 100644 --- a/src/lib/gui/config/AppConfig.h +++ b/src/lib/gui/config/AppConfig.h @@ -139,6 +139,7 @@ public: // // Getters (overrides) // + ProcessMode processMode() const override; ElevateMode elevateMode() const override; bool tlsEnabled() const override; @@ -161,25 +162,25 @@ public: const QString &configFile() const override; const QString &networkInterface() const override; const QString &serverHostname() const override; + bool isActiveScopeWritable() const override; + bool isActiveScopeSystem() const override; + int logLevel() const override; + bool autoHide() const override; + bool enableService() const override; + bool closeToTray() const override; + bool clientGroupChecked() const override; // // Getters (new methods) // - bool isActiveScopeWritable() const; - bool isActiveScopeSystem() const; - int logLevel() const; bool wizardShouldRun() const; bool startedBefore() const; QString logDir() const; - bool autoHide() const; unsigned long long licenseNextCheck() const; bool serverGroupChecked() const; bool useInternalConfig() const; - bool clientGroupChecked() const; QString lastVersion() const; - bool enableService() const; - bool closeToTray() const; bool activationHasRun() const; std::optional mainWindowSize() const; std::optional mainWindowPosition() const; @@ -187,27 +188,36 @@ public: bool showCloseReminder() const; // - // Setters + // Setters (overrides) + // + void setScreenName(const QString &s) override; + void setPort(int i) override; + void setNetworkInterface(const QString &s) override; + void setLogLevel(int i) override; + void setLogToFile(bool b) override; + void setLogFilename(const QString &s) override; + void setElevateMode(ElevateMode em) override; + void setTlsEnabled(bool e) override; + void setAutoHide(bool b) override; + void setInvertScrollDirection(bool b) override; + void setLanguageSync(bool b) override; + void setPreventSleep(bool b) override; + void setEnableService(bool enabled) override; + void setCloseToTray(bool minimize) override; + void setTlsCertPath(const QString &path) override; + void setTlsKeyLength(int length) override; + void setInvertConnection(bool value) override; + + // + // Setters (new methods) // void setActivationHasRun(bool value); - void setScreenName(const QString &s); - void setPort(int i); - void setNetworkInterface(const QString &s); - void setLogLevel(int i); - void setLogToFile(bool b); - void setLogFilename(const QString &s); void setWizardHasRun(); void setStartedBefore(bool b); - void setElevateMode(ElevateMode em); - void setTlsEnabled(bool e); void setSerialKey(const QString &serialKey); void clearSerialKey(); - void setAutoHide(bool b); - void setInvertScrollDirection(bool b); void setLicenseNextCheck(unsigned long long); - void setLanguageSync(bool b); - void setPreventSleep(bool b); void setServerGroupChecked(bool); void setUseExternalConfig(bool); void setConfigFile(const QString &); @@ -215,11 +225,6 @@ public: void setClientGroupChecked(bool); void setServerHostname(const QString &); void setLastVersion(const QString &version); - void setEnableService(bool enabled); - void setCloseToTray(bool minimize); - void setTlsCertPath(const QString &path); - void setTlsKeyLength(int length); - void setInvertConnection(bool value); void setMainWindowSize(const QSize &size); void setMainWindowPosition(const QPoint &position); void setShowDevThanks(bool show); @@ -230,7 +235,7 @@ public: /// True - This will set the variable and load the global scope /// settings. False - This will set the variable and load the user /// scope settings. - void setLoadFromSystemScope(bool value); + void setLoadFromSystemScope(bool value) override; private: static QString settingName(AppConfig::Setting name); diff --git a/src/lib/gui/config/IAppConfig.h b/src/lib/gui/config/IAppConfig.h index 460c25b9a..ccedba6ac 100644 --- a/src/lib/gui/config/IAppConfig.h +++ b/src/lib/gui/config/IAppConfig.h @@ -28,6 +28,11 @@ enum class ProcessMode { kService, kDesktop }; class IAppConfig { public: virtual ~IAppConfig() = default; + + // + // Setters + // + virtual QString tlsCertPath() const = 0; virtual int tlsKeyLength() const = 0; virtual bool tlsEnabled() const = 0; @@ -50,6 +55,36 @@ public: virtual const QString &configFile() const = 0; virtual const QString &networkInterface() const = 0; virtual const QString &serverHostname() const = 0; + virtual int logLevel() const = 0; + virtual bool autoHide() const = 0; + virtual bool enableService() const = 0; + virtual bool closeToTray() const = 0; + virtual bool isActiveScopeSystem() const = 0; + virtual bool isActiveScopeWritable() const = 0; + virtual bool clientGroupChecked() const = 0; + + // + // Getters + // + + virtual void setLoadFromSystemScope(bool loadFromSystemScope) = 0; + virtual void setScreenName(const QString &screenName) = 0; + virtual void setPort(int port) = 0; + virtual void setNetworkInterface(const QString &networkInterface) = 0; + virtual void setLogLevel(int logLevel) = 0; + virtual void setLogToFile(bool logToFile) = 0; + virtual void setLogFilename(const QString &logFilename) = 0; + virtual void setElevateMode(ElevateMode elevateMode) = 0; + virtual void setAutoHide(bool autoHide) = 0; + virtual void setPreventSleep(bool preventSleep) = 0; + virtual void setTlsCertPath(const QString &tlsCertPath) = 0; + virtual void setTlsKeyLength(int tlsKeyLength) = 0; + virtual void setTlsEnabled(bool tlsEnabled) = 0; + virtual void setLanguageSync(bool languageSync) = 0; + virtual void setInvertScrollDirection(bool invertScrollDirection) = 0; + virtual void setEnableService(bool enableService) = 0; + virtual void setCloseToTray(bool closeToTray) = 0; + virtual void setInvertConnection(bool invertConnection) = 0; }; } // namespace synergy::gui diff --git a/src/lib/gui/constants.h b/src/lib/gui/constants.h index eb11ceea1..7e8da3f59 100644 --- a/src/lib/gui/constants.h +++ b/src/lib/gui/constants.h @@ -62,6 +62,8 @@ const auto kUrlGnomeTrayFix = const auto kUrlProduct = QString("%1/synergy").arg(kUrlWebsite); const auto kUrlPurchase = QString("%1/purchase?%2").arg(kUrlProduct, kUrlSourceQuery); +const auto kUrlUpgrade = + QString("%1/purchase/upgrade?%2").arg(kUrlProduct, kUrlSourceQuery); const auto kUrlContact = QString("%1/contact?%2").arg(kUrlProduct, kUrlSourceQuery); const auto kUrlHelp = QString("%1/help?%2").arg(kUrlProduct, kUrlSourceQuery); diff --git a/src/gui/src/SettingsDialog.cpp b/src/lib/gui/dialogs/SettingsDialog.cpp similarity index 79% rename from src/gui/src/SettingsDialog.cpp rename to src/lib/gui/dialogs/SettingsDialog.cpp index e0d34ba8e..8d1a03da5 100644 --- a/src/gui/src/SettingsDialog.cpp +++ b/src/lib/gui/dialogs/SettingsDialog.cpp @@ -18,14 +18,13 @@ #include "SettingsDialog.h" -#include "MainWindow.h" #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" -#include "validators/ValidationError.h" +#include "gui/validators/ScreenNameValidator.h" +#include "gui/validators/ValidationError.h" #include #include @@ -39,7 +38,7 @@ using namespace synergy::gui; const char *const kProProductName = "Synergy 1 Pro"; SettingsDialog::SettingsDialog( - MainWindow *parent, AppConfig &appConfig, const IServerConfig &serverConfig, + QWidget *parent, IAppConfig &appConfig, const IServerConfig &serverConfig, const License &license, const CoreProcess &coreProcess) : QDialog(parent, Qt::WindowTitleHint | Qt::WindowSystemMenuHint), Ui::SettingsDialogBase(), @@ -86,10 +85,12 @@ void SettingsDialog::on_m_pButtonBrowseLog_clicked() { } } -void SettingsDialog::on_m_pCheckBoxEnableCrypto_clicked(bool) { +void SettingsDialog::on_m_pCheckBoxEnableTls_clicked(bool) { updateTlsControlsEnabled(); if (kEnableActivation && !m_tlsUtility.isAvailable()) { + m_pCheckBoxEnableTls->setChecked(false); + auto edition = m_license.productEdition(); if (edition == Edition::kBasic) { UpgradeDialog upgradeDialog(this); @@ -107,14 +108,14 @@ void SettingsDialog::on_m_pRadioSystemScope_toggled(bool checked) { updateControls(); } -void SettingsDialog::on_m_pPushButtonBrowseCert_clicked() { +void SettingsDialog::on_m_pPushButtonTlsCertPath_clicked() { QString fileName = QFileDialog::getSaveFileName( this, tr("Select a TLS certificate to use..."), - m_pLineEditCertificatePath->text(), "Cert (*.pem)", nullptr, + m_pLineEditTlsCertPath->text(), "Cert (*.pem)", nullptr, QFileDialog::DontConfirmOverwrite); if (!fileName.isEmpty()) { - m_pLineEditCertificatePath->setText(fileName); + m_pLineEditTlsCertPath->setText(fileName); if (QFile(fileName).exists()) { updateKeyLengthOnFile(fileName); @@ -125,11 +126,11 @@ void SettingsDialog::on_m_pPushButtonBrowseCert_clicked() { updateTlsRegenerateButton(); } -void SettingsDialog::on_m_pComboBoxKeyLength_currentIndexChanged(int index) { +void SettingsDialog::on_m_pComboBoxTlsKeyLength_currentIndexChanged(int) { updateTlsRegenerateButton(); } -void SettingsDialog::on_m_pPushButtonRegenCert_clicked() { +void SettingsDialog::on_m_pPushButtonTlsRegenCert_clicked() { if (m_tlsUtility.generateCertificate()) { QMessageBox::information( this, tr("TLS Certificate Regenerated"), @@ -163,9 +164,9 @@ void SettingsDialog::accept() { 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.setTlsCertPath(m_pLineEditTlsCertPath->text()); + m_appConfig.setTlsKeyLength(m_pComboBoxTlsKeyLength->currentText().toInt()); + m_appConfig.setTlsEnabled(m_pCheckBoxEnableTls->isChecked()); m_appConfig.setLanguageSync(m_pCheckBoxLanguageSync->isChecked()); m_appConfig.setInvertScrollDirection(m_pCheckBoxScrollDirection->isChecked()); m_appConfig.setEnableService(m_pCheckBoxServiceEnabled->isChecked()); @@ -194,8 +195,6 @@ void SettingsDialog::loadFromConfig() { 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()); @@ -216,15 +215,20 @@ void SettingsDialog::loadFromConfig() { } 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_pComboBoxTlsKeyLength->setCurrentIndex( + m_pComboBoxTlsKeyLength->findText(keyLengthText)); } - m_pCheckBoxEnableCrypto->setChecked(m_appConfig.tlsEnabled()); + const auto tlsEnabled = m_tlsUtility.isAvailableAndEnabled(); + const auto writable = m_appConfig.isActiveScopeWritable(); + + m_pCheckBoxEnableTls->setChecked(writable && tlsEnabled); + m_pLineEditTlsCertPath->setText(m_appConfig.tlsCertPath()); updateTlsControlsEnabled(); } @@ -232,36 +236,30 @@ void SettingsDialog::updateTlsControls() { 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(); + const auto tlsChecked = m_pCheckBoxEnableTls->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); + auto enabled = writable && tlsChecked && !clientMode; + m_pLabelTlsKeyLength->setEnabled(enabled); + m_pComboBoxTlsKeyLength->setEnabled(enabled); + m_pLabelTlsCert->setEnabled(enabled); + m_pLineEditTlsCertPath->setEnabled(enabled); + m_pPushButtonTlsCertPath->setEnabled(enabled); + m_pPushButtonTlsRegenCert->setEnabled(enabled); } bool SettingsDialog::isClientMode() const { - return m_coreProcess.mode() == MainWindow::CoreMode::Client; + return m_coreProcess.mode() == synergy::gui::CoreProcess::Mode::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 keyLength = m_pComboBoxTlsKeyLength->currentText().toInt(); + const auto path = m_pLineEditTlsCertPath->text(); const auto keyChanged = m_appConfig.tlsKeyLength() != keyLength; const auto pathChanged = m_appConfig.tlsCertPath() != path; - const auto tlsEnabled = m_pCheckBoxEnableCrypto->isChecked(); + const auto tlsEnabled = m_pCheckBoxEnableTls->isChecked(); - m_pPushButtonRegenCert->setEnabled( + m_pPushButtonTlsRegenCert->setEnabled( writable && tlsEnabled && (keyChanged || pathChanged)); } @@ -272,8 +270,8 @@ void SettingsDialog::updateKeyLengthOnFile(const QString &path) { } auto length = ssl.getCertKeyLength(path); - auto index = m_pComboBoxKeyLength->findText(QString::number(length)); - m_pComboBoxKeyLength->setCurrentIndex(index); + auto index = m_pComboBoxTlsKeyLength->findText(QString::number(length)); + m_pComboBoxTlsKeyLength->setCurrentIndex(index); m_appConfig.setTlsKeyLength(length); } @@ -298,10 +296,8 @@ void SettingsDialog::updateControls() { m_pCheckBoxLogToFile->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_pLineEditTlsCertPath->setEnabled(writable); + m_pComboBoxTlsKeyLength->setEnabled(writable); m_pCheckBoxCloseToTray->setEnabled(writable); m_pCheckBoxServiceEnabled->setEnabled(writable && serviceAvailable); diff --git a/src/gui/src/SettingsDialog.h b/src/lib/gui/dialogs/SettingsDialog.h similarity index 76% rename from src/gui/src/SettingsDialog.h rename to src/lib/gui/dialogs/SettingsDialog.h index 0f6a3d51b..b536ee6e6 100644 --- a/src/gui/src/SettingsDialog.h +++ b/src/lib/gui/dialogs/SettingsDialog.h @@ -20,19 +20,18 @@ #include "ui_SettingsDialogBase.h" -#include "gui/config/AppConfig.h" +#include "gui/config/IAppConfig.h" #include "gui/config/IServerConfig.h" #include "gui/core/CoreProcess.h" #include "gui/core/CoreTool.h" #include "gui/tls/TlsUtility.h" +#include "gui/validators/ValidationError.h" #include "license/License.h" -#include "validators/ValidationError.h" #include -class MainWindow; - class SettingsDialog : public QDialog, public Ui::SettingsDialogBase { + using IAppConfig = synergy::gui::IAppConfig; using IServerConfig = synergy::gui::IServerConfig; using CoreProcess = synergy::gui::CoreProcess; using License = synergy::license::License; @@ -41,24 +40,17 @@ class SettingsDialog : public QDialog, public Ui::SettingsDialogBase { public: SettingsDialog( - MainWindow *parent, AppConfig &appConfig, - const IServerConfig &serverConfig, const License &license, - const CoreProcess &coreProcess); - static QString browseForSynergyc( - QWidget *parent, const QString &programDir, - const QString &coreClientName); - static QString browseForSynergys( - QWidget *parent, const QString &programDir, - const QString &coreServerName); + QWidget *parent, IAppConfig &appConfig, const IServerConfig &serverConfig, + const License &license, const CoreProcess &coreProcess); private slots: - void on_m_pCheckBoxEnableCrypto_clicked(bool checked); + void on_m_pCheckBoxEnableTls_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_pPushButtonTlsCertPath_clicked(); + void on_m_pComboBoxTlsKeyLength_currentIndexChanged(int index); + void on_m_pPushButtonTlsRegenCert_clicked(); void on_m_pCheckBoxServiceEnabled_toggled(bool checked); private: @@ -89,7 +81,7 @@ private: /// the scope and doesn't save changes bool m_wasOriginallySystemScope = false; - AppConfig &m_appConfig; + IAppConfig &m_appConfig; const IServerConfig &m_serverConfig; const License &m_license; const CoreProcess &m_coreProcess; diff --git a/src/gui/src/SettingsDialogBase.ui b/src/lib/gui/dialogs/SettingsDialogBase.ui similarity index 97% rename from src/gui/src/SettingsDialogBase.ui rename to src/lib/gui/dialogs/SettingsDialogBase.ui index fb4ddd1c9..c4f2c9dcd 100644 --- a/src/gui/src/SettingsDialogBase.ui +++ b/src/lib/gui/dialogs/SettingsDialogBase.ui @@ -165,7 +165,7 @@ 0 - + true @@ -188,7 +188,7 @@ - + 0 @@ -201,7 +201,7 @@ - + 1024 @@ -230,7 +230,7 @@ 0 - + 0 @@ -259,7 +259,7 @@ - + 0 @@ -269,7 +269,7 @@ - + PointingHandCursor @@ -312,7 +312,7 @@ - + Regenerate certificate @@ -740,11 +740,11 @@ m_pLineEditScreenName m_pSpinBoxPort m_pLineEditInterface - m_pCheckBoxEnableCrypto - m_pComboBoxKeyLength - m_pLineEditCertificatePath - m_pPushButtonBrowseCert - m_pPushButtonRegenCert + m_pCheckBoxEnableTls + m_pComboBoxTlsKeyLength + m_pLineEditTlsCertPath + m_pPushButtonTlsCertPath + m_pPushButtonTlsRegenCert m_pCheckBoxLogToFile m_pComboLogLevel m_pLineEditLogFilename diff --git a/src/gui/src/UpgradeDialog.cpp b/src/lib/gui/dialogs/UpgradeDialog.cpp similarity index 71% rename from src/gui/src/UpgradeDialog.cpp rename to src/lib/gui/dialogs/UpgradeDialog.cpp index 8a7bb6e73..40a4b98ec 100644 --- a/src/gui/src/UpgradeDialog.cpp +++ b/src/lib/gui/dialogs/UpgradeDialog.cpp @@ -14,23 +14,24 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ + #include "UpgradeDialog.h" +#include "gui/constants.h" + #include #include UpgradeDialog::UpgradeDialog(QWidget *parent) : QMessageBox(parent) { - setWindowTitle(QObject::tr("Upgrade to access this feature")); - addButton(QObject::tr("Close"), QMessageBox::RejectRole); - addButton(QObject::tr("Upgrade"), QMessageBox::AcceptRole); + setWindowTitle("Upgrade to access this feature"); + addButton("Cancel", QMessageBox::RejectRole); + addButton("Upgrade", QMessageBox::AcceptRole); } void UpgradeDialog::showDialog(const QString &text) { - setText(QObject::tr(text.toStdString().c_str())); + setText(text); if (exec() == QMessageBox::Accepted) { - QDesktopServices::openUrl(QUrl( - QCoreApplication::organizationDomain() + - "/synergy/purchase/upgrade?source=gui")); + QDesktopServices::openUrl(QUrl(synergy::gui::kUrlUpgrade)); } } diff --git a/src/gui/src/UpgradeDialog.h b/src/lib/gui/dialogs/UpgradeDialog.h similarity index 99% rename from src/gui/src/UpgradeDialog.h rename to src/lib/gui/dialogs/UpgradeDialog.h index f9371af5a..85876d804 100644 --- a/src/gui/src/UpgradeDialog.h +++ b/src/lib/gui/dialogs/UpgradeDialog.h @@ -14,7 +14,9 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ + #pragma once + #include class UpgradeDialog : public QMessageBox { diff --git a/src/gui/src/validators/AliasValidator.cpp b/src/lib/gui/validators/AliasValidator.cpp similarity index 92% rename from src/gui/src/validators/AliasValidator.cpp rename to src/lib/gui/validators/AliasValidator.cpp index 010c54f54..62834e91f 100644 --- a/src/gui/src/validators/AliasValidator.cpp +++ b/src/lib/gui/validators/AliasValidator.cpp @@ -15,8 +15,8 @@ * along with this program. If not, see . */ -#include "validators/ComputerNameValidator.h" -#include "validators/SpacesValidator.h" +#include "gui/validators/ComputerNameValidator.h" +#include "gui/validators/SpacesValidator.h" #include "AliasValidator.h" diff --git a/src/gui/src/validators/AliasValidator.h b/src/lib/gui/validators/AliasValidator.h similarity index 95% rename from src/gui/src/validators/AliasValidator.h rename to src/lib/gui/validators/AliasValidator.h index b3bbc366b..36fc0f327 100644 --- a/src/gui/src/validators/AliasValidator.h +++ b/src/lib/gui/validators/AliasValidator.h @@ -18,7 +18,7 @@ #pragma once #include "LineEditValidator.h" -#include "validators/ValidationError.h" +#include "gui/validators/ValidationError.h" namespace validators { diff --git a/src/gui/src/validators/ComputerNameValidator.cpp b/src/lib/gui/validators/ComputerNameValidator.cpp similarity index 92% rename from src/gui/src/validators/ComputerNameValidator.cpp rename to src/lib/gui/validators/ComputerNameValidator.cpp index d5bbd34a7..15ab4d292 100644 --- a/src/gui/src/validators/ComputerNameValidator.cpp +++ b/src/lib/gui/validators/ComputerNameValidator.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 "ComputerNameValidator.h" #include diff --git a/src/gui/src/validators/ComputerNameValidator.h b/src/lib/gui/validators/ComputerNameValidator.h similarity index 86% rename from src/gui/src/validators/ComputerNameValidator.h rename to src/lib/gui/validators/ComputerNameValidator.h index 66f8f48d4..3ddea8e54 100644 --- a/src/gui/src/validators/ComputerNameValidator.h +++ b/src/lib/gui/validators/ComputerNameValidator.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 @@ -26,7 +25,7 @@ namespace validators { class ComputerNameValidator : public IStringValidator { public: - ComputerNameValidator(const QString &message); + explicit ComputerNameValidator(const QString &message); bool validate(const QString &input) const override; }; diff --git a/src/gui/src/validators/EmptyStringValidator.cpp b/src/lib/gui/validators/EmptyStringValidator.cpp similarity index 91% rename from src/gui/src/validators/EmptyStringValidator.cpp rename to src/lib/gui/validators/EmptyStringValidator.cpp index f1392cbef..bb43ae9b9 100644 --- a/src/gui/src/validators/EmptyStringValidator.cpp +++ b/src/lib/gui/validators/EmptyStringValidator.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 "EmptyStringValidator.h" namespace validators { diff --git a/src/gui/src/validators/EmptyStringValidator.h b/src/lib/gui/validators/EmptyStringValidator.h similarity index 83% rename from src/gui/src/validators/EmptyStringValidator.h rename to src/lib/gui/validators/EmptyStringValidator.h index 8677cc4b7..cd44ff202 100644 --- a/src/gui/src/validators/EmptyStringValidator.h +++ b/src/lib/gui/validators/EmptyStringValidator.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 EMPTYSTRINGVALIDATOR_H -#define EMPTYSTRINGVALIDATOR_H + +#pragma once #include "IStringValidator.h" @@ -29,5 +28,3 @@ public: }; } // namespace validators - -#endif // EMPTYSTRINGVALIDATOR_H diff --git a/src/gui/src/validators/IStringValidator.cpp b/src/lib/gui/validators/IStringValidator.cpp similarity index 87% rename from src/gui/src/validators/IStringValidator.cpp rename to src/lib/gui/validators/IStringValidator.cpp index 7a9bbf267..32f65e8bf 100644 --- a/src/gui/src/validators/IStringValidator.cpp +++ b/src/lib/gui/validators/IStringValidator.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,7 +14,8 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -#include "EmptyStringValidator.h" + +#include "IStringValidator.h" namespace validators { diff --git a/src/gui/src/validators/IStringValidator.h b/src/lib/gui/validators/IStringValidator.h similarity index 86% rename from src/gui/src/validators/IStringValidator.h rename to src/lib/gui/validators/IStringValidator.h index bb70600ed..2275dcd9d 100644 --- a/src/gui/src/validators/IStringValidator.h +++ b/src/lib/gui/validators/IStringValidator.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 IVALIDATOR_H -#define IVALIDATOR_H + +#pragma once #include @@ -35,5 +34,3 @@ public: }; } // namespace validators - -#endif // IVALIDATOR_H diff --git a/src/gui/src/validators/LineEditValidator.cpp b/src/lib/gui/validators/LineEditValidator.cpp similarity index 100% rename from src/gui/src/validators/LineEditValidator.cpp rename to src/lib/gui/validators/LineEditValidator.cpp diff --git a/src/gui/src/validators/LineEditValidator.h b/src/lib/gui/validators/LineEditValidator.h similarity index 100% rename from src/gui/src/validators/LineEditValidator.h rename to src/lib/gui/validators/LineEditValidator.h diff --git a/src/gui/src/validators/ScreenDuplicationsValidator.cpp b/src/lib/gui/validators/ScreenDuplicationsValidator.cpp similarity index 100% rename from src/gui/src/validators/ScreenDuplicationsValidator.cpp rename to src/lib/gui/validators/ScreenDuplicationsValidator.cpp diff --git a/src/gui/src/validators/ScreenDuplicationsValidator.h b/src/lib/gui/validators/ScreenDuplicationsValidator.h similarity index 100% rename from src/gui/src/validators/ScreenDuplicationsValidator.h rename to src/lib/gui/validators/ScreenDuplicationsValidator.h diff --git a/src/gui/src/validators/ScreenNameValidator.cpp b/src/lib/gui/validators/ScreenNameValidator.cpp similarity index 85% rename from src/gui/src/validators/ScreenNameValidator.cpp rename to src/lib/gui/validators/ScreenNameValidator.cpp index faec86e56..51c4f49a1 100644 --- a/src/gui/src/validators/ScreenNameValidator.cpp +++ b/src/lib/gui/validators/ScreenNameValidator.cpp @@ -17,11 +17,11 @@ #include "ScreenNameValidator.h" -#include "validators/ComputerNameValidator.h" -#include "validators/EmptyStringValidator.h" -#include "validators/ScreenDuplicationsValidator.h" -#include "validators/SpacesValidator.h" -#include "validators/ValidationError.h" +#include "gui/validators/ComputerNameValidator.h" +#include "gui/validators/EmptyStringValidator.h" +#include "gui/validators/ScreenDuplicationsValidator.h" +#include "gui/validators/SpacesValidator.h" +#include "gui/validators/ValidationError.h" #include #include diff --git a/src/gui/src/validators/ScreenNameValidator.h b/src/lib/gui/validators/ScreenNameValidator.h similarity index 95% rename from src/gui/src/validators/ScreenNameValidator.h rename to src/lib/gui/validators/ScreenNameValidator.h index 3afdc0b4d..0caffc77d 100644 --- a/src/gui/src/validators/ScreenNameValidator.h +++ b/src/lib/gui/validators/ScreenNameValidator.h @@ -19,7 +19,7 @@ #include "LineEditValidator.h" #include "gui/config/ScreenList.h" -#include "validators/ValidationError.h" +#include "gui/validators/ValidationError.h" namespace validators { diff --git a/src/gui/src/validators/SpacesValidator.cpp b/src/lib/gui/validators/SpacesValidator.cpp similarity index 91% rename from src/gui/src/validators/SpacesValidator.cpp rename to src/lib/gui/validators/SpacesValidator.cpp index 6e3cbde22..c7d496fe0 100644 --- a/src/gui/src/validators/SpacesValidator.cpp +++ b/src/lib/gui/validators/SpacesValidator.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 "SpacesValidator.h" namespace validators { diff --git a/src/gui/src/validators/SpacesValidator.h b/src/lib/gui/validators/SpacesValidator.h similarity index 84% rename from src/gui/src/validators/SpacesValidator.h rename to src/lib/gui/validators/SpacesValidator.h index f3d422679..57190a63c 100644 --- a/src/gui/src/validators/SpacesValidator.h +++ b/src/lib/gui/validators/SpacesValidator.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 @@ -16,8 +15,7 @@ * along with this program. If not, see . */ -#ifndef SPACESVALIDATOR_H -#define SPACESVALIDATOR_H +#pragma once #include "IStringValidator.h" @@ -30,5 +28,3 @@ public: }; } // namespace validators - -#endif // SPACESVALIDATOR_H diff --git a/src/gui/src/validators/ValidationError.cpp b/src/lib/gui/validators/ValidationError.cpp similarity index 100% rename from src/gui/src/validators/ValidationError.cpp rename to src/lib/gui/validators/ValidationError.cpp diff --git a/src/gui/src/validators/ValidationError.h b/src/lib/gui/validators/ValidationError.h similarity index 96% rename from src/gui/src/validators/ValidationError.h rename to src/lib/gui/validators/ValidationError.h index 324461e7a..198921a04 100644 --- a/src/gui/src/validators/ValidationError.h +++ b/src/lib/gui/validators/ValidationError.h @@ -23,7 +23,7 @@ namespace validators { -class ValidationError : QObject { +class ValidationError : public QObject { QString m_message; QLabel *m_pLabel = nullptr; diff --git a/src/gui/src/widgets/ClientStateLabel.cpp b/src/lib/gui/widgets/ClientStateLabel.cpp similarity index 87% rename from src/gui/src/widgets/ClientStateLabel.cpp rename to src/lib/gui/widgets/ClientStateLabel.cpp index d0140dfc9..611025e12 100644 --- a/src/gui/src/widgets/ClientStateLabel.cpp +++ b/src/lib/gui/widgets/ClientStateLabel.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,9 +14,10 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ + #include "ClientStateLabel.h" -namespace synergy_widgets { +namespace synergy::gui::widgets { ClientStateLabel::ClientStateLabel(QWidget *parent) : QLabel(parent) { hide(); } @@ -31,4 +31,4 @@ void ClientStateLabel::updateClientState(const QString &line) { } } -} // namespace synergy_widgets +} // namespace synergy::gui::widgets diff --git a/src/gui/src/widgets/ClientStateLabel.h b/src/lib/gui/widgets/ClientStateLabel.h similarity index 78% rename from src/gui/src/widgets/ClientStateLabel.h rename to src/lib/gui/widgets/ClientStateLabel.h index 8612b3051..170e4357c 100644 --- a/src/gui/src/widgets/ClientStateLabel.h +++ b/src/lib/gui/widgets/ClientStateLabel.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 @@ -16,12 +15,11 @@ * along with this program. If not, see . */ -#ifndef CLIENTSTATELABEL_H -#define CLIENTSTATELABEL_H +#pragma once #include -namespace synergy_widgets { +namespace synergy::gui::widgets { class ClientStateLabel : public QLabel { public: @@ -29,6 +27,4 @@ public: void updateClientState(const QString &line); }; -} // namespace synergy_widgets - -#endif // CLIENTSTATELABEL_H +} // namespace synergy::gui::widgets diff --git a/src/gui/src/widgets/ServerStateLabel.cpp b/src/lib/gui/widgets/ServerStateLabel.cpp similarity index 92% rename from src/gui/src/widgets/ServerStateLabel.cpp rename to src/lib/gui/widgets/ServerStateLabel.cpp index 97a13d777..eebb574d2 100644 --- a/src/gui/src/widgets/ServerStateLabel.cpp +++ b/src/lib/gui/widgets/ServerStateLabel.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 @@ -22,7 +21,7 @@ using namespace synergy::gui; -namespace synergy_widgets { +namespace synergy::gui::widgets { ServerStateLabel::ServerStateLabel(QWidget *parent) : QLabel(parent) {} @@ -51,4 +50,4 @@ void ServerStateLabel::updateServerState(const QString &line) { } } -} // namespace synergy_widgets +} // namespace synergy::gui::widgets diff --git a/src/gui/src/widgets/ServerStateLabel.h b/src/lib/gui/widgets/ServerStateLabel.h similarity index 79% rename from src/gui/src/widgets/ServerStateLabel.h rename to src/lib/gui/widgets/ServerStateLabel.h index d740c311d..810d48c7f 100644 --- a/src/gui/src/widgets/ServerStateLabel.h +++ b/src/lib/gui/widgets/ServerStateLabel.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 @@ -16,13 +15,12 @@ * along with this program. If not, see . */ -#ifndef SERVERSTATELABEL_H -#define SERVERSTATELABEL_H +#pragma once #include #include -namespace synergy_widgets { +namespace synergy::gui::widgets { class ServerStateLabel : public QLabel { public: @@ -35,6 +33,4 @@ private: void updateState(); }; -} // namespace synergy_widgets - -#endif // SERVERSTATELABEL_H +} // namespace synergy::gui::widgets diff --git a/src/test/CMakeLists.txt b/src/test/CMakeLists.txt index cfd009e65..045ff2344 100644 --- a/src/test/CMakeLists.txt +++ b/src/test/CMakeLists.txt @@ -132,6 +132,10 @@ macro(config_test_deps) include_directories(${gtest_dir} ${gmock_dir} ${gtest_dir}/include ${gmock_dir}/include) + # gui library autogen headers: + # qt doesn't seem to auto include the autogen headers for libraries. + include_directories(${CMAKE_BINARY_DIR}/src/lib/gui/gui_autogen/include) + add_library(gtest STATIC ${gtest_dir}/src/gtest-all.cc) add_library(gmock STATIC ${gmock_dir}/src/gmock-all.cc) diff --git a/src/test/shared/gui/TestQtCoreApp.h b/src/test/shared/gui/TestQtCoreApp.h index c72e74468..33a5b9462 100644 --- a/src/test/shared/gui/TestQtCoreApp.h +++ b/src/test/shared/gui/TestQtCoreApp.h @@ -19,8 +19,8 @@ #include -int argc = 0; // NOLINT -char **argv = nullptr; // NOLINT +static int argc = 0; // NOLINT NOSONAR +static char **argv = nullptr; // NOLINT NOSONAR class TestQtCoreApp : public QCoreApplication { public: diff --git a/src/test/shared/gui/TestQtFullApp.h b/src/test/shared/gui/TestQtFullApp.h index 810508d86..0bf600eb0 100644 --- a/src/test/shared/gui/TestQtFullApp.h +++ b/src/test/shared/gui/TestQtFullApp.h @@ -19,13 +19,17 @@ #include -int argc = 0; // NOLINT -char **argv = nullptr; // NOLINT +static int argc = 0; // NOLINT NOSONAR +static char **argv = nullptr; // NOLINT NOSONAR /** * Prefer using `TestQtCoreApp` instead. */ class TestQtFullApp : public QApplication { public: - explicit TestQtFullApp() : QApplication(argc, argv) {} + explicit TestQtFullApp() : QApplication(argc, argv) { +#if defined(Q_OS_WIN) +#error "this object causes windows ci to freeze" +#endif + } }; diff --git a/src/test/shared/gui/mocks/AppConfigMock.h b/src/test/shared/gui/mocks/AppConfigMock.h index 966b44b46..c687c377d 100644 --- a/src/test/shared/gui/mocks/AppConfigMock.h +++ b/src/test/shared/gui/mocks/AppConfigMock.h @@ -28,13 +28,20 @@ class AppConfigMock : public synergy::gui::IAppConfig { public: AppConfigMock() { - ON_CALL(*this, screenName()).WillByDefault(testing::ReturnRef(m_stubName)); + ON_CALL(*this, screenName()).WillByDefault(testing::ReturnRef(m_stub)); + ON_CALL(*this, networkInterface()) - .WillByDefault(testing::ReturnRef(m_stubInterface)); - ON_CALL(*this, logLevelText()) - .WillByDefault(testing::Return("stub log level")); + .WillByDefault(testing::ReturnRef(m_stub)); + + ON_CALL(*this, logLevelText()).WillByDefault(testing::Return(m_stub)); + + ON_CALL(*this, logFilename()).WillByDefault(testing::ReturnRef(m_stub)); } + // + // Setters + // + MOCK_METHOD(QString, tlsCertPath, (), (const, override)); MOCK_METHOD(int, tlsKeyLength, (), (const, override)); MOCK_METHOD(bool, tlsEnabled, (), (const, override)); @@ -57,9 +64,40 @@ public: MOCK_METHOD(const QString &, configFile, (), (const, override)); MOCK_METHOD(const QString &, networkInterface, (), (const, override)); MOCK_METHOD(const QString &, serverHostname, (), (const, override)); + MOCK_METHOD(int, logLevel, (), (const, override)); + MOCK_METHOD(bool, autoHide, (), (const, override)); + MOCK_METHOD(bool, enableService, (), (const, override)); + MOCK_METHOD(bool, closeToTray, (), (const, override)); + MOCK_METHOD(bool, isActiveScopeSystem, (), (const, override)); + MOCK_METHOD(bool, isActiveScopeWritable, (), (const, override)); + MOCK_METHOD(bool, clientGroupChecked, (), (const, override)); + + // + // Getters + // + + MOCK_METHOD( + void, setLoadFromSystemScope, (bool loadFromSystemScope), (override)); + MOCK_METHOD(void, setScreenName, (const QString &screenName), (override)); + MOCK_METHOD(void, setPort, (int port), (override)); + MOCK_METHOD( + void, setNetworkInterface, (const QString &networkInterface), (override)); + MOCK_METHOD(void, setLogLevel, (int logLevel), (override)); + MOCK_METHOD(void, setLogToFile, (bool logToFile), (override)); + MOCK_METHOD(void, setLogFilename, (const QString &logFilename), (override)); + MOCK_METHOD(void, setElevateMode, (ElevateMode elevateMode), (override)); + MOCK_METHOD(void, setAutoHide, (bool autoHide), (override)); + MOCK_METHOD(void, setPreventSleep, (bool preventSleep), (override)); + MOCK_METHOD(void, setTlsCertPath, (const QString &tlsCertPath), (override)); + MOCK_METHOD(void, setTlsKeyLength, (int tlsKeyLength), (override)); + MOCK_METHOD(void, setTlsEnabled, (bool tlsEnabled), (override)); + MOCK_METHOD(void, setLanguageSync, (bool languageSync), (override)); + MOCK_METHOD( + void, setInvertScrollDirection, (bool invertScrollDirection), (override)); + MOCK_METHOD(void, setEnableService, (bool enableService), (override)); + MOCK_METHOD(void, setCloseToTray, (bool closeToTray), (override)); + MOCK_METHOD(void, setInvertConnection, (bool invertConnection), (override)); private: - const QString m_stubName = "stub name"; - const QString m_stubInterface = "stub interface"; - const QString m_stubAddress = "stub address"; + const QString m_stub = "stub"; }; diff --git a/src/test/shared/gui/mocks/ServerConfigMock.h b/src/test/shared/gui/mocks/ServerConfigMock.h index d7c4942ab..700593266 100644 --- a/src/test/shared/gui/mocks/ServerConfigMock.h +++ b/src/test/shared/gui/mocks/ServerConfigMock.h @@ -23,6 +23,10 @@ class ServerConfigMock : public synergy::gui::IServerConfig { public: + ServerConfigMock() { + ON_CALL(*this, screens()).WillByDefault(testing::ReturnRef(m_screensStub)); + } + MOCK_METHOD(bool, isFull, (), (const, override)); MOCK_METHOD( bool, screenExists, (const QString &screenName), (const, override)); @@ -30,4 +34,7 @@ public: MOCK_METHOD(void, save, (QFile & file), (const, override)); MOCK_METHOD(bool, enableDragAndDrop, (), (const, override)); MOCK_METHOD(const ScreenList &, screens, (), (const, override)); + +private: + ScreenList m_screensStub; }; diff --git a/src/test/unittests/gui/dialogs/SettingsDialogTests.cpp b/src/test/unittests/gui/dialogs/SettingsDialogTests.cpp new file mode 100644 index 000000000..ce08d2601 --- /dev/null +++ b/src/test/unittests/gui/dialogs/SettingsDialogTests.cpp @@ -0,0 +1,50 @@ +/* + * synergy -- mouse and keyboard sharing utility + * Copyright (C) 2024 Symless Ltd. + * + * This package is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * found in the file LICENSE that should have accompanied this file. + * + * This package is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +// `TestQtFullApp` freezes on windows ci, so exclude this test for now. +#ifndef WIN32 + +#include "gui/core/CoreProcess.h" +#include "gui/dialogs/SettingsDialog.h" +#include "license/SerialKey.h" +#include "shared/gui/TestQtFullApp.h" +#include "shared/gui/mocks/AppConfigMock.h" +#include "shared/gui/mocks/ServerConfigMock.h" + +#include + +using namespace testing; +using namespace synergy::license; +using namespace synergy::gui; + +TEST(SettingsDialogTests, ctor_getsScreenName) { + TestQtFullApp app; + NiceMock appConfig; + NiceMock serverConfig; + SerialKey serialKey = SerialKey::invalid(); + serialKey.isValid = true; + License license(serialKey); + auto cpDeps = std::make_shared(); + CoreProcess coreProcess(appConfig, serverConfig, cpDeps); + + EXPECT_CALL(appConfig, screenName()).Times(1); + + SettingsDialog settingsDialog( + nullptr, appConfig, serverConfig, license, coreProcess); +} + +#endif diff --git a/src/test/unittests/main.cpp b/src/test/unittests/main.cpp index cff778469..d9f6586f7 100644 --- a/src/test/unittests/main.cpp +++ b/src/test/unittests/main.cpp @@ -29,7 +29,7 @@ using synergy::test::ExitTimeout; int main(int argc, char **argv) { - ExitTimeout exitTimeout(1, "Integration tests"); + ExitTimeout exitTimeout(1, "Unit tests"); #if SYSAPI_WIN32 // HACK: shouldn't be needed, but logging fails without this.