Changeset View
Changeset View
Standalone View
Standalone View
kded-module/gtkconfig.cpp
- This file was added.
1 | /* | ||||
---|---|---|---|---|---|
2 | * Copyright (C) 2019 Mikhail Zolotukhin <zomial@protonmail.com> | ||||
3 | * Copyright (C) 2019 Nicolas Fella <nicolas.fella@gmx.de> | ||||
4 | * | ||||
5 | * This program is free software; you can redistribute it and/or | ||||
6 | * modify it under the terms of the GNU General Public License as | ||||
7 | * published by the Free Software Foundation; either version 2 of | ||||
8 | * the License or (at your option) version 3 or any later version | ||||
9 | * accepted by the membership of KDE e.V. (or its successor approved | ||||
10 | * by the membership of KDE e.V.), which shall act as a proxy | ||||
11 | * defined in Section 14 of version 3 of the license. | ||||
12 | * | ||||
13 | * This program is distributed in the hope that it will be useful, | ||||
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||||
16 | * GNU General Public License for more details. | ||||
17 | * | ||||
18 | * You should have received a copy of the GNU General Public License | ||||
19 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||||
20 | */ | ||||
21 | | ||||
22 | #include <QDebug> | ||||
23 | #include <QFont> | ||||
24 | #include <QtDBus/QDBusConnection> | ||||
25 | #include <QGuiApplication> | ||||
nicolasfella: #include <QDBusConnection> | |||||
26 | | ||||
27 | #include <KGlobalSettings> | ||||
28 | #include <KIconLoader> | ||||
29 | #include <KPluginFactory> | ||||
30 | | ||||
31 | #include "gtkconfig.h" | ||||
32 | #include "configvalueprovider.h" | ||||
33 | | ||||
34 | K_PLUGIN_CLASS_WITH_JSON(GtkConfig, "gtkconfig.json") | ||||
35 | | ||||
36 | GtkConfig::GtkConfig(QObject *parent, const QVariantList&) : | ||||
37 | KDEDModule(parent), configValueProvider(new ConfigValueProvider()), configEditor(new ConfigEditor()) | ||||
broulik: One variable per line, please | |||||
38 | { | ||||
39 | connect(qGuiApp, &QGuiApplication::fontChanged, this, &GtkConfig::setFont); | ||||
40 | connect(KIconLoader::global(), &KIconLoader::iconChanged, this, &GtkConfig::setIconTheme); | ||||
41 | QDBusConnection::sessionBus().connect(QString(), | ||||
42 | QStringLiteral("/KGlobalSettings"), | ||||
43 | QStringLiteral("org.kde.KGlobalSettings"), | ||||
44 | QStringLiteral("notifyChange"), | ||||
45 | this, | ||||
46 | SLOT(onGlobalSettingsChange(int,int))); | ||||
47 | } | ||||
broulik: Should this initially apply all the settings? | |||||
48 | | ||||
49 | void GtkConfig::setFont(const QFont &font) | ||||
50 | { | ||||
51 | const QString configFontName(configValueProvider->getConfigFontName(font)); | ||||
52 | configEditor->setGtk2ConfigValue(QStringLiteral("gtk-font-name"), configFontName); | ||||
53 | configEditor->setGtk3ConfigValueDconf(QStringLiteral("font-name"), configFontName); | ||||
54 | configEditor->setGtk3ConfigValueSettingsIni(QStringLiteral("gtk-font-name"), configFontName); | ||||
55 | configEditor->setGtk3ConfigValueXSettingsd(QStringLiteral("Gtk/FontName"), configFontName); | ||||
56 | } | ||||
57 | | ||||
58 | void GtkConfig::setIconTheme(int iconGroup) | ||||
59 | { | ||||
60 | if (iconGroup == KIconLoader::Group::Desktop) { // This is needed to update icons only once | ||||
61 | QString iconThemeName(configValueProvider->getConfigIconThemeName()); | ||||
62 | configEditor->setGtk2ConfigValue(QStringLiteral("gtk-icon-theme-name"), iconThemeName); | ||||
63 | configEditor->setGtk3ConfigValueDconf(QStringLiteral("icon-theme"), iconThemeName); | ||||
64 | configEditor->setGtk3ConfigValueSettingsIni(QStringLiteral("gtk-icon-theme-name"), iconThemeName); | ||||
65 | configEditor->setGtk3ConfigValueXSettingsd(QStringLiteral("Net/IconThemeName"), iconThemeName); | ||||
66 | } | ||||
67 | } | ||||
68 | | ||||
69 | void GtkConfig::setCursorTheme() | ||||
70 | { | ||||
71 | QString cursorThemeName(configValueProvider->getConfigCursorThemeName()); | ||||
72 | configEditor->setGtk2ConfigValue(QStringLiteral("gtk-cursor-theme-name"), cursorThemeName); | ||||
73 | configEditor->setGtk3ConfigValueDconf(QStringLiteral("cursor-theme"), cursorThemeName); | ||||
74 | configEditor->setGtk3ConfigValueSettingsIni(QStringLiteral("gtk-cursor-theme-name"), cursorThemeName); | ||||
75 | configEditor->setGtk3ConfigValueXSettingsd(QStringLiteral("Gtk/CursorThemeName"), cursorThemeName); | ||||
76 | } | ||||
77 | | ||||
78 | void GtkConfig::setIconsOnButtons() | ||||
79 | { | ||||
80 | QString iconsOnButtonsConfigValue(configValueProvider->getIconsOnButtonsConfigValue()); | ||||
81 | configEditor->setGtk2ConfigValue(QStringLiteral("gtk-button-images"), iconsOnButtonsConfigValue); | ||||
82 | configEditor->setGtk3ConfigValueSettingsIni(QStringLiteral("gtk-button-images"), iconsOnButtonsConfigValue); | ||||
83 | configEditor->setGtk3ConfigValueXSettingsd(QStringLiteral("Gtk/ButtonImages"), iconsOnButtonsConfigValue); | ||||
84 | } | ||||
85 | | ||||
86 | void GtkConfig::setIconsInMenus() | ||||
87 | { | ||||
88 | QString iconsInMenusConfigValue(configValueProvider->getIconsInMenusConfigValue()); | ||||
89 | configEditor->setGtk2ConfigValue(QStringLiteral("gtk-menu-images"), iconsInMenusConfigValue); | ||||
90 | configEditor->setGtk3ConfigValueSettingsIni(QStringLiteral("gtk-menu-images"), iconsInMenusConfigValue); | ||||
91 | configEditor->setGtk3ConfigValueXSettingsd(QStringLiteral("Gtk/MenuImages"), iconsInMenusConfigValue); | ||||
92 | } | ||||
93 | | ||||
94 | void GtkConfig::setToolbarStyle() | ||||
95 | { | ||||
96 | using ToolbarStyleNotation = ConfigValueProvider::ToolbarStyleNotation; | ||||
97 | | ||||
98 | QString toolbarStyleSettingsFile(configValueProvider->getToolbarStyle(ToolbarStyleNotation::SETTINGS_INI)); | ||||
99 | QString toolbarStyleDConf(configValueProvider->getToolbarStyle(ToolbarStyleNotation::DCONF)); | ||||
100 | QString toolbarStyleXSettingsd(configValueProvider->getToolbarStyle(ToolbarStyleNotation::XSETTINGSD)); | ||||
101 | | ||||
102 | configEditor->setGtk2ConfigValue(QStringLiteral("gtk-toolbar-style"), toolbarStyleSettingsFile); | ||||
103 | configEditor->setGtk3ConfigValueDconf(QStringLiteral("toolbar-style"), toolbarStyleDConf); | ||||
104 | configEditor->setGtk3ConfigValueSettingsIni(QStringLiteral("gtk-toolbar-style"), toolbarStyleSettingsFile); | ||||
105 | configEditor->setGtk3ConfigValueXSettingsd(QStringLiteral("Gtk/ToolbarStyle"), toolbarStyleXSettingsd); | ||||
106 | } | ||||
107 | | ||||
108 | void GtkConfig::onGlobalSettingsChange(int changeType, int arg) | ||||
109 | { | ||||
110 | using ChangeType = KGlobalSettings::ChangeType; | ||||
You'll have to copy those enum values in since KGlobalSettings is deprecated, sorry. broulik: You'll have to copy those enum values in since `KGlobalSettings` is deprecated, sorry. | |||||
111 | using SettingsCategory = KGlobalSettings::SettingsCategory; | ||||
112 | | ||||
113 | if (changeType == ChangeType::CursorChanged) { | ||||
114 | setCursorTheme(); | ||||
ervin: Are you sure you want to call setFont() twice here? That looks surprising. | |||||
115 | } else if (changeType == ChangeType::SettingsChanged && arg == SettingsCategory::SETTINGS_STYLE) { | ||||
116 | // Since KGlobalSettings::ChangeType::ToolbarStyleChanged is not working, | ||||
In what way? There's a comment in the style KCM saying // ##### FIXME - Doesn't apply all settings correctly due to bugs in KApplication/KToolbar KGlobalSettings::self()->emitChange(KGlobalSettings::ToolbarStyleChanged); broulik: In what way? There's a comment in the style KCM saying
```
// ##### FIXME - Doesn't apply all… | |||||
@broulik signal from KGlobalSettings is never recieved with KGlobalSettings::ToolbarStyleChanged value as an argument. I debuged style kcm and daemon simultaneously and after stepping over the above line and the previous one which is KGlobalSettings::self()->emitChange(KGlobalSettings::SettingsChanged, KGlobalSettings::SETTINGS_STYLE); Only signal with SettingsChanged is received within the daemon. gikari: @broulik signal from `KGlobalSettings` is never recieved with `KGlobalSettings… | |||||
117 | // we use the style settings category as a whole to change the respective settings | ||||
118 | setIconsOnButtons(); | ||||
119 | setIconsInMenus(); | ||||
120 | setToolbarStyle(); | ||||
121 | } | ||||
122 | } | ||||
123 | #include "gtkconfig.moc" | ||||
124 | |
#include <QDBusConnection>