Changeset View
Changeset View
Standalone View
Standalone View
kded/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 <QDBusConnection> | ||||
25 | #include <QGuiApplication> | ||||
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 | { | ||||
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 | | ||||
48 | applyAllSettings(); | ||||
49 | } | ||||
50 | | ||||
51 | void GtkConfig::setFont() const | ||||
52 | { | ||||
53 | const QString configFontName = configValueProvider->fontName(); | ||||
54 | ConfigEditor::setGtk2ConfigValue(QStringLiteral("gtk-font-name"), configFontName); | ||||
55 | ConfigEditor::setGtk3ConfigValueDconf(QStringLiteral("font-name"), configFontName); | ||||
56 | ConfigEditor::setGtk3ConfigValueSettingsIni(QStringLiteral("gtk-font-name"), configFontName); | ||||
57 | ConfigEditor::setGtk3ConfigValueXSettingsd(QStringLiteral("Gtk/FontName"), configFontName); | ||||
58 | } | ||||
59 | | ||||
60 | void GtkConfig::setIconTheme(int iconGroup) const | ||||
61 | { | ||||
62 | if (iconGroup == KIconLoader::Group::Desktop) { // This is needed to update icons only once | ||||
63 | const QString iconThemeName = configValueProvider->iconThemeName(); | ||||
64 | ConfigEditor::setGtk2ConfigValue(QStringLiteral("gtk-icon-theme-name"), iconThemeName); | ||||
65 | ConfigEditor::setGtk3ConfigValueDconf(QStringLiteral("icon-theme"), iconThemeName); | ||||
66 | ConfigEditor::setGtk3ConfigValueSettingsIni(QStringLiteral("gtk-icon-theme-name"), iconThemeName); | ||||
67 | ConfigEditor::setGtk3ConfigValueXSettingsd(QStringLiteral("Net/IconThemeName"), iconThemeName); | ||||
68 | } | ||||
69 | } | ||||
70 | | ||||
71 | void GtkConfig::setCursorTheme() const | ||||
72 | { | ||||
73 | const QString cursorThemeName = configValueProvider->cursorThemeName(); | ||||
74 | ConfigEditor::setGtk2ConfigValue(QStringLiteral("gtk-cursor-theme-name"), cursorThemeName); | ||||
75 | ConfigEditor::setGtk3ConfigValueDconf(QStringLiteral("cursor-theme"), cursorThemeName); | ||||
76 | ConfigEditor::setGtk3ConfigValueSettingsIni(QStringLiteral("gtk-cursor-theme-name"), cursorThemeName); | ||||
77 | ConfigEditor::setGtk3ConfigValueXSettingsd(QStringLiteral("Gtk/CursorThemeName"), cursorThemeName); | ||||
78 | } | ||||
79 | | ||||
80 | void GtkConfig::setIconsOnButtons() const | ||||
81 | { | ||||
82 | const QString iconsOnButtonsConfigValue = configValueProvider->iconsOnButtons(); | ||||
83 | ConfigEditor::setGtk2ConfigValue(QStringLiteral("gtk-button-images"), iconsOnButtonsConfigValue); | ||||
84 | ConfigEditor::setGtk3ConfigValueSettingsIni(QStringLiteral("gtk-button-images"), iconsOnButtonsConfigValue); | ||||
85 | ConfigEditor::setGtk3ConfigValueXSettingsd(QStringLiteral("Gtk/ButtonImages"), iconsOnButtonsConfigValue); | ||||
86 | } | ||||
87 | | ||||
88 | void GtkConfig::setIconsInMenus() const | ||||
89 | { | ||||
90 | const QString iconsInMenusConfigValue = configValueProvider->iconsInMenus(); | ||||
91 | ConfigEditor::setGtk2ConfigValue(QStringLiteral("gtk-menu-images"), iconsInMenusConfigValue); | ||||
92 | ConfigEditor::setGtk3ConfigValueSettingsIni(QStringLiteral("gtk-menu-images"), iconsInMenusConfigValue); | ||||
93 | ConfigEditor::setGtk3ConfigValueXSettingsd(QStringLiteral("Gtk/MenuImages"), iconsInMenusConfigValue); | ||||
94 | } | ||||
95 | | ||||
96 | void GtkConfig::setToolbarStyle() const | ||||
97 | { | ||||
98 | using ToolbarStyleNotation = ConfigValueProvider::ToolbarStyleNotation; | ||||
99 | | ||||
100 | QString toolbarStyleSettingsIni = configValueProvider->toolbarStyle(ToolbarStyleNotation::SettingsIni); | ||||
101 | QString toolbarStyleDConf = configValueProvider->toolbarStyle(ToolbarStyleNotation::Dconf); | ||||
102 | QString toolbarStyleXSettingsd = configValueProvider->toolbarStyle(ToolbarStyleNotation::Xsettingsd); | ||||
103 | | ||||
104 | ConfigEditor::setGtk2ConfigValue(QStringLiteral("gtk-toolbar-style"), toolbarStyleSettingsIni); | ||||
105 | ConfigEditor::setGtk3ConfigValueDconf(QStringLiteral("toolbar-style"), toolbarStyleDConf); | ||||
106 | ConfigEditor::setGtk3ConfigValueSettingsIni(QStringLiteral("gtk-toolbar-style"), toolbarStyleSettingsIni); | ||||
107 | ConfigEditor::setGtk3ConfigValueXSettingsd(QStringLiteral("Gtk/ToolbarStyle"), toolbarStyleXSettingsd); | ||||
108 | } | ||||
109 | | ||||
110 | void GtkConfig::applyAllSettings() const | ||||
111 | { | ||||
112 | setFont(); | ||||
113 | setIconTheme(KIconLoader::Group::Desktop); | ||||
114 | setCursorTheme(); | ||||
115 | setIconsOnButtons(); | ||||
116 | setIconsInMenus(); | ||||
117 | setToolbarStyle(); | ||||
118 | } | ||||
119 | | ||||
120 | void GtkConfig::onGlobalSettingsChange(int settingsChangeType, int arg) const | ||||
121 | { | ||||
122 | SettingsChangeType changeType = static_cast<SettingsChangeType>(settingsChangeType); | ||||
123 | SettingsCategory settingsCategory = static_cast<SettingsCategory>(arg); | ||||
124 | | ||||
125 | if (changeType == SettingsChangeType::Cursor) { | ||||
126 | setCursorTheme(); | ||||
127 | } else if (changeType == SettingsChangeType::Settings && settingsCategory == SettingsCategory::Style) { | ||||
128 | setIconsOnButtons(); | ||||
129 | setIconsInMenus(); | ||||
130 | setToolbarStyle(); | ||||
131 | } | ||||
132 | } | ||||
133 | | ||||
134 | #include "gtkconfig.moc" |