From c63336c7cd5cf78f86cd0163900c22724a2f80d1 Mon Sep 17 00:00:00 2001 From: Nicolas Fella Date: Thu, 25 Aug 2022 15:30:44 +0200 Subject: [PATCH] [kcms/style] Consider GTK theme setting when computing default state The GTK theme name is not managed by KConfigXT, we need to manually track that when determining whether the Defaults button is enabled BUG: 458292 (cherry picked from commit 05f21f51ba12ae0e5398f8b5bc1e382ce7d5ab39) --- kcms/style/gtkpage.cpp | 6 ++++++ kcms/style/gtkpage.h | 1 + kcms/style/kcmstyle.cpp | 32 +++++++++++++++----------------- kcms/style/kcmstyle.h | 4 +++- 4 files changed, 25 insertions(+), 18 deletions(-) diff --git a/kcms/style/gtkpage.cpp b/kcms/style/gtkpage.cpp index 134cc39e3..4f96836f2 100644 --- a/kcms/style/gtkpage.cpp +++ b/kcms/style/gtkpage.cpp @@ -100,5 +100,11 @@ void GtkPage::defaults() void GtkPage::load() { m_gtkThemesModel->load(); + m_gtkThemesModel->setSelectedTheme(m_gtkConfigInterface.gtkTheme()); Q_EMIT selectGtkThemeInCombobox(gtkThemeFromConfig()); } + +bool GtkPage::isDefaults() const +{ + return m_gtkThemesModel->selectedTheme() == QLatin1String("Breeze"); +} diff --git a/kcms/style/gtkpage.h b/kcms/style/gtkpage.h index eda301a7c..efcdd7259 100644 --- a/kcms/style/gtkpage.h +++ b/kcms/style/gtkpage.h @@ -26,6 +26,7 @@ public: Q_INVOKABLE void load(); void save(); void defaults(); + bool isDefaults() const; public Q_SLOTS: QString gtkThemeFromConfig(); diff --git a/kcms/style/kcmstyle.cpp b/kcms/style/kcmstyle.cpp index 778bdc1b2..545a62192 100644 --- a/kcms/style/kcmstyle.cpp +++ b/kcms/style/kcmstyle.cpp @@ -87,19 +87,18 @@ KCMStyle::KCMStyle(QObject *parent, const KPluginMetaData &data, const QVariantL connect(styleSettings(), &StyleSettings::iconsInMenusChanged, this, [this] { m_effectsDirty = true; }); + + m_gtkPage = new GtkPage(this); + connect(m_gtkPage, &GtkPage::gtkThemeSettingsChanged, this, [this]() { + settingsChanged(); + setNeedsSave(true); + }); } KCMStyle::~KCMStyle() = default; -GtkPage *KCMStyle::gtkPage() +GtkPage *KCMStyle::gtkPage() const { - if (!m_gtkPage) { - m_gtkPage = new GtkPage(this); - connect(m_gtkPage, &GtkPage::gtkThemeSettingsChanged, this, [this]() { - setNeedsSave(true); - }); - } - return m_gtkPage; } @@ -249,9 +248,7 @@ void KCMStyle::load() { checkGtkConfigKdedModuleLoaded(); - if (m_gtkPage) { - m_gtkPage->load(); - } + m_gtkPage->load(); ManagedConfigModule::load(); m_model->load(); @@ -264,9 +261,7 @@ void KCMStyle::load() void KCMStyle::save() { - if (m_gtkPage) { - m_gtkPage->save(); - } + m_gtkPage->save(); // Check whether the new style can actually be loaded before saving it. // Otherwise apps will use the default style despite something else having been written to the config @@ -320,9 +315,7 @@ void KCMStyle::save() void KCMStyle::defaults() { - if (m_gtkPage) { - m_gtkPage->defaults(); - } + m_gtkPage->defaults(); // TODO the old code had a fallback chain but do we actually support not having Breeze for Plasma? // defaultStyle() -> oxygen -> plastique -> windows -> platinum -> motif @@ -341,4 +334,9 @@ void KCMStyle::loadSettingsToModel() setOtherToolBarStyle(static_cast(toolBarStyleEnum.keyToValue(qUtf8Printable(styleSettings()->toolButtonStyleOtherToolbars())))); } +bool KCMStyle::isDefaults() const +{ + return m_gtkPage->isDefaults(); +} + #include "kcmstyle.moc" diff --git a/kcms/style/kcmstyle.h b/kcms/style/kcmstyle.h index 723188d4a..05ed04071 100644 --- a/kcms/style/kcmstyle.h +++ b/kcms/style/kcmstyle.h @@ -52,7 +52,7 @@ public: }; Q_ENUM(ToolBarStyle) - GtkPage *gtkPage(); + GtkPage *gtkPage() const; StylesModel *model() const; @@ -75,6 +75,8 @@ public: void save() override; void defaults() override; + bool isDefaults() const override; + Q_SIGNALS: void showErrorMessage(const QString &message); void styleReconfigured(const QString &styleName);