Changeset View
Changeset View
Standalone View
Standalone View
kcms/style/kcmstyle.cpp
Show All 31 Lines | |||||
32 | #include "styleconfdialog.h" | 32 | #include "styleconfdialog.h" | ||
33 | 33 | | |||
34 | #include <KAboutData> | 34 | #include <KAboutData> | ||
35 | #include <KConfigGroup> | 35 | #include <KConfigGroup> | ||
36 | #include <KLocalizedString> | 36 | #include <KLocalizedString> | ||
37 | #include <KPluginFactory> | 37 | #include <KPluginFactory> | ||
38 | #include <KPluginLoader> | 38 | #include <KPluginLoader> | ||
39 | 39 | | |||
40 | #include <QDBusReply> | ||||
40 | #include <QLibrary> | 41 | #include <QLibrary> | ||
41 | #include <QMetaEnum> | 42 | #include <QMetaEnum> | ||
42 | #include <QQuickItem> | 43 | #include <QQuickItem> | ||
43 | #include <QQuickRenderControl> | 44 | #include <QQuickRenderControl> | ||
44 | #include <QQuickWindow> | 45 | #include <QQuickWindow> | ||
45 | #include <QScopedPointer> | 46 | #include <QScopedPointer> | ||
46 | #include <QStyleFactory> | 47 | #include <QStyleFactory> | ||
47 | #include <QWidget> | 48 | #include <QWidget> | ||
48 | #include <QWindow> | 49 | #include <QWindow> | ||
49 | 50 | | |||
50 | #include <KGlobal> | 51 | #include <KGlobal> | ||
51 | #include <KGlobalSettings> | 52 | #include <KGlobalSettings> | ||
52 | 53 | | |||
53 | #include "../krdb/krdb.h" | 54 | #include "../krdb/krdb.h" | ||
54 | 55 | | |||
55 | #include "stylesmodel.h" | 56 | #include "stylesmodel.h" | ||
57 | #include "gtkthemesmodel.h" | ||||
56 | #include "previewitem.h" | 58 | #include "previewitem.h" | ||
57 | #include "stylesettings.h" | 59 | #include "stylesettings.h" | ||
60 | #include "gtkpage.h" | ||||
58 | 61 | | |||
59 | K_PLUGIN_FACTORY_WITH_JSON(KCMStyleFactory, "kcm_style.json", registerPlugin<KCMStyle>();) | 62 | K_PLUGIN_FACTORY_WITH_JSON(KCMStyleFactory, "kcm_style.json", registerPlugin<KCMStyle>();) | ||
60 | 63 | | |||
61 | extern "C" | 64 | extern "C" | ||
62 | { | 65 | { | ||
63 | Q_DECL_EXPORT void kcminit_style() | 66 | Q_DECL_EXPORT void kcminit_style() | ||
64 | { | 67 | { | ||
65 | uint flags = KRdbExportQtSettings | KRdbExportGtkColors | KRdbExportQtColors | KRdbExportXftSettings | KRdbExportGtkTheme; | 68 | uint flags = KRdbExportQtSettings | KRdbExportGtkColors | KRdbExportQtColors | KRdbExportXftSettings | KRdbExportGtkTheme; | ||
66 | KConfig _config( QStringLiteral("kcmdisplayrc"), KConfig::NoGlobals ); | 69 | KConfig _config( QStringLiteral("kcmdisplayrc"), KConfig::NoGlobals ); | ||
67 | KConfigGroup config(&_config, "X11"); | 70 | KConfigGroup config(&_config, "X11"); | ||
68 | 71 | | |||
69 | // This key is written by the "colors" module. | 72 | // This key is written by the "colors" module. | ||
70 | bool exportKDEColors = config.readEntry("exportKDEColors", true); | 73 | bool exportKDEColors = config.readEntry("exportKDEColors", true); | ||
71 | if (exportKDEColors) { | 74 | if (exportKDEColors) { | ||
72 | flags |= KRdbExportColors; | 75 | flags |= KRdbExportColors; | ||
73 | } | 76 | } | ||
74 | runRdb( flags ); | 77 | runRdb( flags ); | ||
75 | } | 78 | } | ||
76 | } | 79 | } | ||
77 | 80 | | |||
78 | KCMStyle::KCMStyle(QObject *parent, const QVariantList &args) | 81 | KCMStyle::KCMStyle(QObject *parent, const QVariantList &args) | ||
79 | : KQuickAddons::ManagedConfigModule(parent, args) | 82 | : KQuickAddons::ManagedConfigModule(parent, args) | ||
80 | , m_settings(new StyleSettings(this)) | 83 | , m_settings(new StyleSettings(this)) | ||
81 | , m_model(new StylesModel(this)) | 84 | , m_model(new StylesModel(this)) | ||
85 | , m_gtkPage() | ||||
82 | { | 86 | { | ||
83 | qmlRegisterUncreatableType<KCMStyle>("org.kde.private.kcms.style", 1, 0, "KCM", QStringLiteral("Cannot create instances of KCM")); | 87 | qmlRegisterUncreatableType<KCMStyle>("org.kde.private.kcms.style", 1, 0, "KCM", QStringLiteral("Cannot create instances of KCM")); | ||
84 | qmlRegisterType<StyleSettings>(); | 88 | qmlRegisterType<StyleSettings>(); | ||
85 | qmlRegisterType<StylesModel>(); | 89 | qmlRegisterType<StylesModel>(); | ||
86 | qmlRegisterType<PreviewItem>("org.kde.private.kcms.style", 1, 0, "PreviewItem"); | 90 | qmlRegisterType<PreviewItem>("org.kde.private.kcms.style", 1, 0, "PreviewItem"); | ||
87 | 91 | | |||
88 | KAboutData *about = | 92 | KAboutData *about = | ||
89 | new KAboutData( QStringLiteral("kcm_style"), i18n("Application Style"), QStringLiteral("2.0"), | 93 | new KAboutData( QStringLiteral("kcm_style"), i18n("Application Style"), QStringLiteral("2.0"), | ||
90 | QString(), KAboutLicense::GPL, | 94 | QString(), KAboutLicense::GPL, | ||
91 | i18n("(c) 2002 Karol Szwed, Daniel Molkentin, (c) 2019 Kai Uwe Broulik")); | 95 | i18n("(c) 2002 Karol Szwed, Daniel Molkentin, (c) 2019 Kai Uwe Broulik")); | ||
92 | 96 | | |||
93 | about->addAuthor(i18n("Karol Szwed"), QString(), QStringLiteral("gallium@kde.org")); | 97 | about->addAuthor(i18n("Karol Szwed"), QString(), QStringLiteral("gallium@kde.org")); | ||
94 | about->addAuthor(i18n("Daniel Molkentin"), QString(), QStringLiteral("molkentin@kde.org")); | 98 | about->addAuthor(i18n("Daniel Molkentin"), QString(), QStringLiteral("molkentin@kde.org")); | ||
95 | about->addAuthor(i18n("Kai Uwe Broulik"), QString(), QStringLiteral("kde@broulik.de")); | 99 | about->addAuthor(i18n("Kai Uwe Broulik"), QString(), QStringLiteral("kde@broulik.de")); | ||
96 | setAboutData(about); | 100 | setAboutData(about); | ||
97 | 101 | | |||
102 | if (gtkConfigKdedModuleLoaded()) { | ||||
103 | m_gtkPage = new GtkPage(this); | ||||
104 | connect(m_gtkPage, &GtkPage::gtkThemeSettingsChanged, this, [this](){ | ||||
105 | setNeedsSave(true); | ||||
106 | }); | ||||
107 | } | ||||
98 | connect(m_model, &StylesModel::selectedStyleChanged, this, [this](const QString &style) { | 108 | connect(m_model, &StylesModel::selectedStyleChanged, this, [this](const QString &style) { | ||
99 | m_settings->setWidgetStyle(style); | 109 | m_settings->setWidgetStyle(style); | ||
100 | }); | 110 | }); | ||
101 | connect(m_settings, &StyleSettings::widgetStyleChanged, this, [this] { | 111 | connect(m_settings, &StyleSettings::widgetStyleChanged, this, [this] { | ||
102 | m_model->setSelectedStyle(m_settings->widgetStyle()); | 112 | m_model->setSelectedStyle(m_settings->widgetStyle()); | ||
103 | }); | 113 | }); | ||
104 | connect(m_settings, &StyleSettings::iconsOnButtonsChanged, this, [this] { | 114 | connect(m_settings, &StyleSettings::iconsOnButtonsChanged, this, [this] { | ||
105 | m_effectsDirty = true; | 115 | m_effectsDirty = true; | ||
▲ Show 20 Lines • Show All 118 Lines • ▼ Show 20 Line(s) | 221 | connect(m_styleConfigDialog.data(), &QDialog::accepted, this, [this, styleName] { | |||
224 | 234 | | |||
225 | // We call setNeedsSave(true) here to make sure we force style re-creation | 235 | // We call setNeedsSave(true) here to make sure we force style re-creation | ||
226 | setNeedsSave(true); | 236 | setNeedsSave(true); | ||
227 | }); | 237 | }); | ||
228 | 238 | | |||
229 | m_styleConfigDialog->show(); | 239 | m_styleConfigDialog->show(); | ||
230 | } | 240 | } | ||
231 | 241 | | |||
242 | bool KCMStyle::gtkConfigKdedModuleLoaded() | ||||
243 | { | ||||
244 | QDBusInterface kdedInterface( | ||||
245 | QStringLiteral("org.kde.kded5"), | ||||
246 | QStringLiteral("/kded"), | ||||
247 | QStringLiteral("org.kde.kded5") | ||||
248 | ); | ||||
249 | QDBusReply<QStringList> loadedKdedModules = kdedInterface.call(QStringLiteral("loadedModules")); | ||||
250 | return loadedKdedModules.value().contains(QStringLiteral("gtkconfig")); | ||||
251 | } | ||||
252 | | ||||
232 | void KCMStyle::load() | 253 | void KCMStyle::load() | ||
233 | { | 254 | { | ||
255 | if (m_gtkPage) { | ||||
256 | m_gtkPage->load(); | ||||
257 | } | ||||
258 | | ||||
234 | ManagedConfigModule::load(); | 259 | ManagedConfigModule::load(); | ||
235 | m_model->load(); | 260 | m_model->load(); | ||
236 | m_previousStyle = m_settings->widgetStyle(); | 261 | m_previousStyle = m_settings->widgetStyle(); | ||
237 | 262 | | |||
238 | loadSettingsToModel(); | 263 | loadSettingsToModel(); | ||
239 | 264 | | |||
240 | m_effectsDirty = false; | 265 | m_effectsDirty = false; | ||
241 | } | 266 | } | ||
242 | 267 | | |||
243 | void KCMStyle::save() | 268 | void KCMStyle::save() | ||
244 | { | 269 | { | ||
270 | if (m_gtkPage) { | ||||
271 | m_gtkPage->save(); | ||||
272 | } | ||||
273 | | ||||
245 | // Check whether the new style can actually be loaded before saving it. | 274 | // Check whether the new style can actually be loaded before saving it. | ||
246 | // Otherwise apps will use the default style despite something else having been written to the config | 275 | // Otherwise apps will use the default style despite something else having been written to the config | ||
247 | bool newStyleLoaded = false; | 276 | bool newStyleLoaded = false; | ||
248 | if (m_settings->widgetStyle() != m_previousStyle) { | 277 | if (m_settings->widgetStyle() != m_previousStyle) { | ||
249 | QScopedPointer<QStyle> newStyle(QStyleFactory::create(m_settings->widgetStyle())); | 278 | QScopedPointer<QStyle> newStyle(QStyleFactory::create(m_settings->widgetStyle())); | ||
250 | if (newStyle) { | 279 | if (newStyle) { | ||
251 | newStyleLoaded = true; | 280 | newStyleLoaded = true; | ||
252 | m_previousStyle = m_settings->widgetStyle(); | 281 | m_previousStyle = m_settings->widgetStyle(); | ||
Show All 32 Lines | 310 | if (m_effectsDirty) { | |||
285 | KGlobalSettings::self()->emitChange(KGlobalSettings::ToolbarStyleChanged); | 314 | KGlobalSettings::self()->emitChange(KGlobalSettings::ToolbarStyleChanged); | ||
286 | } | 315 | } | ||
287 | 316 | | |||
288 | m_effectsDirty = false; | 317 | m_effectsDirty = false; | ||
289 | } | 318 | } | ||
290 | 319 | | |||
291 | void KCMStyle::defaults() | 320 | void KCMStyle::defaults() | ||
292 | { | 321 | { | ||
322 | if (m_gtkPage) { | ||||
323 | m_gtkPage->defaults(); | ||||
324 | } | ||||
325 | | ||||
293 | // TODO the old code had a fallback chain but do we actually support not having Breeze for Plasma? | 326 | // TODO the old code had a fallback chain but do we actually support not having Breeze for Plasma? | ||
294 | // defaultStyle() -> oxygen -> plastique -> windows -> platinum -> motif | 327 | // defaultStyle() -> oxygen -> plastique -> windows -> platinum -> motif | ||
295 | 328 | | |||
296 | ManagedConfigModule::defaults(); | 329 | ManagedConfigModule::defaults(); | ||
297 | 330 | | |||
298 | loadSettingsToModel(); | 331 | loadSettingsToModel(); | ||
299 | } | 332 | } | ||
300 | 333 | | |||
Show All 10 Lines |