2012-06-10 16:50:54 +00:00
|
|
|
/*
|
|
|
|
|
* synergy -- mouse and keyboard sharing utility
|
2024-07-22 16:48:02 +00:00
|
|
|
* Copyright (C) 2012 Symless Ltd.
|
2012-06-10 16:50:54 +00:00
|
|
|
* Copyright (C) 2008 Volker Lanz (vl@fidra.de)
|
2016-10-18 17:45:15 +00:00
|
|
|
*
|
2012-06-10 16:50:54 +00:00
|
|
|
* This package is free software; you can redistribute it and/or
|
|
|
|
|
* modify it under the terms of the GNU General Public License
|
2015-05-03 02:33:52 +00:00
|
|
|
* found in the file LICENSE that should have accompanied this file.
|
2016-10-18 17:45:15 +00:00
|
|
|
*
|
2012-06-10 16:50:54 +00:00
|
|
|
* This package is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include "AppConfig.h"
|
2024-07-16 08:30:35 +00:00
|
|
|
|
2024-08-01 00:13:01 +00:00
|
|
|
#include "ConfigScopes.h"
|
2012-06-10 16:50:54 +00:00
|
|
|
|
2024-07-22 16:48:02 +00:00
|
|
|
#include <QApplication>
|
2024-07-26 22:53:52 +00:00
|
|
|
#include <QMessageBox>
|
2024-07-02 19:07:06 +00:00
|
|
|
#include <QPushButton>
|
2024-08-01 00:13:01 +00:00
|
|
|
#include <QVariant>
|
2012-06-10 16:50:54 +00:00
|
|
|
#include <QtCore>
|
|
|
|
|
#include <QtNetwork>
|
2024-08-01 00:13:01 +00:00
|
|
|
#include <functional>
|
2024-07-22 16:48:02 +00:00
|
|
|
|
2024-08-01 00:13:01 +00:00
|
|
|
using ConfigScopes = synergy::gui::ConfigScopes;
|
|
|
|
|
using IConfigScopes = synergy::gui::IConfigScopes;
|
2024-07-22 16:48:02 +00:00
|
|
|
|
|
|
|
|
// this should be incremented each time the wizard is changed,
|
|
|
|
|
// which will force it to re-run for existing installations.
|
|
|
|
|
const int kWizardVersion = 8;
|
2012-06-10 16:50:54 +00:00
|
|
|
|
|
|
|
|
#if defined(Q_OS_WIN)
|
2024-07-22 16:48:02 +00:00
|
|
|
const char AppConfig::m_CoreServerName[] = "synergys.exe";
|
|
|
|
|
const char AppConfig::m_CoreClientName[] = "synergyc.exe";
|
|
|
|
|
const char AppConfig::m_LogDir[] = "log/";
|
|
|
|
|
const char AppConfig::m_ConfigFilename[] = "synergy.sgc";
|
2012-06-10 16:50:54 +00:00
|
|
|
#else
|
2024-07-22 16:48:02 +00:00
|
|
|
const char AppConfig::m_CoreServerName[] = "synergys";
|
|
|
|
|
const char AppConfig::m_CoreClientName[] = "synergyc";
|
|
|
|
|
const char AppConfig::m_LogDir[] = "/var/log/";
|
|
|
|
|
const char AppConfig::m_ConfigFilename[] = "synergy.conf";
|
2012-06-10 16:50:54 +00:00
|
|
|
#endif
|
|
|
|
|
|
2024-07-26 22:53:52 +00:00
|
|
|
// TODO: instead, use key value pair table, which would be less fragile.
|
2024-07-22 16:48:02 +00:00
|
|
|
const char *const AppConfig::m_SettingsName[] = {
|
2024-07-02 19:07:06 +00:00
|
|
|
"screenName",
|
|
|
|
|
"port",
|
|
|
|
|
"interface",
|
|
|
|
|
"logLevel2",
|
|
|
|
|
"logToFile",
|
|
|
|
|
"logFilename",
|
|
|
|
|
"wizardLastRun",
|
|
|
|
|
"startedBefore",
|
|
|
|
|
"elevateMode",
|
|
|
|
|
"elevateModeEnum",
|
2024-07-26 22:53:52 +00:00
|
|
|
"", // 10 = edition, obsolete (using serial key instead)
|
|
|
|
|
"cryptoEnabled", // kTlsEnabled (retain legacy string value)
|
2024-07-02 19:07:06 +00:00
|
|
|
"autoHide",
|
|
|
|
|
"serialKey",
|
|
|
|
|
"lastVersion",
|
2024-07-26 22:53:52 +00:00
|
|
|
"", // 15 = lastExpiringWarningTime, obsolete
|
2024-07-02 19:07:06 +00:00
|
|
|
"activationHasRun",
|
2024-08-01 00:13:01 +00:00
|
|
|
"", // 17 = minimizeToTray, obsolete
|
2024-07-26 22:53:52 +00:00
|
|
|
"", // 18 = ActivateEmail, obsolete
|
2024-07-02 19:07:06 +00:00
|
|
|
"loadFromSystemScope",
|
2024-07-26 22:53:52 +00:00
|
|
|
"groupServerChecked", // kServerGroupChecked
|
2024-07-02 19:07:06 +00:00
|
|
|
"useExternalConfig",
|
|
|
|
|
"configFile",
|
|
|
|
|
"useInternalConfig",
|
|
|
|
|
"groupClientChecked",
|
|
|
|
|
"serverHostname",
|
|
|
|
|
"tlsCertPath",
|
|
|
|
|
"tlsKeyLength",
|
|
|
|
|
"preventSleep",
|
|
|
|
|
"languageSync",
|
|
|
|
|
"invertScrollDirection",
|
2024-07-26 22:53:52 +00:00
|
|
|
"", // 31 = guid, obsolete
|
|
|
|
|
"", // 32 = licenseRegistryUrl, obsolete
|
2024-07-02 19:07:06 +00:00
|
|
|
"licenseNextCheck",
|
2024-07-26 22:53:52 +00:00
|
|
|
"initiateConnectionFromServer", // kInvertConnection
|
|
|
|
|
"", // 35 = clientHostMode, obsolete
|
|
|
|
|
"", // 36 = serverClientMode, obsolete
|
2024-07-22 16:48:02 +00:00
|
|
|
"serviceEnabled",
|
2024-08-01 00:13:01 +00:00
|
|
|
"closeToTray",
|
|
|
|
|
"mainWindowSize",
|
|
|
|
|
"mainWindowPosition",
|
|
|
|
|
};
|
2024-07-02 19:07:06 +00:00
|
|
|
|
|
|
|
|
static const char *logLevelNames[] = {"INFO", "DEBUG", "DEBUG1", "DEBUG2"};
|
|
|
|
|
|
2024-08-01 00:13:01 +00:00
|
|
|
AppConfig::Deps AppConfig::s_Deps;
|
|
|
|
|
|
|
|
|
|
AppConfig::AppConfig(Deps &deps) : m_Deps(deps), m_ScreenName(deps.hostname()) {
|
|
|
|
|
|
|
|
|
|
m_Deps.scopes().registerReceiver(this);
|
|
|
|
|
}
|
2024-07-22 16:48:02 +00:00
|
|
|
|
2024-07-26 22:53:52 +00:00
|
|
|
void AppConfig::loadAllScopes() {
|
2024-08-01 00:13:01 +00:00
|
|
|
m_Deps.scopes().loadAll();
|
2024-07-02 19:07:06 +00:00
|
|
|
|
|
|
|
|
// User settings exist and the load from system scope variable is true
|
2024-08-01 00:13:01 +00:00
|
|
|
if (m_Deps.scopes().hasSetting(
|
|
|
|
|
settingName(Setting::kLoadSystemSettings),
|
|
|
|
|
ConfigScopes::Scope::User)) {
|
2024-07-02 19:07:06 +00:00
|
|
|
setLoadFromSystemScope(m_LoadFromSystemScope);
|
|
|
|
|
}
|
|
|
|
|
// If user setting don't exist but system ones do, load the system settings
|
2024-08-01 00:13:01 +00:00
|
|
|
else if (m_Deps.scopes().hasSetting(
|
|
|
|
|
settingName(Setting::kScreenName),
|
|
|
|
|
ConfigScopes::Scope::System)) {
|
2024-07-02 19:07:06 +00:00
|
|
|
setLoadFromSystemScope(true);
|
|
|
|
|
}
|
2012-06-10 16:50:54 +00:00
|
|
|
}
|
|
|
|
|
|
2024-07-02 19:07:06 +00:00
|
|
|
void AppConfig::loadSettings() {
|
2024-07-22 16:48:02 +00:00
|
|
|
using enum AppConfig::Setting;
|
|
|
|
|
|
2024-07-26 22:53:52 +00:00
|
|
|
qDebug("loading settings");
|
|
|
|
|
|
2024-08-01 00:13:01 +00:00
|
|
|
loadCommonSettings();
|
|
|
|
|
loadScopeSettings();
|
|
|
|
|
loadSerialKey();
|
|
|
|
|
loadElevateMode();
|
2024-07-02 19:07:06 +00:00
|
|
|
|
2024-08-01 00:13:01 +00:00
|
|
|
emit loaded();
|
|
|
|
|
}
|
2024-07-22 16:48:02 +00:00
|
|
|
|
2024-08-01 00:13:01 +00:00
|
|
|
void AppConfig::loadCommonSettings() {
|
|
|
|
|
using enum Setting;
|
2024-07-22 16:48:02 +00:00
|
|
|
|
2024-08-01 00:13:01 +00:00
|
|
|
m_WizardLastRun = loadCommonSetting(kWizardLastRun, m_WizardLastRun).toInt();
|
2024-07-02 19:07:06 +00:00
|
|
|
m_LoadFromSystemScope =
|
2024-08-01 00:13:01 +00:00
|
|
|
loadCommonSetting(kLoadSystemSettings, m_LoadFromSystemScope).toBool();
|
|
|
|
|
m_licenseNextCheck =
|
|
|
|
|
loadCommonSetting(kLicenseNextCheck, m_licenseNextCheck).toULongLong();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void AppConfig::loadScopeSettings() {
|
|
|
|
|
using enum Setting;
|
2024-07-02 19:07:06 +00:00
|
|
|
|
2024-08-01 00:13:01 +00:00
|
|
|
m_ScreenName = loadSetting(kScreenName, m_ScreenName).toString();
|
|
|
|
|
m_Port = loadSetting(kPort, m_Port).toInt();
|
|
|
|
|
m_Interface = loadSetting(kInterface, m_Interface).toString();
|
|
|
|
|
m_LogLevel = loadSetting(kLogLevel, m_LogLevel).toInt();
|
|
|
|
|
m_LogToFile = loadSetting(kLogToFile, m_LogToFile).toBool();
|
|
|
|
|
m_LogFilename = loadSetting(kLogFilename, m_LogFilename).toString();
|
|
|
|
|
m_StartedBefore = loadSetting(kStartedBefore, m_StartedBefore).toBool();
|
|
|
|
|
m_AutoHide = loadSetting(kAutoHide, m_AutoHide).toBool();
|
|
|
|
|
m_LastVersion = loadSetting(kLastVersion, m_LastVersion).toString();
|
|
|
|
|
m_ActivationHasRun =
|
|
|
|
|
loadSetting(kActivationHasRun, m_ActivationHasRun).toBool();
|
|
|
|
|
m_ServerGroupChecked =
|
|
|
|
|
loadSetting(kServerGroupChecked, m_ServerGroupChecked).toBool();
|
|
|
|
|
m_UseExternalConfig =
|
|
|
|
|
loadSetting(kUseExternalConfig, m_UseExternalConfig).toBool();
|
|
|
|
|
m_ConfigFile = loadSetting(kConfigFile, m_ConfigFile).toString();
|
|
|
|
|
m_UseInternalConfig =
|
|
|
|
|
loadSetting(kUseInternalConfig, m_UseInternalConfig).toBool();
|
|
|
|
|
m_ClientGroupChecked =
|
|
|
|
|
loadSetting(kClientGroupChecked, m_ClientGroupChecked).toBool();
|
|
|
|
|
m_ServerHostname = loadSetting(kServerHostname, m_ServerHostname).toString();
|
|
|
|
|
m_PreventSleep = loadSetting(kPreventSleep, m_PreventSleep).toBool();
|
|
|
|
|
m_LanguageSync = loadSetting(kLanguageSync, m_LanguageSync).toBool();
|
|
|
|
|
m_InvertScrollDirection =
|
|
|
|
|
loadSetting(kInvertScrollDirection, m_InvertScrollDirection).toBool();
|
|
|
|
|
m_InvertConnection =
|
|
|
|
|
loadSetting(kInvertConnection, m_InvertConnection).toBool();
|
2024-07-22 16:48:02 +00:00
|
|
|
m_ServiceEnabled = loadSetting(kServiceEnabled, m_ServiceEnabled).toBool();
|
2024-07-23 19:17:40 +00:00
|
|
|
m_CloseToTray = loadSetting(kCloseToTray, m_CloseToTray).toBool();
|
2024-07-26 22:53:52 +00:00
|
|
|
m_TlsEnabled = loadSetting(kTlsEnabled, m_TlsEnabled).toBool();
|
2024-08-01 00:13:01 +00:00
|
|
|
m_TlsCertPath = loadSetting(kTlsCertPath, m_TlsCertPath).toString();
|
2024-07-26 22:53:52 +00:00
|
|
|
m_TlsKeyLength = loadSetting(kTlsKeyLength, m_TlsKeyLength).toString();
|
2024-08-01 00:13:01 +00:00
|
|
|
m_MainWindowPosition = loadOptional<QPoint>(
|
|
|
|
|
kMainWindowPosition, [](QVariant v) { return v.toPoint(); });
|
|
|
|
|
m_MainWindowSize = loadOptional<QSize>(
|
|
|
|
|
kMainWindowSize, [](QVariant v) { return v.toSize(); });
|
2024-07-02 19:07:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void AppConfig::saveSettings() {
|
2024-07-22 16:48:02 +00:00
|
|
|
using enum Setting;
|
|
|
|
|
|
2024-07-26 22:53:52 +00:00
|
|
|
qDebug("saving settings");
|
|
|
|
|
|
2024-07-22 16:48:02 +00:00
|
|
|
setCommonSetting(kWizardLastRun, m_WizardLastRun);
|
|
|
|
|
setCommonSetting(kLoadSystemSettings, m_LoadFromSystemScope);
|
2024-07-26 22:53:52 +00:00
|
|
|
setCommonSetting(kClientGroupChecked, m_ClientGroupChecked);
|
|
|
|
|
setCommonSetting(kServerGroupChecked, m_ServerGroupChecked);
|
2024-07-22 16:48:02 +00:00
|
|
|
setCommonSetting(kLicenseNextCheck, m_licenseNextCheck);
|
2024-07-02 19:07:06 +00:00
|
|
|
|
|
|
|
|
if (isWritable()) {
|
2024-07-22 16:48:02 +00:00
|
|
|
setSetting(kScreenName, m_ScreenName);
|
|
|
|
|
setSetting(kPort, m_Port);
|
2024-07-26 22:53:52 +00:00
|
|
|
setSetting(kInterface, m_Interface);
|
2024-07-22 16:48:02 +00:00
|
|
|
setSetting(kLogLevel, m_LogLevel);
|
|
|
|
|
setSetting(kLogToFile, m_LogToFile);
|
|
|
|
|
setSetting(kLogFilename, m_LogFilename);
|
|
|
|
|
setSetting(kStartedBefore, m_StartedBefore);
|
2024-08-01 00:13:01 +00:00
|
|
|
setSetting(kElevateMode, static_cast<int>(m_ElevateMode));
|
|
|
|
|
setSetting(kElevateModeLegacy, m_ElevateMode == ElevateAlways);
|
2024-07-26 22:53:52 +00:00
|
|
|
setSetting(kTlsEnabled, m_TlsEnabled);
|
2024-07-22 16:48:02 +00:00
|
|
|
setSetting(kAutoHide, m_AutoHide);
|
2024-07-26 22:53:52 +00:00
|
|
|
setSetting(kSerialKey, m_SerialKey);
|
2024-07-22 16:48:02 +00:00
|
|
|
setSetting(kLastVersion, m_LastVersion);
|
|
|
|
|
setSetting(kActivationHasRun, m_ActivationHasRun);
|
|
|
|
|
setSetting(kUseExternalConfig, m_UseExternalConfig);
|
|
|
|
|
setSetting(kConfigFile, m_ConfigFile);
|
|
|
|
|
setSetting(kUseInternalConfig, m_UseInternalConfig);
|
|
|
|
|
setSetting(kServerHostname, m_ServerHostname);
|
|
|
|
|
setSetting(kPreventSleep, m_PreventSleep);
|
|
|
|
|
setSetting(kLanguageSync, m_LanguageSync);
|
|
|
|
|
setSetting(kInvertScrollDirection, m_InvertScrollDirection);
|
2024-07-26 22:53:52 +00:00
|
|
|
setSetting(kInvertConnection, m_InvertConnection);
|
2024-07-22 16:48:02 +00:00
|
|
|
setSetting(kServiceEnabled, m_ServiceEnabled);
|
2024-07-23 19:17:40 +00:00
|
|
|
setSetting(kCloseToTray, m_CloseToTray);
|
2024-08-01 00:13:01 +00:00
|
|
|
setOptional(kMainWindowSize, m_MainWindowSize);
|
|
|
|
|
setOptional(kMainWindowPosition, m_MainWindowPosition);
|
2024-07-02 19:07:06 +00:00
|
|
|
}
|
|
|
|
|
|
2024-07-22 16:48:02 +00:00
|
|
|
setModified(false);
|
2024-08-01 00:13:01 +00:00
|
|
|
|
|
|
|
|
emit saved();
|
2024-07-26 22:53:52 +00:00
|
|
|
|
|
|
|
|
if (m_TlsChanged) {
|
|
|
|
|
m_TlsChanged = false;
|
|
|
|
|
emit tlsChanged();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-08-01 00:13:01 +00:00
|
|
|
void AppConfig::loadSerialKey() {
|
|
|
|
|
using enum Setting;
|
|
|
|
|
|
|
|
|
|
// only set the serial key if the current settings scope has they key.
|
|
|
|
|
bool shouldLoad = m_Deps.scopes().hasSetting(
|
|
|
|
|
settingName(kLoadSystemSettings), ConfigScopes::Scope::Current);
|
|
|
|
|
|
|
|
|
|
if (!shouldLoad) {
|
|
|
|
|
qDebug("no serial key in current scope, skipping");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const auto &serialKey =
|
|
|
|
|
loadSetting(kSerialKey, m_SerialKey).toString().trimmed();
|
|
|
|
|
|
|
|
|
|
if (serialKey.isEmpty()) {
|
|
|
|
|
qDebug("serial key is empty, skipping");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
m_SerialKey = serialKey;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void AppConfig::loadElevateMode() {
|
|
|
|
|
using enum Setting;
|
|
|
|
|
|
|
|
|
|
if (!m_Deps.scopes().hasSetting(settingName(kElevateMode))) {
|
|
|
|
|
qDebug("elevate mode not set yet, skipping");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QVariant elevateMode = loadSetting(kElevateMode);
|
|
|
|
|
if (!elevateMode.isValid()) {
|
|
|
|
|
qDebug("elevate mode not valid, loading legacy setting");
|
|
|
|
|
elevateMode = loadSetting(
|
|
|
|
|
kElevateModeLegacy, QVariant(static_cast<int>(kDefaultElevateMode)));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
m_ElevateMode = static_cast<ElevateMode>(elevateMode.toInt());
|
|
|
|
|
}
|
|
|
|
|
|
2024-07-26 22:53:52 +00:00
|
|
|
QString AppConfig::defaultTlsCertPath() const {
|
2024-08-01 00:13:01 +00:00
|
|
|
QDir path(m_Deps.profileDir());
|
2024-07-26 22:53:52 +00:00
|
|
|
path = path.filePath("SSL");
|
|
|
|
|
path = path.filePath("Synergy.pem");
|
|
|
|
|
return path.absolutePath();
|
2016-09-30 15:04:49 +00:00
|
|
|
}
|
|
|
|
|
|
2024-07-23 19:17:40 +00:00
|
|
|
QString AppConfig::settingName(Setting name) {
|
|
|
|
|
auto index = static_cast<int>(name);
|
|
|
|
|
return m_SettingsName[index];
|
|
|
|
|
}
|
2016-09-30 15:04:49 +00:00
|
|
|
|
2024-07-23 19:17:40 +00:00
|
|
|
template <typename T> void AppConfig::setSetting(Setting name, T value) {
|
2024-08-01 00:13:01 +00:00
|
|
|
m_Deps.scopes().setSetting(settingName(name), value);
|
2013-04-11 16:51:17 +00:00
|
|
|
}
|
|
|
|
|
|
2024-07-23 19:17:40 +00:00
|
|
|
template <typename T> void AppConfig::setCommonSetting(Setting name, T value) {
|
2024-08-01 00:13:01 +00:00
|
|
|
m_Deps.scopes().setSetting(
|
|
|
|
|
settingName(name), value, ConfigScopes::Scope::User);
|
|
|
|
|
m_Deps.scopes().setSetting(
|
|
|
|
|
settingName(name), value, ConfigScopes::Scope::System);
|
2024-07-23 19:17:40 +00:00
|
|
|
}
|
2016-10-26 14:57:38 +00:00
|
|
|
|
2024-07-23 19:17:40 +00:00
|
|
|
QVariant AppConfig::loadSetting(Setting name, const QVariant &defaultValue) {
|
2024-08-01 00:13:01 +00:00
|
|
|
return m_Deps.scopes().loadSetting(settingName(name), defaultValue);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
|
std::optional<T>
|
|
|
|
|
AppConfig::loadOptional(Setting name, std::function<T(QVariant)> toType) const {
|
|
|
|
|
if (m_Deps.scopes().hasSetting(settingName(name))) {
|
|
|
|
|
return toType(m_Deps.scopes().loadSetting(settingName(name)));
|
|
|
|
|
} else {
|
|
|
|
|
return std::nullopt;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
|
void AppConfig::setOptional(Setting name, const std::optional<T> &value) {
|
|
|
|
|
if (value.has_value()) {
|
|
|
|
|
m_Deps.scopes().setSetting(settingName(name), value.value());
|
|
|
|
|
}
|
2016-10-26 14:57:38 +00:00
|
|
|
}
|
|
|
|
|
|
2024-07-23 19:17:40 +00:00
|
|
|
QVariant
|
|
|
|
|
AppConfig::loadCommonSetting(Setting name, const QVariant &defaultValue) const {
|
|
|
|
|
QVariant result(defaultValue);
|
|
|
|
|
QString setting(settingName(name));
|
|
|
|
|
|
2024-08-01 00:13:01 +00:00
|
|
|
if (m_Deps.scopes().hasSetting(setting)) {
|
|
|
|
|
result = m_Deps.scopes().loadSetting(setting, defaultValue);
|
|
|
|
|
} else if (m_Deps.scopes().getScope() == ConfigScopes::Scope::System) {
|
|
|
|
|
if (m_Deps.scopes().hasSetting(setting, ConfigScopes::Scope::User)) {
|
|
|
|
|
result = m_Deps.scopes().loadSetting(
|
|
|
|
|
setting, defaultValue, ConfigScopes::Scope::User);
|
2024-07-23 19:17:40 +00:00
|
|
|
}
|
2024-08-01 00:13:01 +00:00
|
|
|
} else if (m_Deps.scopes().hasSetting(setting, ConfigScopes::Scope::System)) {
|
|
|
|
|
result = m_Deps.scopes().loadSetting(
|
|
|
|
|
setting, defaultValue, ConfigScopes::Scope::System);
|
2024-07-23 19:17:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return result;
|
2020-03-31 14:18:57 +00:00
|
|
|
}
|
2016-09-30 14:03:49 +00:00
|
|
|
|
2024-08-01 00:13:01 +00:00
|
|
|
void AppConfig::loadScope(ConfigScopes::Scope scope) {
|
2016-09-30 14:03:49 +00:00
|
|
|
|
2024-08-01 00:13:01 +00:00
|
|
|
if (m_Deps.scopes().getScope() != scope) {
|
2024-07-23 19:17:40 +00:00
|
|
|
setDefaultValues();
|
2024-08-01 00:13:01 +00:00
|
|
|
m_Deps.scopes().setScope(scope);
|
|
|
|
|
if (m_Deps.scopes().hasSetting(
|
|
|
|
|
settingName(Setting::kScreenName), m_Deps.scopes().getScope())) {
|
2024-07-23 19:17:40 +00:00
|
|
|
// If the user already has settings, then load them up now.
|
2024-08-01 00:13:01 +00:00
|
|
|
m_Deps.scopes().loadAll();
|
2024-07-23 19:17:40 +00:00
|
|
|
}
|
|
|
|
|
}
|
2020-03-31 14:18:57 +00:00
|
|
|
}
|
2016-09-30 14:03:49 +00:00
|
|
|
|
2024-07-26 22:53:52 +00:00
|
|
|
void AppConfig::setDefaultValues() { m_InvertConnection = false; }
|
2016-09-30 14:03:49 +00:00
|
|
|
|
2024-07-23 19:17:40 +00:00
|
|
|
void AppConfig::setLoadFromSystemScope(bool value) {
|
2016-09-30 14:03:49 +00:00
|
|
|
|
2024-07-23 19:17:40 +00:00
|
|
|
if (value) {
|
2024-07-26 22:53:52 +00:00
|
|
|
qDebug("loading system settings scope");
|
2024-08-01 00:13:01 +00:00
|
|
|
loadScope(ConfigScopes::Scope::System);
|
2024-07-23 19:17:40 +00:00
|
|
|
} else {
|
2024-07-26 22:53:52 +00:00
|
|
|
qDebug("loading user settings scope");
|
2024-08-01 00:13:01 +00:00
|
|
|
loadScope(ConfigScopes::Scope::User);
|
2024-07-23 19:17:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* It's very imprortant to set this variable after loadScope
|
|
|
|
|
* because during scope loading this variable can be rewritten with old value
|
|
|
|
|
*/
|
|
|
|
|
m_LoadFromSystemScope = value;
|
2020-03-31 14:18:57 +00:00
|
|
|
}
|
2016-09-30 14:03:49 +00:00
|
|
|
|
2024-08-01 00:13:01 +00:00
|
|
|
bool AppConfig::isWritable() const { return m_Deps.scopes().isWritable(); }
|
2024-07-23 19:17:40 +00:00
|
|
|
|
|
|
|
|
bool AppConfig::isSystemScoped() const {
|
2024-08-01 00:13:01 +00:00
|
|
|
return m_Deps.scopes().getScope() == ConfigScopes::Scope::System;
|
2020-03-31 14:18:57 +00:00
|
|
|
}
|
2016-09-30 14:03:49 +00:00
|
|
|
|
2024-07-23 19:17:40 +00:00
|
|
|
template <typename T>
|
|
|
|
|
void AppConfig::setSettingModified(T &variable, const T &newValue) {
|
|
|
|
|
if (variable != newValue) {
|
|
|
|
|
variable = newValue;
|
|
|
|
|
setModified(true);
|
|
|
|
|
}
|
2020-03-31 14:18:57 +00:00
|
|
|
}
|
2024-07-26 22:53:52 +00:00
|
|
|
QString AppConfig::logDir() const {
|
|
|
|
|
// by default log to home dir
|
|
|
|
|
return QDir::home().absolutePath() + "/";
|
2020-03-31 14:18:57 +00:00
|
|
|
}
|
2016-09-30 14:03:49 +00:00
|
|
|
|
2024-07-26 22:53:52 +00:00
|
|
|
void AppConfig::persistLogDir() const {
|
|
|
|
|
QDir dir = logDir();
|
|
|
|
|
|
|
|
|
|
// persist the log directory
|
|
|
|
|
if (!dir.exists()) {
|
|
|
|
|
dir.mkpath(dir.path());
|
|
|
|
|
}
|
2024-07-23 19:17:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
2024-07-26 22:53:52 +00:00
|
|
|
// Begin getters
|
2024-07-23 19:17:40 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
2024-08-01 00:13:01 +00:00
|
|
|
IConfigScopes &AppConfig::scopes() { return m_Deps.scopes(); }
|
|
|
|
|
|
2024-07-23 19:17:40 +00:00
|
|
|
bool AppConfig::activationHasRun() const { return m_ActivationHasRun; }
|
|
|
|
|
|
2024-07-26 22:53:52 +00:00
|
|
|
QString AppConfig::serialKey() const { return m_SerialKey; }
|
2024-07-23 19:17:40 +00:00
|
|
|
|
2024-07-26 22:53:52 +00:00
|
|
|
const QString &AppConfig::screenName() const { return m_ScreenName; }
|
2016-09-30 14:03:49 +00:00
|
|
|
|
2024-07-26 22:53:52 +00:00
|
|
|
int AppConfig::port() const { return m_Port; }
|
2016-09-30 14:03:49 +00:00
|
|
|
|
2024-07-26 22:53:52 +00:00
|
|
|
const QString &AppConfig::networkInterface() const { return m_Interface; }
|
2016-09-30 14:03:49 +00:00
|
|
|
|
2024-07-26 22:53:52 +00:00
|
|
|
int AppConfig::logLevel() const { return m_LogLevel; }
|
2016-09-30 14:03:49 +00:00
|
|
|
|
2024-07-26 22:53:52 +00:00
|
|
|
bool AppConfig::logToFile() const { return m_LogToFile; }
|
2016-09-30 14:03:49 +00:00
|
|
|
|
2024-07-26 22:53:52 +00:00
|
|
|
const QString &AppConfig::logFilename() const { return m_LogFilename; }
|
2024-07-23 19:17:40 +00:00
|
|
|
|
2024-07-26 22:53:52 +00:00
|
|
|
QString AppConfig::logLevelText() const { return logLevelNames[logLevel()]; }
|
2024-07-23 19:17:40 +00:00
|
|
|
|
2024-07-26 22:53:52 +00:00
|
|
|
ProcessMode AppConfig::processMode() const {
|
|
|
|
|
return m_ServiceEnabled ? ProcessMode::kService : ProcessMode::kDesktop;
|
2024-07-23 19:17:40 +00:00
|
|
|
}
|
|
|
|
|
|
2024-07-26 22:53:52 +00:00
|
|
|
bool AppConfig::wizardShouldRun() const {
|
|
|
|
|
return m_WizardLastRun < kWizardVersion;
|
2024-07-23 19:17:40 +00:00
|
|
|
}
|
|
|
|
|
|
2024-07-26 22:53:52 +00:00
|
|
|
bool AppConfig::startedBefore() const { return m_StartedBefore; }
|
2024-07-23 19:17:40 +00:00
|
|
|
|
2024-07-26 22:53:52 +00:00
|
|
|
QString AppConfig::lastVersion() const { return m_LastVersion; }
|
2024-07-23 19:17:40 +00:00
|
|
|
|
2024-07-26 22:53:52 +00:00
|
|
|
QString AppConfig::coreServerName() const { return m_CoreServerName; }
|
2024-07-23 19:17:40 +00:00
|
|
|
|
2024-07-26 22:53:52 +00:00
|
|
|
QString AppConfig::coreClientName() const { return m_CoreClientName; }
|
|
|
|
|
|
|
|
|
|
ElevateMode AppConfig::elevateMode() const { return m_ElevateMode; }
|
|
|
|
|
|
|
|
|
|
bool AppConfig::tlsEnabled() const { return m_TlsEnabled; }
|
2024-07-23 19:17:40 +00:00
|
|
|
|
2024-07-26 22:53:52 +00:00
|
|
|
bool AppConfig::autoHide() const { return m_AutoHide; }
|
|
|
|
|
|
|
|
|
|
bool AppConfig::invertScrollDirection() const {
|
|
|
|
|
return m_InvertScrollDirection;
|
2024-07-23 19:17:40 +00:00
|
|
|
}
|
|
|
|
|
|
2024-07-26 22:53:52 +00:00
|
|
|
unsigned long long AppConfig::licenseNextCheck() const {
|
|
|
|
|
return m_licenseNextCheck;
|
2024-07-23 19:17:40 +00:00
|
|
|
}
|
|
|
|
|
|
2024-07-26 22:53:52 +00:00
|
|
|
bool AppConfig::languageSync() const { return m_LanguageSync; }
|
2024-07-23 19:17:40 +00:00
|
|
|
|
2024-07-26 22:53:52 +00:00
|
|
|
bool AppConfig::preventSleep() const { return m_PreventSleep; }
|
2024-07-23 19:17:40 +00:00
|
|
|
|
2024-07-26 22:53:52 +00:00
|
|
|
bool AppConfig::invertConnection() const { return m_InvertConnection; }
|
2024-07-23 19:17:40 +00:00
|
|
|
|
2024-07-26 22:53:52 +00:00
|
|
|
QString AppConfig::tlsCertPath() const { return m_TlsCertPath; }
|
2024-07-23 19:17:40 +00:00
|
|
|
|
2024-07-26 22:53:52 +00:00
|
|
|
QString AppConfig::tlsKeyLength() const { return m_TlsKeyLength; }
|
2024-07-23 19:17:40 +00:00
|
|
|
|
2024-07-26 22:53:52 +00:00
|
|
|
bool AppConfig::serviceEnabled() const { return m_ServiceEnabled; }
|
2024-07-23 19:17:40 +00:00
|
|
|
|
2024-07-26 22:53:52 +00:00
|
|
|
bool AppConfig::closeToTray() const { return m_CloseToTray; }
|
2024-07-23 19:17:40 +00:00
|
|
|
|
2024-07-26 22:53:52 +00:00
|
|
|
bool AppConfig::serverGroupChecked() const { return m_ServerGroupChecked; }
|
2024-07-23 19:17:40 +00:00
|
|
|
|
2024-07-26 22:53:52 +00:00
|
|
|
bool AppConfig::useExternalConfig() const { return m_UseExternalConfig; }
|
|
|
|
|
|
|
|
|
|
const QString &AppConfig::configFile() const { return m_ConfigFile; }
|
|
|
|
|
|
|
|
|
|
bool AppConfig::useInternalConfig() const { return m_UseInternalConfig; }
|
|
|
|
|
|
|
|
|
|
bool AppConfig::clientGroupChecked() const { return m_ClientGroupChecked; }
|
|
|
|
|
|
|
|
|
|
QString AppConfig::serverHostname() const { return m_ServerHostname; }
|
|
|
|
|
|
|
|
|
|
void AppConfig::setActivationHasRun(bool value) { m_ActivationHasRun = value; }
|
|
|
|
|
|
2024-08-01 00:13:01 +00:00
|
|
|
std::optional<QSize> AppConfig::mainWindowSize() const {
|
|
|
|
|
return m_MainWindowSize;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::optional<QPoint> AppConfig::mainWindowPosition() const {
|
|
|
|
|
return m_MainWindowPosition;
|
|
|
|
|
}
|
|
|
|
|
|
2024-07-26 22:53:52 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
// End getters
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
// Begin setters
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
void AppConfig::clearSerialKey() { m_SerialKey.clear(); }
|
|
|
|
|
|
|
|
|
|
void AppConfig::setTlsEnabled(bool value) {
|
|
|
|
|
setSettingModified(m_TlsEnabled, value);
|
|
|
|
|
m_TlsChanged = true;
|
2024-07-23 19:17:40 +00:00
|
|
|
}
|
|
|
|
|
|
2024-07-26 22:53:52 +00:00
|
|
|
void AppConfig::setTlsCertPath(const QString &value) {
|
|
|
|
|
setSettingModified(m_TlsCertPath, value);
|
|
|
|
|
m_TlsChanged = true;
|
|
|
|
|
}
|
2024-07-23 19:17:40 +00:00
|
|
|
|
2024-07-26 22:53:52 +00:00
|
|
|
void AppConfig::setTlsKeyLength(const QString &value) {
|
|
|
|
|
setSettingModified(m_TlsKeyLength, value);
|
|
|
|
|
m_TlsChanged = true;
|
|
|
|
|
}
|
|
|
|
|
void AppConfig::setSerialKey(const QString &serialKey) {
|
|
|
|
|
setSettingModified(m_SerialKey, serialKey);
|
|
|
|
|
setCommonSetting(Setting::kSerialKey, m_SerialKey);
|
|
|
|
|
}
|
|
|
|
|
void AppConfig::setServerGroupChecked(bool newValue) {
|
|
|
|
|
setSettingModified(m_ServerGroupChecked, newValue);
|
2024-07-23 19:17:40 +00:00
|
|
|
}
|
|
|
|
|
|
2024-07-26 22:53:52 +00:00
|
|
|
void AppConfig::setUseExternalConfig(bool newValue) {
|
|
|
|
|
setSettingModified(m_UseExternalConfig, newValue);
|
2024-07-23 19:17:40 +00:00
|
|
|
}
|
|
|
|
|
|
2024-07-26 22:53:52 +00:00
|
|
|
void AppConfig::setConfigFile(const QString &newValue) {
|
|
|
|
|
setSettingModified(m_ConfigFile, newValue);
|
|
|
|
|
}
|
2024-07-23 19:17:40 +00:00
|
|
|
|
2024-07-26 22:53:52 +00:00
|
|
|
void AppConfig::setUseInternalConfig(bool newValue) {
|
|
|
|
|
setSettingModified(m_UseInternalConfig, newValue);
|
|
|
|
|
}
|
2024-07-23 19:17:40 +00:00
|
|
|
|
2024-07-26 22:53:52 +00:00
|
|
|
void AppConfig::setClientGroupChecked(bool newValue) {
|
|
|
|
|
setSettingModified(m_ClientGroupChecked, newValue);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void AppConfig::setServerHostname(const QString &newValue) {
|
|
|
|
|
setSettingModified(m_ServerHostname, newValue);
|
|
|
|
|
}
|
2024-07-23 19:17:40 +00:00
|
|
|
void AppConfig::setLastVersion(const QString &version) {
|
|
|
|
|
setSettingModified(m_LastVersion, version);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void AppConfig::setScreenName(const QString &s) {
|
|
|
|
|
setSettingModified(m_ScreenName, s);
|
|
|
|
|
emit screenNameChanged();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void AppConfig::setPort(int i) { setSettingModified(m_Port, i); }
|
|
|
|
|
|
|
|
|
|
void AppConfig::setNetworkInterface(const QString &s) {
|
|
|
|
|
setSettingModified(m_Interface, s);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void AppConfig::setLogLevel(int i) { setSettingModified(m_LogLevel, i); }
|
|
|
|
|
|
|
|
|
|
void AppConfig::setLogToFile(bool b) { setSettingModified(m_LogToFile, b); }
|
|
|
|
|
|
|
|
|
|
void AppConfig::setLogFilename(const QString &s) {
|
|
|
|
|
setSettingModified(m_LogFilename, s);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void AppConfig::setWizardHasRun() {
|
|
|
|
|
setSettingModified(m_WizardLastRun, kWizardVersion);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void AppConfig::setStartedBefore(bool b) {
|
|
|
|
|
setSettingModified(m_StartedBefore, b);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void AppConfig::setElevateMode(ElevateMode em) {
|
|
|
|
|
setSettingModified(m_ElevateMode, em);
|
|
|
|
|
}
|
2016-09-30 14:03:49 +00:00
|
|
|
|
2024-07-02 19:07:06 +00:00
|
|
|
void AppConfig::setAutoHide(bool b) { setSettingModified(m_AutoHide, b); }
|
2016-09-30 14:03:49 +00:00
|
|
|
|
2022-09-13 15:31:45 +00:00
|
|
|
void AppConfig::setLicenseNextCheck(unsigned long long time) {
|
2024-07-02 19:07:06 +00:00
|
|
|
setSettingModified(m_licenseNextCheck, time);
|
2022-09-13 15:31:45 +00:00
|
|
|
}
|
|
|
|
|
|
2022-01-26 12:07:28 +00:00
|
|
|
void AppConfig::setInvertScrollDirection(bool newValue) {
|
2024-07-02 19:07:06 +00:00
|
|
|
setSettingModified(m_InvertScrollDirection, newValue);
|
2022-01-26 12:07:28 +00:00
|
|
|
}
|
|
|
|
|
|
2021-05-13 06:30:24 +00:00
|
|
|
void AppConfig::setLanguageSync(bool newValue) {
|
2024-07-02 19:07:06 +00:00
|
|
|
setSettingModified(m_LanguageSync, newValue);
|
2021-05-13 06:30:24 +00:00
|
|
|
}
|
|
|
|
|
|
2021-05-31 08:53:49 +00:00
|
|
|
void AppConfig::setPreventSleep(bool newValue) {
|
2024-07-02 19:07:06 +00:00
|
|
|
setSettingModified(m_PreventSleep, newValue);
|
2021-05-31 08:53:49 +00:00
|
|
|
}
|
|
|
|
|
|
2024-07-23 19:17:40 +00:00
|
|
|
void AppConfig::setServiceEnabled(bool enabled) {
|
|
|
|
|
setSettingModified(m_ServiceEnabled, enabled);
|
2021-02-01 19:21:46 +00:00
|
|
|
}
|
2020-02-25 17:00:30 +00:00
|
|
|
|
2024-07-23 19:17:40 +00:00
|
|
|
void AppConfig::setCloseToTray(bool minimize) {
|
|
|
|
|
setSettingModified(m_CloseToTray, minimize);
|
2020-02-25 17:00:30 +00:00
|
|
|
}
|
2020-02-27 00:40:58 +00:00
|
|
|
|
2024-07-26 22:53:52 +00:00
|
|
|
void AppConfig::setInvertConnection(bool value) {
|
|
|
|
|
setSettingModified(m_InvertConnection, value);
|
|
|
|
|
emit invertConnectionChanged();
|
|
|
|
|
}
|
2020-03-31 10:09:50 +00:00
|
|
|
|
2024-08-01 00:13:01 +00:00
|
|
|
void AppConfig::setMainWindowSize(const QSize &size) {
|
|
|
|
|
m_MainWindowSize = size;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void AppConfig::setMainWindowPosition(const QPoint &position) {
|
|
|
|
|
m_MainWindowPosition = position;
|
|
|
|
|
}
|
|
|
|
|
|
2024-07-23 19:17:40 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
2024-07-26 22:53:52 +00:00
|
|
|
// End setters
|
2024-07-23 19:17:40 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|