refactor: move serverHostname to Settings

newKey: client/remoteHost <= General/serverHostName
remove serverHostname from AppConfig
This commit is contained in:
sithlord48 2025-03-08 07:24:03 -05:00 committed by Nick Bolton
parent f456aab196
commit dc9e104f8c
8 changed files with 17 additions and 27 deletions

View file

@ -705,7 +705,7 @@ void MainWindow::setupTrayIcon()
void MainWindow::applyConfig() void MainWindow::applyConfig()
{ {
ui->lineHostname->setText(m_appConfig.serverHostname()); ui->lineHostname->setText(Settings::value(Settings::Client::RemoteHost).toString());
updateLocalFingerprint(); updateLocalFingerprint();
setIcon(); setIcon();
@ -718,7 +718,7 @@ void MainWindow::saveSettings()
{ {
m_appConfig.setServerGroupChecked(ui->rbModeServer->isChecked()); m_appConfig.setServerGroupChecked(ui->rbModeServer->isChecked());
m_appConfig.setClientGroupChecked(ui->rbModeClient->isChecked()); m_appConfig.setClientGroupChecked(ui->rbModeClient->isChecked());
m_appConfig.setServerHostname(ui->lineHostname->text()); Settings::setValue(Settings::Client::RemoteHost, ui->lineHostname->text());
m_configScopes.save(); m_configScopes.save();
} }

View file

@ -32,6 +32,7 @@ public:
struct Client struct Client
{ {
inline static const auto Binary = QStringLiteral("client/binary"); inline static const auto Binary = QStringLiteral("client/binary");
inline static const auto RemoteHost = QStringLiteral("client/remotehost");
}; };
struct Core struct Core
{ {
@ -93,6 +94,7 @@ private:
// clang-format off // clang-format off
inline static const QStringList m_validKeys = { inline static const QStringList m_validKeys = {
Client::Binary Client::Binary
, Client::RemoteHost
, Core::LastVersion , Core::LastVersion
, Core::PreventSleep , Core::PreventSleep
, Core::Scope , Core::Scope

View file

@ -58,7 +58,7 @@ const char *const AppConfig::m_SettingsName[] = {
"configFile", "configFile",
"useInternalConfig", "useInternalConfig",
"groupClientChecked", "groupClientChecked",
"serverHostname", "", // 25 server host name moved to deskflow settings
"", // 26 cert path moved to deskflow settings "", // 26 cert path moved to deskflow settings
"", // 27 key length Moved to Deskflow settings "", // 27 key length Moved to Deskflow settings
"", // 28 Prevent sleep 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_ConfigFile = getFromCurrentScope(kConfigFile, m_ConfigFile).toString();
m_UseInternalConfig = getFromCurrentScope(kUseInternalConfig, m_UseInternalConfig).toBool(); m_UseInternalConfig = getFromCurrentScope(kUseInternalConfig, m_UseInternalConfig).toBool();
m_ClientGroupChecked = getFromCurrentScope(kClientGroupChecked, m_ClientGroupChecked).toBool(); m_ClientGroupChecked = getFromCurrentScope(kClientGroupChecked, m_ClientGroupChecked).toBool();
m_ServerHostname = getFromCurrentScope(kServerHostname, m_ServerHostname).toString();
m_LanguageSync = getFromCurrentScope(kLanguageSync, m_LanguageSync).toBool(); m_LanguageSync = getFromCurrentScope(kLanguageSync, m_LanguageSync).toBool();
m_InvertScrollDirection = getFromCurrentScope(kInvertScrollDirection, m_InvertScrollDirection).toBool(); m_InvertScrollDirection = getFromCurrentScope(kInvertScrollDirection, m_InvertScrollDirection).toBool();
m_EnableService = getFromCurrentScope(kEnableService, m_EnableService).toBool(); m_EnableService = getFromCurrentScope(kEnableService, m_EnableService).toBool();
@ -169,7 +168,6 @@ void AppConfig::commit()
setInCurrentScope(kUseExternalConfig, m_UseExternalConfig); setInCurrentScope(kUseExternalConfig, m_UseExternalConfig);
setInCurrentScope(kConfigFile, m_ConfigFile); setInCurrentScope(kConfigFile, m_ConfigFile);
setInCurrentScope(kUseInternalConfig, m_UseInternalConfig); setInCurrentScope(kUseInternalConfig, m_UseInternalConfig);
setInCurrentScope(kServerHostname, m_ServerHostname);
setInCurrentScope(kLanguageSync, m_LanguageSync); setInCurrentScope(kLanguageSync, m_LanguageSync);
setInCurrentScope(kInvertScrollDirection, m_InvertScrollDirection); setInCurrentScope(kInvertScrollDirection, m_InvertScrollDirection);
setInCurrentScope(kEnableService, m_EnableService); setInCurrentScope(kEnableService, m_EnableService);
@ -451,11 +449,6 @@ bool AppConfig::clientGroupChecked() const
return m_ClientGroupChecked; return m_ClientGroupChecked;
} }
const QString &AppConfig::serverHostname() const
{
return m_ServerHostname;
}
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
// End getters // End getters
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
@ -489,11 +482,6 @@ void AppConfig::setClientGroupChecked(bool newValue)
m_ClientGroupChecked = newValue; m_ClientGroupChecked = newValue;
} }
void AppConfig::setServerHostname(const QString &newValue)
{
m_ServerHostname = newValue;
}
void AppConfig::setScreenName(const QString &s) void AppConfig::setScreenName(const QString &s)
{ {
m_ScreenName = s; m_ScreenName = s;

View file

@ -79,7 +79,7 @@ private:
kConfigFile = 22, kConfigFile = 22,
kUseInternalConfig = 23, kUseInternalConfig = 23,
kClientGroupChecked = 24, kClientGroupChecked = 24,
kServerHostname = 25, // 25 = serverHostName moved to deskflow settings
// 26 = kTlsCertPath moved to deskflow settings // 26 = kTlsCertPath moved to deskflow settings
// 27 = tlsKeyLength Moved to deskflow settings // 27 = tlsKeyLength Moved to deskflow settings
// 28 = Prevent Sleep moved to deskflow settings // 28 = Prevent Sleep moved to deskflow settings
@ -141,7 +141,6 @@ public:
bool useExternalConfig() const override; bool useExternalConfig() const override;
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;
bool isActiveScopeWritable() const override; bool isActiveScopeWritable() const override;
bool isActiveScopeSystem() const override; bool isActiveScopeSystem() const override;
int logLevel() const override; int logLevel() const override;
@ -180,7 +179,6 @@ public:
void setConfigFile(const QString &); void setConfigFile(const QString &);
void setUseInternalConfig(bool); void setUseInternalConfig(bool);
void setClientGroupChecked(bool); void setClientGroupChecked(bool);
void setServerHostname(const QString &);
/// @brief Sets the user preference to load from SystemScope. /// @brief Sets the user preference to load from SystemScope.
/// @param [in] value /// @param [in] value
@ -259,7 +257,6 @@ private:
QString m_ConfigFile = QStringLiteral("%1/%2.%3").arg(QDir::homePath(), kAppId, s_ConfigFileExt); QString m_ConfigFile = QStringLiteral("%1/%2.%3").arg(QDir::homePath(), kAppId, s_ConfigFileExt);
bool m_UseInternalConfig = false; bool m_UseInternalConfig = false;
bool m_ClientGroupChecked = false; bool m_ClientGroupChecked = false;
QString m_ServerHostname = "";
bool m_EnableService = deskflow::gui::kDefaultProcessMode == ProcessMode::kService; bool m_EnableService = deskflow::gui::kDefaultProcessMode == ProcessMode::kService;
bool m_LoadFromSystemScope = false; bool m_LoadFromSystemScope = false;

View file

@ -45,7 +45,6 @@ public:
virtual bool useExternalConfig() const = 0; virtual bool useExternalConfig() const = 0;
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 int logLevel() const = 0; virtual int logLevel() const = 0;
virtual bool enableService() const = 0; virtual bool enableService() const = 0;
virtual bool isActiveScopeSystem() const = 0; virtual bool isActiveScopeSystem() const = 0;

View file

@ -6,6 +6,7 @@
#include "ClientConnection.h" #include "ClientConnection.h"
#include "common/settings.h"
#include "messages.h" #include "messages.h"
#include <QHostAddress> #include <QHostAddress>
@ -57,7 +58,7 @@ void ClientConnection::showMessage(const QString &logLine)
Q_EMIT messageShowing(); 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")) { if (logLine.contains("server already has a connected client with our name")) {
m_deps->showError(m_pParent, AlreadyConnected, address); m_deps->showError(m_pParent, AlreadyConnected, address);

View file

@ -46,7 +46,6 @@ public:
MOCK_METHOD(bool, useExternalConfig, (), (const, override)); MOCK_METHOD(bool, useExternalConfig, (), (const, override));
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(int, logLevel, (), (const, override)); MOCK_METHOD(int, logLevel, (), (const, override));
MOCK_METHOD(bool, enableService, (), (const, override)); MOCK_METHOD(bool, enableService, (), (const, override));
MOCK_METHOD(bool, isActiveScopeSystem, (), (const, override)); MOCK_METHOD(bool, isActiveScopeSystem, (), (const, override));

View file

@ -4,6 +4,7 @@
* SPDX-License-Identifier: GPL-2.0-only WITH LicenseRef-OpenSSL-Exception * SPDX-License-Identifier: GPL-2.0-only WITH LicenseRef-OpenSSL-Exception
*/ */
#include "common/settings.h"
#include "gui/core/ClientConnection.h" #include "gui/core/ClientConnection.h"
#include "shared/gui/mocks/AppConfigMock.h" #include "shared/gui/mocks/AppConfigMock.h"
@ -34,7 +35,7 @@ class ClientConnectionTests : public testing::Test
public: public:
ClientConnectionTests() ClientConnectionTests()
{ {
ON_CALL(m_appConfig, serverHostname()).WillByDefault(testing::ReturnRef(stub)); Settings::setValue(Settings::Client::RemoteHost, stub);
} }
std::shared_ptr<DepsMock> m_pDeps = std::make_shared<NiceMock<DepsMock>>(); std::shared_ptr<DepsMock> m_pDeps = std::make_shared<NiceMock<DepsMock>>();
@ -47,8 +48,9 @@ private:
TEST_F(ClientConnectionTests, handleLogLine_alreadyConnected_showError) TEST_F(ClientConnectionTests, handleLogLine_alreadyConnected_showError)
{ {
ClientConnection clientConnection(nullptr, m_appConfig, m_pDeps); ClientConnection clientConnection(nullptr, m_appConfig, m_pDeps);
const QString serverName = "test server"; 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)); EXPECT_CALL(*m_pDeps, showError(_, AlreadyConnected, serverName));
@ -61,8 +63,9 @@ TEST_F(ClientConnectionTests, handleLogLine_alreadyConnected_showError)
TEST_F(ClientConnectionTests, handleLogLine_withHostname_showError) TEST_F(ClientConnectionTests, handleLogLine_withHostname_showError)
{ {
ClientConnection clientConnection(nullptr, m_appConfig, m_pDeps); 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)); EXPECT_CALL(*m_pDeps, showError(_, HostnameError, serverName));
@ -72,8 +75,9 @@ TEST_F(ClientConnectionTests, handleLogLine_withHostname_showError)
TEST_F(ClientConnectionTests, handleLogLine_withIpAddress_showError) TEST_F(ClientConnectionTests, handleLogLine_withIpAddress_showError)
{ {
ClientConnection clientConnection(nullptr, m_appConfig, m_pDeps); ClientConnection clientConnection(nullptr, m_appConfig, m_pDeps);
const QString serverName = "1.1.1.1"; 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)); EXPECT_CALL(*m_pDeps, showError(_, GenericError, serverName));