Changeset View
Standalone View
kcms/style/kcmstyle.cpp
Show First 20 Lines • Show All 62 Lines • ▼ Show 20 Line(s) | 62 | { | |||
---|---|---|---|---|---|
63 | Q_DECL_EXPORT void kcminit_style() | 63 | Q_DECL_EXPORT void kcminit_style() | ||
64 | { | 64 | { | ||
65 | uint flags = KRdbExportQtSettings | KRdbExportGtkColors | KRdbExportQtColors | KRdbExportXftSettings | KRdbExportGtkTheme; | 65 | uint flags = KRdbExportQtSettings | KRdbExportGtkColors | KRdbExportQtColors | KRdbExportXftSettings | KRdbExportGtkTheme; | ||
66 | KConfig _config( QStringLiteral("kcmdisplayrc"), KConfig::NoGlobals ); | 66 | KConfig _config( QStringLiteral("kcmdisplayrc"), KConfig::NoGlobals ); | ||
67 | KConfigGroup config(&_config, "X11"); | 67 | KConfigGroup config(&_config, "X11"); | ||
68 | 68 | | |||
69 | // This key is written by the "colors" module. | 69 | // This key is written by the "colors" module. | ||
70 | bool exportKDEColors = config.readEntry("exportKDEColors", true); | 70 | bool exportKDEColors = config.readEntry("exportKDEColors", true); | ||
71 | if (exportKDEColors) | 71 | if (exportKDEColors) { | ||
72 | flags |= KRdbExportColors; | 72 | flags |= KRdbExportColors; | ||
73 | } | ||||
73 | runRdb( flags ); | 74 | runRdb( flags ); | ||
74 | } | 75 | } | ||
75 | } | 76 | } | ||
76 | 77 | | |||
77 | KCMStyle::KCMStyle(QObject *parent, const QVariantList &args) | 78 | KCMStyle::KCMStyle(QObject *parent, const QVariantList &args) | ||
78 | : KQuickAddons::ConfigModule(parent, args) | 79 | : KQuickAddons::ManagedConfigModule(parent, args) | ||
79 | , m_settings(new StyleSettings(this)) | 80 | , m_settings(new StyleSettings(this)) | ||
80 | , m_model(new StylesModel(this)) | 81 | , m_model(new StylesModel(this)) | ||
81 | { | 82 | { | ||
82 | qmlRegisterUncreatableType<KCMStyle>("org.kde.private.kcms.style", 1, 0, "KCM", QStringLiteral("Cannot create instances of KCM")); | 83 | qmlRegisterUncreatableType<KCMStyle>("org.kde.private.kcms.style", 1, 0, "KCM", QStringLiteral("Cannot create instances of KCM")); | ||
83 | qmlRegisterType<StyleSettings>(); | 84 | qmlRegisterType<StyleSettings>(); | ||
84 | qmlRegisterType<StylesModel>(); | 85 | qmlRegisterType<StylesModel>(); | ||
85 | qmlRegisterType<PreviewItem>("org.kde.private.kcms.style", 1, 0, "PreviewItem"); | 86 | qmlRegisterType<PreviewItem>("org.kde.private.kcms.style", 1, 0, "PreviewItem"); | ||
86 | 87 | | |||
87 | KAboutData *about = | 88 | KAboutData *about = | ||
88 | new KAboutData( QStringLiteral("kcm_style"), i18n("Application Style"), QStringLiteral("2.0"), | 89 | new KAboutData( QStringLiteral("kcm_style"), i18n("Application Style"), QStringLiteral("2.0"), | ||
89 | QString(), KAboutLicense::GPL, | 90 | QString(), KAboutLicense::GPL, | ||
90 | i18n("(c) 2002 Karol Szwed, Daniel Molkentin, (c) 2019 Kai Uwe Broulik")); | 91 | i18n("(c) 2002 Karol Szwed, Daniel Molkentin, (c) 2019 Kai Uwe Broulik")); | ||
91 | 92 | | |||
92 | about->addAuthor(i18n("Karol Szwed"), QString(), QStringLiteral("gallium@kde.org")); | 93 | about->addAuthor(i18n("Karol Szwed"), QString(), QStringLiteral("gallium@kde.org")); | ||
93 | about->addAuthor(i18n("Daniel Molkentin"), QString(), QStringLiteral("molkentin@kde.org")); | 94 | about->addAuthor(i18n("Daniel Molkentin"), QString(), QStringLiteral("molkentin@kde.org")); | ||
94 | about->addAuthor(i18n("Kai Uwe Broulik"), QString(), QStringLiteral("kde@broulik.de")); | 95 | about->addAuthor(i18n("Kai Uwe Broulik"), QString(), QStringLiteral("kde@broulik.de")); | ||
95 | setAboutData(about); | 96 | setAboutData(about); | ||
96 | 97 | | |||
97 | connect(m_model, &StylesModel::selectedStyleChanged, this, [this] { | 98 | connect(m_model, &StylesModel::selectedStyleChanged, this, [this](const QString &style) { | ||
98 | m_selectedStyleDirty = true; | 99 | m_settings->setWidgetStyle(style); | ||
99 | setNeedsSave(true); | 100 | }); | ||
101 | connect(m_settings, &StyleSettings::widgetStyleChanged, this, [this] { | ||||
102 | m_model->setSelectedStyle(m_settings->widgetStyle()); | ||||
ervin: Space before &, not after. | |||||
crossi: Will fix | |||||
100 | }); | 103 | }); | ||
101 | connect(m_settings, &StyleSettings::iconsOnButtonsChanged, this, [this] { | 104 | connect(m_settings, &StyleSettings::iconsOnButtonsChanged, this, [this] { | ||
102 | m_effectsDirty = true; | 105 | m_effectsDirty = true; | ||
103 | setNeedsSave(true); | | |||
104 | }); | 106 | }); | ||
105 | connect(m_settings, &StyleSettings::iconsInMenusChanged, this, [this] { | 107 | connect(m_settings, &StyleSettings::iconsInMenusChanged, this, [this] { | ||
106 | m_effectsDirty = true; | 108 | m_effectsDirty = true; | ||
107 | setNeedsSave(true); | | |||
108 | }); | 109 | }); | ||
109 | } | 110 | } | ||
110 | 111 | | |||
111 | KCMStyle::~KCMStyle() = default; | 112 | KCMStyle::~KCMStyle() = default; | ||
112 | 113 | | |||
113 | StylesModel *KCMStyle::model() const | 114 | StylesModel *KCMStyle::model() const | ||
114 | { | 115 | { | ||
115 | return m_model; | 116 | return m_model; | ||
Show All 10 Lines | |||||
126 | } | 127 | } | ||
127 | 128 | | |||
128 | void KCMStyle::setMainToolBarStyle(ToolBarStyle style) | 129 | void KCMStyle::setMainToolBarStyle(ToolBarStyle style) | ||
129 | { | 130 | { | ||
130 | if (m_mainToolBarStyle != style) { | 131 | if (m_mainToolBarStyle != style) { | ||
131 | m_mainToolBarStyle = style; | 132 | m_mainToolBarStyle = style; | ||
132 | emit mainToolBarStyleChanged(); | 133 | emit mainToolBarStyleChanged(); | ||
133 | 134 | | |||
135 | const QMetaEnum toolBarStyleEnum = QMetaEnum::fromType<ToolBarStyle>(); | ||||
136 | m_settings->setToolButtonStyle(toolBarStyleEnum.valueToKey(m_mainToolBarStyle)); | ||||
134 | m_effectsDirty = true; | 137 | m_effectsDirty = true; | ||
135 | setNeedsSave(true); | | |||
136 | } | 138 | } | ||
137 | } | 139 | } | ||
138 | 140 | | |||
139 | KCMStyle::ToolBarStyle KCMStyle::otherToolBarStyle() const | 141 | KCMStyle::ToolBarStyle KCMStyle::otherToolBarStyle() const | ||
140 | { | 142 | { | ||
141 | return m_otherToolBarStyle; | 143 | return m_otherToolBarStyle; | ||
142 | } | 144 | } | ||
143 | 145 | | |||
144 | void KCMStyle::setOtherToolBarStyle(ToolBarStyle style) | 146 | void KCMStyle::setOtherToolBarStyle(ToolBarStyle style) | ||
145 | { | 147 | { | ||
146 | if (m_otherToolBarStyle != style) { | 148 | if (m_otherToolBarStyle != style) { | ||
147 | m_otherToolBarStyle = style; | 149 | m_otherToolBarStyle = style; | ||
148 | emit otherToolBarStyleChanged(); | 150 | emit otherToolBarStyleChanged(); | ||
149 | 151 | | |||
152 | const QMetaEnum toolBarStyleEnum = QMetaEnum::fromType<ToolBarStyle>(); | ||||
153 | m_settings->setToolButtonStyleOtherToolbars(toolBarStyleEnum.valueToKey(m_otherToolBarStyle)); | ||||
150 | m_effectsDirty = true; | 154 | m_effectsDirty = true; | ||
151 | setNeedsSave(true); | | |||
152 | } | 155 | } | ||
153 | } | 156 | } | ||
154 | 157 | | |||
155 | void KCMStyle::configure(const QString &styleName, QQuickItem *ctx) | 158 | void KCMStyle::configure(const QString &styleName, QQuickItem *ctx) | ||
156 | { | 159 | { | ||
157 | if (m_styleConfigDialog) { | 160 | if (m_styleConfigDialog) { | ||
158 | return; | 161 | return; | ||
159 | } | 162 | } | ||
▲ Show 20 Lines • Show All 52 Lines • ▼ Show 20 Line(s) | 211 | connect(m_styleConfigDialog.data(), &QDialog::accepted, this, [this, styleName] { | |||
212 | 215 | | |||
213 | // Force re-rendering of the preview, to apply settings | 216 | // Force re-rendering of the preview, to apply settings | ||
214 | emit styleReconfigured(styleName); | 217 | emit styleReconfigured(styleName); | ||
215 | 218 | | |||
216 | //For now, ask all KDE apps to recreate their styles to apply the setitngs | 219 | //For now, ask all KDE apps to recreate their styles to apply the setitngs | ||
217 | KGlobalSettings::self()->emitChange(KGlobalSettings::StyleChanged); | 220 | KGlobalSettings::self()->emitChange(KGlobalSettings::StyleChanged); | ||
218 | 221 | | |||
219 | // When user edited a style, assume they want to use it, too | 222 | // When user edited a style, assume they want to use it, too | ||
220 | m_model->setSelectedStyle(styleName); | 223 | m_settings->setWidgetStyle(styleName); | ||
221 | 224 | | |||
222 | // We call setStyleDirty here to make sure we force style re-creation | 225 | // We call setNeedsSave(true) here to make sure we force style re-creation | ||
223 | m_selectedStyleDirty = true; | | |||
224 | setNeedsSave(true); | 226 | setNeedsSave(true); | ||
225 | }); | 227 | }); | ||
226 | 228 | | |||
227 | m_styleConfigDialog->show(); | 229 | m_styleConfigDialog->show(); | ||
228 | } | 230 | } | ||
229 | 231 | | |||
230 | void KCMStyle::load() | 232 | void KCMStyle::load() | ||
231 | { | 233 | { | ||
234 | ManagedConfigModule::load(); | ||||
232 | m_model->load(); | 235 | m_model->load(); | ||
233 | 236 | m_previousStyle = m_settings->widgetStyle(); | |||
234 | m_settings->load(); | | |||
235 | 237 | | |||
236 | loadSettingsToModel(); | 238 | loadSettingsToModel(); | ||
237 | 239 | | |||
238 | m_selectedStyleDirty = false; | | |||
239 | m_effectsDirty = false; | 240 | m_effectsDirty = false; | ||
240 | setNeedsSave(false); | | |||
241 | } | 241 | } | ||
242 | 242 | | |||
243 | void KCMStyle::save() | 243 | void KCMStyle::save() | ||
244 | { | 244 | { | ||
245 | if (!m_selectedStyleDirty && !m_effectsDirty) { | | |||
AFAICT this is the only place where m_effectsDirty is read. So I think you can remove that flag altogether, which should bring further simplifications. ervin: AFAICT this is the only place where m_effectsDirty is read. So I think you can remove that flag… | |||||
m_effectsDirty is checked line 291, to trigger or not a refresh of all applications. This check before save is now useless, since if we can save, it means a modification has occured, style or effects. crossi: m_effectsDirty is checked line 291, to trigger or not a refresh of all applications.
This… | |||||
Not for this patch, but I still wonder if we could kill it. I think it'd be better to have it as a local variable whose value would be computed from the state of the relevant items in the settings object. This would remove the logic of maintaining an extra state exploited only in save(). Also "effectsDirty" is a weird name I think, it doesn't seem related to any concept of effects. ervin: Not for this patch, but I still wonder if we could kill it. I think it'd be better to have it… | |||||
246 | return; | | |||
247 | } | | |||
248 | | ||||
249 | // Check whether the new style can actually be loaded before saving it. | 245 | // Check whether the new style can actually be loaded before saving it. | ||
250 | // Otherwise apps will use the default style despite something else having been written to the config | 246 | // Otherwise apps will use the default style despite something else having been written to the config | ||
251 | bool newStyleLoaded = false; | 247 | bool newStyleLoaded = false; | ||
252 | if (m_selectedStyleDirty) { | 248 | if (m_settings->widgetStyle() != m_previousStyle) { | ||
Are you sure you need this m_previousStyle? I'd expect it to be exactly m_settings->widgetStyle(). ervin: Are you sure you need this m_previousStyle? I'd expect it to be exactly m_settings->widgetStyle… | |||||
m_model->selectedStyle() is bound to m_settings->widgetStyle() and vice versa, so I need to save previous state to allow a rollback. crossi: m_model->selectedStyle() is bound to m_settings->widgetStyle() and vice versa, so I need to… | |||||
As far as rollback goes (might not be enough in your case), wouldn't checking for isSaveNeeded() on the settings and rollbacking it all be enough? We can't rollback a single item though, I guess that would be the main limitation in your case... Maybe that's something to add to KConfigSkeletonItem? Answer might be no to both, I'm just looking for opportunities to simplify code in modules. :-) ervin: As far as rollback goes (might not be enough in your case), wouldn't checking for isSaveNeeded… | |||||
253 | QScopedPointer<QStyle> newStyle(QStyleFactory::create(m_model->selectedStyle())); | 249 | QScopedPointer<QStyle> newStyle(QStyleFactory::create(m_settings->widgetStyle())); | ||
254 | if (newStyle) { | 250 | if (newStyle) { | ||
255 | newStyleLoaded = true; | 251 | newStyleLoaded = true; | ||
252 | m_previousStyle = m_settings->widgetStyle(); | ||||
256 | } else { | 253 | } else { | ||
257 | const QString styleDisplay = m_model->data(m_model->index(m_model->selectedStyleIndex(), 0), Qt::DisplayRole).toString(); | 254 | const QString styleDisplay = m_model->data(m_model->index(m_model->indexOfStyle(m_settings->widgetStyle()), 0), Qt::DisplayRole).toString(); | ||
258 | emit showErrorMessage(i18n("Failed to apply selected style '%1'.", styleDisplay)); | 255 | emit showErrorMessage(i18n("Failed to apply selected style '%1'.", styleDisplay)); | ||
259 | } | | |||
260 | } | | |||
261 | 256 | | |||
262 | if (newStyleLoaded) { | 257 | // Reset selected style back to current in case of failure | ||
263 | m_settings->setWidgetStyle(m_model->selectedStyle()); | 258 | m_settings->setWidgetStyle(m_previousStyle); | ||
259 | } | ||||
264 | } | 260 | } | ||
265 | 261 | | |||
266 | const QMetaEnum toolBarStyleEnum = QMetaEnum::fromType<ToolBarStyle>(); | 262 | ManagedConfigModule::save(); | ||
267 | m_settings->setToolButtonStyle(toolBarStyleEnum.valueToKey(m_mainToolBarStyle)); | | |||
268 | m_settings->setToolButtonStyleOtherToolbars(toolBarStyleEnum.valueToKey(m_otherToolBarStyle)); | | |||
269 | | ||||
270 | m_settings->save(); | | |||
271 | 263 | | |||
272 | // Export the changes we made to qtrc, and update all qt-only | 264 | // Export the changes we made to qtrc, and update all qt-only | ||
273 | // applications on the fly, ensuring that we still follow the user's | 265 | // applications on the fly, ensuring that we still follow the user's | ||
274 | // export fonts/colors settings. | 266 | // export fonts/colors settings. | ||
275 | if (m_selectedStyleDirty || m_effectsDirty) { | | |||
276 | uint flags = KRdbExportQtSettings | KRdbExportGtkTheme; | 267 | uint flags = KRdbExportQtSettings | KRdbExportGtkTheme; | ||
277 | KConfig _kconfig( QStringLiteral("kcmdisplayrc"), KConfig::NoGlobals ); | 268 | KConfig _kconfig( QStringLiteral("kcmdisplayrc"), KConfig::NoGlobals ); | ||
278 | KConfigGroup kconfig(&_kconfig, "X11"); | 269 | KConfigGroup kconfig(&_kconfig, "X11"); | ||
279 | bool exportKDEColors = kconfig.readEntry("exportKDEColors", true); | 270 | bool exportKDEColors = kconfig.readEntry("exportKDEColors", true); | ||
280 | if (exportKDEColors) { | 271 | if (exportKDEColors) { | ||
281 | flags |= KRdbExportColors; | 272 | flags |= KRdbExportColors; | ||
282 | } | 273 | } | ||
283 | runRdb( flags ); | 274 | runRdb( flags ); | ||
284 | } | | |||
285 | 275 | | |||
286 | // Now allow KDE apps to reconfigure themselves. | 276 | // Now allow KDE apps to reconfigure themselves. | ||
287 | if (newStyleLoaded) { | 277 | if (newStyleLoaded) { | ||
288 | KGlobalSettings::self()->emitChange(KGlobalSettings::StyleChanged); | 278 | KGlobalSettings::self()->emitChange(KGlobalSettings::StyleChanged); | ||
289 | } | 279 | } | ||
290 | 280 | | |||
291 | if (m_effectsDirty) { | 281 | if (m_effectsDirty) { | ||
292 | KGlobalSettings::self()->emitChange(KGlobalSettings::SettingsChanged, KGlobalSettings::SETTINGS_STYLE); | 282 | KGlobalSettings::self()->emitChange(KGlobalSettings::SettingsChanged, KGlobalSettings::SETTINGS_STYLE); | ||
293 | // ##### FIXME - Doesn't apply all settings correctly due to bugs in | 283 | // ##### FIXME - Doesn't apply all settings correctly due to bugs in | ||
294 | // KApplication/KToolbar | 284 | // KApplication/KToolbar | ||
295 | KGlobalSettings::self()->emitChange(KGlobalSettings::ToolbarStyleChanged); | 285 | KGlobalSettings::self()->emitChange(KGlobalSettings::ToolbarStyleChanged); | ||
296 | } | 286 | } | ||
297 | 287 | | |||
298 | // Reset selected style back to current in case of failure | | |||
299 | if (!newStyleLoaded) { | | |||
300 | m_model->setSelectedStyle(m_settings->widgetStyle()); | | |||
301 | } | | |||
302 | | ||||
303 | m_selectedStyleDirty = false; | | |||
304 | m_effectsDirty = false; | 288 | m_effectsDirty = false; | ||
305 | } | 289 | } | ||
306 | 290 | | |||
307 | void KCMStyle::defaults() | 291 | void KCMStyle::defaults() | ||
308 | { | 292 | { | ||
309 | // TODO the old code had a fallback chain but do we actually support not having Breeze for Plasma? | 293 | // TODO the old code had a fallback chain but do we actually support not having Breeze for Plasma? | ||
310 | // defaultStyle() -> oxygen -> plastique -> windows -> platinum -> motif | 294 | // defaultStyle() -> oxygen -> plastique -> windows -> platinum -> motif | ||
311 | 295 | | |||
312 | m_settings->setDefaults(); | 296 | ManagedConfigModule::defaults(); | ||
313 | 297 | | |||
314 | loadSettingsToModel(); | 298 | loadSettingsToModel(); | ||
315 | | ||||
316 | setNeedsSave(m_settings->isSaveNeeded()); | | |||
317 | } | 299 | } | ||
318 | 300 | | |||
319 | void KCMStyle::loadSettingsToModel() | 301 | void KCMStyle::loadSettingsToModel() | ||
320 | { | 302 | { | ||
321 | m_model->setSelectedStyle(m_settings->widgetStyle()); | 303 | emit m_settings->widgetStyleChanged(); | ||
322 | 304 | | |||
323 | const QMetaEnum toolBarStyleEnum = QMetaEnum::fromType<ToolBarStyle>(); | 305 | const QMetaEnum toolBarStyleEnum = QMetaEnum::fromType<ToolBarStyle>(); | ||
324 | setMainToolBarStyle(static_cast<ToolBarStyle>(toolBarStyleEnum.keyToValue(qUtf8Printable(m_settings->toolButtonStyle())))); | 306 | setMainToolBarStyle(static_cast<ToolBarStyle>(toolBarStyleEnum.keyToValue(qUtf8Printable(m_settings->toolButtonStyle())))); | ||
325 | setOtherToolBarStyle(static_cast<ToolBarStyle>(toolBarStyleEnum.keyToValue(qUtf8Printable(m_settings->toolButtonStyleOtherToolbars())))); | 307 | setOtherToolBarStyle(static_cast<ToolBarStyle>(toolBarStyleEnum.keyToValue(qUtf8Printable(m_settings->toolButtonStyleOtherToolbars())))); | ||
326 | } | 308 | } | ||
327 | 309 | | |||
328 | #include "kcmstyle.moc" | 310 | #include "kcmstyle.moc" |
Space before &, not after.