2025-03-06 22:37:37 +00:00
|
|
|
/*
|
|
|
|
|
* Deskflow -- mouse and keyboard sharing utility
|
|
|
|
|
* SPDX-FileCopyrightText: (C) 2025 Chris Rizzitello <sithlord48@gmail.com>
|
2025-03-09 05:54:47 +00:00
|
|
|
* SPDX-FileCopyrightText: (C) 2016 - 2025 Symless Ltd.
|
2025-03-06 22:37:37 +00:00
|
|
|
* SPDX-License-Identifier: GPL-2.0-only WITH LicenseRef-OpenSSL-Exception
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
|
|
#include <QSettings>
|
|
|
|
|
|
|
|
|
|
#include <QDir>
|
|
|
|
|
|
2025-03-19 22:14:27 +00:00
|
|
|
#include "common/Constants.h"
|
2025-03-15 02:17:08 +00:00
|
|
|
#include "common/QSettingsProxy.h"
|
2025-03-06 22:37:37 +00:00
|
|
|
|
|
|
|
|
class Settings : public QObject
|
|
|
|
|
{
|
|
|
|
|
Q_OBJECT
|
|
|
|
|
public:
|
|
|
|
|
#if defined(Q_OS_WIN)
|
2025-03-07 00:42:16 +00:00
|
|
|
inline const static auto UserDir = QStringLiteral("%1/AppData/Local/%2").arg(QDir::homePath(), kAppName);
|
|
|
|
|
inline const static auto SystemDir = QStringLiteral("C:/ProgramData/%1").arg(kAppName);
|
2025-03-06 22:37:37 +00:00
|
|
|
#elif defined(Q_OS_MAC)
|
2025-03-07 00:42:16 +00:00
|
|
|
inline const static auto UserDir = QStringLiteral("%1/Library/%2").arg(QDir::homePath(), kAppName);
|
|
|
|
|
inline const static auto SystemDir = QStringLiteral("/Library/%1").arg(kAppName);
|
2025-03-06 22:37:37 +00:00
|
|
|
#else
|
2025-03-07 00:42:16 +00:00
|
|
|
inline const static auto UserDir = QStringLiteral("%1/.config/%2").arg(QDir::homePath(), kAppName);
|
|
|
|
|
inline const static auto SystemDir = QStringLiteral("/etc/%1").arg(kAppName);
|
2025-03-06 22:37:37 +00:00
|
|
|
#endif
|
2025-03-07 00:42:16 +00:00
|
|
|
inline const static auto UserSettingFile = QStringLiteral("%1/%2.conf").arg(UserDir, kAppName);
|
|
|
|
|
inline const static auto SystemSettingFile = QStringLiteral("%1/%2.conf").arg(SystemDir, kAppName);
|
2025-03-06 22:37:37 +00:00
|
|
|
|
2025-03-08 12:11:51 +00:00
|
|
|
struct Client
|
|
|
|
|
{
|
|
|
|
|
inline static const auto Binary = QStringLiteral("client/binary");
|
2025-03-17 16:45:13 +00:00
|
|
|
inline static const auto InvertScrollDirection = QStringLiteral("client/invertScrollDirection");
|
2025-03-08 21:51:41 +00:00
|
|
|
inline static const auto LanguageSync = QStringLiteral("client/languageSync");
|
2025-03-17 14:28:46 +00:00
|
|
|
inline static const auto RemoteHost = QStringLiteral("client/remoteHost");
|
2025-03-08 12:11:51 +00:00
|
|
|
};
|
2025-03-06 22:37:37 +00:00
|
|
|
struct Core
|
|
|
|
|
{
|
2025-03-10 02:50:44 +00:00
|
|
|
inline static const auto CoreMode = QStringLiteral("core/coreMode");
|
2025-03-09 05:54:47 +00:00
|
|
|
inline static const auto ElevateMode = QStringLiteral("core/elevateMode");
|
2025-03-08 21:58:53 +00:00
|
|
|
inline static const auto Interface = QStringLiteral("core/interface");
|
2025-03-07 02:11:19 +00:00
|
|
|
inline static const auto LastVersion = QStringLiteral("core/lastVersion");
|
2025-03-09 00:25:57 +00:00
|
|
|
inline static const auto Port = QStringLiteral("core/port");
|
2025-03-07 03:07:14 +00:00
|
|
|
inline static const auto PreventSleep = QStringLiteral("core/preventSleep");
|
2025-03-09 04:14:26 +00:00
|
|
|
inline static const auto ProcessMode = QStringLiteral("core/processMode");
|
2025-03-09 03:09:38 +00:00
|
|
|
inline static const auto ScreenName = QStringLiteral("core/screenName");
|
2025-03-05 05:03:48 +00:00
|
|
|
inline static const auto StartedBefore = QStringLiteral("core/startedBefore");
|
2025-03-21 00:36:09 +00:00
|
|
|
inline static const auto UpdateUrl = QStringLiteral("core/updateUrl");
|
2025-03-06 22:37:37 +00:00
|
|
|
};
|
2025-03-14 21:18:54 +00:00
|
|
|
struct Daemon
|
|
|
|
|
{
|
|
|
|
|
inline static const auto Command = QStringLiteral("daemon/command");
|
|
|
|
|
inline static const auto Elevate = QStringLiteral("daemon/elevate");
|
|
|
|
|
inline static const auto LogFile = QStringLiteral("daemon/logFile");
|
|
|
|
|
inline static const auto LogLevel = QStringLiteral("daemon/logLevel");
|
|
|
|
|
};
|
2025-03-08 15:10:42 +00:00
|
|
|
struct Gui
|
|
|
|
|
{
|
2025-03-05 03:29:28 +00:00
|
|
|
inline static const auto Autohide = QStringLiteral("gui/autoHide");
|
2025-03-05 04:25:38 +00:00
|
|
|
inline static const auto AutoUpdateCheck = QStringLiteral("gui/enableUpdateCheck");
|
2025-03-05 05:11:41 +00:00
|
|
|
inline static const auto CloseReminder = QStringLiteral("gui/closeReminder");
|
2025-03-05 04:45:14 +00:00
|
|
|
inline static const auto CloseToTray = QStringLiteral("gui/closeToTray");
|
2025-03-08 15:10:42 +00:00
|
|
|
inline static const auto LogExpanded = QStringLiteral("gui/logExpanded");
|
2025-03-05 04:11:32 +00:00
|
|
|
inline static const auto SymbolicTrayIcon = QStringLiteral("gui/symbolicTrayIcon");
|
2025-03-05 05:28:05 +00:00
|
|
|
inline static const auto WindowGeometry = QStringLiteral("gui/windowGeometry");
|
2025-03-08 15:10:42 +00:00
|
|
|
};
|
2025-03-09 00:34:50 +00:00
|
|
|
struct Log
|
|
|
|
|
{
|
2025-03-09 01:56:29 +00:00
|
|
|
inline static const auto File = QStringLiteral("log/file");
|
2025-03-09 01:13:26 +00:00
|
|
|
inline static const auto Level = QStringLiteral("log/level");
|
2025-03-09 00:34:50 +00:00
|
|
|
inline static const auto ToFile = QStringLiteral("log/toFile");
|
|
|
|
|
};
|
2025-03-06 23:08:08 +00:00
|
|
|
struct Security
|
|
|
|
|
{
|
2025-03-17 16:46:05 +00:00
|
|
|
inline static const auto CheckPeers = QStringLiteral("security/checkPeerFingerprints");
|
2025-03-07 00:04:55 +00:00
|
|
|
inline static const auto Certificate = QStringLiteral("security/certificate");
|
2025-03-06 23:32:14 +00:00
|
|
|
inline static const auto KeySize = QStringLiteral("security/keySize");
|
2025-03-06 23:08:08 +00:00
|
|
|
inline static const auto TlsEnabled = QStringLiteral("security/tlsEnabled");
|
|
|
|
|
};
|
2025-03-08 12:16:18 +00:00
|
|
|
struct Server
|
|
|
|
|
{
|
|
|
|
|
inline static const auto Binary = QStringLiteral("server/binary");
|
2025-03-10 04:26:41 +00:00
|
|
|
inline static const auto ConfigVisible = QStringLiteral("server/configVisible");
|
2025-03-08 15:59:53 +00:00
|
|
|
inline static const auto ExternalConfig = QStringLiteral("server/externalConfig");
|
2025-03-08 16:37:04 +00:00
|
|
|
inline static const auto ExternalConfigFile = QStringLiteral("server/externalConfigFile");
|
2025-03-08 12:16:18 +00:00
|
|
|
};
|
2025-03-06 22:37:37 +00:00
|
|
|
|
2025-03-09 04:14:26 +00:00
|
|
|
// Enums types used in settings
|
|
|
|
|
// The use of enum classes is not use for these
|
|
|
|
|
// enum classes are more specific when used with QVariant
|
|
|
|
|
// This leads longer function calls in code
|
|
|
|
|
// and longer more cryptic output in the settings file
|
|
|
|
|
// The using of standard enum will just write ints
|
|
|
|
|
// and we can read / write them as if they were ints
|
|
|
|
|
enum ProcessMode
|
|
|
|
|
{
|
|
|
|
|
Service,
|
|
|
|
|
Desktop
|
|
|
|
|
};
|
|
|
|
|
Q_ENUM(ProcessMode)
|
|
|
|
|
|
2025-03-09 05:54:47 +00:00
|
|
|
/**
|
|
|
|
|
* @brief The elevate mode tristate determines two behaviors on Windows.
|
|
|
|
|
* The matrix for these two behaviors is as follows:
|
|
|
|
|
* | sods | elevate |
|
|
|
|
|
* |-----------|------------|
|
|
|
|
|
* kAutomatic | true | false |
|
|
|
|
|
* kAlways | false | true |
|
|
|
|
|
* kNever | false | false |
|
|
|
|
|
* The first, --stop-on-desk-switch (sods), is passed through the daemon as a
|
|
|
|
|
* command line argument to the server/client, and determines if it restarts
|
|
|
|
|
* when switching Windows desktops (e.g. when Windows UAC dialog pops up).
|
|
|
|
|
* The second, elevate, is passed as a boolean flag to the daemon over IPC,
|
|
|
|
|
* and determines whether the server/client should be started with elevated privileges.
|
|
|
|
|
*/
|
|
|
|
|
enum ElevateMode
|
|
|
|
|
{
|
|
|
|
|
Automatic = 0,
|
|
|
|
|
Always = 1,
|
|
|
|
|
Never = 2
|
|
|
|
|
};
|
|
|
|
|
Q_ENUM(ElevateMode)
|
|
|
|
|
|
2025-03-10 02:50:44 +00:00
|
|
|
enum CoreMode
|
|
|
|
|
{
|
|
|
|
|
None,
|
|
|
|
|
Client,
|
|
|
|
|
Server
|
|
|
|
|
};
|
|
|
|
|
Q_ENUM(CoreMode)
|
|
|
|
|
|
2025-03-06 22:37:37 +00:00
|
|
|
static Settings *instance();
|
|
|
|
|
static void setSettingFile(const QString &settingsFile = QString());
|
|
|
|
|
static void setValue(const QString &key = QString(), const QVariant &value = QVariant());
|
|
|
|
|
static QVariant value(const QString &key = QString());
|
|
|
|
|
static void restoreDefaultSettings();
|
|
|
|
|
static QVariant defaultValue(const QString &key);
|
|
|
|
|
static bool isWritable();
|
|
|
|
|
static const QString settingsFile();
|
|
|
|
|
static const QString settingsPath();
|
2025-03-18 01:18:37 +00:00
|
|
|
static const QString tlsDir();
|
2025-03-18 01:36:37 +00:00
|
|
|
static const QString tlsLocalDb();
|
2025-03-18 01:41:14 +00:00
|
|
|
static const QString tlsTrustedServersDb();
|
2025-03-18 01:47:21 +00:00
|
|
|
static const QString tlsTrustedClientsDb();
|
2025-03-09 01:13:26 +00:00
|
|
|
static const QString logLevelText();
|
2025-03-15 02:17:08 +00:00
|
|
|
static QSettingsProxy &proxy();
|
|
|
|
|
static void save(bool emitSaving = true);
|
2025-03-06 22:37:37 +00:00
|
|
|
|
|
|
|
|
signals:
|
|
|
|
|
void settingsChanged(const QString key);
|
2025-03-15 02:17:08 +00:00
|
|
|
void serverSettingsChanged();
|
2025-03-06 22:37:37 +00:00
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
explicit Settings(QObject *parent = nullptr);
|
|
|
|
|
Settings *operator=(Settings &other) = delete;
|
|
|
|
|
Settings(const Settings &other) = delete;
|
|
|
|
|
~Settings() = default;
|
|
|
|
|
void cleanSettings();
|
|
|
|
|
|
|
|
|
|
QSettings *m_settings = nullptr;
|
2025-03-14 04:08:58 +00:00
|
|
|
QString m_portableSettingsFile = QStringLiteral("settings/%1.conf").arg(kAppName);
|
2025-03-15 02:17:08 +00:00
|
|
|
std::shared_ptr<QSettingsProxy> m_settingsProxy;
|
2025-03-09 04:14:26 +00:00
|
|
|
|
2025-03-08 15:10:42 +00:00
|
|
|
// clang-format off
|
2025-03-09 01:13:26 +00:00
|
|
|
inline static const QStringList m_logLevels = {
|
|
|
|
|
QStringLiteral("INFO")
|
|
|
|
|
, QStringLiteral("DEBUG")
|
|
|
|
|
, QStringLiteral("DEBUG1")
|
|
|
|
|
, QStringLiteral("DEBUG2")
|
|
|
|
|
};
|
|
|
|
|
|
2025-03-08 15:10:42 +00:00
|
|
|
inline static const QStringList m_validKeys = {
|
2025-03-10 04:26:41 +00:00
|
|
|
Settings::Client::Binary
|
|
|
|
|
, Settings::Client::InvertScrollDirection
|
|
|
|
|
, Settings::Client::LanguageSync
|
|
|
|
|
, Settings::Client::RemoteHost
|
|
|
|
|
, Settings::Core::CoreMode
|
|
|
|
|
, Settings::Core::ElevateMode
|
|
|
|
|
, Settings::Core::Interface
|
|
|
|
|
, Settings::Core::LastVersion
|
|
|
|
|
, Settings::Core::Port
|
|
|
|
|
, Settings::Core::PreventSleep
|
|
|
|
|
, Settings::Core::ProcessMode
|
|
|
|
|
, Settings::Core::ScreenName
|
|
|
|
|
, Settings::Core::StartedBefore
|
2025-03-21 00:36:09 +00:00
|
|
|
, Settings::Core::UpdateUrl
|
2025-03-14 21:18:54 +00:00
|
|
|
, Settings::Daemon::Command
|
|
|
|
|
, Settings::Daemon::Elevate
|
|
|
|
|
, Settings::Daemon::LogFile
|
2025-03-10 04:26:41 +00:00
|
|
|
, Settings::Log::File
|
|
|
|
|
, Settings::Log::Level
|
|
|
|
|
, Settings::Log::ToFile
|
|
|
|
|
, Settings::Gui::Autohide
|
|
|
|
|
, Settings::Gui::AutoUpdateCheck
|
|
|
|
|
, Settings::Gui::CloseReminder
|
|
|
|
|
, Settings::Gui::CloseToTray
|
|
|
|
|
, Settings::Gui::LogExpanded
|
|
|
|
|
, Settings::Gui::SymbolicTrayIcon
|
|
|
|
|
, Settings::Gui::WindowGeometry
|
|
|
|
|
, Settings::Security::Certificate
|
|
|
|
|
, Settings::Security::CheckPeers
|
|
|
|
|
, Settings::Security::KeySize
|
|
|
|
|
, Settings::Security::TlsEnabled
|
|
|
|
|
, Settings::Server::Binary
|
|
|
|
|
, Settings::Server::ConfigVisible
|
|
|
|
|
, Settings::Server::ExternalConfig
|
|
|
|
|
, Settings::Server::ExternalConfigFile
|
2025-03-08 15:10:42 +00:00
|
|
|
};
|
|
|
|
|
// clang-format on
|
2025-03-09 04:14:26 +00:00
|
|
|
|
|
|
|
|
#ifdef Q_OS_WIN
|
|
|
|
|
inline static const auto defaultProcessMode = Settings::ProcessMode::Service;
|
|
|
|
|
#else
|
|
|
|
|
inline static const auto defaultProcessMode = Settings::ProcessMode::Desktop;
|
|
|
|
|
#endif
|
2025-03-06 22:37:37 +00:00
|
|
|
};
|