From fbbaab3eafc32bac5635be729e59137edb067710 Mon Sep 17 00:00:00 2001 From: Aleix Pol Date: Fri, 9 Jun 2023 19:04:34 +0200 Subject: [PATCH] kcm/decoration: Allow specifying the kcm separately from the decoration It makes decorations lighter as they don't need to bundle its configuration logic. Deprecates the kcmodule property in favour of kcmoduleName which instead of assuming that the kcm is local to the plugin, it provides the plugin name to find and load. --- .../fakedecoration_with_shadows.json | 3 +-- .../declarative-plugin/previewbridge.cpp | 27 +++++++++++++++++-- .../declarative-plugin/previewbridge.h | 15 +++++++++++ src/kcms/decoration/decorationmodel.cpp | 21 +++++++-------- src/kcms/decoration/decorationmodel.h | 1 + src/kcms/decoration/ui/Themes.qml | 1 + .../kdecorations/aurorae/src/aurorae.cpp | 8 ++++-- .../kdecorations/aurorae/src/aurorae.json | 9 ++++--- 8 files changed, 64 insertions(+), 21 deletions(-) diff --git a/autotests/integration/fakes/org.kde.kdecoration2/fakedecoration_with_shadows.json b/autotests/integration/fakes/org.kde.kdecoration2/fakedecoration_with_shadows.json index ab3fe21dc1..028fc62f79 100644 --- a/autotests/integration/fakes/org.kde.kdecoration2/fakedecoration_with_shadows.json +++ b/autotests/integration/fakes/org.kde.kdecoration2/fakedecoration_with_shadows.json @@ -6,7 +6,6 @@ "Name": "Fake Decoration With Shadows" }, "org.kde.kdecoration2": { - "blur": false, - "kcmodule": false + "blur": false } } diff --git a/src/kcms/decoration/declarative-plugin/previewbridge.cpp b/src/kcms/decoration/declarative-plugin/previewbridge.cpp index 8adf797cd6..43d9095afb 100644 --- a/src/kcms/decoration/declarative-plugin/previewbridge.cpp +++ b/src/kcms/decoration/declarative-plugin/previewbridge.cpp @@ -33,6 +33,7 @@ namespace Preview { static const QString s_pluginName = QStringLiteral("org.kde.kdecoration2"); +static const QString s_kcmName = QStringLiteral("org.kde.kdecoration2.kcm"); PreviewBridge::PreviewBridge(QObject *parent) : DecorationBridge(parent) @@ -92,6 +93,20 @@ void PreviewBridge::setTheme(const QString &theme) Q_EMIT themeChanged(); } +QString PreviewBridge::kcmoduleName() const +{ + return m_kcmoduleName; +} + +void PreviewBridge::setKcmoduleName(const QString &kcmoduleName) +{ + if (m_kcmoduleName == kcmoduleName) { + return; + } + m_kcmoduleName = kcmoduleName; + Q_EMIT themeChanged(); +} + QString PreviewBridge::plugin() const { return m_plugin; @@ -155,6 +170,7 @@ DecorationButton *PreviewBridge::createButton(KDecoration2::Decoration *decorati void PreviewBridge::configure(QQuickItem *ctx) { if (!m_valid) { + qWarning() << "Cannot show an invalid decoration's configuration dialog"; return; } // setup the UI @@ -169,10 +185,16 @@ void PreviewBridge::configure(QQuickItem *ctx) if (!m_theme.isNull()) { args.insert(QStringLiteral("theme"), m_theme); } + Q_ASSERT(!m_kcmoduleName.isEmpty()); + const auto md = KPluginMetaData::findPluginById(s_kcmName, m_kcmoduleName); + const auto result = KPluginFactory::instantiatePlugin(md, dialog, QVariantList({args})); + if (!result) { + qWarning() << "error loading kcm" << result.errorReason << result.errorText; + } - KCModule *kcm = m_factory->create(dialog, QVariantList({args})); - + KCModule *kcm = result.plugin; if (!kcm) { + qWarning() << "Could not find the kcm for" << args << m_kcmoduleName << m_theme; return; } @@ -223,6 +245,7 @@ BridgeItem::BridgeItem(QObject *parent) connect(m_bridge, &PreviewBridge::themeChanged, this, &BridgeItem::themeChanged); connect(m_bridge, &PreviewBridge::pluginChanged, this, &BridgeItem::pluginChanged); connect(m_bridge, &PreviewBridge::validChanged, this, &BridgeItem::validChanged); + connect(m_bridge, &PreviewBridge::kcmoduleNameChanged, this, &BridgeItem::kcmoduleNameChanged); } BridgeItem::~BridgeItem() diff --git a/src/kcms/decoration/declarative-plugin/previewbridge.h b/src/kcms/decoration/declarative-plugin/previewbridge.h index b1a5f8393f..4801c044fe 100644 --- a/src/kcms/decoration/declarative-plugin/previewbridge.h +++ b/src/kcms/decoration/declarative-plugin/previewbridge.h @@ -29,6 +29,7 @@ class PreviewBridge : public DecorationBridge Q_OBJECT Q_PROPERTY(QString plugin READ plugin WRITE setPlugin NOTIFY pluginChanged) Q_PROPERTY(QString theme READ theme WRITE setTheme NOTIFY themeChanged) + Q_PROPERTY(QString kcmoduleName READ kcmoduleName WRITE setKcmoduleName NOTIFY kcmoduleNameChanged) Q_PROPERTY(bool valid READ isValid NOTIFY validChanged) public: explicit PreviewBridge(QObject *parent = nullptr); @@ -50,6 +51,8 @@ public: void setPlugin(const QString &plugin); QString plugin() const; + void setKcmoduleName(const QString &name); + QString kcmoduleName() const; void setTheme(const QString &theme); QString theme() const; bool isValid() const; @@ -64,6 +67,7 @@ Q_SIGNALS: void pluginChanged(); void themeChanged(); void validChanged(); + void kcmoduleNameChanged(); private: void createFactory(); @@ -73,6 +77,7 @@ private: QList m_previewItems; QString m_plugin; QString m_theme; + QString m_kcmoduleName; QPointer m_factory; bool m_valid; }; @@ -82,6 +87,7 @@ class BridgeItem : public QObject Q_OBJECT Q_PROPERTY(QString plugin READ plugin WRITE setPlugin NOTIFY pluginChanged) Q_PROPERTY(QString theme READ theme WRITE setTheme NOTIFY themeChanged) + Q_PROPERTY(QString kcmoduleName READ kcmoduleName WRITE setKcmoduleName NOTIFY kcmoduleNameChanged) Q_PROPERTY(bool valid READ isValid NOTIFY validChanged) Q_PROPERTY(KDecoration2::Preview::PreviewBridge *bridge READ bridge CONSTANT) @@ -101,6 +107,14 @@ public: { m_bridge->setTheme(theme); } + QString kcmoduleName() const + { + return m_bridge->kcmoduleName(); + } + void setKcmoduleName(const QString &name) + { + m_bridge->setKcmoduleName(name); + } QString theme() const { return m_bridge->theme(); @@ -118,6 +132,7 @@ public: Q_SIGNALS: void pluginChanged(); void themeChanged(); + void kcmoduleNameChanged(); void validChanged(); private: diff --git a/src/kcms/decoration/decorationmodel.cpp b/src/kcms/decoration/decorationmodel.cpp index 640b1238ce..7beb62f6d2 100644 --- a/src/kcms/decoration/decorationmodel.cpp +++ b/src/kcms/decoration/decorationmodel.cpp @@ -50,7 +50,9 @@ QVariant DecorationsModel::data(const QModelIndex &index, int role) const case ThemeNameRole: return d.themeName(); case ConfigurationRole: - return d.hasConfiguration(); + return !d.configurationName().isEmpty(); + case KcmoduleNameRole: + return d.configurationName(); case RecommendedBorderSizeRole: return Utils::borderSizeToString(d.borderSize()); } @@ -63,6 +65,7 @@ QHash DecorationsModel::roleNames() const {PluginNameRole, QByteArrayLiteral("plugin")}, {ThemeNameRole, QByteArrayLiteral("theme")}, {ConfigurationRole, QByteArrayLiteral("configureable")}, + {KcmoduleNameRole, QByteArrayLiteral("kcmoduleName")}, {RecommendedBorderSizeRole, QByteArrayLiteral("recommendedbordersize")}}); return roles; } @@ -76,15 +79,6 @@ static bool isThemeEngine(const QVariantMap &decoSettingsMap) return it.value().toBool(); } -static bool isConfigureable(const QVariantMap &decoSettingsMap) -{ - auto it = decoSettingsMap.find(QStringLiteral("kcmodule")); - if (it == decoSettingsMap.end()) { - return false; - } - return it.value().toBool(); -} - static KDecoration2::BorderSize recommendedBorderSize(const QVariantMap &decoSettingsMap) { auto it = decoSettingsMap.find(QStringLiteral("recommendedBorderSize")); @@ -142,7 +136,12 @@ void DecorationsModel::init() continue; } } - data.setHasConfiguration(isConfigureable(decoSettingsMap)); + + if (decoSettingsMap.contains(QStringLiteral("kcmodule"))) { + qWarning() << "The use of 'kcmodule' is deprecated in favor of 'kcmoduleName', please update" << info.name(); + } + + data.setConfigurationName(info.value("X-KDE-ConfigModule")); data.setBorderSize(recommendedBorderSize(decoSettingsMap)); data.setVisibleName(info.name().isEmpty() ? info.pluginId() : info.name()); data.setPluginId(info.pluginId()); diff --git a/src/kcms/decoration/decorationmodel.h b/src/kcms/decoration/decorationmodel.h index a22fd70e70..a52e4c7807 100644 --- a/src/kcms/decoration/decorationmodel.h +++ b/src/kcms/decoration/decorationmodel.h @@ -25,6 +25,7 @@ public: ThemeNameRole, ConfigurationRole, RecommendedBorderSizeRole, + KcmoduleNameRole, }; public: diff --git a/src/kcms/decoration/ui/Themes.qml b/src/kcms/decoration/ui/Themes.qml index c9d6a5b29b..bc31342e51 100644 --- a/src/kcms/decoration/ui/Themes.qml +++ b/src/kcms/decoration/ui/Themes.qml @@ -42,6 +42,7 @@ KCM.GridView { id: bridgeItem plugin: model.plugin theme: model.theme + kcmoduleName: model.kcmoduleName } KDecoration.Settings { id: settingsItem diff --git a/src/plugins/kdecorations/aurorae/src/aurorae.cpp b/src/plugins/kdecorations/aurorae/src/aurorae.cpp index e7164e1ffd..1ef5de6e9d 100644 --- a/src/plugins/kdecorations/aurorae/src/aurorae.cpp +++ b/src/plugins/kdecorations/aurorae/src/aurorae.cpp @@ -617,7 +617,9 @@ void ThemeProvider::findAllQmlThemes() data.setPluginId(m_data.pluginId()); data.setThemeName(offer.pluginId()); data.setVisibleName(offer.name()); - data.setHasConfiguration(hasConfiguration(offer.pluginId())); + if (hasConfiguration(offer.pluginId())) { + data.setConfigurationName("kwin_aurorae_config"); + } m_themes.append(data); } } @@ -654,7 +656,9 @@ void ThemeProvider::findAllSvgThemes() data.setPluginId(m_data.pluginId()); data.setThemeName(QLatin1String("__aurorae__svg__") + packageName); data.setVisibleName(name); - data.setHasConfiguration(hasConfiguration(data.themeName())); + if (hasConfiguration(data.themeName())) { + data.setConfigurationName("kwin_aurorae_config"); + } m_themes.append(data); } } diff --git a/src/plugins/kdecorations/aurorae/src/aurorae.json b/src/plugins/kdecorations/aurorae/src/aurorae.json index 78555b266c..344881e108 100644 --- a/src/plugins/kdecorations/aurorae/src/aurorae.json +++ b/src/plugins/kdecorations/aurorae/src/aurorae.json @@ -1,8 +1,9 @@ { "org.kde.kdecoration2": { - "KNewStuff": "aurorae.knsrc", - "defaultTheme": "kwin4_decoration_qml_plastik", - "themeListKeyword": "themes", + "KNewStuff": "aurorae.knsrc", + "defaultTheme": "kwin4_decoration_qml_plastik", + "themeListKeyword": "themes", "themes": true - } + }, + "X-KDE-ConfigModule": "kwin4_decoration_qml_plastik" }