diff --git a/src/kcmkwin/kwindecoration/decorationmodel.cpp b/src/kcmkwin/kwindecoration/decorationmodel.cpp index 88d0f20f17..ec3351f71d 100644 --- a/src/kcmkwin/kwindecoration/decorationmodel.cpp +++ b/src/kcmkwin/kwindecoration/decorationmodel.cpp @@ -5,8 +5,9 @@ */ #include "decorationmodel.h" // KDecoration2 -#include #include +#include +#include // KDE #include #include @@ -41,18 +42,18 @@ QVariant DecorationsModel::data(const QModelIndex &index, int role) const if (!index.isValid() || index.column() != 0 || index.row() < 0 || index.row() >= int(m_plugins.size())) { return QVariant(); } - const Data &d = m_plugins.at(index.row()); + const KDecoration2::DecorationThemeMetaData &d = m_plugins.at(index.row()); switch (role) { case Qt::DisplayRole: - return d.visibleName; + return d.visibleName(); case PluginNameRole: - return d.pluginName; + return d.pluginId(); case ThemeNameRole: - return d.themeName; + return d.themeName(); case ConfigurationRole: - return d.configuration; + return d.hasConfiguration(); case RecommendedBorderSizeRole: - return Utils::borderSizeToString(d.recommendedBorderSize); + return Utils::borderSizeToString(d.borderSize()); } return QVariant(); } @@ -118,17 +119,13 @@ void DecorationsModel::init() { beginResetModel(); m_plugins.clear(); - const auto plugins = KPluginLoader::findPlugins(s_pluginName); + const auto plugins = KPluginMetaData::findPlugins(s_pluginName); for (const auto &info : plugins) { - KPluginLoader loader(info.fileName()); - KPluginFactory *factory = loader.factory(); - if (!factory) { - continue; - } - auto metadata = loader.metaData().value(QStringLiteral("MetaData")).toObject().value(s_pluginName); - Data data; - if (!metadata.isUndefined()) { - const auto decoSettingsMap = metadata.toObject().toVariantMap(); + QScopedPointer themeFinder( + KPluginFactory::instantiatePlugin(info).plugin); + KDecoration2::DecorationThemeMetaData data; + if (themeFinder) { + const auto decoSettingsMap = info.rawData().value("org.kde.kdecoration2").toObject().toVariantMap(); const QString &kns = findKNewStuff(decoSettingsMap); if (!kns.isEmpty() && !m_knsProviders.contains(kns)) { m_knsProviders.append(kns); @@ -139,35 +136,20 @@ void DecorationsModel::init() // We cannot list the themes continue; } - QScopedPointer themeFinder(factory->create(keyword)); - if (themeFinder.isNull()) { - continue; - } - QVariant themes = themeFinder->property("themes"); - if (!themes.isValid()) { - continue; - } - const auto themesMap = themes.toMap(); - for (auto it = themesMap.begin(); it != themesMap.end(); ++it) { - Data d; - d.pluginName = info.pluginId(); - d.themeName = it.value().toString(); - d.visibleName = it.key(); - QMetaObject::invokeMethod(themeFinder.data(), "hasConfiguration", - Q_RETURN_ARG(bool, d.configuration), - Q_ARG(QString, d.themeName)); - m_plugins.emplace_back(std::move(d)); + const auto themesList = themeFinder->themes(); + for (const KDecoration2::DecorationThemeMetaData &data : themesList) { + m_plugins.emplace_back(data); } // it's a theme engine, we don't want to show this entry continue; } - data.configuration = isConfigureable(decoSettingsMap); - data.recommendedBorderSize = recommendedBorderSize(decoSettingsMap); + data.setHasConfiguration(isConfigureable(decoSettingsMap)); + data.setBorderSize(recommendedBorderSize(decoSettingsMap)); } - data.pluginName = info.pluginId(); - data.visibleName = info.name().isEmpty() ? info.pluginId() : info.name(); - data.themeName = data.visibleName; + data.setVisibleName(info.name().isEmpty() ? info.pluginId() : info.name()); + data.setPluginId(info.pluginId()); + data.setThemeName(data.visibleName()); m_plugins.emplace_back(std::move(data)); } @@ -176,11 +158,9 @@ void DecorationsModel::init() QModelIndex DecorationsModel::findDecoration(const QString &pluginName, const QString &themeName) const { - auto it = std::find_if(m_plugins.cbegin(), m_plugins.cend(), - [pluginName, themeName](const Data &d) { - return d.pluginName == pluginName && d.themeName == themeName; - } - ); + auto it = std::find_if(m_plugins.cbegin(), m_plugins.cend(), [pluginName, themeName](const KDecoration2::DecorationThemeMetaData &d) { + return d.pluginId() == pluginName && d.themeName() == themeName; + }); if (it == m_plugins.cend()) { return QModelIndex(); } diff --git a/src/kcmkwin/kwindecoration/decorationmodel.h b/src/kcmkwin/kwindecoration/decorationmodel.h index 31843bec1e..203fedcf10 100644 --- a/src/kcmkwin/kwindecoration/decorationmodel.h +++ b/src/kcmkwin/kwindecoration/decorationmodel.h @@ -8,6 +8,7 @@ #include "utils.h" +#include #include namespace KDecoration2 @@ -45,14 +46,7 @@ public Q_SLOTS: void init(); private: - struct Data { - QString pluginName; - QString themeName; - QString visibleName; - bool configuration = false; - KDecoration2::BorderSize recommendedBorderSize = KDecoration2::BorderSize::Normal; - }; - std::vector m_plugins; + std::vector m_plugins; QStringList m_knsProviders; }; diff --git a/src/plugins/kdecorations/aurorae/src/aurorae.cpp b/src/plugins/kdecorations/aurorae/src/aurorae.cpp index e0df405ef2..7bb812dd56 100644 --- a/src/plugins/kdecorations/aurorae/src/aurorae.cpp +++ b/src/plugins/kdecorations/aurorae/src/aurorae.cpp @@ -49,10 +49,11 @@ K_PLUGIN_FACTORY_WITH_JSON(AuroraeDecoFactory, "aurorae.json", registerPlugin(); - registerPlugin(QStringLiteral("themes")); - registerPlugin(QStringLiteral("kcmodule")); + registerPlugin(); + registerPlugin(); ) + namespace Aurorae { @@ -600,28 +601,33 @@ KDecoration2::DecoratedClient *Decoration::clientPointer() const return client().toStrongRef().data(); } -ThemeFinder::ThemeFinder(QObject *parent, const QVariantList &args) - : QObject(parent) +ThemeProvider::ThemeProvider(QObject *parent, const KPluginMetaData &data, const QVariantList &args) + : KDecoration2::DecorationThemeProvider(parent, data, args) + , m_data(data) { - Q_UNUSED(args) init(); } -void ThemeFinder::init() +void ThemeProvider::init() { findAllQmlThemes(); findAllSvgThemes(); } -void ThemeFinder::findAllQmlThemes() +void ThemeProvider::findAllQmlThemes() { const auto offers = KPackage::PackageLoader::self()->findPackages(QStringLiteral("KWin/Decoration"), s_qmlPackageFolder); for (const auto &offer : offers) { - m_themes.insert(offer.name(), offer.pluginId()); + KDecoration2::DecorationThemeMetaData data; + data.setPluginId(m_data.pluginId()); + data.setThemeName(offer.pluginId()); + data.setVisibleName(offer.name()); + data.setHasConfiguration(hasConfiguration(offer.pluginId())); + m_themes.append(data); } } -void ThemeFinder::findAllSvgThemes() +void ThemeProvider::findAllSvgThemes() { QStringList themes; const QStringList dirs = QStandardPaths::locateAll(QStandardPaths::GenericDataLocation, QStringLiteral("aurorae/themes/"), QStandardPaths::LocateDirectory); @@ -649,14 +655,19 @@ void ThemeFinder::findAllSvgThemes() name = packageName; } - m_themes.insert(name, QString(QLatin1String("__aurorae__svg__") + packageName)); + KDecoration2::DecorationThemeMetaData data; + data.setPluginId(m_data.pluginId()); + data.setThemeName(QLatin1String("__aurorae__svg__") + packageName); + data.setVisibleName(name); + data.setHasConfiguration(hasConfiguration(data.themeName())); + m_themes.append(data); } } static const QString s_configUiPath = QStringLiteral("kwin/decorations/%1/contents/ui/config.ui"); static const QString s_configXmlPath = QStringLiteral("kwin/decorations/%1/contents/config/main.xml"); -bool ThemeFinder::hasConfiguration(const QString &theme) const +bool ThemeProvider::hasConfiguration(const QString &theme) { if (theme.startsWith(QLatin1String("__aurorae__svg__"))) { return true; diff --git a/src/plugins/kdecorations/aurorae/src/aurorae.h b/src/plugins/kdecorations/aurorae/src/aurorae.h index 035aaee79f..6df257e6d1 100644 --- a/src/plugins/kdecorations/aurorae/src/aurorae.h +++ b/src/plugins/kdecorations/aurorae/src/aurorae.h @@ -7,10 +7,12 @@ #ifndef AURORAE_H #define AURORAE_H +#include #include +#include +#include #include #include -#include class QQmlComponent; class QQmlContext; @@ -78,25 +80,24 @@ private: QElapsedTimer m_doubleClickTimer; }; -class ThemeFinder : public QObject +class ThemeProvider : public KDecoration2::DecorationThemeProvider { Q_OBJECT - Q_PROPERTY(QVariantMap themes READ themes) public: - explicit ThemeFinder(QObject *parent = nullptr, const QVariantList &args = QVariantList()); + explicit ThemeProvider(QObject *parent, const KPluginMetaData &data, const QVariantList &args); - QVariantMap themes() const { + QList themes() const override + { return m_themes; } -public Q_SLOTS: - bool hasConfiguration(const QString &theme) const; - private: void init(); void findAllQmlThemes(); void findAllSvgThemes(); - QVariantMap m_themes; + bool hasConfiguration(const QString &theme); + QList m_themes; + const KPluginMetaData m_data; }; class ConfigurationModule : public KCModule