2012-06-10 16:50:54 +00:00
|
|
|
/*
|
2024-09-17 19:00:25 +00:00
|
|
|
* Deskflow -- mouse and keyboard sharing utility
|
2024-11-29 17:03:51 +00:00
|
|
|
* SPDX-FileCopyrightText: (C) 2025 Deskflow Developers
|
2025-01-24 00:11:17 +00:00
|
|
|
* SPDX-FileCopyrightText: (C) 2012 Symless Ltd.
|
|
|
|
|
* SPDX-FileCopyrightText: (C) 2008 Volker Lanz <vl@fidra.de>
|
|
|
|
|
* SPDX-License-Identifier: GPL-2.0-only WITH LicenseRef-OpenSSL-Exception
|
2012-06-10 16:50:54 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include "AppConfig.h"
|
2024-07-16 08:30:35 +00:00
|
|
|
|
2025-03-11 22:45:54 +00:00
|
|
|
#include "common/Settings.h"
|
|
|
|
|
|
2024-08-01 00:13:01 +00:00
|
|
|
#include "ConfigScopes.h"
|
2012-06-10 16:50:54 +00:00
|
|
|
|
2024-07-22 16:48:02 +00:00
|
|
|
#include <QApplication>
|
2024-07-26 22:53:52 +00:00
|
|
|
#include <QMessageBox>
|
2024-07-02 19:07:06 +00:00
|
|
|
#include <QPushButton>
|
2024-08-01 00:13:01 +00:00
|
|
|
#include <QVariant>
|
2025-02-07 17:02:20 +00:00
|
|
|
|
2024-08-01 00:13:01 +00:00
|
|
|
#include <functional>
|
2024-07-22 16:48:02 +00:00
|
|
|
|
2024-09-17 19:00:25 +00:00
|
|
|
using namespace deskflow::gui;
|
2024-07-22 16:48:02 +00:00
|
|
|
|
2025-03-09 03:09:38 +00:00
|
|
|
AppConfig::AppConfig(deskflow::gui::IConfigScopes &scopes, std::shared_ptr<Deps> deps) : m_Scopes(scopes), m_pDeps(deps)
|
2024-10-17 18:04:35 +00:00
|
|
|
{
|
2025-03-11 22:45:54 +00:00
|
|
|
setLoadFromSystemScope(Settings::isSystemScope());
|
2020-03-31 14:18:57 +00:00
|
|
|
}
|
2016-09-30 14:03:49 +00:00
|
|
|
|
2024-10-17 18:04:35 +00:00
|
|
|
void AppConfig::loadScope(ConfigScopes::Scope scope)
|
|
|
|
|
{
|
2024-08-03 00:17:29 +00:00
|
|
|
using enum ConfigScopes::Scope;
|
2016-09-30 14:03:49 +00:00
|
|
|
|
2024-08-03 00:17:29 +00:00
|
|
|
switch (scope) {
|
|
|
|
|
case User:
|
|
|
|
|
qDebug("loading user settings scope");
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case System:
|
|
|
|
|
qDebug("loading system settings scope");
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
qFatal("invalid scope");
|
2024-07-23 19:17:40 +00:00
|
|
|
}
|
2016-09-30 14:03:49 +00:00
|
|
|
|
2024-08-07 14:05:18 +00:00
|
|
|
if (m_Scopes.activeScope() == scope) {
|
2024-08-03 00:17:29 +00:00
|
|
|
qDebug("already in required scope, skipping");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2024-08-07 14:05:18 +00:00
|
|
|
m_Scopes.setActiveScope(scope);
|
2024-08-03 00:17:29 +00:00
|
|
|
|
2024-08-12 15:39:18 +00:00
|
|
|
qDebug("active scope file path: %s", qPrintable(m_Scopes.activeFilePath()));
|
|
|
|
|
|
2024-08-03 00:17:29 +00:00
|
|
|
// only signal ready if there is at least one setting in the required scope.
|
|
|
|
|
// this prevents the current settings from being set back to default.
|
2025-03-11 22:45:54 +00:00
|
|
|
if (m_Scopes.scopeContains("core", m_Scopes.activeScope())) {
|
2024-08-07 14:05:18 +00:00
|
|
|
m_Scopes.signalReady();
|
2024-08-03 00:17:29 +00:00
|
|
|
} else {
|
|
|
|
|
qDebug("no screen name in scope, skipping");
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-09-30 14:03:49 +00:00
|
|
|
|
2024-10-17 18:04:35 +00:00
|
|
|
void AppConfig::setLoadFromSystemScope(bool value)
|
|
|
|
|
{
|
2024-08-03 00:17:29 +00:00
|
|
|
using enum ConfigScopes::Scope;
|
2024-07-23 19:17:40 +00:00
|
|
|
if (value) {
|
2024-08-03 00:17:29 +00:00
|
|
|
loadScope(System);
|
2024-07-23 19:17:40 +00:00
|
|
|
} else {
|
2024-08-03 00:17:29 +00:00
|
|
|
loadScope(User);
|
2024-07-23 19:17:40 +00:00
|
|
|
}
|
2020-03-31 14:18:57 +00:00
|
|
|
}
|
2016-09-30 14:03:49 +00:00
|
|
|
|
2024-10-17 18:04:35 +00:00
|
|
|
bool AppConfig::isActiveScopeWritable() const
|
|
|
|
|
{
|
2024-08-07 14:05:18 +00:00
|
|
|
return m_Scopes.isActiveScopeWritable();
|
2020-03-31 14:18:57 +00:00
|
|
|
}
|
2016-09-30 14:03:49 +00:00
|
|
|
|
2024-10-17 18:04:35 +00:00
|
|
|
bool AppConfig::isActiveScopeSystem() const
|
|
|
|
|
{
|
2024-08-07 14:05:18 +00:00
|
|
|
return m_Scopes.activeScope() == ConfigScopes::Scope::System;
|
2020-03-31 14:18:57 +00:00
|
|
|
}
|
2024-08-03 00:17:29 +00:00
|
|
|
|
2024-07-23 19:17:40 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
2024-07-26 22:53:52 +00:00
|
|
|
// Begin getters
|
2024-07-23 19:17:40 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
2024-10-17 18:04:35 +00:00
|
|
|
IConfigScopes &AppConfig::scopes() const
|
|
|
|
|
{
|
|
|
|
|
return m_Scopes;
|
|
|
|
|
}
|
2024-08-01 00:13:01 +00:00
|
|
|
|
2024-07-26 22:53:52 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
// End getters
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|