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>
|
|
|
|
|
|
|
|
|
|
#include "common/constants.h"
|
|
|
|
|
|
|
|
|
|
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-08 21:35:02 +00:00
|
|
|
inline static const auto InvertScrollDirection = QStringLiteral("client/invertscolldirection");
|
2025-03-08 21:51:41 +00:00
|
|
|
inline static const auto LanguageSync = QStringLiteral("client/languageSync");
|
2025-03-08 12:24:03 +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-06 22:37:37 +00:00
|
|
|
inline static const auto Scope = QStringLiteral("core/loadFromSystemScope");
|
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-06 22:37:37 +00:00
|
|
|
};
|
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-07 00:42:16 +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-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 bool isSystemScope();
|
|
|
|
|
static void setScope(bool systemScope);
|
|
|
|
|
static const QString settingsFile();
|
|
|
|
|
static const QString settingsPath();
|
2025-03-09 01:13:26 +00:00
|
|
|
static const QString logLevelText();
|
2025-03-06 22:37:37 +00:00
|
|
|
|
|
|
|
|
signals:
|
|
|
|
|
void scopeChanged(bool isSystemScope);
|
|
|
|
|
void writableChanged(bool canWrite);
|
|
|
|
|
void settingsChanged(const QString key);
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
explicit Settings(QObject *parent = nullptr);
|
|
|
|
|
Settings *operator=(Settings &other) = delete;
|
|
|
|
|
Settings(const Settings &other) = delete;
|
|
|
|
|
~Settings() = default;
|
|
|
|
|
static bool isPortableSettings();
|
|
|
|
|
void cleanSettings();
|
|
|
|
|
void initSettings();
|
|
|
|
|
|
|
|
|
|
QSettings *m_settings = nullptr;
|
|
|
|
|
QString m_portableSettingsFile = QStringLiteral("%1.conf").arg(kAppName);
|
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-08 12:11:51 +00:00
|
|
|
Client::Binary
|
2025-03-08 21:35:02 +00:00
|
|
|
, Client::InvertScrollDirection
|
2025-03-08 21:51:41 +00:00
|
|
|
, Client::LanguageSync
|
2025-03-08 12:24:03 +00:00
|
|
|
, Client::RemoteHost
|
2025-03-10 02:50:44 +00:00
|
|
|
, Core::CoreMode
|
2025-03-09 05:54:47 +00:00
|
|
|
, Core::ElevateMode
|
2025-03-08 21:58:53 +00:00
|
|
|
, Core::Interface
|
2025-03-08 12:11:51 +00:00
|
|
|
, Core::LastVersion
|
2025-03-09 00:25:57 +00:00
|
|
|
, Core::Port
|
2025-03-07 03:07:14 +00:00
|
|
|
, Core::PreventSleep
|
2025-03-09 04:14:26 +00:00
|
|
|
, Core::ProcessMode
|
2025-03-07 02:11:19 +00:00
|
|
|
, Core::Scope
|
2025-03-09 03:09:38 +00:00
|
|
|
, Core::ScreenName
|
2025-03-05 05:03:48 +00:00
|
|
|
, Core::StartedBefore
|
2025-03-09 01:56:29 +00:00
|
|
|
, Log::File
|
2025-03-09 01:13:26 +00:00
|
|
|
, Log::Level
|
2025-03-09 00:34:50 +00:00
|
|
|
, Log::ToFile
|
2025-03-05 03:29:28 +00:00
|
|
|
, Gui::Autohide
|
2025-03-05 04:25:38 +00:00
|
|
|
, Gui::AutoUpdateCheck
|
2025-03-05 05:11:41 +00:00
|
|
|
, Gui::CloseReminder
|
2025-03-05 04:45:14 +00:00
|
|
|
, Gui::CloseToTray
|
2025-03-08 15:10:42 +00:00
|
|
|
, Gui::LogExpanded
|
2025-03-05 04:11:32 +00:00
|
|
|
, Gui::SymbolicTrayIcon
|
2025-03-05 05:28:05 +00:00
|
|
|
, Gui::WindowGeometry
|
2025-03-07 00:04:55 +00:00
|
|
|
, Security::Certificate
|
2025-03-07 00:42:16 +00:00
|
|
|
, Security::CheckPeers
|
2025-03-06 23:32:14 +00:00
|
|
|
, Security::KeySize
|
2025-03-06 23:08:08 +00:00
|
|
|
, Security::TlsEnabled
|
2025-03-08 12:16:18 +00:00
|
|
|
, Server::Binary
|
2025-03-08 15:59:53 +00:00
|
|
|
, Server::ExternalConfig
|
2025-03-08 16:37:04 +00:00
|
|
|
, 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
|
|
|
};
|