2025-03-06 22:37:37 +00:00
|
|
|
/*
|
|
|
|
|
* Deskflow -- mouse and keyboard sharing utility
|
|
|
|
|
* SPDX-FileCopyrightText: (C) 2025 Chris Rizzitello <sithlord48@gmail.com>
|
|
|
|
|
* 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 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-07 02:11:19 +00:00
|
|
|
inline static const auto LastVersion = QStringLiteral("core/lastVersion");
|
2025-03-07 03:07:14 +00:00
|
|
|
inline static const auto PreventSleep = QStringLiteral("core/preventSleep");
|
2025-03-06 22:37:37 +00:00
|
|
|
inline static const auto Scope = QStringLiteral("core/loadFromSystemScope");
|
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-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 12:16:18 +00:00
|
|
|
};
|
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();
|
|
|
|
|
|
|
|
|
|
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-08 15:10:42 +00:00
|
|
|
// clang-format off
|
|
|
|
|
inline static const QStringList m_validKeys = {
|
2025-03-08 12:11:51 +00:00
|
|
|
Client::Binary
|
2025-03-08 12:24:03 +00:00
|
|
|
, Client::RemoteHost
|
2025-03-08 12:11:51 +00:00
|
|
|
, Core::LastVersion
|
2025-03-07 03:07:14 +00:00
|
|
|
, Core::PreventSleep
|
2025-03-07 02:11:19 +00:00
|
|
|
, Core::Scope
|
2025-03-05 05:03:48 +00:00
|
|
|
, Core::StartedBefore
|
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 15:10:42 +00:00
|
|
|
};
|
|
|
|
|
// clang-format on
|
2025-03-06 22:37:37 +00:00
|
|
|
};
|