deskflow/src/gui/src/AppConfig.h

342 lines
10 KiB
C
Raw Normal View History

2012-06-10 16:50:54 +00:00
/*
* synergy -- mouse and keyboard sharing utility
2016-09-07 14:24:00 +00:00
* Copyright (C) 2012-2016 Symless Ltd.
2012-06-10 16:50:54 +00:00
* Copyright (C) 2008 Volker Lanz (vl@fidra.de)
*
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
* found in the file LICENSE that should have accompanied this file.
*
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/>.
*/
#if !defined(APPCONFIG_H)
#define APPCONFIG_H
#include "ConfigBase.h"
#include "ConfigWriter.h"
#include "CoreInterface.h"
#include "ElevateMode.h"
#include <QObject>
2012-06-10 16:50:54 +00:00
#include <QString>
#include <QVariant>
#include <mutex>
#include <shared/EditionType.h>
2013-04-11 16:51:17 +00:00
// this should be incremented each time a new page is added. this is
// saved to settings when the user finishes running the wizard. if
// the saved wizard version is lower than this number, the wizard
// will be displayed. each version incrememnt should be described
// here...
//
// 1: first version
2013-06-04 17:37:27 +00:00
// 2: added language page
// 3: added premium page and removed
// 4: ssl plugin 'ns' v1.0
// 5: ssl plugin 'ns' v1.1
// 6: ssl plugin 'ns' v1.2
// 7: serial key activation
2016-06-24 17:27:03 +00:00
// 8: Visual Studio 2015 support
//
2016-06-24 17:27:03 +00:00
const int kWizardVersion = 8;
2012-06-10 16:50:54 +00:00
class QSettings;
class SettingsDialog;
class ServerConfig;
class LicenseRegister;
2012-06-10 16:50:54 +00:00
Solve SonarCloud security hotspots and bugs (#7383) * Test: allocLockCursorToScreenInfo_withState_setsState * Merge remote-tracking branch 'origin/master' into S1-1717-sonarcloud-issues * Remove header wrappers for gmock/gtest * Convenience wrapper script for tests * Use `std::copy` instead of `strcpy` * Use `std::ranges::copy` instead of `stdcpy` * Delete dead code * Add guitests VS Code config and test wrapper * Revert "Delete dead code" This reverts commit aa40f5cd35a22b4b69acfd1876aceea053088060. * Build guitests with CMake * Run all tests * Don't use --gtest_filter for Qt tests * Undo skip for GUI tests * Coverage for `IpcClient::sendCommand` * Remove provider and proxy * Use lamda for StreamProvider to reduce boilerplate * Restore version checker tests * Remove activation souces * Tasks for current/all tests * Change command for tasks * Mock QNetworkAccessManager * Create core app to satisfy Qt assertations * Use `std::copy` instead of `std::ranges::copy` * Remove integtests * Merge guitests into unittests * Use std::string::length * Remove include (resolves to root) * Fix memory leaks * Disable sigsegv tests * Fixed formatting * Remove guitests from CI * New MainWindowTests * Passing test for MainWindowTests * Use alternative to strlen in MainWindow::checkSecureSocket * Passing test for Log::print * Fixed dtor call order * Fixed var name typo * Use proxy instead of `#define protected public` * Add args test for log * Add license ctor * Fixed log test for release * Add error log test * Init qt with -platform offscreen * Back-out initQt function * Use QT_QPA_PLATFORM * Try QT_QPA_PLATFORM=offscreen * Use more readable env node * Set QT_QPA_PLATFORM in CI and CodeQL * Remove env not needed * Modernize Log::print * Calculate the length of the format string fmt during the initial scan loop * More direct and efficient alterative to `strlen` * Fixed major maint issues in AppConfig * New clang and cmake rules * Set `max_pargs_hwrap` to 4 * Undo clang format for now * Fix missing `Setting::` * Fixed missing `m_S` on Windows * Re-add accidental dep resolution (fix later) * Fixed missing buffer position increment * Turn on errors * Fixed tests and improve error message * Fixed segfault on log refactor * Extract log time to function * Copyright date * Update ChangeLog
2024-07-16 08:30:35 +00:00
enum class ProcessMode { kService, kDesktop };
class AppConfig : public QObject, public GUI::Config::ConfigBase {
Q_OBJECT
friend class SettingsDialog;
friend class MainWindow;
friend class SetupWizard;
friend class ServerConfig;
public:
Solve SonarCloud security hotspots and bugs (#7383) * Test: allocLockCursorToScreenInfo_withState_setsState * Merge remote-tracking branch 'origin/master' into S1-1717-sonarcloud-issues * Remove header wrappers for gmock/gtest * Convenience wrapper script for tests * Use `std::copy` instead of `strcpy` * Use `std::ranges::copy` instead of `stdcpy` * Delete dead code * Add guitests VS Code config and test wrapper * Revert "Delete dead code" This reverts commit aa40f5cd35a22b4b69acfd1876aceea053088060. * Build guitests with CMake * Run all tests * Don't use --gtest_filter for Qt tests * Undo skip for GUI tests * Coverage for `IpcClient::sendCommand` * Remove provider and proxy * Use lamda for StreamProvider to reduce boilerplate * Restore version checker tests * Remove activation souces * Tasks for current/all tests * Change command for tasks * Mock QNetworkAccessManager * Create core app to satisfy Qt assertations * Use `std::copy` instead of `std::ranges::copy` * Remove integtests * Merge guitests into unittests * Use std::string::length * Remove include (resolves to root) * Fix memory leaks * Disable sigsegv tests * Fixed formatting * Remove guitests from CI * New MainWindowTests * Passing test for MainWindowTests * Use alternative to strlen in MainWindow::checkSecureSocket * Passing test for Log::print * Fixed dtor call order * Fixed var name typo * Use proxy instead of `#define protected public` * Add args test for log * Add license ctor * Fixed log test for release * Add error log test * Init qt with -platform offscreen * Back-out initQt function * Use QT_QPA_PLATFORM * Try QT_QPA_PLATFORM=offscreen * Use more readable env node * Set QT_QPA_PLATFORM in CI and CodeQL * Remove env not needed * Modernize Log::print * Calculate the length of the format string fmt during the initial scan loop * More direct and efficient alterative to `strlen` * Fixed major maint issues in AppConfig * New clang and cmake rules * Set `max_pargs_hwrap` to 4 * Undo clang format for now * Fix missing `Setting::` * Fixed missing `m_S` on Windows * Re-add accidental dep resolution (fix later) * Fixed missing buffer position increment * Turn on errors * Fixed tests and improve error message * Fixed segfault on log refactor * Extract log time to function * Copyright date * Update ChangeLog
2024-07-16 08:30:35 +00:00
explicit AppConfig(bool globalLoad = true);
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;
const QString logFilenameCmd() const;
QString logLevelText() const;
ProcessMode processMode() const;
bool wizardShouldRun() const;
bool startedBefore() const;
Simplify compile options and use comprehensive edition logic (#7365) * Simplify options * Use more sensible edition logic * Use set instead of option for string * Improve macro for product name * Add tests launch config * Restore unregistered state * Reorganize cases for title and improve function name * Code coverage on by default * Fixed copyright * Improve code coverage and test readability * Separate build-all and build-coverage * Back out coverage on by default * Fixed bad var in cmake * More verbose logging for coverage * Restore tasks * Restore preLaunchTask * Use default comparitor * Move temp files to temp dir * Add tasks for tests * Support for wstring * Upgrade sonar-scanner to 6 on Debian 12 * Use modern pip install * Install python for sonarcloud * Use Ubuntu and install deps * Fixed sonar-scanner URL * Fix exported dir * Persist build dir * Don't use venv for pip install gcovr * Fixed another path * Update actions/checkout to v4 for SonarCloud analysis workflow * Add coverage task * Improve coverage for SerialKeyEdition.cpp * Enable licensing for builds * Fixed invalid macro names, missing arguments, etc * Fixed more copyright * Fixed incorrect use of "enterprise" * Fixed incorrect use of "business" * Experiment with environment * Make package prefix variable * Add environment matrix to all OS * Improve job names * Make job names easier to read * Roll back environment matrix (too much noise) * Fixed: default should override required * Refactor CI with vars * Fixed arg for env.get_env
2024-07-04 09:14:54 +00:00
#ifdef SYNERGY_ENABLE_LICENSING
void setEdition(Edition);
Edition edition() const;
void setSerialKey(const QString &serial);
void clearSerialKey();
QString serialKey() const;
int lastExpiringWarningTime() const;
void setLastExpiringWarningTime(int t);
#endif
QString synergysName() const;
QString synergycName() const;
QString synergyProgramDir() const;
QString synergyLogDir() const;
void persistLogDir();
ElevateMode elevateMode();
bool isCryptoAvailable() const;
void setCryptoEnabled(bool e);
bool getCryptoEnabled() const;
void setAutoHide(bool b);
bool getAutoHide();
void setInvertScrollDirection(bool b);
bool getInvertScrollDirection() const;
void setLicenseNextCheck(unsigned long long);
const QString &getLicenseRegistryUrl() const;
unsigned long long getLicenseNextCheck() const;
const QString &getGuid() const;
void setLanguageSync(bool b);
bool getLanguageSync() const;
void setPreventSleep(bool b);
bool getPreventSleep() const;
bool getClientHostMode() const;
bool getServerClientMode() const;
bool getInitiateConnectionFromServer() const;
Simplify compile options and use comprehensive edition logic (#7365) * Simplify options * Use more sensible edition logic * Use set instead of option for string * Improve macro for product name * Add tests launch config * Restore unregistered state * Reorganize cases for title and improve function name * Code coverage on by default * Fixed copyright * Improve code coverage and test readability * Separate build-all and build-coverage * Back out coverage on by default * Fixed bad var in cmake * More verbose logging for coverage * Restore tasks * Restore preLaunchTask * Use default comparitor * Move temp files to temp dir * Add tasks for tests * Support for wstring * Upgrade sonar-scanner to 6 on Debian 12 * Use modern pip install * Install python for sonarcloud * Use Ubuntu and install deps * Fixed sonar-scanner URL * Fix exported dir * Persist build dir * Don't use venv for pip install gcovr * Fixed another path * Update actions/checkout to v4 for SonarCloud analysis workflow * Add coverage task * Improve coverage for SerialKeyEdition.cpp * Enable licensing for builds * Fixed invalid macro names, missing arguments, etc * Fixed more copyright * Fixed incorrect use of "enterprise" * Fixed incorrect use of "business" * Experiment with environment * Make package prefix variable * Add environment matrix to all OS * Improve job names * Make job names easier to read * Roll back environment matrix (too much noise) * Fixed: default should override required * Refactor CI with vars * Fixed arg for env.get_env
2024-07-04 09:14:54 +00:00
#ifdef SYNERGY_ENABLE_LICENSING
bool activationHasRun() const;
AppConfig &activationHasRun(bool value);
#endif
/// @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);
bool getServerGroupChecked() const;
bool getUseExternalConfig() const;
const QString &getConfigFile() const;
bool getUseInternalConfig() const;
bool getClientGroupChecked() const;
QString getServerHostname() const;
/// @brief Gets the current TLS certificate path
/// @return QString The path to the cert
QString getTLSCertPath() const;
/// @brief Get the key length to be used for the private key of a TLS cert
/// @return QString The key length in bits
QString getTLSKeyLength() const;
void setServerGroupChecked(bool);
void setUseExternalConfig(bool);
void setConfigFile(const QString &);
void setUseInternalConfig(bool);
void setClientGroupChecked(bool);
void setServerHostname(const QString &);
void setClientHostMode(bool newValue);
void setServerClientMode(bool newValue);
/// @brief Set the path to the TLS/SSL certificate file that will be used
/// @param [in] path The path to the Certificate
void setTLSCertPath(const QString &path);
/// @brief Sets the key length of the private key to use in a TLS connection
/// @param [in] QString length The key length eg: 1024, 2048, 4096
void setTLSKeyLength(const QString &length);
QString lastVersion() const;
void setMinimizeToTray(bool b);
bool getMinimizeToTray();
void saveSettings() override;
void setLastVersion(const QString &version);
/// @brief Generates TLS certificate
/// @param [in] bool forceGeneration Generate certificate even if it's exists.
void generateCertificate(bool forceGeneration = false) const;
protected:
/// @brief The enumeration to easily access the names of the setting inside
/// m_SynergySettingsName
Solve SonarCloud security hotspots and bugs (#7383) * Test: allocLockCursorToScreenInfo_withState_setsState * Merge remote-tracking branch 'origin/master' into S1-1717-sonarcloud-issues * Remove header wrappers for gmock/gtest * Convenience wrapper script for tests * Use `std::copy` instead of `strcpy` * Use `std::ranges::copy` instead of `stdcpy` * Delete dead code * Add guitests VS Code config and test wrapper * Revert "Delete dead code" This reverts commit aa40f5cd35a22b4b69acfd1876aceea053088060. * Build guitests with CMake * Run all tests * Don't use --gtest_filter for Qt tests * Undo skip for GUI tests * Coverage for `IpcClient::sendCommand` * Remove provider and proxy * Use lamda for StreamProvider to reduce boilerplate * Restore version checker tests * Remove activation souces * Tasks for current/all tests * Change command for tasks * Mock QNetworkAccessManager * Create core app to satisfy Qt assertations * Use `std::copy` instead of `std::ranges::copy` * Remove integtests * Merge guitests into unittests * Use std::string::length * Remove include (resolves to root) * Fix memory leaks * Disable sigsegv tests * Fixed formatting * Remove guitests from CI * New MainWindowTests * Passing test for MainWindowTests * Use alternative to strlen in MainWindow::checkSecureSocket * Passing test for Log::print * Fixed dtor call order * Fixed var name typo * Use proxy instead of `#define protected public` * Add args test for log * Add license ctor * Fixed log test for release * Add error log test * Init qt with -platform offscreen * Back-out initQt function * Use QT_QPA_PLATFORM * Try QT_QPA_PLATFORM=offscreen * Use more readable env node * Set QT_QPA_PLATFORM in CI and CodeQL * Remove env not needed * Modernize Log::print * Calculate the length of the format string fmt during the initial scan loop * More direct and efficient alterative to `strlen` * Fixed major maint issues in AppConfig * New clang and cmake rules * Set `max_pargs_hwrap` to 4 * Undo clang format for now * Fix missing `Setting::` * Fixed missing `m_S` on Windows * Re-add accidental dep resolution (fix later) * Fixed missing buffer position increment * Turn on errors * Fixed tests and improve error message * Fixed segfault on log refactor * Extract log time to function * Copyright date * Update ChangeLog
2024-07-16 08:30:35 +00:00
enum class Setting {
kScreenName,
kPort,
kInterfaceSetting,
kLogLevel,
kLogToFile,
kLogFilename,
kWizardLastRun,
kStartedBefore,
kElevateModeSetting,
kElevateModeEnum,
kEditionSetting,
kCryptoEnabled,
kAutoHide,
kSerialKey,
kLastVersion,
kLastExpireWarningTime,
kActivationHasRun,
kMinimizeToTray,
kActivateEmail,
kLoadSystemSettings,
kGroupServerCheck,
kUseExternalConfig,
kConfigFile,
kUseInternalConfig,
kGroupClientCheck,
kServerHostname,
kTLSCertPath,
kTLSKeyLength,
kPreventSleep,
kLanguageSync,
kInvertScrollDirection,
kGuid,
kLicenseRegistryUrl,
kLicenseNextCheck,
kInitiateConnectionFromServer,
kClientHostMode,
kServerClientMode
};
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);
/// @brief loads the setting from the current scope
/// @param ignoreSystem should the load feature ignore the globalScope setting
/// that was saved
void loadSettings() override;
static QString settingName(AppConfig::Setting name);
private:
QString m_ScreenName;
int m_Port;
QString m_Interface;
int m_LogLevel;
bool m_LogToFile;
QString m_LogFilename;
int m_WizardLastRun;
ProcessMode m_ProcessMode;
bool m_StartedBefore;
ElevateMode m_ElevateMode;
Edition m_Edition;
QString m_ActivateEmail;
bool m_CryptoEnabled;
bool m_AutoHide;
QString m_Serialkey;
QString m_lastVersion;
QString m_guid;
QString m_licenseRegistryUrl;
unsigned long long m_licenseNextCheck;
int m_LastExpiringWarningTime;
bool m_ActivationHasRun;
bool m_MinimizeToTray;
bool m_InvertScrollDirection = false;
bool m_LanguageSync = true;
bool m_PreventSleep = false;
bool m_InitiateConnectionFromServer = false;
bool m_ClientHostMode = true;
bool m_ServerClientMode = true;
bool m_ServerGroupChecked;
bool m_UseExternalConfig;
QString m_ConfigFile;
bool m_UseInternalConfig;
bool m_ClientGroupChecked;
QString m_ServerHostname;
QString m_TLSCertificatePath; /// @brief The path to the TLS certificate file
QString m_TLSKeyLength; /// @brief The key length of the TLS cert to make
bool m_LoadFromSystemScope; /// @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
CoreInterface m_CoreInterface;
static const char m_SynergysName[];
static const char m_SynergycName[];
static const char m_SynergyLogDir[];
/// @brief Contains the string values of the settings names that will be saved
static const char *m_SynergySettingsName[];
/// @brief Contains the name of the default configuration filename
Solve SonarCloud security hotspots and bugs (#7383) * Test: allocLockCursorToScreenInfo_withState_setsState * Merge remote-tracking branch 'origin/master' into S1-1717-sonarcloud-issues * Remove header wrappers for gmock/gtest * Convenience wrapper script for tests * Use `std::copy` instead of `strcpy` * Use `std::ranges::copy` instead of `stdcpy` * Delete dead code * Add guitests VS Code config and test wrapper * Revert "Delete dead code" This reverts commit aa40f5cd35a22b4b69acfd1876aceea053088060. * Build guitests with CMake * Run all tests * Don't use --gtest_filter for Qt tests * Undo skip for GUI tests * Coverage for `IpcClient::sendCommand` * Remove provider and proxy * Use lamda for StreamProvider to reduce boilerplate * Restore version checker tests * Remove activation souces * Tasks for current/all tests * Change command for tasks * Mock QNetworkAccessManager * Create core app to satisfy Qt assertations * Use `std::copy` instead of `std::ranges::copy` * Remove integtests * Merge guitests into unittests * Use std::string::length * Remove include (resolves to root) * Fix memory leaks * Disable sigsegv tests * Fixed formatting * Remove guitests from CI * New MainWindowTests * Passing test for MainWindowTests * Use alternative to strlen in MainWindow::checkSecureSocket * Passing test for Log::print * Fixed dtor call order * Fixed var name typo * Use proxy instead of `#define protected public` * Add args test for log * Add license ctor * Fixed log test for release * Add error log test * Init qt with -platform offscreen * Back-out initQt function * Use QT_QPA_PLATFORM * Try QT_QPA_PLATFORM=offscreen * Use more readable env node * Set QT_QPA_PLATFORM in CI and CodeQL * Remove env not needed * Modernize Log::print * Calculate the length of the format string fmt during the initial scan loop * More direct and efficient alterative to `strlen` * Fixed major maint issues in AppConfig * New clang and cmake rules * Set `max_pargs_hwrap` to 4 * Undo clang format for now * Fix missing `Setting::` * Fixed missing `m_S` on Windows * Re-add accidental dep resolution (fix later) * Fixed missing buffer position increment * Turn on errors * Fixed tests and improve error message * Fixed segfault on log refactor * Extract log time to function * Copyright date * Update ChangeLog
2024-07-16 08:30:35 +00:00
static const char m_SynergyConfigName[];
/// @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
QVariant loadSetting(
AppConfig::Setting name, const QVariant &defaultValue = QVariant());
/// @brief Loads a common setting
/// @param [in] name The setting to be loaded
/// @param [in] defaultValue The default value of the setting
QVariant loadCommonSetting(
AppConfig::Setting name, const QVariant &defaultValue = QVariant()) const;
/// @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;
/// @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.
void loadScope(GUI::Config::ConfigWriter::Scope scope);
/// @brief This function sets default values
/// for settings that shouldn't be copied from between scopes.
void setDefaultValues();
signals:
void sslToggled() const;
void screenNameChanged() const;
2012-06-10 16:50:54 +00:00
};
#endif