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 <KIconLoader> | ||||
28 | #include <KPluginFactory> | ||||
29 | | ||||
30 | #include "gtkconfig.h" | ||||
31 | #include "configvalueprovider.h" | ||||
32 | | ||||
33 | K_PLUGIN_CLASS_WITH_JSON(GtkConfig, "gtkconfig.json") | ||||
34 | | ||||
35 | GtkConfig::GtkConfig(QObject *parent, const QVariantList&) : | ||||
36 | KDEDModule(parent), | ||||
37 | configValueProvider(new ConfigValueProvider()), | ||||
38 | configEditor(new ConfigEditor()) | ||||
broulik: One variable per line, please | |||||
39 | { | ||||
40 | connect(qGuiApp, &QGuiApplication::fontChanged, this, &GtkConfig::setFont); | ||||
41 | connect(KIconLoader::global(), &KIconLoader::iconChanged, this, &GtkConfig::setIconTheme); | ||||
42 | QDBusConnection::sessionBus().connect(QString(), | ||||
43 | QStringLiteral("/KGlobalSettings"), | ||||
44 | QStringLiteral("org.kde.KGlobalSettings"), | ||||
45 | QStringLiteral("notifyChange"), | ||||
46 | this, | ||||
47 | SLOT(onGlobalSettingsChange(int,int))); | ||||
48 | | ||||
broulik: Should this initially apply all the settings? | |||||
49 | applyAllSettings(); | ||||
50 | } | ||||
51 | | ||||
52 | void GtkConfig::setFont() const | ||||
53 | { | ||||
54 | const QString configFontName(configValueProvider->getConfigFontName()); | ||||
55 | configEditor->setGtk2ConfigValue(QStringLiteral("gtk-font-name"), configFontName); | ||||
56 | configEditor->setGtk3ConfigValueDconf(QStringLiteral("font-name"), configFontName); | ||||
57 | configEditor->setGtk3ConfigValueSettingsIni(QStringLiteral("gtk-font-name"), configFontName); | ||||
58 | configEditor->setGtk3ConfigValueXSettingsd(QStringLiteral("Gtk/FontName"), configFontName); | ||||
59 | } | ||||
60 | | ||||
61 | void GtkConfig::setIconTheme(int iconGroup) const | ||||
62 | { | ||||
63 | if (iconGroup == KIconLoader::Group::Desktop) { // This is needed to update icons only once | ||||
64 | const QString iconThemeName(configValueProvider->getConfigIconThemeName()); | ||||
65 | configEditor->setGtk2ConfigValue(QStringLiteral("gtk-icon-theme-name"), iconThemeName); | ||||
66 | configEditor->setGtk3ConfigValueDconf(QStringLiteral("icon-theme"), iconThemeName); | ||||
67 | configEditor->setGtk3ConfigValueSettingsIni(QStringLiteral("gtk-icon-theme-name"), iconThemeName); | ||||
68 | configEditor->setGtk3ConfigValueXSettingsd(QStringLiteral("Net/IconThemeName"), iconThemeName); | ||||
69 | } | ||||
70 | } | ||||
71 | | ||||
72 | void GtkConfig::setCursorTheme() const | ||||
73 | { | ||||
74 | const QString cursorThemeName(configValueProvider->getConfigCursorThemeName()); | ||||
75 | configEditor->setGtk2ConfigValue(QStringLiteral("gtk-cursor-theme-name"), cursorThemeName); | ||||
76 | configEditor->setGtk3ConfigValueDconf(QStringLiteral("cursor-theme"), cursorThemeName); | ||||
77 | configEditor->setGtk3ConfigValueSettingsIni(QStringLiteral("gtk-cursor-theme-name"), cursorThemeName); | ||||
78 | configEditor->setGtk3ConfigValueXSettingsd(QStringLiteral("Gtk/CursorThemeName"), cursorThemeName); | ||||
79 | } | ||||
80 | | ||||
81 | void GtkConfig::setIconsOnButtons() const | ||||
82 | { | ||||
83 | const QString iconsOnButtonsConfigValue(configValueProvider->getIconsOnButtonsConfigValue()); | ||||
84 | configEditor->setGtk2ConfigValue(QStringLiteral("gtk-button-images"), iconsOnButtonsConfigValue); | ||||
85 | configEditor->setGtk3ConfigValueSettingsIni(QStringLiteral("gtk-button-images"), iconsOnButtonsConfigValue); | ||||
86 | configEditor->setGtk3ConfigValueXSettingsd(QStringLiteral("Gtk/ButtonImages"), iconsOnButtonsConfigValue); | ||||
87 | } | ||||
88 | | ||||
89 | void GtkConfig::setIconsInMenus() const | ||||
90 | { | ||||
91 | const QString iconsInMenusConfigValue(configValueProvider->getIconsInMenusConfigValue()); | ||||
92 | configEditor->setGtk2ConfigValue(QStringLiteral("gtk-menu-images"), iconsInMenusConfigValue); | ||||
93 | configEditor->setGtk3ConfigValueSettingsIni(QStringLiteral("gtk-menu-images"), iconsInMenusConfigValue); | ||||
94 | configEditor->setGtk3ConfigValueXSettingsd(QStringLiteral("Gtk/MenuImages"), iconsInMenusConfigValue); | ||||
95 | } | ||||
96 | | ||||
97 | void GtkConfig::setToolbarStyle() const | ||||
98 | { | ||||
99 | using ToolbarStyleNotation = ConfigValueProvider::ToolbarStyleNotation; | ||||
100 | | ||||
101 | QString toolbarStyleSettingsFile(configValueProvider->getToolbarStyle(ToolbarStyleNotation::SettingsIni)); | ||||
102 | QString toolbarStyleDConf(configValueProvider->getToolbarStyle(ToolbarStyleNotation::Dconf)); | ||||
103 | QString toolbarStyleXSettingsd(configValueProvider->getToolbarStyle(ToolbarStyleNotation::Xsettingsd)); | ||||
104 | | ||||
105 | configEditor->setGtk2ConfigValue(QStringLiteral("gtk-toolbar-style"), toolbarStyleSettingsFile); | ||||
106 | configEditor->setGtk3ConfigValueDconf(QStringLiteral("toolbar-style"), toolbarStyleDConf); | ||||
107 | configEditor->setGtk3ConfigValueSettingsIni(QStringLiteral("gtk-toolbar-style"), toolbarStyleSettingsFile); | ||||
108 | configEditor->setGtk3ConfigValueXSettingsd(QStringLiteral("Gtk/ToolbarStyle"), toolbarStyleXSettingsd); | ||||
109 | } | ||||
110 | | ||||
111 | void GtkConfig::applyAllSettings() const | ||||
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. | |||||
112 | { | ||||
113 | setFont(); | ||||
114 | setFont(); | ||||
ervin: Are you sure you want to call setFont() twice here? That looks surprising. | |||||
115 | setIconTheme(KIconLoader::Group::Desktop); | ||||
116 | setCursorTheme(); | ||||
117 | setIconsOnButtons(); | ||||
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… | |||||
118 | setIconsInMenus(); | ||||
119 | setToolbarStyle(); | ||||
120 | } | ||||
121 | | ||||
122 | void GtkConfig::onGlobalSettingsChange(int settingsChangeType, int arg) const | ||||
123 | { | ||||
124 | SettingsChangeType changeType(static_cast<SettingsChangeType>(settingsChangeType)); | ||||
125 | SettingsCategory settingsCategory(static_cast<SettingsCategory>(arg)); | ||||
126 | | ||||
127 | if (changeType == SettingsChangeType::Cursor) { | ||||
128 | setCursorTheme(); | ||||
129 | } else if (changeType == SettingsChangeType::Settings && settingsCategory == SettingsCategory::Style) { | ||||
130 | // Since KGlobalSettings::ChangeType::ToolbarStyleChanged is not working, | ||||
131 | // we use the style settings category as a whole to change the respective settings | ||||
132 | setIconsOnButtons(); | ||||
133 | setIconsInMenus(); | ||||
134 | setToolbarStyle(); | ||||
135 | } | ||||
136 | } | ||||
137 | #include "gtkconfig.moc" | ||||
138 | |
#include <QDBusConnection>