summaryrefslogtreecommitdiff
path: root/src/settings/settings.cpp
blob: d7216b2e715c3f082bbe73669ea4d1efae31103d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
/* ============================================================
 *     The rekonq project
 * ============================================================
 * SPDX-License-Identifier: GPL-3.0-only
 * Copyright (C) 2022 aqua <aqua@iserlohn-fortress.net>
 * ============================================================
 * Description: Application Settings
 * ============================================================ */

#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);
}

Settings::~Settings()
{
  delete d;
  delete b;
}

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)
{
  if (value == b->value(key)) d->remove(key);
  else
    d->setValue(key, value);
  emit changed(key, value);
}

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(); }