Changeset View
Changeset View
Standalone View
Standalone View
kded/configvalueprovider.cpp
- This file was added.
1 | /* | ||||
---|---|---|---|---|---|
2 | * Copyright (C) 2019 Mikhail Zolotukhin <zomial@protonmail.com> | ||||
3 | * | ||||
4 | * This program is free software; you can redistribute it and/or | ||||
5 | * modify it under the terms of the GNU General Public License as | ||||
6 | * published by the Free Software Foundation; either version 2 of | ||||
7 | * the License or (at your option) version 3 or any later version | ||||
8 | * accepted by the membership of KDE e.V. (or its successor approved | ||||
9 | * by the membership of KDE e.V.), which shall act as a proxy | ||||
10 | * defined in Section 14 of version 3 of the license. | ||||
11 | * | ||||
12 | * This program is distributed in the hope that it will be useful, | ||||
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||||
15 | * GNU General Public License for more details. | ||||
16 | * | ||||
17 | * You should have received a copy of the GNU General Public License | ||||
18 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||||
19 | */ | ||||
20 | | ||||
21 | #include <QFont> | ||||
22 | #include <QString> | ||||
23 | | ||||
24 | #include <KConfig> | ||||
25 | #include <KIconTheme> | ||||
26 | #include <KSharedConfig> | ||||
27 | #include <KConfigGroup> | ||||
28 | | ||||
29 | #include "configvalueprovider.h" | ||||
30 | | ||||
31 | ConfigValueProvider::ConfigValueProvider() : | ||||
32 | kdeglobalsConfig(KSharedConfig::openConfig(QStringLiteral("kdeglobals"))), | ||||
33 | inputConfig(KSharedConfig::openConfig(QStringLiteral("kcminputrc"))) | ||||
34 | { | ||||
35 | | ||||
36 | } | ||||
37 | | ||||
38 | QString ConfigValueProvider::fontName() const | ||||
39 | { | ||||
40 | static const QFont defaultFont(QStringLiteral("Noto Sans"), 10); | ||||
41 | | ||||
42 | kdeglobalsConfig->reparseConfiguration(); | ||||
43 | KConfigGroup configGroup = kdeglobalsConfig->group(QStringLiteral("General")); | ||||
44 | QString fontAsString = configGroup.readEntry(QStringLiteral("font"), defaultFont.toString()); | ||||
45 | static QFont font; | ||||
46 | font.fromString(fontAsString); | ||||
47 | return font.family() + ' ' + font.styleName() + ' ' + QString::number(font.pointSize()); | ||||
48 | } | ||||
49 | | ||||
50 | QString ConfigValueProvider::iconThemeName() const | ||||
51 | { | ||||
52 | KIconTheme *newIconTheme = KIconLoader::global()->theme(); | ||||
53 | if (newIconTheme) { | ||||
54 | return newIconTheme->internalName(); | ||||
55 | } else { | ||||
56 | return QStringLiteral("breeze"); | ||||
57 | } | ||||
58 | } | ||||
59 | | ||||
60 | QString ConfigValueProvider::cursorThemeName() const | ||||
61 | { | ||||
62 | inputConfig->reparseConfiguration(); | ||||
63 | KConfigGroup configGroup = inputConfig->group(QStringLiteral("Mouse")); | ||||
64 | return configGroup.readEntry(QStringLiteral("cursorTheme")); | ||||
65 | } | ||||
66 | | ||||
67 | QString ConfigValueProvider::iconsOnButtons() const | ||||
68 | { | ||||
69 | kdeglobalsConfig->reparseConfiguration(); | ||||
70 | KConfigGroup configGroup = kdeglobalsConfig->group(QStringLiteral("KDE")); | ||||
71 | bool kdeConfigValue = configGroup.readEntry(QStringLiteral("ShowIconsOnPushButtons"), true); | ||||
72 | | ||||
73 | if (kdeConfigValue) { | ||||
74 | return QStringLiteral("1"); | ||||
75 | } else { | ||||
76 | return QStringLiteral("0"); | ||||
77 | } | ||||
78 | } | ||||
79 | | ||||
80 | QString ConfigValueProvider::iconsInMenus() const | ||||
81 | { | ||||
82 | kdeglobalsConfig->reparseConfiguration(); | ||||
83 | KConfigGroup configGroup = kdeglobalsConfig->group(QStringLiteral("KDE")); | ||||
84 | bool kdeConfigValue = configGroup.readEntry(QStringLiteral("ShowIconsInMenuItems"), true); | ||||
85 | | ||||
86 | if (kdeConfigValue) { | ||||
87 | return QStringLiteral("1"); | ||||
88 | } else { | ||||
89 | return QStringLiteral("0"); | ||||
90 | } | ||||
91 | } | ||||
92 | | ||||
93 | QString ConfigValueProvider::toolbarStyle(ConfigValueProvider::ToolbarStyleNotation notation) const | ||||
94 | { | ||||
95 | kdeglobalsConfig->reparseConfiguration(); | ||||
96 | KConfigGroup configGroup = kdeglobalsConfig->group(QStringLiteral("Toolbar style")); | ||||
97 | QString kdeConfigValue = configGroup.readEntry(QStringLiteral("ToolButtonStyle"), "TextBesideIcon"); | ||||
98 | return toolbarStyleInDesiredNotation(kdeConfigValue, notation); | ||||
99 | } | ||||
100 | | ||||
101 | QString ConfigValueProvider::toolbarStyleInDesiredNotation(const QString &kdeConfigValue, ConfigValueProvider::ToolbarStyleNotation notation) const | ||||
102 | { | ||||
103 | QStringList toolbarStyles {}; | ||||
104 | if (notation == ToolbarStyleNotation::SettingsIni) { | ||||
105 | toolbarStyles.append({ | ||||
106 | QStringLiteral("GTK_TOOLBAR_ICONS"), | ||||
107 | QStringLiteral("GTK_TOOLBAR_TEXT"), | ||||
108 | QStringLiteral("GTK_TOOLBAR_BOTH_HORIZ"), | ||||
109 | QStringLiteral("GTK_TOOLBAR_BOTH") | ||||
110 | }); | ||||
111 | } else if (notation == ToolbarStyleNotation::Xsettingsd) { | ||||
112 | toolbarStyles.append({ | ||||
113 | QStringLiteral("0"), | ||||
114 | QStringLiteral("1"), | ||||
115 | QStringLiteral("3"), | ||||
116 | QStringLiteral("2") | ||||
117 | }); | ||||
118 | } else { | ||||
119 | toolbarStyles.append({ | ||||
120 | QStringLiteral("icons"), | ||||
121 | QStringLiteral("text"), | ||||
122 | QStringLiteral("both-horiz"), | ||||
123 | QStringLiteral("both") | ||||
124 | }); | ||||
125 | } | ||||
126 | | ||||
127 | if (kdeConfigValue == QStringLiteral("NoText")) { | ||||
128 | return toolbarStyles[0]; | ||||
129 | } else if (kdeConfigValue == QStringLiteral("TextOnly")) { | ||||
130 | return toolbarStyles[1]; | ||||
131 | } else if (kdeConfigValue == QStringLiteral("TextBesideIcon")) { | ||||
132 | return toolbarStyles[2]; | ||||
133 | } else { | ||||
134 | return toolbarStyles[3]; | ||||
135 | } | ||||
136 | } |