diff options
author | aqua <aqua@iserlohn-fortress.net> | 2022-09-08 10:27:30 +0300 |
---|---|---|
committer | aqua <aqua@iserlohn-fortress.net> | 2022-09-08 16:33:03 +0300 |
commit | af1eff03c9e839914aab4109970c4a9f6fac8a99 (patch) | |
tree | ae11034560b0e1c270614077ffd8f0f7485c7381 /src/settings/settings.cpp | |
parent | Add RekonqWindow tests (diff) | |
download | rekonq-af1eff03c9e839914aab4109970c4a9f6fac8a99.tar.xz |
RekonqSettings: add resetValue and remove value's defaultValue parameter
- generate default rekonqrc and include it in libsettings
- Settings uses :/settings/rekonqrc to provide default values
- Add Settings::path() to get the default settings location
Diffstat (limited to 'src/settings/settings.cpp')
-rw-r--r-- | src/settings/settings.cpp | 51 |
1 files changed, 47 insertions, 4 deletions
diff --git a/src/settings/settings.cpp b/src/settings/settings.cpp index 190bc977..d7216b2e 100644 --- a/src/settings/settings.cpp +++ b/src/settings/settings.cpp @@ -8,23 +8,66 @@ * ============================================================ */ #include "settings.hpp" +#include "../rekonq.hpp" +#include "helpers.hpp" +#include <QDir> #include <QSettings> +#include <QStandardPaths> + +QString Settings::path() +{ + return QDir(QStandardPaths::writableLocation(QStandardPaths::AppConfigLocation)).filePath("rekonqrc"); +} Settings::Settings(const QString &path, QObject *parent) : RekonqSettings(parent) { d = new QSettings(path, QSettings::IniFormat, this); + b = new QSettings(":/settings/rekonqrc", QSettings::IniFormat, this); } -void Settings::beginGroup(const QString &prefix) { d->beginGroup(prefix); } +Settings::~Settings() +{ + delete d; + delete b; +} -void Settings::endGroup() { d->endGroup(); } +void Settings::beginGroup(const QString &prefix) +{ + d->beginGroup(prefix); + b->beginGroup(prefix); +} + +void Settings::endGroup() +{ + d->endGroup(); + b->endGroup(); +} void Settings::setValue(const QString &key, const QVariant &value) { - d->setValue(key, value); + if (value == b->value(key)) d->remove(key); + else + d->setValue(key, value); emit changed(key, value); } -QVariant Settings::value(const QString &key, const QVariant &defaultValue) const { return d->value(key, defaultValue); } +void Settings::resetValue(const QString &key) { d->remove(key); } + +QVariant Settings::value(const QString &key) const +{ + auto v = d->value(key); + if (v.isValid()) return v; + + if (key == QL1S("standardFontFamily")) return getFont(QFont::System).family(); + if (key == QL1S("fixedFontFamily")) return getFont(QFont::Monospace).family(); + if (key == QL1S("serifFontFamily")) return getFont(QFont::Times).family(); + if (key == QL1S("sansSerifFontFamily")) return getFont(QFont::Helvetica).family(); + if (key == QL1S("cursiveFontFamily")) return getFont(QFont::Cursive).family(); + if (key == QL1S("fantasyFontFamily")) return getFont(QFont::Fantasy).family(); + + v = b->value(key); + Q_ASSERT_X(v.isValid(), __PRETTY_FUNCTION__, qUtf8Printable(key)); + return v; +} QString Settings::filePath() const { return d->fileName(); } |