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/>.
|
|
|
|
|
*/
|
|
|
|
|
|
2024-07-22 16:48:02 +00:00
|
|
|
#pragma once
|
2012-06-10 16:50:54 +00:00
|
|
|
|
2024-07-22 16:48:02 +00:00
|
|
|
#include "CommonConfig.h"
|
2024-08-01 00:13:01 +00:00
|
|
|
#include "ConfigScopes.h"
|
|
|
|
|
#include "CoreInterface.h"
|
|
|
|
|
#include "ElevateMode.h"
|
|
|
|
|
#include "IAppConfig.h"
|
2024-07-22 16:48:02 +00:00
|
|
|
|
2024-08-01 00:13:01 +00:00
|
|
|
#include <QDir>
|
|
|
|
|
#include <QHostInfo>
|
2016-10-04 12:41:27 +00:00
|
|
|
#include <QObject>
|
2024-08-01 00:13:01 +00:00
|
|
|
#include <QPoint>
|
|
|
|
|
#include <QSize>
|
2012-06-10 16:50:54 +00:00
|
|
|
#include <QString>
|
2020-02-13 09:21:02 +00:00
|
|
|
#include <QVariant>
|
2020-02-25 17:00:30 +00:00
|
|
|
#include <mutex>
|
2012-06-10 16:50:54 +00:00
|
|
|
|
2024-07-16 08:30:35 +00:00
|
|
|
enum class ProcessMode { kService, kDesktop };
|
2024-07-02 19:07:06 +00:00
|
|
|
|
2024-07-22 16:48:02 +00:00
|
|
|
const ElevateMode kDefaultElevateMode = ElevateAsNeeded;
|
2024-08-01 00:13:01 +00:00
|
|
|
const QString kDefaultLogFile = "synergy.log";
|
2024-07-22 16:48:02 +00:00
|
|
|
|
|
|
|
|
#if defined(Q_OS_WIN)
|
|
|
|
|
const ProcessMode kDefaultProcessMode = ProcessMode::kService;
|
|
|
|
|
#else
|
|
|
|
|
const ProcessMode kDefaultProcessMode = ProcessMode::kDesktop;
|
|
|
|
|
#endif
|
|
|
|
|
|
2024-07-26 22:53:52 +00:00
|
|
|
/**
|
|
|
|
|
* @brief Simply reads and writes app settings.
|
|
|
|
|
*
|
|
|
|
|
* Important: Maintain a clear separation of concerns and keep it simple.
|
|
|
|
|
* It is tempting to add logic (e.g. license checks) to this class since it
|
|
|
|
|
* instance is widely accessible, but that has previously led to this class
|
|
|
|
|
* becoming a god object.
|
|
|
|
|
*/
|
|
|
|
|
class AppConfig : public QObject,
|
|
|
|
|
public synergy::gui::CommonConfig,
|
|
|
|
|
public synergy::gui::IAppConfig {
|
2024-07-02 19:07:06 +00:00
|
|
|
Q_OBJECT
|
|
|
|
|
|
2024-07-26 22:53:52 +00:00
|
|
|
private:
|
|
|
|
|
enum class Setting {
|
|
|
|
|
kScreenName = 0,
|
|
|
|
|
kPort = 1,
|
|
|
|
|
kInterface = 2,
|
|
|
|
|
kLogLevel = 3,
|
|
|
|
|
kLogToFile = 4,
|
|
|
|
|
kLogFilename = 5,
|
|
|
|
|
kWizardLastRun = 6,
|
|
|
|
|
kStartedBefore = 7,
|
2024-08-01 00:13:01 +00:00
|
|
|
kElevateModeLegacy = 8,
|
|
|
|
|
kElevateMode = 9,
|
2024-07-26 22:53:52 +00:00
|
|
|
// 10 = edition, obsolete (using serial key instead)
|
|
|
|
|
kTlsEnabled = 11,
|
|
|
|
|
kAutoHide = 12,
|
|
|
|
|
kSerialKey = 13,
|
|
|
|
|
kLastVersion = 14,
|
|
|
|
|
// 15 = last expire time, obsolete
|
|
|
|
|
kActivationHasRun = 16,
|
2024-08-01 00:13:01 +00:00
|
|
|
// 17 = minimize to tray, obsolete
|
2024-07-26 22:53:52 +00:00
|
|
|
// 18 = activate email, obsolete
|
|
|
|
|
kLoadSystemSettings = 19,
|
|
|
|
|
kServerGroupChecked = 20,
|
|
|
|
|
kUseExternalConfig = 21,
|
|
|
|
|
kConfigFile = 22,
|
|
|
|
|
kUseInternalConfig = 23,
|
|
|
|
|
kClientGroupChecked = 24,
|
|
|
|
|
kServerHostname = 25,
|
|
|
|
|
kTlsCertPath = 26,
|
|
|
|
|
kTlsKeyLength = 27,
|
|
|
|
|
kPreventSleep = 28,
|
|
|
|
|
kLanguageSync = 29,
|
|
|
|
|
kInvertScrollDirection = 30,
|
|
|
|
|
// 31 = guid, obsolete
|
|
|
|
|
// 32 = license registry url, obsolete
|
|
|
|
|
kLicenseNextCheck = 33,
|
|
|
|
|
kInvertConnection = 34,
|
|
|
|
|
// 35 = client-host-mode, obsolete
|
|
|
|
|
// 36 = server-client-mode, obsolete
|
|
|
|
|
kServiceEnabled = 37,
|
|
|
|
|
kCloseToTray = 38,
|
2024-08-01 00:13:01 +00:00
|
|
|
kMainWindowSize = 39,
|
|
|
|
|
kMainWindowPosition = 40,
|
2024-07-26 22:53:52 +00:00
|
|
|
};
|
2024-07-02 19:07:06 +00:00
|
|
|
|
|
|
|
|
public:
|
2024-08-01 00:13:01 +00:00
|
|
|
struct Deps {
|
|
|
|
|
virtual ~Deps() = default;
|
|
|
|
|
virtual QString profileDir() const {
|
|
|
|
|
return m_coreInterface.getProfileDir();
|
|
|
|
|
}
|
|
|
|
|
virtual synergy::gui::IConfigScopes &scopes() { return m_Scopes; }
|
|
|
|
|
virtual QString hostname() const { return QHostInfo::localHostName(); }
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
[[no_unique_address]] CoreInterface m_coreInterface;
|
|
|
|
|
synergy::gui::ConfigScopes m_Scopes;
|
|
|
|
|
};
|
2024-07-22 16:48:02 +00:00
|
|
|
|
2024-08-01 00:13:01 +00:00
|
|
|
explicit AppConfig() : AppConfig(s_Deps) {}
|
|
|
|
|
explicit AppConfig(Deps &deps);
|
2024-07-22 16:48:02 +00:00
|
|
|
|
2024-08-01 00:13:01 +00:00
|
|
|
synergy::gui::IConfigScopes &scopes();
|
2024-07-22 16:48:02 +00:00
|
|
|
void saveSettings() override;
|
2024-08-01 00:13:01 +00:00
|
|
|
void loadAllScopes();
|
|
|
|
|
void loadSettings() override;
|
2024-07-22 16:48:02 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Getters
|
|
|
|
|
*/
|
2024-07-02 19:07:06 +00:00
|
|
|
|
2024-08-01 00:13:01 +00:00
|
|
|
void setActivationHasRun(bool value);
|
2024-07-02 19:07:06 +00:00
|
|
|
bool isWritable() const;
|
|
|
|
|
bool isSystemScoped() const;
|
|
|
|
|
const QString &screenName() const;
|
|
|
|
|
int port() const;
|
|
|
|
|
const QString &networkInterface() const;
|
|
|
|
|
int logLevel() const;
|
|
|
|
|
bool logToFile() const;
|
|
|
|
|
const QString &logFilename() const;
|
|
|
|
|
QString logLevelText() const;
|
|
|
|
|
ProcessMode processMode() const;
|
|
|
|
|
bool wizardShouldRun() const;
|
|
|
|
|
bool startedBefore() const;
|
2024-07-22 16:48:02 +00:00
|
|
|
QString coreServerName() const;
|
|
|
|
|
QString coreClientName() const;
|
|
|
|
|
QString logDir() const;
|
|
|
|
|
void persistLogDir() const;
|
2024-07-26 22:53:52 +00:00
|
|
|
ElevateMode elevateMode() const;
|
2024-07-23 19:17:40 +00:00
|
|
|
bool autoHide() const;
|
2024-07-22 16:48:02 +00:00
|
|
|
bool invertScrollDirection() const;
|
|
|
|
|
unsigned long long licenseNextCheck() const;
|
|
|
|
|
bool languageSync() const;
|
|
|
|
|
bool preventSleep() const;
|
2024-07-26 22:53:52 +00:00
|
|
|
bool invertConnection() const;
|
2024-07-22 16:48:02 +00:00
|
|
|
bool serverGroupChecked() const;
|
|
|
|
|
bool useExternalConfig() const;
|
|
|
|
|
const QString &configFile() const;
|
|
|
|
|
bool useInternalConfig() const;
|
|
|
|
|
bool clientGroupChecked() const;
|
|
|
|
|
QString serverHostname() const;
|
|
|
|
|
QString lastVersion() const;
|
|
|
|
|
bool serviceEnabled() const;
|
2024-07-23 19:17:40 +00:00
|
|
|
bool closeToTray() const;
|
2024-07-22 16:48:02 +00:00
|
|
|
QString serialKey() const;
|
|
|
|
|
bool activationHasRun() const;
|
2024-07-26 22:53:52 +00:00
|
|
|
bool tlsEnabled() const override;
|
|
|
|
|
QString tlsCertPath() const override;
|
|
|
|
|
QString tlsKeyLength() const override;
|
2024-08-01 00:13:01 +00:00
|
|
|
std::optional<QSize> mainWindowSize() const;
|
|
|
|
|
std::optional<QPoint> mainWindowPosition() const;
|
2024-07-26 22:53:52 +00:00
|
|
|
|
2024-07-22 16:48:02 +00:00
|
|
|
/**
|
|
|
|
|
* Setters
|
|
|
|
|
*/
|
|
|
|
|
|
2024-07-02 19:07:06 +00:00
|
|
|
void setScreenName(const QString &s);
|
|
|
|
|
void setPort(int i);
|
|
|
|
|
void setNetworkInterface(const QString &s);
|
|
|
|
|
void setLogLevel(int i);
|
|
|
|
|
void setLogToFile(bool b);
|
|
|
|
|
void setLogFilename(const QString &s);
|
|
|
|
|
void setWizardHasRun();
|
|
|
|
|
void setStartedBefore(bool b);
|
|
|
|
|
void setElevateMode(ElevateMode em);
|
2024-07-26 22:53:52 +00:00
|
|
|
void setTlsEnabled(bool e);
|
|
|
|
|
void setSerialKey(const QString &serialKey);
|
2024-07-22 16:48:02 +00:00
|
|
|
void clearSerialKey();
|
|
|
|
|
void setAutoHide(bool b);
|
|
|
|
|
void setInvertScrollDirection(bool b);
|
|
|
|
|
void setLicenseNextCheck(unsigned long long);
|
|
|
|
|
void setLanguageSync(bool b);
|
|
|
|
|
void setPreventSleep(bool b);
|
|
|
|
|
void setServerGroupChecked(bool);
|
|
|
|
|
void setUseExternalConfig(bool);
|
|
|
|
|
void setConfigFile(const QString &);
|
|
|
|
|
void setUseInternalConfig(bool);
|
|
|
|
|
void setClientGroupChecked(bool);
|
|
|
|
|
void setServerHostname(const QString &);
|
|
|
|
|
void setLastVersion(const QString &version);
|
|
|
|
|
void setServiceEnabled(bool enabled);
|
2024-07-23 19:17:40 +00:00
|
|
|
void setCloseToTray(bool minimize);
|
2024-07-26 22:53:52 +00:00
|
|
|
void setTlsCertPath(const QString &path);
|
|
|
|
|
void setTlsKeyLength(const QString &length);
|
|
|
|
|
void setInvertConnection(bool value);
|
2024-08-01 00:13:01 +00:00
|
|
|
void setMainWindowSize(const QSize &size);
|
|
|
|
|
void setMainWindowPosition(const QPoint &position);
|
2024-07-02 19:07:06 +00:00
|
|
|
|
2024-07-22 16:48:02 +00:00
|
|
|
/// @brief Sets the user preference to load from SystemScope.
|
|
|
|
|
/// @param [in] value
|
|
|
|
|
/// True - This will set the variable and load the global scope
|
|
|
|
|
/// settings. False - This will set the variable and load the user
|
|
|
|
|
/// scope settings.
|
|
|
|
|
void setLoadFromSystemScope(bool value);
|
2024-07-02 19:07:06 +00:00
|
|
|
|
2024-08-01 00:13:01 +00:00
|
|
|
private:
|
|
|
|
|
static QString settingName(AppConfig::Setting name);
|
2024-08-02 09:54:02 +00:00
|
|
|
void loadScreenName();
|
2024-08-01 00:13:01 +00:00
|
|
|
void loadSerialKey();
|
|
|
|
|
void loadElevateMode();
|
|
|
|
|
void loadCommonSettings();
|
|
|
|
|
void loadScopeSettings();
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief Loads a setting if it exists, otherwise returns `std::nullopt`
|
|
|
|
|
*
|
|
|
|
|
* @param toType A function to convert the QVariant to the desired type.
|
|
|
|
|
*/
|
|
|
|
|
template <typename T>
|
|
|
|
|
std::optional<T>
|
|
|
|
|
loadOptional(Setting name, std::function<T(QVariant)> toType) const;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief Sets a setting if the value is not `std::nullopt`.
|
|
|
|
|
*/
|
|
|
|
|
template <typename T>
|
|
|
|
|
void setOptional(Setting name, const std::optional<T> &value);
|
2024-07-02 19:07:06 +00:00
|
|
|
|
|
|
|
|
/// @brief Sets the value of a setting
|
|
|
|
|
/// @param [in] name The Setting to be saved
|
|
|
|
|
/// @param [in] value The Value to be saved
|
|
|
|
|
template <typename T> void setSetting(AppConfig::Setting name, T value);
|
|
|
|
|
|
|
|
|
|
/// @brief Sets the value of a common setting
|
|
|
|
|
/// which should have the same value for all scopes
|
|
|
|
|
/// @param [in] name The Setting to be saved
|
|
|
|
|
/// @param [in] value The Value to be saved
|
|
|
|
|
template <typename T> void setCommonSetting(AppConfig::Setting name, T value);
|
|
|
|
|
|
|
|
|
|
/// @brief Loads a setting
|
|
|
|
|
/// @param [in] name The setting to be loaded
|
|
|
|
|
/// @param [in] defaultValue The default value of the setting
|
2024-07-16 13:36:44 +00:00
|
|
|
QVariant loadSetting(
|
|
|
|
|
AppConfig::Setting name, const QVariant &defaultValue = QVariant());
|
2024-07-02 19:07:06 +00:00
|
|
|
|
|
|
|
|
/// @brief Loads a common setting
|
|
|
|
|
/// @param [in] name The setting to be loaded
|
|
|
|
|
/// @param [in] defaultValue The default value of the setting
|
2024-07-16 13:36:44 +00:00
|
|
|
QVariant loadCommonSetting(
|
|
|
|
|
AppConfig::Setting name, const QVariant &defaultValue = QVariant()) const;
|
2024-07-02 19:07:06 +00:00
|
|
|
|
|
|
|
|
/// @brief Sets the setting in the config checking if it has changed and
|
|
|
|
|
/// flagging that settings
|
|
|
|
|
/// needs to be saved if the setting was different
|
|
|
|
|
/// @param [in] variable the setting that will be changed
|
|
|
|
|
/// @param [in] newValue The new value of the setting
|
|
|
|
|
template <typename T> void setSettingModified(T &variable, const T &newValue);
|
|
|
|
|
|
|
|
|
|
/// @brief This method loads config from specified scope
|
|
|
|
|
/// @param [in] scope which should be loaded.
|
2024-08-01 00:13:01 +00:00
|
|
|
void loadScope(synergy::gui::ConfigScopes::Scope scope);
|
2024-07-02 19:07:06 +00:00
|
|
|
|
|
|
|
|
/// @brief This function sets default values
|
|
|
|
|
/// for settings that shouldn't be copied from between scopes.
|
|
|
|
|
void setDefaultValues();
|
|
|
|
|
|
2024-07-26 22:53:52 +00:00
|
|
|
/**
|
|
|
|
|
* @brief Gets a TLS certificate path based on the user's profile dir.
|
|
|
|
|
*/
|
|
|
|
|
QString defaultTlsCertPath() const;
|
|
|
|
|
|
2024-08-01 00:13:01 +00:00
|
|
|
static Deps s_Deps;
|
|
|
|
|
Deps &m_Deps;
|
|
|
|
|
QString m_ScreenName;
|
2024-07-22 16:48:02 +00:00
|
|
|
int m_Port = 24800;
|
|
|
|
|
QString m_Interface = "";
|
|
|
|
|
int m_LogLevel = 0;
|
|
|
|
|
bool m_LogToFile = false;
|
2024-08-01 00:13:01 +00:00
|
|
|
QString m_LogFilename = logDir() + kDefaultLogFile;
|
2024-07-22 16:48:02 +00:00
|
|
|
int m_WizardLastRun = 0;
|
|
|
|
|
bool m_StartedBefore = false;
|
|
|
|
|
ElevateMode m_ElevateMode = kDefaultElevateMode;
|
|
|
|
|
QString m_ActivateEmail = "";
|
2024-07-26 22:53:52 +00:00
|
|
|
bool m_TlsEnabled = true;
|
2024-07-22 16:48:02 +00:00
|
|
|
bool m_AutoHide = false;
|
2024-07-26 22:53:52 +00:00
|
|
|
QString m_SerialKey = "";
|
2024-07-22 16:48:02 +00:00
|
|
|
QString m_LastVersion = "";
|
|
|
|
|
unsigned long long m_licenseNextCheck = 0;
|
|
|
|
|
bool m_ActivationHasRun = false;
|
|
|
|
|
bool m_InvertScrollDirection = false;
|
|
|
|
|
bool m_LanguageSync = true;
|
|
|
|
|
bool m_PreventSleep = false;
|
2024-07-26 22:53:52 +00:00
|
|
|
bool m_InvertConnection = false;
|
2024-07-22 16:48:02 +00:00
|
|
|
bool m_ServerGroupChecked = false;
|
|
|
|
|
bool m_UseExternalConfig = false;
|
2024-08-01 00:13:01 +00:00
|
|
|
QString m_ConfigFile = QDir::homePath() + "/" + m_ConfigFilename;
|
2024-07-22 16:48:02 +00:00
|
|
|
bool m_UseInternalConfig = false;
|
|
|
|
|
bool m_ClientGroupChecked = false;
|
|
|
|
|
QString m_ServerHostname = "";
|
|
|
|
|
bool m_ServiceEnabled = kDefaultProcessMode == ProcessMode::kService;
|
2024-07-26 22:53:52 +00:00
|
|
|
bool m_CloseToTray = false;
|
2024-08-01 00:13:01 +00:00
|
|
|
QString m_TlsCertPath = defaultTlsCertPath();
|
2024-07-26 22:53:52 +00:00
|
|
|
QString m_TlsKeyLength = "2048";
|
2024-08-01 00:13:01 +00:00
|
|
|
std::optional<QSize> m_MainWindowSize;
|
|
|
|
|
std::optional<QPoint> m_MainWindowPosition;
|
2024-07-22 16:48:02 +00:00
|
|
|
|
2024-07-26 22:53:52 +00:00
|
|
|
/**
|
|
|
|
|
* @brief Flag is set when any TLS is setting is changed, and is reset
|
|
|
|
|
* when the TLS changed event is emitted.
|
|
|
|
|
*/
|
|
|
|
|
bool m_TlsChanged = false;
|
2024-07-22 16:48:02 +00:00
|
|
|
|
|
|
|
|
/// @brief should the setting be loaded from
|
|
|
|
|
/// SystemScope
|
|
|
|
|
/// If the user has settings but this is
|
|
|
|
|
/// true then system settings will be
|
|
|
|
|
/// loaded instead of the users
|
|
|
|
|
bool m_LoadFromSystemScope = false;
|
|
|
|
|
|
|
|
|
|
/// @brief As the settings will be accessible by multiple objects this lock
|
|
|
|
|
/// will ensure that
|
|
|
|
|
/// it cant be modified by more that one object at a time if the
|
|
|
|
|
/// setting is being switched from system to user.
|
|
|
|
|
std::mutex m_settings_lock;
|
|
|
|
|
|
|
|
|
|
static const char m_CoreServerName[];
|
|
|
|
|
static const char m_CoreClientName[];
|
|
|
|
|
static const char m_LogDir[];
|
|
|
|
|
|
|
|
|
|
/// @brief Contains the string values of the settings names that will be saved
|
|
|
|
|
static const char *const m_SettingsName[];
|
|
|
|
|
|
|
|
|
|
/// @brief Contains the name of the default configuration filename
|
|
|
|
|
static const char m_ConfigFilename[];
|
|
|
|
|
|
2024-07-02 19:07:06 +00:00
|
|
|
signals:
|
2024-07-26 22:53:52 +00:00
|
|
|
void loaded();
|
|
|
|
|
void saved();
|
|
|
|
|
void tlsChanged();
|
|
|
|
|
void screenNameChanged();
|
|
|
|
|
void invertConnectionChanged();
|
2012-06-10 16:50:54 +00:00
|
|
|
};
|