refactor: move external configfile to Settings

newkey: server/externalConfigFile <= General/configFile
remove configFile from AppConfig
This commit is contained in:
sithlord48 2025-03-08 11:37:04 -05:00 committed by Nick Bolton
parent b833ca7a45
commit b20d6361d6
10 changed files with 15 additions and 32 deletions

View file

@ -404,9 +404,9 @@ void ServerConfig::updateServerName()
}
}
const QString &ServerConfig::configFile() const
const QString ServerConfig::configFile() const
{
return m_pAppConfig->configFile();
return Settings::value(Settings::Server::ExternalConfigFile).toString();
}
bool ServerConfig::useExternalConfig() const
@ -457,7 +457,7 @@ void ServerConfig::addClient(const QString &clientName)
void ServerConfig::setConfigFile(const QString &configFile)
{
m_pAppConfig->setConfigFile(configFile);
Settings::setValue(Settings::Server::ExternalConfigFile, configFile);
}
void ServerConfig::setUseExternalConfig(bool useExternalConfig)

View file

@ -157,7 +157,7 @@ public:
int autoAddScreen(const QString name);
const QString &getServerName() const;
void updateServerName();
const QString &configFile() const;
const QString configFile() const;
bool useExternalConfig() const;
void addClient(const QString &clientName);
QString getClientAddress() const;

View file

@ -95,6 +95,11 @@ QVariant Settings::defaultValue(const QString &key)
if (key == Server::Binary)
return kServerBinName;
if (key == Server::ExternalConfigFile) {
const auto baseDir = QFileInfo(instance()->m_settings->fileName()).absolutePath();
return QStringLiteral("%1/%2.conf").arg(baseDir, kAppId);
}
return QVariant();
}

View file

@ -62,6 +62,7 @@ public:
{
inline static const auto Binary = QStringLiteral("server/binary");
inline static const auto ExternalConfig = QStringLiteral("server/externalConfig");
inline static const auto ExternalConfigFile = QStringLiteral("server/externalConfigFile");
};
static Settings *instance();
@ -113,6 +114,7 @@ private:
, Security::TlsEnabled
, Server::Binary
, Server::ExternalConfig
, Server::ExternalConfigFile
};
// clang-format on
};

View file

@ -55,7 +55,7 @@ const char *const AppConfig::m_SettingsName[] = {
"loadFromSystemScope",
"groupServerChecked", // kServerGroupChecked
"", // 21 = use external config moved to deskflow settings
"configFile",
"", // 22 config file moved to dekflow settings
"useInternalConfig",
"groupClientChecked",
"", // 25 server host name moved to deskflow settings
@ -120,7 +120,6 @@ void AppConfig::recallFromCurrentScope()
m_LogToFile = getFromCurrentScope(kLogToFile, m_LogToFile).toBool();
m_LogFilename = getFromCurrentScope(kLogFilename, m_LogFilename).toString();
m_ServerGroupChecked = getFromCurrentScope(kServerGroupChecked, m_ServerGroupChecked).toBool();
m_ConfigFile = getFromCurrentScope(kConfigFile, m_ConfigFile).toString();
m_UseInternalConfig = getFromCurrentScope(kUseInternalConfig, m_UseInternalConfig).toBool();
m_ClientGroupChecked = getFromCurrentScope(kClientGroupChecked, m_ClientGroupChecked).toBool();
m_LanguageSync = getFromCurrentScope(kLanguageSync, m_LanguageSync).toBool();
@ -164,7 +163,6 @@ void AppConfig::commit()
setInCurrentScope(kLogFilename, m_LogFilename);
setInCurrentScope(kElevateMode, static_cast<int>(m_ElevateMode));
setInCurrentScope(kElevateModeLegacy, m_ElevateMode == ElevateMode::kAlways);
setInCurrentScope(kConfigFile, m_ConfigFile);
setInCurrentScope(kUseInternalConfig, m_UseInternalConfig);
setInCurrentScope(kLanguageSync, m_LanguageSync);
setInCurrentScope(kInvertScrollDirection, m_InvertScrollDirection);
@ -427,11 +425,6 @@ bool AppConfig::serverGroupChecked() const
return m_ServerGroupChecked;
}
const QString &AppConfig::configFile() const
{
return m_ConfigFile;
}
bool AppConfig::useInternalConfig() const
{
return m_UseInternalConfig;
@ -455,11 +448,6 @@ void AppConfig::setServerGroupChecked(bool newValue)
m_ServerGroupChecked = newValue;
}
void AppConfig::setConfigFile(const QString &newValue)
{
m_ConfigFile = newValue;
}
void AppConfig::setUseInternalConfig(bool newValue)
{
m_UseInternalConfig = newValue;

View file

@ -76,7 +76,7 @@ private:
kLoadSystemSettings = 19,
kServerGroupChecked = 20,
// 21 = use external config moved to deskflow settings
kConfigFile = 22,
// 22 = k config file moved to deskflow settings
kUseInternalConfig = 23,
kClientGroupChecked = 24,
// 25 = serverHostName moved to deskflow settings
@ -138,7 +138,6 @@ public:
bool languageSync() const override;
bool invertScrollDirection() const override;
int port() const override;
const QString &configFile() const override;
const QString &networkInterface() const override;
bool isActiveScopeWritable() const override;
bool isActiveScopeSystem() const override;
@ -174,7 +173,6 @@ public:
//
void setServerGroupChecked(bool);
void setConfigFile(const QString &);
void setUseInternalConfig(bool);
void setClientGroupChecked(bool);
@ -235,13 +233,6 @@ private:
/// @brief Contains the string values of the settings names that will be saved
static const char *const m_SettingsName[];
/// @brief Core config file extention (not the Qt settings filename)
#ifdef Q_OS_WIN
inline static const auto s_ConfigFileExt = QStringLiteral("sgc");
#else
inline static const auto s_ConfigFileExt = QStringLiteral("conf");
#endif
int m_Port = 24800;
QString m_Interface = "";
int m_LogLevel = 0;
@ -251,7 +242,6 @@ private:
bool m_InvertScrollDirection = false;
bool m_LanguageSync = true;
bool m_ServerGroupChecked = false;
QString m_ConfigFile = QStringLiteral("%1/%2.%3").arg(QDir::homePath(), kAppId, s_ConfigFileExt);
bool m_UseInternalConfig = false;
bool m_ClientGroupChecked = false;
bool m_EnableService = deskflow::gui::kDefaultProcessMode == ProcessMode::kService;

View file

@ -42,7 +42,6 @@ public:
virtual bool languageSync() const = 0;
virtual bool invertScrollDirection() const = 0;
virtual int port() const = 0;
virtual const QString &configFile() const = 0;
virtual const QString &networkInterface() const = 0;
virtual int logLevel() const = 0;
virtual bool enableService() const = 0;

View file

@ -603,7 +603,7 @@ bool CoreProcess::addClientArgs(QStringList &args, QString &app)
QString CoreProcess::persistServerConfig() const
{
if (Settings::value(Settings::Server::ExternalConfig).toBool()) {
return m_appConfig.configFile();
return Settings::value(Settings::Server::ExternalConfigFile).toString();
}
const auto configDir = paths::configDir(true);

View file

@ -43,7 +43,6 @@ public:
MOCK_METHOD(bool, languageSync, (), (const, override));
MOCK_METHOD(bool, invertScrollDirection, (), (const, override));
MOCK_METHOD(int, port, (), (const, override));
MOCK_METHOD(const QString &, configFile, (), (const, override));
MOCK_METHOD(const QString &, networkInterface, (), (const, override));
MOCK_METHOD(int, logLevel, (), (const, override));
MOCK_METHOD(bool, enableService, (), (const, override));

View file

@ -70,7 +70,7 @@ public:
CoreProcessTests() : m_coreProcess(m_appConfig, m_serverConfig, m_pDeps)
{
Settings::setValue(Settings::Server::ExternalConfig, true);
ON_CALL(m_appConfig, configFile()).WillByDefault(testing::ReturnRef(m_configFile));
Settings::setValue(Settings::Server::ExternalConfigFile, m_configFile);
ON_CALL(m_appConfig, processMode()).WillByDefault(Return(ProcessMode::kDesktop));
}