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-10-09 13:56:34 +00:00
|
|
|
inline const static auto UserDir = QStringLiteral("%1/AppData/Roaming/%2").arg(QDir::homePath(), kAppName);
|
2025-04-08 11:43:25 +00:00
|
|
|
inline const static auto SystemDir = QStringLiteral("%1ProgramData/%2").arg(QDir::rootPath(), kAppName);
|
2025-11-20 02:07:38 +00:00
|
|
|
#elif defined(Q_OS_MACOS)
|
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-10-09 13:56:34 +00:00
|
|
|
|
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
|
|
|
|
|
{
|
2025-03-17 16:45:13 +00:00
|
|
|
inline static const auto InvertScrollDirection = QStringLiteral("client/invertScrollDirection");
|
2025-09-25 23:17:01 +00:00
|
|
|
inline static const auto ScrollSpeed = QStringLiteral("client/yscroll");
|
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-08-18 14:23:57 +00:00
|
|
|
inline static const auto XdpRestoreToken = QStringLiteral("client/xdpRestoreToken");
|
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-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-09-18 00:55:01 +00:00
|
|
|
inline static const auto Display = QStringLiteral("core/display");
|
2025-09-25 00:38:18 +00:00
|
|
|
inline static const auto UseHooks = QStringLiteral("core/useHooks");
|
2025-10-15 02:39:45 +00:00
|
|
|
inline static const auto Language = QStringLiteral("core/language");
|
2025-11-16 13:08:28 +00:00
|
|
|
inline static const auto useWlClipboard = QStringLiteral("core/wlClipboard");
|
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-10-29 18:31:18 +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-08-29 19:50:16 +00:00
|
|
|
inline static const auto ShowGenericClientFailureDialog = QStringLiteral("gui/showGenericClientFailureDialog");
|
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-11-04 16:27:52 +00:00
|
|
|
inline static const auto GuiDebug = QStringLiteral("log/guiDebug");
|
2025-03-09 00:34:50 +00:00
|
|
|
};
|
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
|
|
|
|
|
{
|
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-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();
|
2025-10-15 12:42:55 +00:00
|
|
|
static void setSettingsFile(const QString &settingsFile = QString());
|
2025-11-11 19:44:28 +00:00
|
|
|
static void setStateFile(const QString &stateFile = QString());
|
2025-03-06 22:37:37 +00:00
|
|
|
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();
|
2025-10-09 13:56:34 +00:00
|
|
|
static bool isPortableMode();
|
2025-06-19 22:30:32 +00:00
|
|
|
static QString settingsFile();
|
|
|
|
|
static QString settingsPath();
|
|
|
|
|
static QString tlsDir();
|
|
|
|
|
static QString tlsLocalDb();
|
|
|
|
|
static QString tlsTrustedServersDb();
|
|
|
|
|
static QString tlsTrustedClientsDb();
|
|
|
|
|
static QString logLevelText();
|
2025-03-15 02:17:08 +00:00
|
|
|
static QSettingsProxy &proxy();
|
|
|
|
|
static void save(bool emitSaving = true);
|
2025-06-19 22:30:32 +00:00
|
|
|
static QStringList validKeys();
|
2025-08-23 05:58:37 +00:00
|
|
|
static int logLevelToInt(const QString &level = "INFO");
|
2025-10-09 13:56:34 +00:00
|
|
|
static QString portableSettingsFile();
|
2025-03-06 22:37:37 +00:00
|
|
|
|
2025-05-31 15:35:37 +00:00
|
|
|
Q_SIGNALS:
|
2025-03-06 22:37:37 +00:00
|
|
|
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;
|
2025-04-28 01:27:48 +00:00
|
|
|
~Settings() override = default;
|
2025-03-06 22:37:37 +00:00
|
|
|
void cleanSettings();
|
2025-11-11 19:44:28 +00:00
|
|
|
void cleanStateSettings();
|
2025-03-06 22:37:37 +00:00
|
|
|
|
2025-11-14 14:47:29 +00:00
|
|
|
/**
|
|
|
|
|
* @brief write an initial screen name
|
|
|
|
|
*/
|
|
|
|
|
void setupScreenName();
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief cleanScreenName ensure a valid screenName from the provided one
|
|
|
|
|
* @param name any string to be used as the screenName
|
|
|
|
|
* @return a valid screeName
|
|
|
|
|
*/
|
|
|
|
|
static QString cleanScreenName(const QString &name);
|
|
|
|
|
|
2025-03-06 22:37:37 +00:00
|
|
|
QSettings *m_settings = nullptr;
|
2025-11-11 19:44:28 +00:00
|
|
|
QSettings *m_stateSettings = nullptr;
|
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 = {
|
2025-08-23 17:31:04 +00:00
|
|
|
QStringLiteral("FATAL")
|
|
|
|
|
, QStringLiteral("ERROR")
|
|
|
|
|
, QStringLiteral("WARNING")
|
|
|
|
|
, QStringLiteral("NOTE")
|
|
|
|
|
, QStringLiteral("INFO")
|
2025-03-09 01:13:26 +00:00
|
|
|
, QStringLiteral("DEBUG")
|
|
|
|
|
, QStringLiteral("DEBUG1")
|
|
|
|
|
, QStringLiteral("DEBUG2")
|
|
|
|
|
};
|
|
|
|
|
|
2025-03-08 15:10:42 +00:00
|
|
|
inline static const QStringList m_validKeys = {
|
2025-09-27 15:59:19 +00:00
|
|
|
Settings::Client::InvertScrollDirection
|
2025-03-10 04:26:41 +00:00
|
|
|
, Settings::Client::LanguageSync
|
|
|
|
|
, Settings::Client::RemoteHost
|
2025-09-25 23:17:01 +00:00
|
|
|
, Settings::Client::ScrollSpeed
|
2025-08-20 04:34:40 +00:00
|
|
|
, Settings::Client::XdpRestoreToken
|
2025-03-10 04:26:41 +00:00
|
|
|
, Settings::Core::CoreMode
|
|
|
|
|
, 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-09-18 00:55:01 +00:00
|
|
|
, Settings::Core::Display
|
2025-09-25 00:38:18 +00:00
|
|
|
, Settings::Core::UseHooks
|
2025-11-16 13:08:28 +00:00
|
|
|
, Settings::Core::useWlClipboard
|
2025-10-15 02:39:45 +00:00
|
|
|
, Settings::Core::Language
|
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
|
2025-11-04 16:27:52 +00:00
|
|
|
, Settings::Log::GuiDebug
|
2025-03-10 04:26:41 +00:00
|
|
|
, Settings::Gui::Autohide
|
|
|
|
|
, Settings::Gui::AutoUpdateCheck
|
|
|
|
|
, Settings::Gui::CloseReminder
|
|
|
|
|
, Settings::Gui::CloseToTray
|
|
|
|
|
, Settings::Gui::LogExpanded
|
2025-10-29 18:31:18 +00:00
|
|
|
, Settings::Gui::SymbolicTrayIcon
|
2025-03-10 04:26:41 +00:00
|
|
|
, Settings::Gui::WindowGeometry
|
2025-08-29 19:50:16 +00:00
|
|
|
, Settings::Gui::ShowGenericClientFailureDialog
|
2025-03-10 04:26:41 +00:00
|
|
|
, Settings::Security::Certificate
|
|
|
|
|
, Settings::Security::CheckPeers
|
|
|
|
|
, Settings::Security::KeySize
|
|
|
|
|
, Settings::Security::TlsEnabled
|
|
|
|
|
, Settings::Server::ExternalConfig
|
|
|
|
|
, Settings::Server::ExternalConfigFile
|
2025-03-08 15:10:42 +00:00
|
|
|
};
|
2025-11-04 16:17:39 +00:00
|
|
|
|
|
|
|
|
// When checking the default values this list contains the ones that default to false.
|
|
|
|
|
inline static const QStringList m_defaultFalseValues = {
|
|
|
|
|
Settings::Gui::Autohide
|
|
|
|
|
, Settings::Core::StartedBefore
|
|
|
|
|
, Settings::Core::PreventSleep
|
2025-11-16 13:08:28 +00:00
|
|
|
, Settings::Core::useWlClipboard
|
2025-11-04 16:17:39 +00:00
|
|
|
, Settings::Server::ExternalConfig
|
|
|
|
|
, Settings::Client::InvertScrollDirection
|
|
|
|
|
, Settings::Log::ToFile
|
2025-11-04 16:27:52 +00:00
|
|
|
, Settings::Log::GuiDebug
|
2025-11-04 16:17:39 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// When checking the default values this list contains the ones that default to true.
|
|
|
|
|
inline static const QStringList m_defaultTrueValues = {
|
|
|
|
|
Settings::Core::UseHooks
|
|
|
|
|
, Settings::Client::LanguageSync
|
|
|
|
|
, Settings::Gui::CloseToTray
|
|
|
|
|
, Settings::Gui::CloseReminder
|
|
|
|
|
, Settings::Gui::LogExpanded
|
|
|
|
|
, Settings::Gui::SymbolicTrayIcon
|
|
|
|
|
, Settings::Gui::ShowGenericClientFailureDialog
|
|
|
|
|
, Settings::Security::TlsEnabled
|
|
|
|
|
, Settings::Security::CheckPeers
|
|
|
|
|
};
|
2025-11-11 19:44:28 +00:00
|
|
|
|
|
|
|
|
// Settings saved in our State file
|
|
|
|
|
inline static const QStringList m_stateKeys = { Settings::Gui::WindowGeometry };
|
2025-03-08 15:10:42 +00:00
|
|
|
// clang-format on
|
2025-03-06 22:37:37 +00:00
|
|
|
};
|