From dc9e104f8cbe73e46f83e66acfd691160ce70d5d Mon Sep 17 00:00:00 2001 From: sithlord48 Date: Sat, 8 Mar 2025 07:24:03 -0500 Subject: [PATCH] refactor: move serverHostname to Settings newKey: client/remoteHost <= General/serverHostName remove serverHostname from AppConfig --- src/apps/deskflow-gui/MainWindow.cpp | 4 ++-- src/lib/common/Settings.h | 2 ++ src/lib/gui/config/AppConfig.cpp | 14 +------------- src/lib/gui/config/AppConfig.h | 5 +---- src/lib/gui/config/IAppConfig.h | 1 - src/lib/gui/core/ClientConnection.cpp | 3 ++- src/test/shared/gui/mocks/AppConfigMock.h | 1 - .../unittests/gui/core/ClientConnectionTests.cpp | 14 +++++++++----- 8 files changed, 17 insertions(+), 27 deletions(-) diff --git a/src/apps/deskflow-gui/MainWindow.cpp b/src/apps/deskflow-gui/MainWindow.cpp index 6e1540f8d..5ae34e234 100644 --- a/src/apps/deskflow-gui/MainWindow.cpp +++ b/src/apps/deskflow-gui/MainWindow.cpp @@ -705,7 +705,7 @@ void MainWindow::setupTrayIcon() void MainWindow::applyConfig() { - ui->lineHostname->setText(m_appConfig.serverHostname()); + ui->lineHostname->setText(Settings::value(Settings::Client::RemoteHost).toString()); updateLocalFingerprint(); setIcon(); @@ -718,7 +718,7 @@ void MainWindow::saveSettings() { m_appConfig.setServerGroupChecked(ui->rbModeServer->isChecked()); m_appConfig.setClientGroupChecked(ui->rbModeClient->isChecked()); - m_appConfig.setServerHostname(ui->lineHostname->text()); + Settings::setValue(Settings::Client::RemoteHost, ui->lineHostname->text()); m_configScopes.save(); } diff --git a/src/lib/common/Settings.h b/src/lib/common/Settings.h index da88d47fb..75f7677ae 100644 --- a/src/lib/common/Settings.h +++ b/src/lib/common/Settings.h @@ -32,6 +32,7 @@ public: struct Client { inline static const auto Binary = QStringLiteral("client/binary"); + inline static const auto RemoteHost = QStringLiteral("client/remotehost"); }; struct Core { @@ -93,6 +94,7 @@ private: // clang-format off inline static const QStringList m_validKeys = { Client::Binary + , Client::RemoteHost , Core::LastVersion , Core::PreventSleep , Core::Scope diff --git a/src/lib/gui/config/AppConfig.cpp b/src/lib/gui/config/AppConfig.cpp index a91412220..2567d8af3 100644 --- a/src/lib/gui/config/AppConfig.cpp +++ b/src/lib/gui/config/AppConfig.cpp @@ -58,7 +58,7 @@ const char *const AppConfig::m_SettingsName[] = { "configFile", "useInternalConfig", "groupClientChecked", - "serverHostname", + "", // 25 server host name moved to deskflow settings "", // 26 cert path moved to deskflow settings "", // 27 key length Moved to Deskflow settings "", // 28 Prevent sleep moved to deskflow settings @@ -124,7 +124,6 @@ void AppConfig::recallFromCurrentScope() m_ConfigFile = getFromCurrentScope(kConfigFile, m_ConfigFile).toString(); m_UseInternalConfig = getFromCurrentScope(kUseInternalConfig, m_UseInternalConfig).toBool(); m_ClientGroupChecked = getFromCurrentScope(kClientGroupChecked, m_ClientGroupChecked).toBool(); - m_ServerHostname = getFromCurrentScope(kServerHostname, m_ServerHostname).toString(); m_LanguageSync = getFromCurrentScope(kLanguageSync, m_LanguageSync).toBool(); m_InvertScrollDirection = getFromCurrentScope(kInvertScrollDirection, m_InvertScrollDirection).toBool(); m_EnableService = getFromCurrentScope(kEnableService, m_EnableService).toBool(); @@ -169,7 +168,6 @@ void AppConfig::commit() setInCurrentScope(kUseExternalConfig, m_UseExternalConfig); setInCurrentScope(kConfigFile, m_ConfigFile); setInCurrentScope(kUseInternalConfig, m_UseInternalConfig); - setInCurrentScope(kServerHostname, m_ServerHostname); setInCurrentScope(kLanguageSync, m_LanguageSync); setInCurrentScope(kInvertScrollDirection, m_InvertScrollDirection); setInCurrentScope(kEnableService, m_EnableService); @@ -451,11 +449,6 @@ bool AppConfig::clientGroupChecked() const return m_ClientGroupChecked; } -const QString &AppConfig::serverHostname() const -{ - return m_ServerHostname; -} - /////////////////////////////////////////////////////////////////////////////// // End getters /////////////////////////////////////////////////////////////////////////////// @@ -489,11 +482,6 @@ void AppConfig::setClientGroupChecked(bool newValue) m_ClientGroupChecked = newValue; } -void AppConfig::setServerHostname(const QString &newValue) -{ - m_ServerHostname = newValue; -} - void AppConfig::setScreenName(const QString &s) { m_ScreenName = s; diff --git a/src/lib/gui/config/AppConfig.h b/src/lib/gui/config/AppConfig.h index 8d87cdc91..5d140c9f0 100644 --- a/src/lib/gui/config/AppConfig.h +++ b/src/lib/gui/config/AppConfig.h @@ -79,7 +79,7 @@ private: kConfigFile = 22, kUseInternalConfig = 23, kClientGroupChecked = 24, - kServerHostname = 25, + // 25 = serverHostName moved to deskflow settings // 26 = kTlsCertPath moved to deskflow settings // 27 = tlsKeyLength Moved to deskflow settings // 28 = Prevent Sleep moved to deskflow settings @@ -141,7 +141,6 @@ public: bool useExternalConfig() const override; 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; @@ -180,7 +179,6 @@ public: void setConfigFile(const QString &); void setUseInternalConfig(bool); void setClientGroupChecked(bool); - void setServerHostname(const QString &); /// @brief Sets the user preference to load from SystemScope. /// @param [in] value @@ -259,7 +257,6 @@ private: QString m_ConfigFile = QStringLiteral("%1/%2.%3").arg(QDir::homePath(), kAppId, s_ConfigFileExt); bool m_UseInternalConfig = false; bool m_ClientGroupChecked = false; - QString m_ServerHostname = ""; bool m_EnableService = deskflow::gui::kDefaultProcessMode == ProcessMode::kService; bool m_LoadFromSystemScope = false; diff --git a/src/lib/gui/config/IAppConfig.h b/src/lib/gui/config/IAppConfig.h index abb86f9ab..f9e704e53 100644 --- a/src/lib/gui/config/IAppConfig.h +++ b/src/lib/gui/config/IAppConfig.h @@ -45,7 +45,6 @@ public: virtual bool useExternalConfig() const = 0; 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 enableService() const = 0; virtual bool isActiveScopeSystem() const = 0; diff --git a/src/lib/gui/core/ClientConnection.cpp b/src/lib/gui/core/ClientConnection.cpp index 6cc5309a4..571a07121 100644 --- a/src/lib/gui/core/ClientConnection.cpp +++ b/src/lib/gui/core/ClientConnection.cpp @@ -6,6 +6,7 @@ #include "ClientConnection.h" +#include "common/settings.h" #include "messages.h" #include @@ -57,7 +58,7 @@ void ClientConnection::showMessage(const QString &logLine) Q_EMIT messageShowing(); - const auto address = m_appConfig.serverHostname(); + const auto address = Settings::value(Settings::Client::RemoteHost).toString(); if (logLine.contains("server already has a connected client with our name")) { m_deps->showError(m_pParent, AlreadyConnected, address); diff --git a/src/test/shared/gui/mocks/AppConfigMock.h b/src/test/shared/gui/mocks/AppConfigMock.h index fbe085e6f..6fb06bb94 100644 --- a/src/test/shared/gui/mocks/AppConfigMock.h +++ b/src/test/shared/gui/mocks/AppConfigMock.h @@ -46,7 +46,6 @@ public: MOCK_METHOD(bool, useExternalConfig, (), (const, override)); 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, enableService, (), (const, override)); MOCK_METHOD(bool, isActiveScopeSystem, (), (const, override)); diff --git a/src/test/unittests/gui/core/ClientConnectionTests.cpp b/src/test/unittests/gui/core/ClientConnectionTests.cpp index 77491f3e1..68da00892 100644 --- a/src/test/unittests/gui/core/ClientConnectionTests.cpp +++ b/src/test/unittests/gui/core/ClientConnectionTests.cpp @@ -4,6 +4,7 @@ * SPDX-License-Identifier: GPL-2.0-only WITH LicenseRef-OpenSSL-Exception */ +#include "common/settings.h" #include "gui/core/ClientConnection.h" #include "shared/gui/mocks/AppConfigMock.h" @@ -34,7 +35,7 @@ class ClientConnectionTests : public testing::Test public: ClientConnectionTests() { - ON_CALL(m_appConfig, serverHostname()).WillByDefault(testing::ReturnRef(stub)); + Settings::setValue(Settings::Client::RemoteHost, stub); } std::shared_ptr m_pDeps = std::make_shared>(); @@ -47,8 +48,9 @@ private: TEST_F(ClientConnectionTests, handleLogLine_alreadyConnected_showError) { ClientConnection clientConnection(nullptr, m_appConfig, m_pDeps); + const QString serverName = "test server"; - ON_CALL(m_appConfig, serverHostname()).WillByDefault(testing::ReturnRef(serverName)); + Settings::setValue(Settings::Client::RemoteHost, serverName); EXPECT_CALL(*m_pDeps, showError(_, AlreadyConnected, serverName)); @@ -61,8 +63,9 @@ TEST_F(ClientConnectionTests, handleLogLine_alreadyConnected_showError) TEST_F(ClientConnectionTests, handleLogLine_withHostname_showError) { ClientConnection clientConnection(nullptr, m_appConfig, m_pDeps); - const QString serverName = "test-hostname"; - ON_CALL(m_appConfig, serverHostname()).WillByDefault(testing::ReturnRef(serverName)); + + const QString serverName = "test hostname"; + Settings::setValue(Settings::Client::RemoteHost, serverName); EXPECT_CALL(*m_pDeps, showError(_, HostnameError, serverName)); @@ -72,8 +75,9 @@ TEST_F(ClientConnectionTests, handleLogLine_withHostname_showError) TEST_F(ClientConnectionTests, handleLogLine_withIpAddress_showError) { ClientConnection clientConnection(nullptr, m_appConfig, m_pDeps); + const QString serverName = "1.1.1.1"; - ON_CALL(m_appConfig, serverHostname()).WillByDefault(testing::ReturnRef(serverName)); + Settings::setValue(Settings::Client::RemoteHost, serverName); EXPECT_CALL(*m_pDeps, showError(_, GenericError, serverName));