refactor: move serverHostname to Settings
newKey: client/remoteHost <= General/serverHostName remove serverHostname from AppConfig
This commit is contained in:
@ -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();
|
||||
}
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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;
|
||||
|
||||
@ -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;
|
||||
|
||||
|
||||
@ -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;
|
||||
|
||||
@ -6,6 +6,7 @@
|
||||
|
||||
#include "ClientConnection.h"
|
||||
|
||||
#include "common/settings.h"
|
||||
#include "messages.h"
|
||||
|
||||
#include <QHostAddress>
|
||||
@ -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);
|
||||
|
||||
@ -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));
|
||||
|
||||
@ -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<DepsMock> m_pDeps = std::make_shared<NiceMock<DepsMock>>();
|
||||
@ -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));
|
||||
|
||||
|
||||
Reference in New Issue
Block a user