2012-06-10 16:50:54 +00:00
|
|
|
/*
|
2024-09-17 19:00:25 +00:00
|
|
|
* Deskflow -- mouse and keyboard sharing utility
|
2024-11-29 17:03:51 +00:00
|
|
|
* SPDX-FileCopyrightText: (C) 2025 Deskflow Developers
|
2025-01-24 00:11:17 +00:00
|
|
|
* SPDX-FileCopyrightText: (C) 2012 Symless Ltd.
|
|
|
|
|
* SPDX-FileCopyrightText: (C) 2008 Volker Lanz <vl@fidra.de>
|
|
|
|
|
* SPDX-License-Identifier: GPL-2.0-only WITH LicenseRef-OpenSSL-Exception
|
2012-06-10 16:50:54 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#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>
|
2025-02-07 17:02:20 +00:00
|
|
|
|
2024-08-01 00:13:01 +00:00
|
|
|
#include <functional>
|
2024-07-22 16:48:02 +00:00
|
|
|
|
2024-09-17 19:00:25 +00:00
|
|
|
using namespace deskflow::gui;
|
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_LogDir[] = "log/";
|
2012-06-10 16:50:54 +00:00
|
|
|
#else
|
2024-07-22 16:48:02 +00:00
|
|
|
const char AppConfig::m_LogDir[] = "/var/log/";
|
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[] = {
|
2025-03-09 03:09:38 +00:00
|
|
|
"", // screenName moved to deskflow settings
|
2025-03-09 00:25:57 +00:00
|
|
|
"", // port moved to deskflow settings
|
2025-03-08 21:58:53 +00:00
|
|
|
"", // interface moved to deskflow settings
|
2025-03-09 01:13:26 +00:00
|
|
|
"", // log level moved to deskflow settings
|
2025-03-09 00:34:50 +00:00
|
|
|
"", // Log to file Moved to Deskflow settings
|
2025-03-09 01:56:29 +00:00
|
|
|
"", // 5 logFilename, moved to deskflow settings
|
2025-03-04 14:05:52 +00:00
|
|
|
"", // 6 wizardLastRun, obsolete
|
2025-03-05 05:03:48 +00:00
|
|
|
"", // 7 statedBefore moved to deskflow settings
|
2025-03-09 05:54:47 +00:00
|
|
|
"", // 8 elevateMode,
|
|
|
|
|
"", // 9 elevateModeEnum,
|
2025-03-06 23:08:08 +00:00
|
|
|
"", // 10 = edition, obsolete (using serial key instead)
|
|
|
|
|
"", // 11 = kTlsEnabled (retain legacy string value) Moved to Settings
|
|
|
|
|
"", // 12 AutoHide, moved to Settings
|
|
|
|
|
"", // 13 = serialKey, obsolete
|
2025-03-07 02:11:19 +00:00
|
|
|
"", // 14 last Version moved ot deskflow settings
|
2024-07-26 22:53:52 +00:00
|
|
|
"", // 15 = lastExpiringWarningTime, obsolete
|
2024-10-01 13:30:24 +00:00
|
|
|
"", // 16 = activationHasRun, obsolete
|
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",
|
2025-03-10 02:50:44 +00:00
|
|
|
"", // kServerGroupChecked
|
|
|
|
|
"", // 21 = use external config moved to deskflow settings
|
|
|
|
|
"", // 22 config file moved to dekflow settings
|
2024-07-02 19:07:06 +00:00
|
|
|
"useInternalConfig",
|
2025-03-10 02:50:44 +00:00
|
|
|
"", // Client groupchecked
|
2025-03-08 12:24:03 +00:00
|
|
|
"", // 25 server host name moved to deskflow settings
|
2025-03-07 00:04:55 +00:00
|
|
|
"", // 26 cert path moved to deskflow settings
|
2025-03-06 23:32:14 +00:00
|
|
|
"", // 27 key length Moved to Deskflow settings
|
2025-03-07 03:07:14 +00:00
|
|
|
"", // 28 Prevent sleep moved to deskflow settings
|
2025-03-08 21:51:41 +00:00
|
|
|
"", // 29 Language sync moved to deskflow settings
|
2025-03-08 21:35:02 +00:00
|
|
|
"", // 30 = invertscrolldriection moved to deskflow settings
|
2025-02-22 06:01:58 +00:00
|
|
|
"", // 31 = guid, obsolete
|
|
|
|
|
"", // 32 = licenseRegistryUrl, obsolete
|
|
|
|
|
"", // 33 = licenseNextCheck, obsolete
|
|
|
|
|
"", // 34 = kInvertConnection, obsolete
|
|
|
|
|
"", // 35 = clientHostMode, obsolete
|
|
|
|
|
"", // 36 = serverClientMode, obsolete
|
2025-03-09 04:42:52 +00:00
|
|
|
"", // 37 enable service moved to deskflow settings
|
2025-03-05 04:45:14 +00:00
|
|
|
"", // 38 Moved to deskflow settings
|
2025-03-05 05:28:05 +00:00
|
|
|
"", // 39 window size moved to deskflow settings
|
|
|
|
|
"", // 40 window position moved to deskflow settings
|
2024-10-31 18:47:40 +00:00
|
|
|
"", // 41 = Show dev thanks, obsolete
|
2025-03-05 05:11:41 +00:00
|
|
|
"", // 42 show Close Reminder moved to deskflow settings
|
2025-03-05 04:25:38 +00:00
|
|
|
"", // 43 Moved to deskflow settings
|
2025-03-08 15:10:42 +00:00
|
|
|
"", // 44, Moved to deskflow settings.
|
2025-03-05 04:11:32 +00:00
|
|
|
"", // 45 Moved to deskflow settings
|
2025-03-07 00:42:16 +00:00
|
|
|
"", // 46 require peer certs, Moved to deskflow settings
|
2024-08-01 00:13:01 +00:00
|
|
|
};
|
2024-07-02 19:07:06 +00:00
|
|
|
|
2025-03-09 03:09:38 +00:00
|
|
|
AppConfig::AppConfig(deskflow::gui::IConfigScopes &scopes, std::shared_ptr<Deps> deps) : m_Scopes(scopes), m_pDeps(deps)
|
2024-10-17 18:04:35 +00:00
|
|
|
{
|
2024-08-03 00:17:29 +00:00
|
|
|
determineScope();
|
|
|
|
|
recall();
|
2012-06-10 16:50:54 +00:00
|
|
|
}
|
|
|
|
|
|
2024-10-17 18:04:35 +00:00
|
|
|
void AppConfig::recall()
|
|
|
|
|
{
|
2024-07-22 16:48:02 +00:00
|
|
|
using enum AppConfig::Setting;
|
|
|
|
|
|
2024-08-03 00:17:29 +00:00
|
|
|
qDebug("recalling app config");
|
2024-07-02 19:07:06 +00:00
|
|
|
|
2024-08-03 00:17:29 +00:00
|
|
|
recallFromAllScopes();
|
|
|
|
|
recallFromCurrentScope();
|
2024-08-01 00:13:01 +00:00
|
|
|
}
|
2024-07-22 16:48:02 +00:00
|
|
|
|
2024-10-17 18:04:35 +00:00
|
|
|
void AppConfig::recallFromAllScopes()
|
|
|
|
|
{
|
2024-08-01 00:13:01 +00:00
|
|
|
using enum Setting;
|
2024-10-17 18:04:35 +00:00
|
|
|
m_LoadFromSystemScope = findInAllScopes(kLoadSystemSettings, m_LoadFromSystemScope).toBool();
|
2024-08-01 00:13:01 +00:00
|
|
|
}
|
|
|
|
|
|
2024-10-17 18:04:35 +00:00
|
|
|
void AppConfig::recallFromCurrentScope()
|
|
|
|
|
{
|
2024-08-01 00:13:01 +00:00
|
|
|
using enum Setting;
|
2024-07-02 19:07:06 +00:00
|
|
|
|
2024-10-17 18:04:35 +00:00
|
|
|
m_UseInternalConfig = getFromCurrentScope(kUseInternalConfig, m_UseInternalConfig).toBool();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void AppConfig::commit()
|
|
|
|
|
{
|
2024-08-03 00:17:29 +00:00
|
|
|
using enum Setting;
|
2024-08-01 00:13:01 +00:00
|
|
|
|
2024-08-07 14:05:18 +00:00
|
|
|
qDebug("committing app config");
|
2024-08-03 00:17:29 +00:00
|
|
|
|
|
|
|
|
saveToAllScopes(kLoadSystemSettings, m_LoadFromSystemScope);
|
|
|
|
|
|
|
|
|
|
if (isActiveScopeWritable()) {
|
|
|
|
|
setInCurrentScope(kUseInternalConfig, m_UseInternalConfig);
|
|
|
|
|
}
|
2024-07-26 22:53:52 +00:00
|
|
|
}
|
|
|
|
|
|
2024-10-17 18:04:35 +00:00
|
|
|
void AppConfig::determineScope()
|
|
|
|
|
{
|
2024-08-02 09:54:02 +00:00
|
|
|
|
2024-08-03 00:17:29 +00:00
|
|
|
qDebug("determining config scope");
|
2024-08-02 09:54:02 +00:00
|
|
|
|
2024-08-03 00:17:29 +00:00
|
|
|
// first, try to determine if the system scope should be used according to the
|
|
|
|
|
// user scope...
|
2024-10-17 18:04:35 +00:00
|
|
|
if (m_Scopes.scopeContains(settingName(Setting::kLoadSystemSettings), ConfigScopes::Scope::User)) {
|
2024-08-03 00:17:29 +00:00
|
|
|
auto loadFromSystemScope =
|
2024-08-07 14:05:18 +00:00
|
|
|
m_Scopes
|
2024-10-17 18:04:35 +00:00
|
|
|
.getFromScope(settingName(Setting::kLoadSystemSettings), m_LoadFromSystemScope, ConfigScopes::Scope::User)
|
2024-08-03 00:17:29 +00:00
|
|
|
.toBool();
|
2024-08-10 00:48:27 +00:00
|
|
|
if (loadFromSystemScope) {
|
|
|
|
|
qDebug("user settings indicates system scope should be used");
|
|
|
|
|
} else {
|
|
|
|
|
qDebug("user settings indicates user scope should be used");
|
|
|
|
|
}
|
2024-08-03 00:17:29 +00:00
|
|
|
setLoadFromSystemScope(loadFromSystemScope);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ...failing that, check the system scope instead to see if an arbitrary
|
|
|
|
|
// required setting is present. if it is, then we can assume that the system
|
|
|
|
|
// scope should be used.
|
2025-03-09 03:09:38 +00:00
|
|
|
else if (m_Scopes.scopeContains(settingName(Setting::kUseInternalConfig), ConfigScopes::Scope::System)) {
|
2024-08-10 00:48:27 +00:00
|
|
|
qDebug("system settings scope contains screen name, using system scope");
|
2024-08-03 00:17:29 +00:00
|
|
|
setLoadFromSystemScope(true);
|
2024-08-02 09:54:02 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-10-17 18:04:35 +00:00
|
|
|
QString AppConfig::settingName(Setting name)
|
|
|
|
|
{
|
2024-07-23 19:17:40 +00:00
|
|
|
auto index = static_cast<int>(name);
|
|
|
|
|
return m_SettingsName[index];
|
|
|
|
|
}
|
2016-09-30 15:04:49 +00:00
|
|
|
|
2024-10-17 18:04:35 +00:00
|
|
|
template <typename T> void AppConfig::setInCurrentScope(Setting name, T value)
|
|
|
|
|
{
|
2024-08-07 14:05:18 +00:00
|
|
|
m_Scopes.setInScope(settingName(name), value);
|
2013-04-11 16:51:17 +00:00
|
|
|
}
|
|
|
|
|
|
2024-10-17 18:04:35 +00:00
|
|
|
template <typename T> void AppConfig::saveToAllScopes(Setting name, T value)
|
|
|
|
|
{
|
2024-08-07 14:05:18 +00:00
|
|
|
m_Scopes.setInScope(settingName(name), value, ConfigScopes::Scope::User);
|
|
|
|
|
m_Scopes.setInScope(settingName(name), value, ConfigScopes::Scope::System);
|
2024-07-23 19:17:40 +00:00
|
|
|
}
|
2016-10-26 14:57:38 +00:00
|
|
|
|
2024-10-17 18:04:35 +00:00
|
|
|
QVariant AppConfig::getFromCurrentScope(Setting name, const QVariant &defaultValue) const
|
|
|
|
|
{
|
2024-08-07 14:05:18 +00:00
|
|
|
return m_Scopes.getFromScope(settingName(name), defaultValue);
|
2024-08-01 00:13:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template <typename T>
|
2024-10-17 18:04:35 +00:00
|
|
|
std::optional<T> AppConfig::getFromCurrentScope(Setting name, std::function<T(const QVariant &)> toType) const
|
|
|
|
|
{
|
2024-08-07 14:05:18 +00:00
|
|
|
if (m_Scopes.scopeContains(settingName(name))) {
|
|
|
|
|
return toType(m_Scopes.getFromScope(settingName(name)));
|
2024-08-01 00:13:01 +00:00
|
|
|
} else {
|
|
|
|
|
return std::nullopt;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-10-17 18:04:35 +00:00
|
|
|
template <typename T> void AppConfig::setInCurrentScope(Setting name, const std::optional<T> &value)
|
|
|
|
|
{
|
2024-08-01 00:13:01 +00:00
|
|
|
if (value.has_value()) {
|
2024-08-07 14:05:18 +00:00
|
|
|
m_Scopes.setInScope(settingName(name), value.value());
|
2024-08-01 00:13:01 +00:00
|
|
|
}
|
2016-10-26 14:57:38 +00:00
|
|
|
}
|
|
|
|
|
|
2024-10-17 18:04:35 +00:00
|
|
|
QVariant AppConfig::findInAllScopes(Setting name, const QVariant &defaultValue) const
|
|
|
|
|
{
|
2024-08-03 00:17:29 +00:00
|
|
|
using enum ConfigScopes::Scope;
|
|
|
|
|
|
2024-07-23 19:17:40 +00:00
|
|
|
QVariant result(defaultValue);
|
|
|
|
|
QString setting(settingName(name));
|
|
|
|
|
|
2024-08-07 14:05:18 +00:00
|
|
|
if (m_Scopes.scopeContains(setting)) {
|
|
|
|
|
result = m_Scopes.getFromScope(setting, defaultValue);
|
|
|
|
|
} else if (m_Scopes.activeScope() == System) {
|
|
|
|
|
if (m_Scopes.scopeContains(setting, User)) {
|
|
|
|
|
result = m_Scopes.getFromScope(setting, defaultValue, User);
|
2024-07-23 19:17:40 +00:00
|
|
|
}
|
2024-08-07 14:05:18 +00:00
|
|
|
} else if (m_Scopes.scopeContains(setting, System)) {
|
|
|
|
|
result = m_Scopes.getFromScope(setting, defaultValue, 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-10-17 18:04:35 +00:00
|
|
|
void AppConfig::loadScope(ConfigScopes::Scope scope)
|
|
|
|
|
{
|
2024-08-03 00:17:29 +00:00
|
|
|
using enum ConfigScopes::Scope;
|
2016-09-30 14:03:49 +00:00
|
|
|
|
2024-08-03 00:17:29 +00:00
|
|
|
switch (scope) {
|
|
|
|
|
case User:
|
|
|
|
|
qDebug("loading user settings scope");
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case System:
|
|
|
|
|
qDebug("loading system settings scope");
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
qFatal("invalid scope");
|
2024-07-23 19:17:40 +00:00
|
|
|
}
|
2016-09-30 14:03:49 +00:00
|
|
|
|
2024-08-07 14:05:18 +00:00
|
|
|
if (m_Scopes.activeScope() == scope) {
|
2024-08-03 00:17:29 +00:00
|
|
|
qDebug("already in required scope, skipping");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2024-08-07 14:05:18 +00:00
|
|
|
m_Scopes.setActiveScope(scope);
|
2024-08-03 00:17:29 +00:00
|
|
|
|
2024-08-12 15:39:18 +00:00
|
|
|
qDebug("active scope file path: %s", qPrintable(m_Scopes.activeFilePath()));
|
|
|
|
|
|
2024-08-03 00:17:29 +00:00
|
|
|
// only signal ready if there is at least one setting in the required scope.
|
|
|
|
|
// this prevents the current settings from being set back to default.
|
2025-03-09 03:09:38 +00:00
|
|
|
if (m_Scopes.scopeContains(settingName(Setting::kUseInternalConfig), m_Scopes.activeScope())) {
|
2024-08-07 14:05:18 +00:00
|
|
|
m_Scopes.signalReady();
|
2024-08-03 00:17:29 +00:00
|
|
|
} else {
|
|
|
|
|
qDebug("no screen name in scope, skipping");
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-09-30 14:03:49 +00:00
|
|
|
|
2024-10-17 18:04:35 +00:00
|
|
|
void AppConfig::setLoadFromSystemScope(bool value)
|
|
|
|
|
{
|
2024-08-03 00:17:29 +00:00
|
|
|
using enum ConfigScopes::Scope;
|
2016-09-30 14:03:49 +00:00
|
|
|
|
2024-07-23 19:17:40 +00:00
|
|
|
if (value) {
|
2024-08-03 00:17:29 +00:00
|
|
|
loadScope(System);
|
2024-07-23 19:17:40 +00:00
|
|
|
} else {
|
2024-08-03 00:17:29 +00:00
|
|
|
loadScope(User);
|
2024-07-23 19:17:40 +00:00
|
|
|
}
|
|
|
|
|
|
2024-08-03 00:17:29 +00:00
|
|
|
// set after loading scope since it may have been overridden.
|
2024-07-23 19:17:40 +00:00
|
|
|
m_LoadFromSystemScope = value;
|
2020-03-31 14:18:57 +00:00
|
|
|
}
|
2016-09-30 14:03:49 +00:00
|
|
|
|
2024-10-17 18:04:35 +00:00
|
|
|
bool AppConfig::isActiveScopeWritable() const
|
|
|
|
|
{
|
2024-08-07 14:05:18 +00:00
|
|
|
return m_Scopes.isActiveScopeWritable();
|
2020-03-31 14:18:57 +00:00
|
|
|
}
|
2016-09-30 14:03:49 +00:00
|
|
|
|
2024-10-17 18:04:35 +00:00
|
|
|
bool AppConfig::isActiveScopeSystem() const
|
|
|
|
|
{
|
2024-08-07 14:05:18 +00:00
|
|
|
return m_Scopes.activeScope() == ConfigScopes::Scope::System;
|
2020-03-31 14:18:57 +00:00
|
|
|
}
|
2024-08-03 00:17:29 +00:00
|
|
|
|
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-10-17 18:04:35 +00:00
|
|
|
IConfigScopes &AppConfig::scopes() const
|
|
|
|
|
{
|
|
|
|
|
return m_Scopes;
|
|
|
|
|
}
|
2024-08-01 00:13:01 +00:00
|
|
|
|
2024-10-17 18:04:35 +00:00
|
|
|
bool AppConfig::useInternalConfig() const
|
|
|
|
|
{
|
|
|
|
|
return m_UseInternalConfig;
|
|
|
|
|
}
|
2024-07-26 22:53:52 +00:00
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
// End getters
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
// Begin setters
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
2024-10-17 18:04:35 +00:00
|
|
|
void AppConfig::setUseInternalConfig(bool newValue)
|
|
|
|
|
{
|
2024-08-03 00:17:29 +00:00
|
|
|
m_UseInternalConfig = newValue;
|
2024-07-26 22:53:52 +00:00
|
|
|
}
|
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
|
|
|
///////////////////////////////////////////////////////////////////////////////
|