From a9292f651fff8619ec637212faf0bf4682568b67 Mon Sep 17 00:00:00 2001 From: Alexander Lohnau Date: Sun, 16 Apr 2023 09:21:13 +0200 Subject: [PATCH] Port deprecated KPluginLoader usage --- core/pluginloader.cpp | 34 +++++++++++----------------------- interfaces/pluginmodel.cpp | 7 +++++++ 2 files changed, 18 insertions(+), 23 deletions(-) diff --git a/core/pluginloader.cpp b/core/pluginloader.cpp index 037807067..a99064b03 100644 --- a/core/pluginloader.cpp +++ b/core/pluginloader.cpp @@ -7,7 +7,6 @@ #include "pluginloader.h" #include -#include #include #include #include @@ -26,7 +25,7 @@ PluginLoader *PluginLoader::instance() PluginLoader::PluginLoader() { - const QVector data = KPluginLoader::findPlugins(QStringLiteral("kdeconnect/")); + const QVector data = KPluginMetaData::findPlugins(QStringLiteral("kdeconnect/")); for (const KPluginMetaData &metadata : data) { plugins[metadata.pluginId()] = metadata; } @@ -57,18 +56,17 @@ KdeConnectPlugin *PluginLoader::instantiatePluginForDevice(const QString &plugin return ret; } - KPluginLoader loader(service.fileName()); - KPluginFactory *factory = loader.factory(); - if (!factory) { - qCDebug(KDECONNECT_CORE) << "KPluginFactory could not load the plugin:" << service.pluginId() << loader.errorString(); + auto factoryResult = KPluginFactory::loadFactory(service); + if (!factoryResult) { + qCDebug(KDECONNECT_CORE) << "KPluginFactory could not load the plugin:" << service.pluginId() << factoryResult.errorString; return ret; } - const QStringList outgoingInterfaces = KPluginMetaData::readStringList(service.rawData(), QStringLiteral("X-KdeConnect-OutgoingPacketType")); + const QStringList outgoingInterfaces = service.value(QStringLiteral("X-KdeConnect-OutgoingPacketType"), QStringList()); QVariant deviceVariant = QVariant::fromValue(device); - ret = factory->create(device, QVariantList() << deviceVariant << pluginName << outgoingInterfaces << service.iconName()); + ret = factoryResult.plugin->create(device, QVariantList() << deviceVariant << pluginName << outgoingInterfaces << service.iconName()); if (!ret) { qCDebug(KDECONNECT_CORE) << "Error loading plugin"; return ret; @@ -106,8 +104,7 @@ QSet PluginLoader::pluginsForCapabilities(const QSet &incoming for (const KPluginMetaData &service : qAsConst(plugins)) { // Check if the plugin support this device type - const QSet supportedDeviceTypes = - KPluginMetaData::readStringList(service.rawData(), QStringLiteral("X-KdeConnect-SupportedDeviceTypes")).toSet(); + const QStringList supportedDeviceTypes = service.rawData().value(QStringLiteral("X-KdeConnect-SupportedDeviceTypes")).toVariant().toStringList(); if (!supportedDeviceTypes.isEmpty()) { if (!supportedDeviceTypes.contains(myDeviceType)) { qCDebug(KDECONNECT_CORE) << "Not loading plugin" << service.pluginId() << "because this device of type" << myDeviceType @@ -117,22 +114,13 @@ QSet PluginLoader::pluginsForCapabilities(const QSet &incoming } // Check if capbilites intersect with the remote device - const QSet pluginIncomingCapabilities = - KPluginMetaData::readStringList(service.rawData(), QStringLiteral("X-KdeConnect-SupportedPacketType")).toSet(); - const QSet pluginOutgoingCapabilities = - KPluginMetaData::readStringList(service.rawData(), QStringLiteral("X-KdeConnect-OutgoingPacketType")).toSet(); + const QStringList pluginIncomingCapabilities = service.rawData().value(QStringLiteral("X-KdeConnect-SupportedPacketType")).toVariant().toStringList(); + const QStringList pluginOutgoingCapabilities = service.rawData().value(QStringLiteral("X-KdeConnect-OutgoingPacketType")).toVariant().toStringList(); bool capabilitiesEmpty = (pluginIncomingCapabilities.isEmpty() && pluginOutgoingCapabilities.isEmpty()); if (!capabilitiesEmpty) { -#if (QT_VERSION >= QT_VERSION_CHECK(5, 6, 0)) - bool capabilitiesIntersect = (outgoing.intersects(pluginIncomingCapabilities) || incoming.intersects(pluginOutgoingCapabilities)); -#else - QSet commonIncoming = incoming; - commonIncoming.intersect(pluginOutgoingCapabilities); - QSet commonOutgoing = outgoing; - commonOutgoing.intersect(pluginIncomingCapabilities); - bool capabilitiesIntersect = (!commonIncoming.isEmpty() || !commonOutgoing.isEmpty()); -#endif + bool capabilitiesIntersect = (outgoing.intersects(QSet(pluginIncomingCapabilities.begin(), pluginIncomingCapabilities.end())) + || incoming.intersects(QSet(pluginIncomingCapabilities.begin(), pluginIncomingCapabilities.end()))); if (!capabilitiesIntersect) { qCDebug(KDECONNECT_CORE) << "Not loading plugin" << service.pluginId() << "because device doesn't support it"; diff --git a/interfaces/pluginmodel.cpp b/interfaces/pluginmodel.cpp index 925df8c56..73dc7d8fb 100644 --- a/interfaces/pluginmodel.cpp +++ b/interfaces/pluginmodel.cpp @@ -8,8 +8,11 @@ #include +#include "kcoreaddons_version.h" #include +#if KCOREADDONS_VERSION < QT_VERSION_CHECK(5, 86, 0) #include +#endif PluginModel::PluginModel(QObject *parent) : QAbstractListModel(parent) @@ -18,7 +21,11 @@ PluginModel::PluginModel(QObject *parent) connect(this, &QAbstractItemModel::rowsRemoved, this, &PluginModel::rowsChanged); beginResetModel(); +#if KCOREADDONS_VERSION < QT_VERSION_CHECK(5, 84, 0) m_plugins = KPluginLoader::findPlugins(QStringLiteral("kdeconnect/")); +#else + m_plugins = KPluginMetaData::findPlugins(QStringLiteral("kdeconnect/")); +#endif endResetModel(); }