2018-09-29 15:56:04 +03:00
|
|
|
/*
|
2024-12-30 22:39:49 +01:00
|
|
|
* Copyright (C) 2021-2025 QuasarApp.
|
2018-09-29 15:56:04 +03:00
|
|
|
* Distributed under the lgplv3 software license, see the accompanying
|
|
|
|
* Everyone is permitted to copy and distribute verbatim copies
|
|
|
|
* of this license document, but changing it is not allowed.
|
|
|
|
*/
|
|
|
|
|
2021-11-05 23:58:23 +03:00
|
|
|
|
2018-09-29 15:56:04 +03:00
|
|
|
#include "settings.h"
|
|
|
|
#include <QSettings>
|
2019-09-23 18:36:29 +03:00
|
|
|
#include <QCoreApplication>
|
2022-06-24 17:36:22 +03:00
|
|
|
#include <QDebug>
|
2018-09-29 15:56:04 +03:00
|
|
|
|
2021-11-05 23:58:23 +03:00
|
|
|
namespace QuasarAppUtils {
|
2018-09-29 15:56:04 +03:00
|
|
|
|
2021-11-05 23:58:23 +03:00
|
|
|
Settings::Settings() {
|
2019-09-23 18:36:29 +03:00
|
|
|
auto name = QCoreApplication::applicationName();
|
2019-09-27 20:35:37 +03:00
|
|
|
auto company = QCoreApplication::organizationName();
|
2019-09-23 18:36:29 +03:00
|
|
|
if (name.isEmpty()) {
|
|
|
|
name = "QuasarAppUtils";
|
|
|
|
}
|
|
|
|
|
2019-09-27 20:35:37 +03:00
|
|
|
if (company.isEmpty()) {
|
|
|
|
company = "QuasarApp";
|
|
|
|
}
|
|
|
|
|
2022-06-24 17:36:22 +03:00
|
|
|
_settings = new QSettings(QSettings::NativeFormat, QSettings::Scope::UserScope, company, name);
|
2018-09-29 15:56:04 +03:00
|
|
|
}
|
|
|
|
|
2021-11-05 23:58:23 +03:00
|
|
|
void Settings::syncImplementation() {
|
|
|
|
return _settings->sync();
|
2018-09-29 15:56:04 +03:00
|
|
|
}
|
|
|
|
|
2021-11-05 23:58:23 +03:00
|
|
|
QVariant Settings::getValueImplementation(const QString &key, const QVariant &def) {
|
2022-06-24 23:54:04 +03:00
|
|
|
if (isBool(key)) {
|
|
|
|
return _settings->value(key, def).toBool();
|
|
|
|
}
|
|
|
|
|
2022-06-24 17:36:22 +03:00
|
|
|
return _settings->value(key, def);
|
2018-09-29 15:56:04 +03:00
|
|
|
}
|
|
|
|
|
2021-11-05 23:58:23 +03:00
|
|
|
void Settings::setValueImplementation(const QString key, const QVariant &value) {
|
|
|
|
return _settings->setValue(key, value);
|
2018-09-29 15:56:04 +03:00
|
|
|
}
|
|
|
|
|
2022-08-21 22:25:59 +03:00
|
|
|
bool Settings::ignoreToRest(const QString &) const {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
QHash<QString, QVariant> Settings::defaultSettings() {
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
2022-06-24 23:54:04 +03:00
|
|
|
bool Settings::isBool(const QString &) const {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
const QSet<QString> &Settings::boolOptions() const
|
|
|
|
{
|
|
|
|
return _boolOptions;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Settings::setBoolOptions(const QSet<QString> &newBoolOptions)
|
|
|
|
{
|
|
|
|
_boolOptions = newBoolOptions;
|
|
|
|
}
|
|
|
|
|
2023-08-16 13:34:40 +02:00
|
|
|
bool Settings::initService() {
|
|
|
|
return ISettings::initService(std::make_unique<Settings>());
|
|
|
|
}
|
|
|
|
|
2025-02-18 14:12:54 +01:00
|
|
|
ISettings *Settings::autoInstance() {
|
|
|
|
if (auto result = instance()) {
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
Settings::initService();
|
|
|
|
return ISettings::instance();
|
|
|
|
}
|
|
|
|
|
2018-09-29 15:56:04 +03:00
|
|
|
}
|