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
This commit is contained in:
Nick Bolton 2024-08-09 09:08:29 +01:00 committed by GitHub
parent a686f19ca2
commit ef186d398d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
45 changed files with 321 additions and 197 deletions

View file

@ -73,6 +73,7 @@ Enhancements:
- #7427 More reliable button click detection for add client dialog - #7427 More reliable button click detection for add client dialog
- #7428 Refactor settings dialog to simplify enable/disable logic - #7428 Refactor settings dialog to simplify enable/disable logic
- #7429 Parse date numbers as long instead of int - #7429 Parse date numbers as long instead of int
- #7430 Improve setting enable logic and test coverage
# 1.14.6 # 1.14.6

View file

@ -37,6 +37,7 @@
"Pixmap", "Pixmap",
"Poschta", "Poschta",
"Priddy", "Priddy",
"Regen",
"runas", "runas",
"Sbârnea", "Sbârnea",
"Schoeneman", "Schoeneman",

View file

@ -41,8 +41,13 @@ add_executable(
res/Synergy.qrc res/Synergy.qrc
${QM_FILES}) ${QM_FILES})
# regular exe headers
include_directories(./src) 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_link_libraries(
${target} ${target}
gui gui

View file

@ -21,13 +21,13 @@
#include "AboutDialog.h" #include "AboutDialog.h"
#include "ActivationDialog.h" #include "ActivationDialog.h"
#include "ServerConfigDialog.h" #include "ServerConfigDialog.h"
#include "SettingsDialog.h"
#include "gui/Logger.h" #include "gui/Logger.h"
#include "gui/TrayIcon.h" #include "gui/TrayIcon.h"
#include "gui/VersionChecker.h" #include "gui/VersionChecker.h"
#include "gui/config/ConfigScopes.h" #include "gui/config/ConfigScopes.h"
#include "gui/constants.h" #include "gui/constants.h"
#include "gui/core/CoreProcess.h" #include "gui/core/CoreProcess.h"
#include "gui/dialogs/SettingsDialog.h"
#include "gui/license/LicenseHandler.h" #include "gui/license/LicenseHandler.h"
#include "gui/license/license_notices.h" #include "gui/license/license_notices.h"
#include "gui/messages.h" #include "gui/messages.h"

View file

@ -201,7 +201,7 @@
</widget> </widget>
</item> </item>
<item> <item>
<widget class="synergy_widgets::ServerStateLabel" name="m_pLabelServerState"> <widget class="synergy::gui::widgets::ServerStateLabel" name="m_pLabelServerState">
<property name="text"> <property name="text">
<string>No clients connected</string> <string>No clients connected</string>
</property> </property>
@ -358,7 +358,7 @@
</layout> </layout>
</item> </item>
<item> <item>
<widget class="synergy_widgets::ClientStateLabel" name="m_pLabelClientState"> <widget class="synergy::gui::widgets::ClientStateLabel" name="m_pLabelClientState">
<property name="text"> <property name="text">
<string>Connected to server</string> <string>Connected to server</string>
</property> </property>
@ -662,14 +662,14 @@
</widget> </widget>
<customwidgets> <customwidgets>
<customwidget> <customwidget>
<class>synergy_widgets::ServerStateLabel</class> <class>synergy::gui::widgets::ServerStateLabel</class>
<extends>QLabel</extends> <extends>QLabel</extends>
<header>widgets/ServerStateLabel.h</header> <header>gui/widgets/ServerStateLabel.h</header>
</customwidget> </customwidget>
<customwidget> <customwidget>
<class>synergy_widgets::ClientStateLabel</class> <class>synergy::gui::widgets::ClientStateLabel</class>
<extends>QLabel</extends> <extends>QLabel</extends>
<header>widgets/ClientStateLabel.h</header> <header>gui/widgets/ClientStateLabel.h</header>
</customwidget> </customwidget>
</customwidgets> </customwidgets>
<tabstops> <tabstops>

View file

@ -20,9 +20,9 @@
#include "gui/config/Screen.h" #include "gui/config/Screen.h"
#include "gui/styles.h" #include "gui/styles.h"
#include "validators/AliasValidator.h" #include "gui/validators/AliasValidator.h"
#include "validators/ScreenNameValidator.h" #include "gui/validators/ScreenNameValidator.h"
#include "validators/ValidationError.h" #include "gui/validators/ValidationError.h"
#include <QMessageBox> #include <QMessageBox>
#include <QtCore> #include <QtCore>

View file

@ -18,8 +18,8 @@
#include "SetupWizard.h" #include "SetupWizard.h"
#include "gui/styles.h" #include "gui/styles.h"
#include "validators/ScreenNameValidator.h" #include "gui/validators/ScreenNameValidator.h"
#include "validators/ValidationError.h" #include "gui/validators/ValidationError.h"
using namespace synergy::gui; using namespace synergy::gui;

View file

@ -22,6 +22,7 @@ set(CMAKE_INCLUDE_CURRENT_DIR ON)
file(GLOB_RECURSE sources *.cpp) file(GLOB_RECURSE sources *.cpp)
file(GLOB_RECURSE headers *.h) file(GLOB_RECURSE headers *.h)
file(GLOB_RECURSE ui_files *.ui)
if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin") if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
file(GLOB mac_sources *.mm) file(GLOB mac_sources *.mm)
@ -32,7 +33,7 @@ if(ADD_HEADERS_TO_SOURCES)
list(APPEND sources ${headers}) list(APPEND sources ${headers})
endif() endif()
add_library(${target} STATIC ${sources}) add_library(${target} STATIC ${sources} ${ui_files})
target_link_libraries( target_link_libraries(
${target} ${target}
global global

View file

@ -139,6 +139,7 @@ public:
// //
// Getters (overrides) // Getters (overrides)
// //
ProcessMode processMode() const override; ProcessMode processMode() const override;
ElevateMode elevateMode() const override; ElevateMode elevateMode() const override;
bool tlsEnabled() const override; bool tlsEnabled() const override;
@ -161,25 +162,25 @@ public:
const QString &configFile() const override; const QString &configFile() const override;
const QString &networkInterface() const override; const QString &networkInterface() const override;
const QString &serverHostname() 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) // Getters (new methods)
// //
bool isActiveScopeWritable() const;
bool isActiveScopeSystem() const;
int logLevel() const;
bool wizardShouldRun() const; bool wizardShouldRun() const;
bool startedBefore() const; bool startedBefore() const;
QString logDir() const; QString logDir() const;
bool autoHide() const;
unsigned long long licenseNextCheck() const; unsigned long long licenseNextCheck() const;
bool serverGroupChecked() const; bool serverGroupChecked() const;
bool useInternalConfig() const; bool useInternalConfig() const;
bool clientGroupChecked() const;
QString lastVersion() const; QString lastVersion() const;
bool enableService() const;
bool closeToTray() const;
bool activationHasRun() const; bool activationHasRun() const;
std::optional<QSize> mainWindowSize() const; std::optional<QSize> mainWindowSize() const;
std::optional<QPoint> mainWindowPosition() const; std::optional<QPoint> mainWindowPosition() const;
@ -187,27 +188,36 @@ public:
bool showCloseReminder() const; 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 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 setWizardHasRun();
void setStartedBefore(bool b); void setStartedBefore(bool b);
void setElevateMode(ElevateMode em);
void setTlsEnabled(bool e);
void setSerialKey(const QString &serialKey); void setSerialKey(const QString &serialKey);
void clearSerialKey(); void clearSerialKey();
void setAutoHide(bool b);
void setInvertScrollDirection(bool b);
void setLicenseNextCheck(unsigned long long); void setLicenseNextCheck(unsigned long long);
void setLanguageSync(bool b);
void setPreventSleep(bool b);
void setServerGroupChecked(bool); void setServerGroupChecked(bool);
void setUseExternalConfig(bool); void setUseExternalConfig(bool);
void setConfigFile(const QString &); void setConfigFile(const QString &);
@ -215,11 +225,6 @@ public:
void setClientGroupChecked(bool); void setClientGroupChecked(bool);
void setServerHostname(const QString &); void setServerHostname(const QString &);
void setLastVersion(const QString &version); 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 setMainWindowSize(const QSize &size);
void setMainWindowPosition(const QPoint &position); void setMainWindowPosition(const QPoint &position);
void setShowDevThanks(bool show); void setShowDevThanks(bool show);
@ -230,7 +235,7 @@ public:
/// True - This will set the variable and load the global scope /// True - This will set the variable and load the global scope
/// settings. False - This will set the variable and load the user /// settings. False - This will set the variable and load the user
/// scope settings. /// scope settings.
void setLoadFromSystemScope(bool value); void setLoadFromSystemScope(bool value) override;
private: private:
static QString settingName(AppConfig::Setting name); static QString settingName(AppConfig::Setting name);

View file

@ -28,6 +28,11 @@ enum class ProcessMode { kService, kDesktop };
class IAppConfig { class IAppConfig {
public: public:
virtual ~IAppConfig() = default; virtual ~IAppConfig() = default;
//
// Setters
//
virtual QString tlsCertPath() const = 0; virtual QString tlsCertPath() const = 0;
virtual int tlsKeyLength() const = 0; virtual int tlsKeyLength() const = 0;
virtual bool tlsEnabled() const = 0; virtual bool tlsEnabled() const = 0;
@ -50,6 +55,36 @@ public:
virtual const QString &configFile() const = 0; virtual const QString &configFile() const = 0;
virtual const QString &networkInterface() const = 0; virtual const QString &networkInterface() const = 0;
virtual const QString &serverHostname() 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 } // namespace synergy::gui

View file

@ -62,6 +62,8 @@ const auto kUrlGnomeTrayFix =
const auto kUrlProduct = QString("%1/synergy").arg(kUrlWebsite); const auto kUrlProduct = QString("%1/synergy").arg(kUrlWebsite);
const auto kUrlPurchase = const auto kUrlPurchase =
QString("%1/purchase?%2").arg(kUrlProduct, kUrlSourceQuery); QString("%1/purchase?%2").arg(kUrlProduct, kUrlSourceQuery);
const auto kUrlUpgrade =
QString("%1/purchase/upgrade?%2").arg(kUrlProduct, kUrlSourceQuery);
const auto kUrlContact = const auto kUrlContact =
QString("%1/contact?%2").arg(kUrlProduct, kUrlSourceQuery); QString("%1/contact?%2").arg(kUrlProduct, kUrlSourceQuery);
const auto kUrlHelp = QString("%1/help?%2").arg(kUrlProduct, kUrlSourceQuery); const auto kUrlHelp = QString("%1/help?%2").arg(kUrlProduct, kUrlSourceQuery);

View file

@ -18,14 +18,13 @@
#include "SettingsDialog.h" #include "SettingsDialog.h"
#include "MainWindow.h"
#include "UpgradeDialog.h" #include "UpgradeDialog.h"
#include "gui/config/AppConfig.h"
#include "gui/constants.h" #include "gui/constants.h"
#include "gui/core/CoreProcess.h"
#include "gui/tls/TlsCertificate.h" #include "gui/tls/TlsCertificate.h"
#include "gui/tls/TlsUtility.h" #include "gui/tls/TlsUtility.h"
#include "validators/ScreenNameValidator.h" #include "gui/validators/ScreenNameValidator.h"
#include "validators/ValidationError.h" #include "gui/validators/ValidationError.h"
#include <QDir> #include <QDir>
#include <QFileDialog> #include <QFileDialog>
@ -39,7 +38,7 @@ using namespace synergy::gui;
const char *const kProProductName = "Synergy 1 Pro"; const char *const kProProductName = "Synergy 1 Pro";
SettingsDialog::SettingsDialog( SettingsDialog::SettingsDialog(
MainWindow *parent, AppConfig &appConfig, const IServerConfig &serverConfig, QWidget *parent, IAppConfig &appConfig, const IServerConfig &serverConfig,
const License &license, const CoreProcess &coreProcess) const License &license, const CoreProcess &coreProcess)
: QDialog(parent, Qt::WindowTitleHint | Qt::WindowSystemMenuHint), : QDialog(parent, Qt::WindowTitleHint | Qt::WindowSystemMenuHint),
Ui::SettingsDialogBase(), 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(); updateTlsControlsEnabled();
if (kEnableActivation && !m_tlsUtility.isAvailable()) { if (kEnableActivation && !m_tlsUtility.isAvailable()) {
m_pCheckBoxEnableTls->setChecked(false);
auto edition = m_license.productEdition(); auto edition = m_license.productEdition();
if (edition == Edition::kBasic) { if (edition == Edition::kBasic) {
UpgradeDialog upgradeDialog(this); UpgradeDialog upgradeDialog(this);
@ -107,14 +108,14 @@ void SettingsDialog::on_m_pRadioSystemScope_toggled(bool checked) {
updateControls(); updateControls();
} }
void SettingsDialog::on_m_pPushButtonBrowseCert_clicked() { void SettingsDialog::on_m_pPushButtonTlsCertPath_clicked() {
QString fileName = QFileDialog::getSaveFileName( QString fileName = QFileDialog::getSaveFileName(
this, tr("Select a TLS certificate to use..."), this, tr("Select a TLS certificate to use..."),
m_pLineEditCertificatePath->text(), "Cert (*.pem)", nullptr, m_pLineEditTlsCertPath->text(), "Cert (*.pem)", nullptr,
QFileDialog::DontConfirmOverwrite); QFileDialog::DontConfirmOverwrite);
if (!fileName.isEmpty()) { if (!fileName.isEmpty()) {
m_pLineEditCertificatePath->setText(fileName); m_pLineEditTlsCertPath->setText(fileName);
if (QFile(fileName).exists()) { if (QFile(fileName).exists()) {
updateKeyLengthOnFile(fileName); updateKeyLengthOnFile(fileName);
@ -125,11 +126,11 @@ void SettingsDialog::on_m_pPushButtonBrowseCert_clicked() {
updateTlsRegenerateButton(); updateTlsRegenerateButton();
} }
void SettingsDialog::on_m_pComboBoxKeyLength_currentIndexChanged(int index) { void SettingsDialog::on_m_pComboBoxTlsKeyLength_currentIndexChanged(int) {
updateTlsRegenerateButton(); updateTlsRegenerateButton();
} }
void SettingsDialog::on_m_pPushButtonRegenCert_clicked() { void SettingsDialog::on_m_pPushButtonTlsRegenCert_clicked() {
if (m_tlsUtility.generateCertificate()) { if (m_tlsUtility.generateCertificate()) {
QMessageBox::information( QMessageBox::information(
this, tr("TLS Certificate Regenerated"), this, tr("TLS Certificate Regenerated"),
@ -163,9 +164,9 @@ void SettingsDialog::accept() {
static_cast<ElevateMode>(m_pComboElevate->currentIndex())); static_cast<ElevateMode>(m_pComboElevate->currentIndex()));
m_appConfig.setAutoHide(m_pCheckBoxAutoHide->isChecked()); m_appConfig.setAutoHide(m_pCheckBoxAutoHide->isChecked());
m_appConfig.setPreventSleep(m_pCheckBoxPreventSleep->isChecked()); m_appConfig.setPreventSleep(m_pCheckBoxPreventSleep->isChecked());
m_appConfig.setTlsCertPath(m_pLineEditCertificatePath->text()); m_appConfig.setTlsCertPath(m_pLineEditTlsCertPath->text());
m_appConfig.setTlsKeyLength(m_pComboBoxKeyLength->currentText().toInt()); m_appConfig.setTlsKeyLength(m_pComboBoxTlsKeyLength->currentText().toInt());
m_appConfig.setTlsEnabled(m_pCheckBoxEnableCrypto->isChecked()); m_appConfig.setTlsEnabled(m_pCheckBoxEnableTls->isChecked());
m_appConfig.setLanguageSync(m_pCheckBoxLanguageSync->isChecked()); m_appConfig.setLanguageSync(m_pCheckBoxLanguageSync->isChecked());
m_appConfig.setInvertScrollDirection(m_pCheckBoxScrollDirection->isChecked()); m_appConfig.setInvertScrollDirection(m_pCheckBoxScrollDirection->isChecked());
m_appConfig.setEnableService(m_pCheckBoxServiceEnabled->isChecked()); m_appConfig.setEnableService(m_pCheckBoxServiceEnabled->isChecked());
@ -194,8 +195,6 @@ void SettingsDialog::loadFromConfig() {
m_pLineEditLogFilename->setText(m_appConfig.logFilename()); m_pLineEditLogFilename->setText(m_appConfig.logFilename());
m_pCheckBoxAutoHide->setChecked(m_appConfig.autoHide()); m_pCheckBoxAutoHide->setChecked(m_appConfig.autoHide());
m_pCheckBoxPreventSleep->setChecked(m_appConfig.preventSleep()); 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_pCheckBoxLanguageSync->setChecked(m_appConfig.languageSync());
m_pCheckBoxScrollDirection->setChecked(m_appConfig.invertScrollDirection()); m_pCheckBoxScrollDirection->setChecked(m_appConfig.invertScrollDirection());
m_pCheckBoxServiceEnabled->setChecked(m_appConfig.enableService()); m_pCheckBoxServiceEnabled->setChecked(m_appConfig.enableService());
@ -216,15 +215,20 @@ void SettingsDialog::loadFromConfig() {
} }
void SettingsDialog::updateTlsControls() { void SettingsDialog::updateTlsControls() {
if (QFile(m_appConfig.tlsCertPath()).exists()) { if (QFile(m_appConfig.tlsCertPath()).exists()) {
updateKeyLengthOnFile(m_appConfig.tlsCertPath()); updateKeyLengthOnFile(m_appConfig.tlsCertPath());
} else { } else {
const auto keyLengthText = QString::number(m_appConfig.tlsKeyLength()); const auto keyLengthText = QString::number(m_appConfig.tlsKeyLength());
m_pComboBoxKeyLength->setCurrentIndex( m_pComboBoxTlsKeyLength->setCurrentIndex(
m_pComboBoxKeyLength->findText(keyLengthText)); 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(); updateTlsControlsEnabled();
} }
@ -232,36 +236,30 @@ void SettingsDialog::updateTlsControls() {
void SettingsDialog::updateTlsControlsEnabled() { void SettingsDialog::updateTlsControlsEnabled() {
const auto writable = m_appConfig.isActiveScopeWritable(); const auto writable = m_appConfig.isActiveScopeWritable();
const auto clientMode = m_appConfig.clientGroupChecked(); const auto clientMode = m_appConfig.clientGroupChecked();
const auto tlsAvailable = m_tlsUtility.isAvailableAndEnabled(); const auto tlsChecked = m_pCheckBoxEnableTls->isChecked();
const auto tlsChecked = m_pCheckBoxEnableCrypto->isChecked();
auto enabled = writable && !clientMode && tlsAvailable && tlsChecked; auto enabled = writable && tlsChecked && !clientMode;
m_pLabelTlsKeyLength->setEnabled(enabled);
qDebug( m_pComboBoxTlsKeyLength->setEnabled(enabled);
"tls enabled=%d, writable=%d, client=%d, available=%d, checked=%d", m_pLabelTlsCert->setEnabled(enabled);
enabled, writable, clientMode, tlsAvailable, tlsChecked); m_pLineEditTlsCertPath->setEnabled(enabled);
m_pPushButtonTlsCertPath->setEnabled(enabled);
m_pLabelKeyLength->setEnabled(enabled); m_pPushButtonTlsRegenCert->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 { bool SettingsDialog::isClientMode() const {
return m_coreProcess.mode() == MainWindow::CoreMode::Client; return m_coreProcess.mode() == synergy::gui::CoreProcess::Mode::Client;
} }
void SettingsDialog::updateTlsRegenerateButton() { void SettingsDialog::updateTlsRegenerateButton() {
const auto writable = m_appConfig.isActiveScopeWritable(); const auto writable = m_appConfig.isActiveScopeWritable();
const auto keyLength = m_pComboBoxKeyLength->currentText().toInt(); const auto keyLength = m_pComboBoxTlsKeyLength->currentText().toInt();
const auto path = m_pLineEditCertificatePath->text(); const auto path = m_pLineEditTlsCertPath->text();
const auto keyChanged = m_appConfig.tlsKeyLength() != keyLength; const auto keyChanged = m_appConfig.tlsKeyLength() != keyLength;
const auto pathChanged = m_appConfig.tlsCertPath() != path; 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)); writable && tlsEnabled && (keyChanged || pathChanged));
} }
@ -272,8 +270,8 @@ void SettingsDialog::updateKeyLengthOnFile(const QString &path) {
} }
auto length = ssl.getCertKeyLength(path); auto length = ssl.getCertKeyLength(path);
auto index = m_pComboBoxKeyLength->findText(QString::number(length)); auto index = m_pComboBoxTlsKeyLength->findText(QString::number(length));
m_pComboBoxKeyLength->setCurrentIndex(index); m_pComboBoxTlsKeyLength->setCurrentIndex(index);
m_appConfig.setTlsKeyLength(length); m_appConfig.setTlsKeyLength(length);
} }
@ -298,10 +296,8 @@ void SettingsDialog::updateControls() {
m_pCheckBoxLogToFile->setEnabled(writable); m_pCheckBoxLogToFile->setEnabled(writable);
m_pCheckBoxAutoHide->setEnabled(writable); m_pCheckBoxAutoHide->setEnabled(writable);
m_pCheckBoxPreventSleep->setEnabled(writable); m_pCheckBoxPreventSleep->setEnabled(writable);
m_pLineEditCertificatePath->setEnabled(writable); m_pLineEditTlsCertPath->setEnabled(writable);
m_pComboBoxKeyLength->setEnabled(writable); m_pComboBoxTlsKeyLength->setEnabled(writable);
m_pPushButtonBrowseCert->setEnabled(writable);
m_pCheckBoxEnableCrypto->setEnabled(writable);
m_pCheckBoxCloseToTray->setEnabled(writable); m_pCheckBoxCloseToTray->setEnabled(writable);
m_pCheckBoxServiceEnabled->setEnabled(writable && serviceAvailable); m_pCheckBoxServiceEnabled->setEnabled(writable && serviceAvailable);

View file

@ -20,19 +20,18 @@
#include "ui_SettingsDialogBase.h" #include "ui_SettingsDialogBase.h"
#include "gui/config/AppConfig.h" #include "gui/config/IAppConfig.h"
#include "gui/config/IServerConfig.h" #include "gui/config/IServerConfig.h"
#include "gui/core/CoreProcess.h" #include "gui/core/CoreProcess.h"
#include "gui/core/CoreTool.h" #include "gui/core/CoreTool.h"
#include "gui/tls/TlsUtility.h" #include "gui/tls/TlsUtility.h"
#include "gui/validators/ValidationError.h"
#include "license/License.h" #include "license/License.h"
#include "validators/ValidationError.h"
#include <QDialog> #include <QDialog>
class MainWindow;
class SettingsDialog : public QDialog, public Ui::SettingsDialogBase { class SettingsDialog : public QDialog, public Ui::SettingsDialogBase {
using IAppConfig = synergy::gui::IAppConfig;
using IServerConfig = synergy::gui::IServerConfig; using IServerConfig = synergy::gui::IServerConfig;
using CoreProcess = synergy::gui::CoreProcess; using CoreProcess = synergy::gui::CoreProcess;
using License = synergy::license::License; using License = synergy::license::License;
@ -41,24 +40,17 @@ class SettingsDialog : public QDialog, public Ui::SettingsDialogBase {
public: public:
SettingsDialog( SettingsDialog(
MainWindow *parent, AppConfig &appConfig, QWidget *parent, IAppConfig &appConfig, const IServerConfig &serverConfig,
const IServerConfig &serverConfig, const License &license, const License &license, const CoreProcess &coreProcess);
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);
private slots: 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_pCheckBoxLogToFile_stateChanged(int);
void on_m_pButtonBrowseLog_clicked(); void on_m_pButtonBrowseLog_clicked();
void on_m_pRadioSystemScope_toggled(bool checked); void on_m_pRadioSystemScope_toggled(bool checked);
void on_m_pPushButtonBrowseCert_clicked(); void on_m_pPushButtonTlsCertPath_clicked();
void on_m_pComboBoxKeyLength_currentIndexChanged(int index); void on_m_pComboBoxTlsKeyLength_currentIndexChanged(int index);
void on_m_pPushButtonRegenCert_clicked(); void on_m_pPushButtonTlsRegenCert_clicked();
void on_m_pCheckBoxServiceEnabled_toggled(bool checked); void on_m_pCheckBoxServiceEnabled_toggled(bool checked);
private: private:
@ -89,7 +81,7 @@ private:
/// the scope and doesn't save changes /// the scope and doesn't save changes
bool m_wasOriginallySystemScope = false; bool m_wasOriginallySystemScope = false;
AppConfig &m_appConfig; IAppConfig &m_appConfig;
const IServerConfig &m_serverConfig; const IServerConfig &m_serverConfig;
const License &m_license; const License &m_license;
const CoreProcess &m_coreProcess; const CoreProcess &m_coreProcess;

View file

@ -165,7 +165,7 @@
<number>0</number> <number>0</number>
</property> </property>
<item> <item>
<widget class="QCheckBox" name="m_pCheckBoxEnableCrypto"> <widget class="QCheckBox" name="m_pCheckBoxEnableTls">
<property name="enabled"> <property name="enabled">
<bool>true</bool> <bool>true</bool>
</property> </property>
@ -188,7 +188,7 @@
</spacer> </spacer>
</item> </item>
<item> <item>
<widget class="QLabel" name="m_pLabelKeyLength"> <widget class="QLabel" name="m_pLabelTlsKeyLength">
<property name="sizePolicy"> <property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed"> <sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>0</horstretch> <horstretch>0</horstretch>
@ -201,7 +201,7 @@
</widget> </widget>
</item> </item>
<item> <item>
<widget class="QComboBox" name="m_pComboBoxKeyLength"> <widget class="QComboBox" name="m_pComboBoxTlsKeyLength">
<property name="currentText"> <property name="currentText">
<string>1024</string> <string>1024</string>
</property> </property>
@ -230,7 +230,7 @@
<number>0</number> <number>0</number>
</property> </property>
<item> <item>
<widget class="QLabel" name="m_pLabelCertificate"> <widget class="QLabel" name="m_pLabelTlsCert">
<property name="sizePolicy"> <property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed"> <sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>0</horstretch> <horstretch>0</horstretch>
@ -259,7 +259,7 @@
</spacer> </spacer>
</item> </item>
<item> <item>
<widget class="QLineEdit" name="m_pLineEditCertificatePath"> <widget class="QLineEdit" name="m_pLineEditTlsCertPath">
<property name="minimumSize"> <property name="minimumSize">
<size> <size>
<width>0</width> <width>0</width>
@ -269,7 +269,7 @@
</widget> </widget>
</item> </item>
<item> <item>
<widget class="QPushButton" name="m_pPushButtonBrowseCert"> <widget class="QPushButton" name="m_pPushButtonTlsCertPath">
<property name="cursor"> <property name="cursor">
<cursorShape>PointingHandCursor</cursorShape> <cursorShape>PointingHandCursor</cursorShape>
</property> </property>
@ -312,7 +312,7 @@
</spacer> </spacer>
</item> </item>
<item> <item>
<widget class="QPushButton" name="m_pPushButtonRegenCert"> <widget class="QPushButton" name="m_pPushButtonTlsRegenCert">
<property name="text"> <property name="text">
<string>Regenerate certificate</string> <string>Regenerate certificate</string>
</property> </property>
@ -740,11 +740,11 @@
<tabstop>m_pLineEditScreenName</tabstop> <tabstop>m_pLineEditScreenName</tabstop>
<tabstop>m_pSpinBoxPort</tabstop> <tabstop>m_pSpinBoxPort</tabstop>
<tabstop>m_pLineEditInterface</tabstop> <tabstop>m_pLineEditInterface</tabstop>
<tabstop>m_pCheckBoxEnableCrypto</tabstop> <tabstop>m_pCheckBoxEnableTls</tabstop>
<tabstop>m_pComboBoxKeyLength</tabstop> <tabstop>m_pComboBoxTlsKeyLength</tabstop>
<tabstop>m_pLineEditCertificatePath</tabstop> <tabstop>m_pLineEditTlsCertPath</tabstop>
<tabstop>m_pPushButtonBrowseCert</tabstop> <tabstop>m_pPushButtonTlsCertPath</tabstop>
<tabstop>m_pPushButtonRegenCert</tabstop> <tabstop>m_pPushButtonTlsRegenCert</tabstop>
<tabstop>m_pCheckBoxLogToFile</tabstop> <tabstop>m_pCheckBoxLogToFile</tabstop>
<tabstop>m_pComboLogLevel</tabstop> <tabstop>m_pComboLogLevel</tabstop>
<tabstop>m_pLineEditLogFilename</tabstop> <tabstop>m_pLineEditLogFilename</tabstop>

View file

@ -14,23 +14,24 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include "UpgradeDialog.h" #include "UpgradeDialog.h"
#include "gui/constants.h"
#include <QtCore> #include <QtCore>
#include <QtGui> #include <QtGui>
UpgradeDialog::UpgradeDialog(QWidget *parent) : QMessageBox(parent) { UpgradeDialog::UpgradeDialog(QWidget *parent) : QMessageBox(parent) {
setWindowTitle(QObject::tr("Upgrade to access this feature")); setWindowTitle("Upgrade to access this feature");
addButton(QObject::tr("Close"), QMessageBox::RejectRole); addButton("Cancel", QMessageBox::RejectRole);
addButton(QObject::tr("Upgrade"), QMessageBox::AcceptRole); addButton("Upgrade", QMessageBox::AcceptRole);
} }
void UpgradeDialog::showDialog(const QString &text) { void UpgradeDialog::showDialog(const QString &text) {
setText(QObject::tr(text.toStdString().c_str())); setText(text);
if (exec() == QMessageBox::Accepted) { if (exec() == QMessageBox::Accepted) {
QDesktopServices::openUrl(QUrl( QDesktopServices::openUrl(QUrl(synergy::gui::kUrlUpgrade));
QCoreApplication::organizationDomain() +
"/synergy/purchase/upgrade?source=gui"));
} }
} }

View file

@ -14,7 +14,9 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#pragma once #pragma once
#include <QMessageBox> #include <QMessageBox>
class UpgradeDialog : public QMessageBox { class UpgradeDialog : public QMessageBox {

View file

@ -15,8 +15,8 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include "validators/ComputerNameValidator.h" #include "gui/validators/ComputerNameValidator.h"
#include "validators/SpacesValidator.h" #include "gui/validators/SpacesValidator.h"
#include "AliasValidator.h" #include "AliasValidator.h"

View file

@ -18,7 +18,7 @@
#pragma once #pragma once
#include "LineEditValidator.h" #include "LineEditValidator.h"
#include "validators/ValidationError.h" #include "gui/validators/ValidationError.h"
namespace validators { namespace validators {

View file

@ -1,7 +1,6 @@
/* /*
* synergy -- mouse and keyboard sharing utility * synergy -- mouse and keyboard sharing utility
* Copyright (C) 2012-2021 Symless Ltd. * Copyright (C) 2021 Symless Ltd.
* Copyright (C) 2008 Volker Lanz (vl@fidra.de)
* *
* This package is free software; you can redistribute it and/or * This package is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License * 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 * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include "ComputerNameValidator.h" #include "ComputerNameValidator.h"
#include <QRegularExpression> #include <QRegularExpression>

View file

@ -1,7 +1,6 @@
/* /*
* synergy -- mouse and keyboard sharing utility * synergy -- mouse and keyboard sharing utility
* Copyright (C) 2012-2021 Symless Ltd. * Copyright (C) 2021 Symless Ltd.
* Copyright (C) 2008 Volker Lanz (vl@fidra.de)
* *
* This package is free software; you can redistribute it and/or * This package is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License * modify it under the terms of the GNU General Public License
@ -26,7 +25,7 @@ namespace validators {
class ComputerNameValidator : public IStringValidator { class ComputerNameValidator : public IStringValidator {
public: public:
ComputerNameValidator(const QString &message); explicit ComputerNameValidator(const QString &message);
bool validate(const QString &input) const override; bool validate(const QString &input) const override;
}; };

View file

@ -1,7 +1,6 @@
/* /*
* synergy -- mouse and keyboard sharing utility * synergy -- mouse and keyboard sharing utility
* Copyright (C) 2012-2021 Symless Ltd. * Copyright (C) 2021 Symless Ltd.
* Copyright (C) 2008 Volker Lanz (vl@fidra.de)
* *
* This package is free software; you can redistribute it and/or * This package is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License * 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 * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include "EmptyStringValidator.h" #include "EmptyStringValidator.h"
namespace validators { namespace validators {

View file

@ -1,7 +1,6 @@
/* /*
* synergy -- mouse and keyboard sharing utility * synergy -- mouse and keyboard sharing utility
* Copyright (C) 2012-2021 Symless Ltd. * Copyright (C) 2021 Symless Ltd.
* Copyright (C) 2008 Volker Lanz (vl@fidra.de)
* *
* This package is free software; you can redistribute it and/or * This package is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License * 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 * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef EMPTYSTRINGVALIDATOR_H
#define EMPTYSTRINGVALIDATOR_H #pragma once
#include "IStringValidator.h" #include "IStringValidator.h"
@ -29,5 +28,3 @@ public:
}; };
} // namespace validators } // namespace validators
#endif // EMPTYSTRINGVALIDATOR_H

View file

@ -1,7 +1,6 @@
/* /*
* synergy -- mouse and keyboard sharing utility * synergy -- mouse and keyboard sharing utility
* Copyright (C) 2012-2021 Symless Ltd. * Copyright (C) 2021 Symless Ltd.
* Copyright (C) 2008 Volker Lanz (vl@fidra.de)
* *
* This package is free software; you can redistribute it and/or * This package is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License * 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 * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include "EmptyStringValidator.h"
#include "IStringValidator.h"
namespace validators { namespace validators {

View file

@ -1,7 +1,6 @@
/* /*
* synergy -- mouse and keyboard sharing utility * synergy -- mouse and keyboard sharing utility
* Copyright (C) 2012-2021 Symless Ltd. * Copyright (C) 2021 Symless Ltd.
* Copyright (C) 2008 Volker Lanz (vl@fidra.de)
* *
* This package is free software; you can redistribute it and/or * This package is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License * 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 * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef IVALIDATOR_H
#define IVALIDATOR_H #pragma once
#include <QString> #include <QString>
@ -35,5 +34,3 @@ public:
}; };
} // namespace validators } // namespace validators
#endif // IVALIDATOR_H

View file

@ -17,11 +17,11 @@
#include "ScreenNameValidator.h" #include "ScreenNameValidator.h"
#include "validators/ComputerNameValidator.h" #include "gui/validators/ComputerNameValidator.h"
#include "validators/EmptyStringValidator.h" #include "gui/validators/EmptyStringValidator.h"
#include "validators/ScreenDuplicationsValidator.h" #include "gui/validators/ScreenDuplicationsValidator.h"
#include "validators/SpacesValidator.h" #include "gui/validators/SpacesValidator.h"
#include "validators/ValidationError.h" #include "gui/validators/ValidationError.h"
#include <QRegularExpression> #include <QRegularExpression>
#include <memory> #include <memory>

View file

@ -19,7 +19,7 @@
#include "LineEditValidator.h" #include "LineEditValidator.h"
#include "gui/config/ScreenList.h" #include "gui/config/ScreenList.h"
#include "validators/ValidationError.h" #include "gui/validators/ValidationError.h"
namespace validators { namespace validators {

View file

@ -1,7 +1,6 @@
/* /*
* synergy -- mouse and keyboard sharing utility * synergy -- mouse and keyboard sharing utility
* Copyright (C) 2012-2021 Symless Ltd. * Copyright (C) 2021 Symless Ltd.
* Copyright (C) 2008 Volker Lanz (vl@fidra.de)
* *
* This package is free software; you can redistribute it and/or * This package is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License * 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 * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include "SpacesValidator.h" #include "SpacesValidator.h"
namespace validators { namespace validators {

View file

@ -1,7 +1,6 @@
/* /*
* synergy -- mouse and keyboard sharing utility * synergy -- mouse and keyboard sharing utility
* Copyright (C) 2012-2021 Symless Ltd. * Copyright (C) 2021 Symless Ltd.
* Copyright (C) 2008 Volker Lanz (vl@fidra.de)
* *
* This package is free software; you can redistribute it and/or * This package is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License * modify it under the terms of the GNU General Public License
@ -16,8 +15,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef SPACESVALIDATOR_H #pragma once
#define SPACESVALIDATOR_H
#include "IStringValidator.h" #include "IStringValidator.h"
@ -30,5 +28,3 @@ public:
}; };
} // namespace validators } // namespace validators
#endif // SPACESVALIDATOR_H

View file

@ -23,7 +23,7 @@
namespace validators { namespace validators {
class ValidationError : QObject { class ValidationError : public QObject {
QString m_message; QString m_message;
QLabel *m_pLabel = nullptr; QLabel *m_pLabel = nullptr;

View file

@ -1,7 +1,6 @@
/* /*
* synergy -- mouse and keyboard sharing utility * synergy -- mouse and keyboard sharing utility
* Copyright (C) 2012-2021 Symless Ltd. * Copyright (C) 2021 Symless Ltd.
* Copyright (C) 2008 Volker Lanz (vl@fidra.de)
* *
* This package is free software; you can redistribute it and/or * This package is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License * 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 * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include "ClientStateLabel.h" #include "ClientStateLabel.h"
namespace synergy_widgets { namespace synergy::gui::widgets {
ClientStateLabel::ClientStateLabel(QWidget *parent) : QLabel(parent) { hide(); } ClientStateLabel::ClientStateLabel(QWidget *parent) : QLabel(parent) { hide(); }
@ -31,4 +31,4 @@ void ClientStateLabel::updateClientState(const QString &line) {
} }
} }
} // namespace synergy_widgets } // namespace synergy::gui::widgets

View file

@ -1,7 +1,6 @@
/* /*
* synergy -- mouse and keyboard sharing utility * synergy -- mouse and keyboard sharing utility
* Copyright (C) 2012-2021 Symless Ltd. * Copyright (C) 2021 Symless Ltd.
* Copyright (C) 2008 Volker Lanz (vl@fidra.de)
* *
* This package is free software; you can redistribute it and/or * This package is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License * modify it under the terms of the GNU General Public License
@ -16,12 +15,11 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef CLIENTSTATELABEL_H #pragma once
#define CLIENTSTATELABEL_H
#include <QLabel> #include <QLabel>
namespace synergy_widgets { namespace synergy::gui::widgets {
class ClientStateLabel : public QLabel { class ClientStateLabel : public QLabel {
public: public:
@ -29,6 +27,4 @@ public:
void updateClientState(const QString &line); void updateClientState(const QString &line);
}; };
} // namespace synergy_widgets } // namespace synergy::gui::widgets
#endif // CLIENTSTATELABEL_H

View file

@ -1,7 +1,6 @@
/* /*
* synergy -- mouse and keyboard sharing utility * synergy -- mouse and keyboard sharing utility
* Copyright (C) 2012-2021 Symless Ltd. * Copyright (C) 2021 Symless Ltd.
* Copyright (C) 2008 Volker Lanz (vl@fidra.de)
* *
* This package is free software; you can redistribute it and/or * This package is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License * modify it under the terms of the GNU General Public License
@ -22,7 +21,7 @@
using namespace synergy::gui; using namespace synergy::gui;
namespace synergy_widgets { namespace synergy::gui::widgets {
ServerStateLabel::ServerStateLabel(QWidget *parent) : QLabel(parent) {} ServerStateLabel::ServerStateLabel(QWidget *parent) : QLabel(parent) {}
@ -51,4 +50,4 @@ void ServerStateLabel::updateServerState(const QString &line) {
} }
} }
} // namespace synergy_widgets } // namespace synergy::gui::widgets

View file

@ -1,7 +1,6 @@
/* /*
* synergy -- mouse and keyboard sharing utility * synergy -- mouse and keyboard sharing utility
* Copyright (C) 2012-2021 Symless Ltd. * Copyright (C) 2021 Symless Ltd.
* Copyright (C) 2008 Volker Lanz (vl@fidra.de)
* *
* This package is free software; you can redistribute it and/or * This package is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License * modify it under the terms of the GNU General Public License
@ -16,13 +15,12 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef SERVERSTATELABEL_H #pragma once
#define SERVERSTATELABEL_H
#include <QLabel> #include <QLabel>
#include <QStringList> #include <QStringList>
namespace synergy_widgets { namespace synergy::gui::widgets {
class ServerStateLabel : public QLabel { class ServerStateLabel : public QLabel {
public: public:
@ -35,6 +33,4 @@ private:
void updateState(); void updateState();
}; };
} // namespace synergy_widgets } // namespace synergy::gui::widgets
#endif // SERVERSTATELABEL_H

View file

@ -132,6 +132,10 @@ macro(config_test_deps)
include_directories(${gtest_dir} ${gmock_dir} ${gtest_dir}/include include_directories(${gtest_dir} ${gmock_dir} ${gtest_dir}/include
${gmock_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(gtest STATIC ${gtest_dir}/src/gtest-all.cc)
add_library(gmock STATIC ${gmock_dir}/src/gmock-all.cc) add_library(gmock STATIC ${gmock_dir}/src/gmock-all.cc)

View file

@ -19,8 +19,8 @@
#include <QCoreApplication> #include <QCoreApplication>
int argc = 0; // NOLINT static int argc = 0; // NOLINT NOSONAR
char **argv = nullptr; // NOLINT static char **argv = nullptr; // NOLINT NOSONAR
class TestQtCoreApp : public QCoreApplication { class TestQtCoreApp : public QCoreApplication {
public: public:

View file

@ -19,13 +19,17 @@
#include <QApplication> #include <QApplication>
int argc = 0; // NOLINT static int argc = 0; // NOLINT NOSONAR
char **argv = nullptr; // NOLINT static char **argv = nullptr; // NOLINT NOSONAR
/** /**
* Prefer using `TestQtCoreApp` instead. * Prefer using `TestQtCoreApp` instead.
*/ */
class TestQtFullApp : public QApplication { class TestQtFullApp : public QApplication {
public: 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
}
}; };

View file

@ -28,13 +28,20 @@ class AppConfigMock : public synergy::gui::IAppConfig {
public: public:
AppConfigMock() { AppConfigMock() {
ON_CALL(*this, screenName()).WillByDefault(testing::ReturnRef(m_stubName)); ON_CALL(*this, screenName()).WillByDefault(testing::ReturnRef(m_stub));
ON_CALL(*this, networkInterface()) ON_CALL(*this, networkInterface())
.WillByDefault(testing::ReturnRef(m_stubInterface)); .WillByDefault(testing::ReturnRef(m_stub));
ON_CALL(*this, logLevelText())
.WillByDefault(testing::Return("stub log level")); 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(QString, tlsCertPath, (), (const, override));
MOCK_METHOD(int, tlsKeyLength, (), (const, override)); MOCK_METHOD(int, tlsKeyLength, (), (const, override));
MOCK_METHOD(bool, tlsEnabled, (), (const, override)); MOCK_METHOD(bool, tlsEnabled, (), (const, override));
@ -57,9 +64,40 @@ public:
MOCK_METHOD(const QString &, configFile, (), (const, override)); MOCK_METHOD(const QString &, configFile, (), (const, override));
MOCK_METHOD(const QString &, networkInterface, (), (const, override)); MOCK_METHOD(const QString &, networkInterface, (), (const, override));
MOCK_METHOD(const QString &, serverHostname, (), (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: private:
const QString m_stubName = "stub name"; const QString m_stub = "stub";
const QString m_stubInterface = "stub interface";
const QString m_stubAddress = "stub address";
}; };

View file

@ -23,6 +23,10 @@
class ServerConfigMock : public synergy::gui::IServerConfig { class ServerConfigMock : public synergy::gui::IServerConfig {
public: public:
ServerConfigMock() {
ON_CALL(*this, screens()).WillByDefault(testing::ReturnRef(m_screensStub));
}
MOCK_METHOD(bool, isFull, (), (const, override)); MOCK_METHOD(bool, isFull, (), (const, override));
MOCK_METHOD( MOCK_METHOD(
bool, screenExists, (const QString &screenName), (const, override)); bool, screenExists, (const QString &screenName), (const, override));
@ -30,4 +34,7 @@ public:
MOCK_METHOD(void, save, (QFile & file), (const, override)); MOCK_METHOD(void, save, (QFile & file), (const, override));
MOCK_METHOD(bool, enableDragAndDrop, (), (const, override)); MOCK_METHOD(bool, enableDragAndDrop, (), (const, override));
MOCK_METHOD(const ScreenList &, screens, (), (const, override)); MOCK_METHOD(const ScreenList &, screens, (), (const, override));
private:
ScreenList m_screensStub;
}; };

View file

@ -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 <http://www.gnu.org/licenses/>.
*/
// `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 <gtest/gtest.h>
using namespace testing;
using namespace synergy::license;
using namespace synergy::gui;
TEST(SettingsDialogTests, ctor_getsScreenName) {
TestQtFullApp app;
NiceMock<AppConfigMock> appConfig;
NiceMock<ServerConfigMock> serverConfig;
SerialKey serialKey = SerialKey::invalid();
serialKey.isValid = true;
License license(serialKey);
auto cpDeps = std::make_shared<CoreProcess::Deps>();
CoreProcess coreProcess(appConfig, serverConfig, cpDeps);
EXPECT_CALL(appConfig, screenName()).Times(1);
SettingsDialog settingsDialog(
nullptr, appConfig, serverConfig, license, coreProcess);
}
#endif

View file

@ -29,7 +29,7 @@
using synergy::test::ExitTimeout; using synergy::test::ExitTimeout;
int main(int argc, char **argv) { int main(int argc, char **argv) {
ExitTimeout exitTimeout(1, "Integration tests"); ExitTimeout exitTimeout(1, "Unit tests");
#if SYSAPI_WIN32 #if SYSAPI_WIN32
// HACK: shouldn't be needed, but logging fails without this. // HACK: shouldn't be needed, but logging fails without this.