From dffbfcc9f71d6246bd330ca97eb9d624176a5d11 Mon Sep 17 00:00:00 2001 From: Alexander Lohnau Date: Tue, 19 Oct 2021 21:39:51 +0200 Subject: [PATCH] Fully port away from KPluginLoader --- autotests/test_plugin_effectloader.cpp | 1 - autotests/test_x11_timestamp_update.cpp | 3 +-- src/composite.cpp | 1 - src/decorations/decorationbridge.cpp | 12 +++++------- src/effectloader.cpp | 5 ++--- src/kcmkwin/common/effectsmodel.cpp | 15 +++------------ .../declarative-plugin/previewbridge.cpp | 4 +--- src/kcmkwin/kwindecoration/decorationmodel.cpp | 1 - src/kcmkwin/kwinoptions/main.cpp | 1 - src/kcmkwin/kwintabbox/main.cpp | 10 +--------- src/main_wayland.cpp | 1 - src/main_x11.cpp | 1 - src/pluginmanager.cpp | 3 +-- 13 files changed, 14 insertions(+), 44 deletions(-) diff --git a/autotests/test_plugin_effectloader.cpp b/autotests/test_plugin_effectloader.cpp index eea5110325..87dd2a1cf1 100644 --- a/autotests/test_plugin_effectloader.cpp +++ b/autotests/test_plugin_effectloader.cpp @@ -12,7 +12,6 @@ // KDE #include #include -#include // Qt #include #include diff --git a/autotests/test_x11_timestamp_update.cpp b/autotests/test_x11_timestamp_update.cpp index 1210b51b6e..41830b172c 100644 --- a/autotests/test_x11_timestamp_update.cpp +++ b/autotests/test_x11_timestamp_update.cpp @@ -10,7 +10,6 @@ #include #include -#include #include #include "main.h" @@ -37,7 +36,7 @@ X11TestApplication::X11TestApplication(int &argc, char **argv) setX11Connection(QX11Info::connection()); setX11RootWindow(QX11Info::appRootWindow()); - // move directory containing executable to front, so that KPluginLoader prefers the plugins in + // move directory containing executable to front, so that KPluginMetaData::findPluginById prefers the plugins in // the build dir over system installed ones const auto ownPath = libraryPaths().last(); removeLibraryPath(ownPath); diff --git a/src/composite.cpp b/src/composite.cpp index 5d42c8a54f..0b767767ec 100644 --- a/src/composite.cpp +++ b/src/composite.cpp @@ -36,7 +36,6 @@ #include #include -#include #include #include #include diff --git a/src/decorations/decorationbridge.cpp b/src/decorations/decorationbridge.cpp index 7eecdc106d..2a689d6325 100644 --- a/src/decorations/decorationbridge.cpp +++ b/src/decorations/decorationbridge.cpp @@ -27,7 +27,6 @@ // Frameworks #include #include -#include // Qt #include @@ -143,13 +142,12 @@ void DecorationBridge::initPlugin() return; } qCDebug(KWIN_DECORATIONS) << "Trying to load decoration plugin: " << metaData.fileName(); - KPluginLoader loader(metaData.fileName()); - KPluginFactory *factory = loader.factory(); - if (!factory) { - qCWarning(KWIN_DECORATIONS) << "Error loading plugin:" << loader.errorString(); + auto factoryResult = KPluginFactory::loadFactory(metaData); + if (!factoryResult) { + qCWarning(KWIN_DECORATIONS) << "Error loading plugin:" << factoryResult.errorText; } else { - m_factory = factory; - loadMetaData(loader.metaData().value(QStringLiteral("MetaData")).toObject()); + m_factory = factoryResult.plugin; + loadMetaData(metaData.rawData()); } } diff --git a/src/effectloader.cpp b/src/effectloader.cpp index eca1f07275..627b7f27a1 100644 --- a/src/effectloader.cpp +++ b/src/effectloader.cpp @@ -16,7 +16,6 @@ #include "utils.h" // KDE #include -#include #include #include // Qt @@ -381,12 +380,12 @@ EffectPluginFactory *PluginEffectLoader::factory(const KPluginMetaData &info) co if (!info.isValid()) { return nullptr; } - KPluginLoader loader(info.fileName()); + QPluginLoader loader(info.fileName()); if (loader.metaData().value("IID").toString() != EffectPluginFactory_iid) { qCDebug(KWIN_CORE) << info.pluginId() << " has not matching plugin version, expected " << PluginFactory_iid << "got " << loader.metaData().value("IID"); return nullptr; } - KPluginFactory *factory = loader.factory(); + KPluginFactory *factory = qobject_cast(loader.instance()); if (!factory) { qCDebug(KWIN_CORE) << "Did not get KPluginFactory for " << info.pluginId(); return nullptr; diff --git a/src/kcmkwin/common/effectsmodel.cpp b/src/kcmkwin/common/effectsmodel.cpp index eb6cffea76..dc11ee6447 100644 --- a/src/kcmkwin/common/effectsmodel.cpp +++ b/src/kcmkwin/common/effectsmodel.cpp @@ -18,7 +18,6 @@ #include #include #include -#include #include #include #include @@ -630,21 +629,13 @@ static KCModule *loadBinaryConfig(const QString &configModule, QObject *parent) return nullptr; } - KPluginLoader loader(metaData.fileName()); - KPluginFactory *factory = loader.factory(); - - return factory->create(parent); + return KPluginFactory::instantiatePlugin(metaData, parent).plugin; } static KCModule *findScriptedConfig(const QString &pluginId, QObject *parent) { - KPluginLoader loader(QStringLiteral("kwin/effects/configs/kcm_kwin4_genericscripted")); - KPluginFactory *factory = loader.factory(); - if (!factory) { - return nullptr; - } - - return factory->create(parent, QVariantList{pluginId}); + KPluginMetaData metaData(QStringLiteral("kwin/effects/configs/kcm_kwin4_genericscripted")); + return KPluginFactory::instantiatePlugin(metaData, parent, QVariantList{pluginId}).plugin; } void EffectsModel::requestConfigure(const QModelIndex &index, QWindow *transientParent) diff --git a/src/kcmkwin/kwindecoration/declarative-plugin/previewbridge.cpp b/src/kcmkwin/kwindecoration/declarative-plugin/previewbridge.cpp index d702e33e66..913eef0705 100644 --- a/src/kcmkwin/kwindecoration/declarative-plugin/previewbridge.cpp +++ b/src/kcmkwin/kwindecoration/declarative-plugin/previewbridge.cpp @@ -12,7 +12,6 @@ #include #include -#include #include #include @@ -111,8 +110,7 @@ void PreviewBridge::createFactory() const auto offers = KPluginMetaData::findPlugins(s_pluginName); auto item = std::find_if(offers.constBegin(), offers.constEnd(), [this](const auto &plugin) { return plugin.pluginId() == m_plugin; }); if (item != offers.constEnd()) { - KPluginLoader loader(item->fileName()); - m_factory = loader.factory(); + m_factory = KPluginFactory::loadFactory(*item).plugin; } setValid(!m_factory.isNull()); diff --git a/src/kcmkwin/kwindecoration/decorationmodel.cpp b/src/kcmkwin/kwindecoration/decorationmodel.cpp index dd5e1594a6..d7ec832151 100644 --- a/src/kcmkwin/kwindecoration/decorationmodel.cpp +++ b/src/kcmkwin/kwindecoration/decorationmodel.cpp @@ -9,7 +9,6 @@ #include #include // KDE -#include #include #include // Qt diff --git a/src/kcmkwin/kwinoptions/main.cpp b/src/kcmkwin/kwinoptions/main.cpp index 950721294e..2beb632f31 100644 --- a/src/kcmkwin/kwinoptions/main.cpp +++ b/src/kcmkwin/kwinoptions/main.cpp @@ -16,7 +16,6 @@ #include #include #include -#include #include "mouse.h" #include "windows.h" diff --git a/src/kcmkwin/kwintabbox/main.cpp b/src/kcmkwin/kwintabbox/main.cpp index 97ff04e789..bfecdbf02f 100644 --- a/src/kcmkwin/kwintabbox/main.cpp +++ b/src/kcmkwin/kwintabbox/main.cpp @@ -398,15 +398,7 @@ void KWinTabBoxConfig::configureEffectClicked() return; } - KCModule *kcm = nullptr; - - KPluginLoader loader(plugins.first().fileName()); - KPluginFactory *factory = loader.factory(); - if (!factory) { - qWarning() << "Error loading plugin:" << loader.errorString(); - } else { - kcm = factory->create(configDialog); - } + KCModule *kcm = KPluginFactory::instantiatePlugin(plugins.first(), configDialog).plugin; if (!kcm) { delete configDialog; diff --git a/src/main_wayland.cpp b/src/main_wayland.cpp index 3e49fa0f2d..eb013810d7 100644 --- a/src/main_wayland.cpp +++ b/src/main_wayland.cpp @@ -28,7 +28,6 @@ #include #include #include -#include #include #include #include diff --git a/src/main_x11.cpp b/src/main_x11.cpp index 2674282d3d..ea18936824 100644 --- a/src/main_x11.cpp +++ b/src/main_x11.cpp @@ -21,7 +21,6 @@ #include #include #include -#include #include #include #include diff --git a/src/pluginmanager.cpp b/src/pluginmanager.cpp index 961fdc7325..d5ad2bc413 100644 --- a/src/pluginmanager.cpp +++ b/src/pluginmanager.cpp @@ -12,7 +12,6 @@ #include #include -#include #include namespace KWin @@ -144,7 +143,7 @@ bool PluginManager::loadDynamicPlugin(const KPluginMetaData &metadata) } const QString pluginId = metadata.pluginId(); - KPluginLoader pluginLoader(metadata.fileName()); + QPluginLoader pluginLoader(metadata.fileName()); if (pluginLoader.metaData().value("IID").toString() != PluginFactory_iid) { qCWarning(KWIN_CORE) << pluginId << "has mismatching plugin version"; return false;