refactor: move port to Settigns

newkey: core/port <= General/port
remove port from AppConfig
This commit is contained in:
sithlord48 2025-03-08 19:25:57 -05:00 committed by Nick Bolton
parent 9aa1d6b79d
commit 5e6381c88a
8 changed files with 21 additions and 33 deletions

View file

@ -143,7 +143,7 @@ void SettingsDialog::showReadOnlyMessage()
void SettingsDialog::accept() void SettingsDialog::accept()
{ {
m_appConfig.setLoadFromSystemScope(ui->rbScopeSystem->isChecked()); m_appConfig.setLoadFromSystemScope(ui->rbScopeSystem->isChecked());
m_appConfig.setPort(ui->sbPort->value()); Settings::setValue(Settings::Core::Port, ui->sbPort->value());
Settings::setValue(Settings::Core::Interface, ui->lineInterface->text()); Settings::setValue(Settings::Core::Interface, ui->lineInterface->text());
m_appConfig.setLogLevel(ui->comboLogLevel->currentIndex()); m_appConfig.setLogLevel(ui->comboLogLevel->currentIndex());
m_appConfig.setLogToFile(ui->cbLogToFile->isChecked()); m_appConfig.setLogToFile(ui->cbLogToFile->isChecked());
@ -178,7 +178,7 @@ void SettingsDialog::reject()
void SettingsDialog::loadFromConfig() void SettingsDialog::loadFromConfig()
{ {
ui->sbPort->setValue(m_appConfig.port()); ui->sbPort->setValue(Settings::value(Settings::Core::Port).toInt());
ui->lineInterface->setText(Settings::value(Settings::Core::Interface).toString()); ui->lineInterface->setText(Settings::value(Settings::Core::Interface).toString());
ui->comboLogLevel->setCurrentIndex(m_appConfig.logLevel()); ui->comboLogLevel->setCurrentIndex(m_appConfig.logLevel());
ui->cbLogToFile->setChecked(m_appConfig.logToFile()); ui->cbLogToFile->setChecked(m_appConfig.logToFile());

View file

@ -84,22 +84,26 @@ QVariant Settings::defaultValue(const QString &key)
if (key == Gui::WindowGeometry) if (key == Gui::WindowGeometry)
return QRect(); return QRect();
if (key == Security::KeySize)
return 2048;
if (key == Security::Certificate) if (key == Security::Certificate)
return QStringLiteral("%1/%2/%3").arg(instance()->settingsPath(), kTlsDirName, kTlsCertificateFilename); return QStringLiteral("%1/%2/%3").arg(instance()->settingsPath(), kTlsDirName, kTlsCertificateFilename);
if (key == Security::KeySize)
return 2048;
if (key == Client::Binary) if (key == Client::Binary)
return kClientBinName; return kClientBinName;
if (key == Server::Binary) if (key == Server::Binary)
return kServerBinName; return kServerBinName;
if (key == Server::ExternalConfigFile) { if (key == Server::ExternalConfigFile)
const auto baseDir = QFileInfo(instance()->m_settings->fileName()).absolutePath(); return QStringLiteral("%1/%2.conf").arg(instance()->settingsPath(), kAppId);
return QStringLiteral("%1/%2.conf").arg(baseDir, kAppId);
} if (key == Security::KeySize)
return 2048;
if (key == Core::Port)
return 24800;
return QVariant(); return QVariant();
} }

View file

@ -40,6 +40,7 @@ public:
{ {
inline static const auto Interface = QStringLiteral("core/interface"); inline static const auto Interface = QStringLiteral("core/interface");
inline static const auto LastVersion = QStringLiteral("core/lastVersion"); inline static const auto LastVersion = QStringLiteral("core/lastVersion");
inline static const auto Port = QStringLiteral("core/port");
inline static const auto PreventSleep = QStringLiteral("core/preventSleep"); inline static const auto PreventSleep = QStringLiteral("core/preventSleep");
inline static const auto Scope = QStringLiteral("core/loadFromSystemScope"); inline static const auto Scope = QStringLiteral("core/loadFromSystemScope");
inline static const auto StartedBefore = QStringLiteral("core/startedBefore"); inline static const auto StartedBefore = QStringLiteral("core/startedBefore");
@ -104,6 +105,7 @@ private:
, Client::RemoteHost , Client::RemoteHost
, Core::Interface , Core::Interface
, Core::LastVersion , Core::LastVersion
, Core::Port
, Core::PreventSleep , Core::PreventSleep
, Core::Scope , Core::Scope
, Core::StartedBefore , Core::StartedBefore

View file

@ -34,7 +34,7 @@ const char AppConfig::m_LogDir[] = "/var/log/";
// TODO: instead, use key value pair table, which would be less fragile. // TODO: instead, use key value pair table, which would be less fragile.
const char *const AppConfig::m_SettingsName[] = { const char *const AppConfig::m_SettingsName[] = {
"screenName", "screenName",
"port", "", // port moved to deskflow settings
"", // interface moved to deskflow settings "", // interface moved to deskflow settings
"logLevel2", "logLevel2",
"logToFile", "logToFile",
@ -114,7 +114,6 @@ void AppConfig::recallFromCurrentScope()
recallScreenName(); recallScreenName();
recallElevateMode(); recallElevateMode();
m_Port = getFromCurrentScope(kPort, m_Port).toInt();
m_LogLevel = getFromCurrentScope(kLogLevel, m_LogLevel).toInt(); m_LogLevel = getFromCurrentScope(kLogLevel, m_LogLevel).toInt();
m_LogToFile = getFromCurrentScope(kLogToFile, m_LogToFile).toBool(); m_LogToFile = getFromCurrentScope(kLogToFile, m_LogToFile).toBool();
m_LogFilename = getFromCurrentScope(kLogFilename, m_LogFilename).toString(); m_LogFilename = getFromCurrentScope(kLogFilename, m_LogFilename).toString();
@ -153,7 +152,6 @@ void AppConfig::commit()
if (isActiveScopeWritable()) { if (isActiveScopeWritable()) {
setInCurrentScope(kScreenName, m_ScreenName); setInCurrentScope(kScreenName, m_ScreenName);
setInCurrentScope(kPort, m_Port);
setInCurrentScope(kLogLevel, m_LogLevel); setInCurrentScope(kLogLevel, m_LogLevel);
setInCurrentScope(kLogToFile, m_LogToFile); setInCurrentScope(kLogToFile, m_LogToFile);
setInCurrentScope(kLogFilename, m_LogFilename); setInCurrentScope(kLogFilename, m_LogFilename);
@ -359,11 +357,6 @@ const QString &AppConfig::screenName() const
return m_ScreenName; return m_ScreenName;
} }
int AppConfig::port() const
{
return m_Port;
}
int AppConfig::logLevel() const int AppConfig::logLevel() const
{ {
return m_LogLevel; return m_LogLevel;
@ -443,11 +436,6 @@ void AppConfig::setScreenName(const QString &s)
Q_EMIT screenNameChanged(); Q_EMIT screenNameChanged();
} }
void AppConfig::setPort(int i)
{
m_Port = i;
}
void AppConfig::setLogLevel(int i) void AppConfig::setLogLevel(int i)
{ {
const auto changed = (m_LogLevel != i); const auto changed = (m_LogLevel != i);

View file

@ -55,7 +55,7 @@ private:
enum class Setting enum class Setting
{ {
kScreenName = 0, kScreenName = 0,
kPort = 1, // kPort = 1, moved to deskflow settings
// kInterface = 2, moved to deskflow settings // kInterface = 2, moved to deskflow settings
kLogLevel = 3, kLogLevel = 3,
kLogToFile = 4, kLogToFile = 4,
@ -135,7 +135,6 @@ public:
bool logToFile() const override; bool logToFile() const override;
const QString &logFilename() const override; const QString &logFilename() const override;
void persistLogDir() const override; void persistLogDir() const override;
int port() 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;
@ -155,7 +154,6 @@ public:
// //
void setScreenName(const QString &s) override; void setScreenName(const QString &s) override;
void setPort(int i) override;
void setLogLevel(int i) override; void setLogLevel(int i) override;
void setLogToFile(bool b) override; void setLogToFile(bool b) override;
void setLogFilename(const QString &s) override; void setLogFilename(const QString &s) override;
@ -227,7 +225,6 @@ private:
/// @brief Contains the string values of the settings names that will be saved /// @brief Contains the string values of the settings names that will be saved
static const char *const m_SettingsName[]; static const char *const m_SettingsName[];
int m_Port = 24800;
int m_LogLevel = 0; int m_LogLevel = 0;
bool m_LogToFile = false; bool m_LogToFile = false;
QString m_LogFilename = logDir() + deskflow::gui::kDefaultLogFile; QString m_LogFilename = logDir() + deskflow::gui::kDefaultLogFile;

View file

@ -39,7 +39,6 @@ public:
virtual bool logToFile() const = 0; virtual bool logToFile() const = 0;
virtual const QString &logFilename() const = 0; virtual const QString &logFilename() const = 0;
virtual void persistLogDir() const = 0; virtual void persistLogDir() const = 0;
virtual int port() 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;
@ -52,7 +51,6 @@ public:
virtual void setLoadFromSystemScope(bool loadFromSystemScope) = 0; virtual void setLoadFromSystemScope(bool loadFromSystemScope) = 0;
virtual void setScreenName(const QString &screenName) = 0; virtual void setScreenName(const QString &screenName) = 0;
virtual void setPort(int port) = 0;
virtual void setLogLevel(int logLevel) = 0; virtual void setLogLevel(int logLevel) = 0;
virtual void setLogToFile(bool logToFile) = 0; virtual void setLogToFile(bool logToFile) = 0;
virtual void setLogFilename(const QString &logFilename) = 0; virtual void setLogFilename(const QString &logFilename) = 0;

View file

@ -595,7 +595,7 @@ bool CoreProcess::addClientArgs(QStringList &args, QString &app)
return false; return false;
} }
args << correctedAddress() + ":" + QString::number(m_appConfig.port()); args << correctedAddress() + ":" + Settings::value(Settings::Core::Port).toString();
return true; return true;
} }
@ -720,8 +720,9 @@ void CoreProcess::checkOSXNotification(const QString &line)
QString CoreProcess::correctedInterface() const QString CoreProcess::correctedInterface() const
{ {
QString interface = wrapIpv6(Settings::value(Settings::Core::Interface).toString()); const QString interface = wrapIpv6(Settings::value(Settings::Core::Interface).toString());
return interface + ":" + QString::number(m_appConfig.port()); const auto port = Settings::value(Settings::Core::Port).toString();
return QStringLiteral("%1:%2").arg(interface, port);
} }
QString CoreProcess::correctedAddress() const QString CoreProcess::correctedAddress() const

View file

@ -38,7 +38,6 @@ public:
MOCK_METHOD(bool, logToFile, (), (const, override)); MOCK_METHOD(bool, logToFile, (), (const, override));
MOCK_METHOD(const QString &, logFilename, (), (const, override)); MOCK_METHOD(const QString &, logFilename, (), (const, override));
MOCK_METHOD(void, persistLogDir, (), (const, override)); MOCK_METHOD(void, persistLogDir, (), (const, override));
MOCK_METHOD(int, port, (), (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));
@ -51,7 +50,6 @@ public:
MOCK_METHOD(void, setLoadFromSystemScope, (bool loadFromSystemScope), (override)); MOCK_METHOD(void, setLoadFromSystemScope, (bool loadFromSystemScope), (override));
MOCK_METHOD(void, setScreenName, (const QString &screenName), (override)); MOCK_METHOD(void, setScreenName, (const QString &screenName), (override));
MOCK_METHOD(void, setPort, (int port), (override));
MOCK_METHOD(void, setLogLevel, (int logLevel), (override)); MOCK_METHOD(void, setLogLevel, (int logLevel), (override));
MOCK_METHOD(void, setLogToFile, (bool logToFile), (override)); MOCK_METHOD(void, setLogToFile, (bool logToFile), (override));
MOCK_METHOD(void, setLogFilename, (const QString &logFilename), (override)); MOCK_METHOD(void, setLogFilename, (const QString &logFilename), (override));