chore: remove unused ConfigScopes
This commit is contained in:
parent
1b01a010ed
commit
6056e5850b
5 changed files with 0 additions and 462 deletions
|
|
@ -31,9 +31,6 @@ add_library(${target} STATIC
|
|||
string_utils.h
|
||||
style_utils.h
|
||||
styles.h
|
||||
config/ConfigScopes.cpp
|
||||
config/ConfigScopes.h
|
||||
config/IConfigScopes.h
|
||||
config/IServerConfig.h
|
||||
config/Screen.cpp
|
||||
config/Screen.h
|
||||
|
|
|
|||
|
|
@ -1,147 +0,0 @@
|
|||
/*
|
||||
* Deskflow -- mouse and keyboard sharing utility
|
||||
* SPDX-FileCopyrightText: (C) 2020 Symless Ltd.
|
||||
* SPDX-License-Identifier: GPL-2.0-only WITH LicenseRef-OpenSSL-Exception
|
||||
*/
|
||||
|
||||
#include "ConfigScopes.h"
|
||||
|
||||
#include "common/QSettingsProxy.h"
|
||||
|
||||
#include <QCoreApplication>
|
||||
#include <QDir>
|
||||
#include <QFile>
|
||||
#include <QtCore/qfileinfo.h>
|
||||
#include <QtCore/qlogging.h>
|
||||
#include <memory>
|
||||
|
||||
namespace deskflow::gui {
|
||||
|
||||
//
|
||||
// ConfigScopes::Deps
|
||||
//
|
||||
|
||||
std::shared_ptr<QSettingsProxy> ConfigScopes::Deps::makeUserSettings()
|
||||
{
|
||||
return std::make_shared<QSettingsProxy>();
|
||||
}
|
||||
|
||||
std::shared_ptr<QSettingsProxy> ConfigScopes::Deps::makeSystemSettings()
|
||||
{
|
||||
return std::make_shared<QSettingsProxy>();
|
||||
}
|
||||
|
||||
//
|
||||
// ConfigScopes
|
||||
//
|
||||
|
||||
ConfigScopes::ConfigScopes(std::shared_ptr<Deps> deps)
|
||||
: m_pUserSettingsProxy(deps->makeUserSettings()),
|
||||
m_pSystemSettingsProxy(deps->makeSystemSettings())
|
||||
{
|
||||
|
||||
m_pUserSettingsProxy->loadUser();
|
||||
m_pSystemSettingsProxy->loadSystem();
|
||||
}
|
||||
|
||||
void ConfigScopes::clear() const
|
||||
{
|
||||
m_pUserSettingsProxy->clear();
|
||||
m_pSystemSettingsProxy->clear();
|
||||
}
|
||||
|
||||
void ConfigScopes::signalReady()
|
||||
{
|
||||
Q_EMIT ready();
|
||||
}
|
||||
|
||||
void ConfigScopes::save(bool emitSaving)
|
||||
{
|
||||
if (emitSaving) {
|
||||
qDebug("emitting config saving signal");
|
||||
Q_EMIT saving();
|
||||
}
|
||||
|
||||
qDebug("writing config to filesystem");
|
||||
m_pUserSettingsProxy->sync();
|
||||
m_pSystemSettingsProxy->sync();
|
||||
}
|
||||
|
||||
bool ConfigScopes::isActiveScopeWritable() const
|
||||
{
|
||||
return activeSettings().isWritable();
|
||||
}
|
||||
|
||||
void ConfigScopes::setActiveScope(ConfigScopes::Scope scope)
|
||||
{
|
||||
m_currentScope = scope;
|
||||
}
|
||||
|
||||
ConfigScopes::Scope ConfigScopes::activeScope() const
|
||||
{
|
||||
return m_currentScope;
|
||||
}
|
||||
|
||||
bool ConfigScopes::scopeContains(const QString &name, Scope scope) const
|
||||
{
|
||||
switch (scope) {
|
||||
case Scope::User:
|
||||
return m_pUserSettingsProxy->contains(name);
|
||||
case Scope::System:
|
||||
return m_pSystemSettingsProxy->contains(name);
|
||||
default:
|
||||
return activeSettings().contains(name);
|
||||
}
|
||||
}
|
||||
|
||||
QSettingsProxy &ConfigScopes::activeSettings()
|
||||
{
|
||||
if (m_currentScope == Scope::User) {
|
||||
return *m_pUserSettingsProxy;
|
||||
} else {
|
||||
return *m_pSystemSettingsProxy;
|
||||
}
|
||||
}
|
||||
|
||||
const QSettingsProxy &ConfigScopes::activeSettings() const
|
||||
{
|
||||
if (m_currentScope == Scope::User) {
|
||||
return *m_pUserSettingsProxy;
|
||||
} else {
|
||||
return *m_pSystemSettingsProxy;
|
||||
}
|
||||
}
|
||||
|
||||
QString ConfigScopes::activeFilePath() const
|
||||
{
|
||||
return activeSettings().fileName();
|
||||
}
|
||||
|
||||
QVariant ConfigScopes::getFromScope(const QString &name, const QVariant &defaultValue, Scope scope) const
|
||||
{
|
||||
switch (scope) {
|
||||
case Scope::User:
|
||||
return m_pUserSettingsProxy->value(name, defaultValue);
|
||||
case Scope::System:
|
||||
return m_pSystemSettingsProxy->value(name, defaultValue);
|
||||
default:
|
||||
return activeSettings().value(name, defaultValue);
|
||||
}
|
||||
}
|
||||
|
||||
void ConfigScopes::setInScope(const QString &name, const QVariant &value, Scope scope)
|
||||
{
|
||||
switch (scope) {
|
||||
case Scope::User:
|
||||
m_pUserSettingsProxy->setValue(name, value);
|
||||
break;
|
||||
case Scope::System:
|
||||
m_pSystemSettingsProxy->setValue(name, value);
|
||||
break;
|
||||
default:
|
||||
activeSettings().setValue(name, value);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace deskflow::gui
|
||||
|
|
@ -1,61 +0,0 @@
|
|||
/*
|
||||
* Deskflow -- mouse and keyboard sharing utility
|
||||
* SPDX-FileCopyrightText: (C) 2020 Symless Ltd.
|
||||
* SPDX-License-Identifier: GPL-2.0-only WITH LicenseRef-OpenSSL-Exception
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "IConfigScopes.h"
|
||||
#include "common/QSettingsProxy.h"
|
||||
|
||||
#include <QObject>
|
||||
#include <QSettings>
|
||||
#include <QVariant>
|
||||
#include <memory>
|
||||
|
||||
namespace deskflow::gui {
|
||||
|
||||
/// @brief Encapsulates Qt config for both user and global scopes.
|
||||
class ConfigScopes : public QObject, public IConfigScopes
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
struct Deps
|
||||
{
|
||||
virtual ~Deps() = default;
|
||||
virtual std::shared_ptr<QSettingsProxy> makeUserSettings();
|
||||
virtual std::shared_ptr<QSettingsProxy> makeSystemSettings();
|
||||
};
|
||||
|
||||
explicit ConfigScopes(std::shared_ptr<Deps> deps = std::make_shared<Deps>());
|
||||
~ConfigScopes() override = default;
|
||||
|
||||
void clear() const;
|
||||
|
||||
void signalReady() override;
|
||||
void save(bool emitSaving = true) override;
|
||||
bool scopeContains(const QString &name, Scope scope = Scope::Current) const override;
|
||||
bool isActiveScopeWritable() const override;
|
||||
void setInScope(const QString &name, const QVariant &value, Scope scope = Scope::Current) override;
|
||||
QVariant getFromScope(
|
||||
const QString &name, const QVariant &defaultValue = QVariant(), Scope scope = Scope::Current
|
||||
) const override;
|
||||
void setActiveScope(Scope scope = Scope::User) override;
|
||||
Scope activeScope() const override;
|
||||
QSettingsProxy &activeSettings() override;
|
||||
const QSettingsProxy &activeSettings() const override;
|
||||
QString activeFilePath() const override;
|
||||
|
||||
signals:
|
||||
void ready();
|
||||
void saving();
|
||||
|
||||
private:
|
||||
Scope m_currentScope = Scope::User;
|
||||
std::shared_ptr<QSettingsProxy> m_pUserSettingsProxy;
|
||||
std::shared_ptr<QSettingsProxy> m_pSystemSettingsProxy;
|
||||
};
|
||||
|
||||
} // namespace deskflow::gui
|
||||
|
|
@ -1,68 +0,0 @@
|
|||
/*
|
||||
* Deskflow -- mouse and keyboard sharing utility
|
||||
* SPDX-FileCopyrightText: (C) 2024 Symless Ltd.
|
||||
* SPDX-License-Identifier: GPL-2.0-only WITH LicenseRef-OpenSSL-Exception
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "common/QSettingsProxy.h"
|
||||
|
||||
#include <QSettings>
|
||||
#include <QString>
|
||||
#include <QVariant>
|
||||
|
||||
namespace deskflow::gui {
|
||||
|
||||
class IConfigScopes
|
||||
{
|
||||
|
||||
public:
|
||||
enum class Scope
|
||||
{
|
||||
Current,
|
||||
System,
|
||||
User
|
||||
};
|
||||
|
||||
virtual ~IConfigScopes() = default;
|
||||
|
||||
virtual Scope activeScope() const = 0;
|
||||
virtual void setActiveScope(Scope scope = Scope::User) = 0;
|
||||
virtual bool isActiveScopeWritable() const = 0;
|
||||
virtual QSettingsProxy &activeSettings() = 0;
|
||||
virtual const QSettingsProxy &activeSettings() const = 0;
|
||||
virtual QString activeFilePath() const = 0;
|
||||
|
||||
/**
|
||||
* @brief Signals to listeners that the settings that they should read.
|
||||
*/
|
||||
virtual void signalReady() = 0;
|
||||
|
||||
/**
|
||||
* @brief Signals to listeners to save and calls `sync` on underlying Qt
|
||||
* config.
|
||||
*
|
||||
* @param emitSaving Whether to emit the saving signal which typically
|
||||
* triggers listeners to write their current state to the config.
|
||||
*/
|
||||
virtual void save(bool emitSaving = true) = 0;
|
||||
|
||||
/**
|
||||
* @brief Check a scope for a config value (default is current scope).
|
||||
*/
|
||||
virtual bool scopeContains(const QString &name, Scope scope = Scope::Current) const = 0;
|
||||
|
||||
/**
|
||||
* @brief Load a config value from a scope (default is current scope).
|
||||
*/
|
||||
virtual QVariant
|
||||
getFromScope(const QString &name, const QVariant &defaultValue = QVariant(), Scope scope = Scope::Current) const = 0;
|
||||
|
||||
/**
|
||||
* @brief Set a config value in a scope (default is current scope).
|
||||
*/
|
||||
virtual void setInScope(const QString &name, const QVariant &value, Scope scope = Scope::Current) = 0;
|
||||
};
|
||||
|
||||
} // namespace deskflow::gui
|
||||
|
|
@ -1,183 +0,0 @@
|
|||
/*
|
||||
* Deskflow -- mouse and keyboard sharing utility
|
||||
* SPDX-FileCopyrightText: (C) 2024 Symless Ltd.
|
||||
* SPDX-License-Identifier: GPL-2.0-only WITH LicenseRef-OpenSSL-Exception
|
||||
*/
|
||||
|
||||
#include "gui/config/ConfigScopes.h"
|
||||
|
||||
#include "gmock/gmock.h"
|
||||
#include <gmock/gmock.h>
|
||||
#include <gtest/gtest.h>
|
||||
#include <memory>
|
||||
|
||||
using namespace testing;
|
||||
using namespace deskflow::gui;
|
||||
|
||||
namespace {
|
||||
|
||||
class QSettingsProxyMock : public QSettingsProxy
|
||||
{
|
||||
public:
|
||||
MOCK_METHOD(void, loadSystem, (), (override));
|
||||
MOCK_METHOD(void, loadUser, (), (override));
|
||||
MOCK_METHOD(QString, fileName, (), (const, override));
|
||||
MOCK_METHOD(void, sync, (), (override));
|
||||
MOCK_METHOD(bool, isWritable, (), (const, override));
|
||||
MOCK_METHOD(bool, contains, (const QString &), (const, override));
|
||||
MOCK_METHOD(QVariant, value, (const QString &), (const, override));
|
||||
MOCK_METHOD(QVariant, value, (const QString &, const QVariant &), (const, override));
|
||||
MOCK_METHOD(void, setValue, (const QString &, const QVariant &), (override));
|
||||
};
|
||||
|
||||
struct DepsMock : public ConfigScopes::Deps
|
||||
{
|
||||
DepsMock()
|
||||
{
|
||||
ON_CALL(*this, makeUserSettings()).WillByDefault(Return(m_pUserSettings));
|
||||
ON_CALL(*this, makeSystemSettings()).WillByDefault(Return(m_pSystemSettings));
|
||||
}
|
||||
|
||||
MOCK_METHOD(std::shared_ptr<QSettingsProxy>, makeUserSettings, (), (override));
|
||||
MOCK_METHOD(std::shared_ptr<QSettingsProxy>, makeSystemSettings, (), (override));
|
||||
|
||||
std::shared_ptr<QSettingsProxyMock> m_pUserSettings = std::make_shared<NiceMock<QSettingsProxyMock>>();
|
||||
std::shared_ptr<QSettingsProxyMock> m_pSystemSettings = std::make_shared<NiceMock<QSettingsProxyMock>>();
|
||||
};
|
||||
|
||||
} // namespace
|
||||
|
||||
TEST(ConfigScopesTests, ctor_callsMakeUserSettings)
|
||||
{
|
||||
auto deps = std::make_shared<NiceMock<DepsMock>>();
|
||||
|
||||
EXPECT_CALL(*deps, makeUserSettings()).Times(1);
|
||||
|
||||
ConfigScopes configScopes(deps);
|
||||
}
|
||||
|
||||
TEST(ConfigScopesTests, ctor_callsMakeSystemSettings)
|
||||
{
|
||||
auto deps = std::make_shared<NiceMock<DepsMock>>();
|
||||
|
||||
EXPECT_CALL(*deps, makeSystemSettings()).Times(1);
|
||||
|
||||
ConfigScopes configScopes(deps);
|
||||
}
|
||||
|
||||
TEST(ConfigScopesTests, save_syncsBothScopes)
|
||||
{
|
||||
auto deps = std::make_shared<NiceMock<DepsMock>>();
|
||||
|
||||
ConfigScopes configScopes(deps);
|
||||
|
||||
EXPECT_CALL(*deps->m_pUserSettings, sync()).Times(1);
|
||||
EXPECT_CALL(*deps->m_pSystemSettings, sync()).Times(1);
|
||||
|
||||
configScopes.save();
|
||||
}
|
||||
|
||||
TEST(ConfigScopesTests, activeSettings_returnsUserSettingsByDefault)
|
||||
{
|
||||
auto deps = std::make_shared<NiceMock<DepsMock>>();
|
||||
|
||||
ConfigScopes configScopes(deps);
|
||||
|
||||
EXPECT_EQ(&configScopes.activeSettings(), deps->m_pUserSettings.get());
|
||||
}
|
||||
|
||||
TEST(ConfigScopesTests, activeSettings_returnsSystemSettingsWhenSystemScope)
|
||||
{
|
||||
auto deps = std::make_shared<NiceMock<DepsMock>>();
|
||||
|
||||
ConfigScopes configScopes(deps);
|
||||
configScopes.setActiveScope(ConfigScopes::Scope::System);
|
||||
|
||||
EXPECT_EQ(&configScopes.activeSettings(), deps->m_pSystemSettings.get());
|
||||
}
|
||||
|
||||
TEST(ConfigScopesTests, setActiveScope_setsCurrentScope)
|
||||
{
|
||||
auto deps = std::make_shared<NiceMock<DepsMock>>();
|
||||
|
||||
ConfigScopes configScopes(deps);
|
||||
|
||||
configScopes.setActiveScope(ConfigScopes::Scope::System);
|
||||
|
||||
EXPECT_EQ(configScopes.activeScope(), ConfigScopes::Scope::System);
|
||||
}
|
||||
|
||||
TEST(ConfigScopesTests, isActiveScopeWritable_returnsTrueWhenUserSettingsWritable)
|
||||
{
|
||||
auto deps = std::make_shared<NiceMock<DepsMock>>();
|
||||
|
||||
ConfigScopes configScopes(deps);
|
||||
|
||||
EXPECT_CALL(*deps->m_pUserSettings, isWritable()).WillOnce(Return(true));
|
||||
|
||||
EXPECT_TRUE(configScopes.isActiveScopeWritable());
|
||||
}
|
||||
|
||||
TEST(ConfigScopesTests, scopeContains_byDefault_returnsTrueWhenUserSettingsContainsKey)
|
||||
{
|
||||
auto deps = std::make_shared<NiceMock<DepsMock>>();
|
||||
|
||||
ON_CALL(*deps->m_pUserSettings, contains(_)).WillByDefault(Return(true));
|
||||
|
||||
ConfigScopes configScopes(deps);
|
||||
|
||||
EXPECT_TRUE(configScopes.scopeContains("stub"));
|
||||
}
|
||||
|
||||
TEST(ConfigScopesTests, scopeContains_userScope_returnsTrueWhenUserSettingsContainsKey)
|
||||
{
|
||||
auto deps = std::make_shared<NiceMock<DepsMock>>();
|
||||
|
||||
ON_CALL(*deps->m_pUserSettings, contains(_)).WillByDefault(Return(true));
|
||||
|
||||
ConfigScopes configScopes(deps);
|
||||
|
||||
EXPECT_TRUE(configScopes.scopeContains("stub", ConfigScopes::Scope::User));
|
||||
}
|
||||
|
||||
TEST(ConfigScopesTests, scopeContains_systemScope_returnsTrueWhenSystemSettingsContainsKey)
|
||||
{
|
||||
auto deps = std::make_shared<NiceMock<DepsMock>>();
|
||||
|
||||
ON_CALL(*deps->m_pSystemSettings, contains(_)).WillByDefault(Return(true));
|
||||
|
||||
ConfigScopes configScopes(deps);
|
||||
|
||||
EXPECT_TRUE(configScopes.scopeContains("stub", ConfigScopes::Scope::System));
|
||||
}
|
||||
|
||||
TEST(ConfigScopesTests, activeFilePath_returnsUserSettingsFileNameByDefault)
|
||||
{
|
||||
auto deps = std::make_shared<NiceMock<DepsMock>>();
|
||||
ON_CALL(*deps->m_pUserSettings, fileName()).WillByDefault(Return("test"));
|
||||
|
||||
ConfigScopes configScopes(deps);
|
||||
|
||||
EXPECT_EQ(configScopes.activeFilePath(), "test");
|
||||
}
|
||||
|
||||
TEST(ConfigScopesTests, getFromScope_byDefault_returnsValueFromActiveSettings)
|
||||
{
|
||||
auto deps = std::make_shared<NiceMock<DepsMock>>();
|
||||
ON_CALL(*deps->m_pUserSettings, value(_, _)).WillByDefault(Return("test"));
|
||||
|
||||
ConfigScopes configScopes(deps);
|
||||
|
||||
EXPECT_EQ(configScopes.getFromScope("stub"), "test");
|
||||
}
|
||||
|
||||
TEST(ConfigScopesTests, setInScope_byDefault_setsValueInActiveSettings)
|
||||
{
|
||||
auto deps = std::make_shared<NiceMock<DepsMock>>();
|
||||
|
||||
ConfigScopes configScopes(deps);
|
||||
|
||||
EXPECT_CALL(*deps->m_pUserSettings, setValue(_, _)).Times(1);
|
||||
|
||||
configScopes.setInScope("stub", "test");
|
||||
}
|
||||
Loading…
Reference in a new issue