Changeset View
Changeset View
Standalone View
Standalone View
kded/configvalueprovider.cpp
Show All 21 Lines | |||||
22 | #include <QString> | 22 | #include <QString> | ||
23 | #include <QColor> | 23 | #include <QColor> | ||
24 | 24 | | |||
25 | #include <KConfig> | 25 | #include <KConfig> | ||
26 | #include <KIconTheme> | 26 | #include <KIconTheme> | ||
27 | #include <KSharedConfig> | 27 | #include <KSharedConfig> | ||
28 | #include <KConfigGroup> | 28 | #include <KConfigGroup> | ||
29 | 29 | | |||
30 | #include <gtk/gtk.h> | ||||
31 | | ||||
30 | #include "configvalueprovider.h" | 32 | #include "configvalueprovider.h" | ||
31 | 33 | | |||
32 | ConfigValueProvider::ConfigValueProvider() : | 34 | ConfigValueProvider::ConfigValueProvider() : | ||
33 | kdeglobalsConfig(KSharedConfig::openConfig(QStringLiteral("kdeglobals"))), | 35 | kdeglobalsConfig(KSharedConfig::openConfig(QStringLiteral("kdeglobals"))), | ||
34 | inputConfig(KSharedConfig::openConfig(QStringLiteral("kcminputrc"))), | 36 | inputConfig(KSharedConfig::openConfig(QStringLiteral("kcminputrc"))), | ||
35 | kwinConfig(KSharedConfig::openConfig(QStringLiteral("kwinrc"))) | 37 | kwinConfig(KSharedConfig::openConfig(QStringLiteral("kwinrc"))) | ||
36 | { | 38 | { | ||
37 | 39 | | |||
▲ Show 20 Lines • Show All 80 Lines • ▼ Show 20 Line(s) | |||||
118 | } | 120 | } | ||
119 | 121 | | |||
120 | QString ConfigValueProvider::cursorThemeName() const | 122 | QString ConfigValueProvider::cursorThemeName() const | ||
121 | { | 123 | { | ||
122 | KConfigGroup configGroup = inputConfig->group(QStringLiteral("Mouse")); | 124 | KConfigGroup configGroup = inputConfig->group(QStringLiteral("Mouse")); | ||
123 | return configGroup.readEntry(QStringLiteral("cursorTheme"), QStringLiteral("breeze_cursors")); | 125 | return configGroup.readEntry(QStringLiteral("cursorTheme"), QStringLiteral("breeze_cursors")); | ||
124 | } | 126 | } | ||
125 | 127 | | |||
126 | QString ConfigValueProvider::iconsOnButtons() const | 128 | bool ConfigValueProvider::iconsOnButtons() const | ||
127 | { | 129 | { | ||
128 | KConfigGroup configGroup = kdeglobalsConfig->group(QStringLiteral("KDE")); | 130 | KConfigGroup configGroup = kdeglobalsConfig->group(QStringLiteral("KDE")); | ||
129 | bool kdeConfigValue = configGroup.readEntry(QStringLiteral("ShowIconsOnPushButtons"), true); | 131 | return configGroup.readEntry(QStringLiteral("ShowIconsOnPushButtons"), true); | ||
130 | | ||||
131 | if (kdeConfigValue) { | | |||
132 | return QStringLiteral("1"); | | |||
133 | } else { | | |||
134 | return QStringLiteral("0"); | | |||
135 | } | | |||
136 | } | 132 | } | ||
137 | 133 | | |||
138 | QString ConfigValueProvider::iconsInMenus() const | 134 | bool ConfigValueProvider::iconsInMenus() const | ||
139 | { | 135 | { | ||
140 | KConfigGroup configGroup = kdeglobalsConfig->group(QStringLiteral("KDE")); | 136 | KConfigGroup configGroup = kdeglobalsConfig->group(QStringLiteral("KDE")); | ||
141 | bool kdeConfigValue = configGroup.readEntry(QStringLiteral("ShowIconsInMenuItems"), true); | 137 | return configGroup.readEntry(QStringLiteral("ShowIconsInMenuItems"), true); | ||
142 | | ||||
143 | if (kdeConfigValue) { | | |||
144 | return QStringLiteral("1"); | | |||
145 | } else { | | |||
146 | return QStringLiteral("0"); | | |||
147 | } | | |||
148 | } | 138 | } | ||
149 | 139 | | |||
150 | QString ConfigValueProvider::toolbarStyle(ConfigValueProvider::ToolbarStyleNotation notation) const | 140 | int ConfigValueProvider::toolbarStyle() const | ||
151 | { | 141 | { | ||
152 | KConfigGroup configGroup = kdeglobalsConfig->group(QStringLiteral("Toolbar style")); | 142 | KConfigGroup configGroup = kdeglobalsConfig->group(QStringLiteral("Toolbar style")); | ||
153 | QString kdeConfigValue = configGroup.readEntry(QStringLiteral("ToolButtonStyle"), "TextBesideIcon"); | 143 | QString kdeConfigValue = configGroup.readEntry(QStringLiteral("ToolButtonStyle"), "TextBesideIcon"); | ||
154 | return toolbarStyleInDesiredNotation(kdeConfigValue, notation); | 144 | | ||
145 | if (kdeConfigValue == QStringLiteral("NoText")) { | ||||
146 | return GtkToolbarStyle::GTK_TOOLBAR_ICONS; | ||||
147 | } else if (kdeConfigValue == QStringLiteral("TextOnly")) { | ||||
148 | return GtkToolbarStyle::GTK_TOOLBAR_TEXT; | ||||
149 | } else if (kdeConfigValue == QStringLiteral("TextBesideIcon")) { | ||||
150 | return GtkToolbarStyle::GTK_TOOLBAR_BOTH_HORIZ; | ||||
151 | } else { | ||||
152 | return GtkToolbarStyle::GTK_TOOLBAR_BOTH; | ||||
153 | } | ||||
155 | } | 154 | } | ||
156 | 155 | | |||
157 | QString ConfigValueProvider::scrollbarBehavior() const | 156 | bool ConfigValueProvider::scrollbarBehavior() const | ||
158 | { | 157 | { | ||
159 | KConfigGroup configGroup = kdeglobalsConfig->group(QStringLiteral("KDE")); | 158 | KConfigGroup configGroup = kdeglobalsConfig->group(QStringLiteral("KDE")); | ||
160 | bool kdeConfigValue = configGroup.readEntry(QStringLiteral("ScrollbarLeftClickNavigatesByPage"), true); | 159 | bool kdeConfigValue = configGroup.readEntry(QStringLiteral("ScrollbarLeftClickNavigatesByPage"), true); | ||
161 | if (kdeConfigValue) { // GTK setting is inverted | 160 | return !kdeConfigValue; // GTK setting is inverted | ||
162 | return QStringLiteral("0"); | | |||
163 | } else { | | |||
164 | return QStringLiteral("1"); | | |||
165 | } | | |||
166 | } | 161 | } | ||
167 | 162 | | |||
168 | QString ConfigValueProvider::preferDarkTheme() const | 163 | bool ConfigValueProvider::preferDarkTheme() const | ||
169 | { | 164 | { | ||
170 | KConfigGroup colorsConfigGroup = kdeglobalsConfig->group(QStringLiteral("Colors:Window")); | 165 | KConfigGroup colorsConfigGroup = kdeglobalsConfig->group(QStringLiteral("Colors:Window")); | ||
171 | QColor windowBackgroundColor = colorsConfigGroup.readEntry(QStringLiteral("BackgroundNormal"), QColor(239, 240, 241)); | 166 | QColor windowBackgroundColor = colorsConfigGroup.readEntry(QStringLiteral("BackgroundNormal"), QColor(239, 240, 241)); | ||
172 | const int windowBackgroundGray = qGray(windowBackgroundColor.rgb()); | 167 | const int windowBackgroundGray = qGray(windowBackgroundColor.rgb()); | ||
173 | 168 | | |||
174 | // We use heuristic to determine if current color scheme is dark or not | 169 | // We use heuristic to determine if current color scheme is dark or not | ||
175 | if (windowBackgroundGray >= 192) { | 170 | return windowBackgroundGray < 192; | ||
176 | return QStringLiteral("0"); | | |||
177 | } else { | | |||
178 | return QStringLiteral("1"); | | |||
179 | } | | |||
180 | } | 171 | } | ||
181 | 172 | | |||
182 | QString ConfigValueProvider::windowDecorationsButtonsOrder() const | 173 | QString ConfigValueProvider::windowDecorationsButtonsOrder() const | ||
183 | { | 174 | { | ||
184 | KConfigGroup configGroup = kwinConfig->group(QStringLiteral("org.kde.kdecoration2")); | 175 | KConfigGroup configGroup = kwinConfig->group(QStringLiteral("org.kde.kdecoration2")); | ||
185 | QString buttonsOnLeftKdeConfigValue = configGroup.readEntry(QStringLiteral("ButtonsOnLeft"), "MS"); | 176 | QString buttonsOnLeftKdeConfigValue = configGroup.readEntry(QStringLiteral("ButtonsOnLeft"), "MS"); | ||
186 | QString buttonsOnRightKdeConfigValue = configGroup.readEntry(QStringLiteral("ButtonsOnRight"), "HIAX"); | 177 | QString buttonsOnRightKdeConfigValue = configGroup.readEntry(QStringLiteral("ButtonsOnRight"), "HIAX"); | ||
187 | 178 | | |||
188 | QString buttonsOnLeftInGtkNotation = windowDecorationButtonsOrderInGtkNotation(buttonsOnLeftKdeConfigValue); | 179 | QString buttonsOnLeftInGtkNotation = windowDecorationButtonsOrderInGtkNotation(buttonsOnLeftKdeConfigValue); | ||
189 | QString buttonsOnRightInGtkNotation = windowDecorationButtonsOrderInGtkNotation(buttonsOnRightKdeConfigValue); | 180 | QString buttonsOnRightInGtkNotation = windowDecorationButtonsOrderInGtkNotation(buttonsOnRightKdeConfigValue); | ||
190 | 181 | | |||
191 | return buttonsOnLeftInGtkNotation + QStringLiteral(":") + buttonsOnRightInGtkNotation; | 182 | return buttonsOnLeftInGtkNotation + QStringLiteral(":") + buttonsOnRightInGtkNotation; | ||
192 | } | 183 | } | ||
193 | 184 | | |||
194 | QString ConfigValueProvider::enableAnimations() const | 185 | bool ConfigValueProvider::enableAnimations() const | ||
195 | { | 186 | { | ||
196 | KConfigGroup generalCfg = kdeglobalsConfig->group(QStringLiteral("KDE")); | 187 | KConfigGroup generalCfg = kdeglobalsConfig->group(QStringLiteral("KDE")); | ||
197 | const qreal animationSpeedModifier = qMax(0.0, generalCfg.readEntry("AnimationDurationFactor", 1.0)); | 188 | const qreal animationSpeedModifier = qMax(0.0, generalCfg.readEntry("AnimationDurationFactor", 1.0)); | ||
198 | 189 | | |||
199 | const bool enableAnimations = !qFuzzyIsNull(animationSpeedModifier); | 190 | return !qFuzzyIsNull(animationSpeedModifier); | ||
200 | | ||||
201 | if (enableAnimations) { | | |||
202 | return QStringLiteral("1"); | | |||
203 | } else { | | |||
204 | return QStringLiteral("0"); | | |||
205 | } | | |||
206 | } | | |||
207 | | ||||
208 | QString ConfigValueProvider::toolbarStyleInDesiredNotation(const QString &kdeConfigValue, ConfigValueProvider::ToolbarStyleNotation notation) const | | |||
209 | { | | |||
210 | QStringList toolbarStyles {}; | | |||
211 | if (notation == ToolbarStyleNotation::SettingsIni) { | | |||
212 | toolbarStyles.append({ | | |||
213 | QStringLiteral("GTK_TOOLBAR_ICONS"), | | |||
214 | QStringLiteral("GTK_TOOLBAR_TEXT"), | | |||
215 | QStringLiteral("GTK_TOOLBAR_BOTH_HORIZ"), | | |||
216 | QStringLiteral("GTK_TOOLBAR_BOTH") | | |||
217 | }); | | |||
218 | } else if (notation == ToolbarStyleNotation::Xsettingsd) { | | |||
219 | toolbarStyles.append({ | | |||
220 | QStringLiteral("0"), | | |||
221 | QStringLiteral("1"), | | |||
222 | QStringLiteral("3"), | | |||
223 | QStringLiteral("2") | | |||
224 | }); | | |||
225 | } else { | | |||
226 | toolbarStyles.append({ | | |||
227 | QStringLiteral("icons"), | | |||
228 | QStringLiteral("text"), | | |||
229 | QStringLiteral("both-horiz"), | | |||
230 | QStringLiteral("both") | | |||
231 | }); | | |||
232 | } | | |||
233 | | ||||
234 | if (kdeConfigValue == QStringLiteral("NoText")) { | | |||
235 | return toolbarStyles[0]; | | |||
236 | } else if (kdeConfigValue == QStringLiteral("TextOnly")) { | | |||
237 | return toolbarStyles[1]; | | |||
238 | } else if (kdeConfigValue == QStringLiteral("TextBesideIcon")) { | | |||
239 | return toolbarStyles[2]; | | |||
240 | } else { | | |||
241 | return toolbarStyles[3]; | | |||
242 | } | | |||
243 | } | 191 | } | ||
244 | 192 | | |||
245 | QString ConfigValueProvider::windowDecorationButtonsOrderInGtkNotation(const QString &kdeConfigValue) const | 193 | QString ConfigValueProvider::windowDecorationButtonsOrderInGtkNotation(const QString &kdeConfigValue) const | ||
246 | { | 194 | { | ||
247 | QString gtkNotation; | 195 | QString gtkNotation; | ||
248 | 196 | | |||
249 | for (const QChar &buttonAbbreviation : kdeConfigValue) { | 197 | for (const QChar &buttonAbbreviation : kdeConfigValue) { | ||
250 | if (buttonAbbreviation == 'X') { | 198 | if (buttonAbbreviation == 'X') { | ||
Show All 13 Lines |