diff --git a/core/pluginloader.cpp b/core/pluginloader.cpp index 7f3efcaa5..b1e893a9a 100644 --- a/core/pluginloader.cpp +++ b/core/pluginloader.cpp @@ -7,18 +7,17 @@ #include "pluginloader.h" #include -#include #include #include #include #include -#include "kdeconnectconfig.h" #include "core_debug.h" #include "device.h" +#include "kdeconnectconfig.h" #include "kdeconnectplugin.h" -// In older Qt released, qAsConst isnt available +// In older Qt released, qAsConst isn't available #include "qtcompat_p.h" PluginLoader *PluginLoader::instance() @@ -40,7 +39,7 @@ PluginLoader::PluginLoader() } } #else - const QVector data = KPluginLoader::findPlugins(QStringLiteral("kdeconnect/")); + const QVector data = KPluginMetaData::findPlugins(QStringLiteral("kdeconnect/")); for (const KPluginMetaData &metadata : data) { plugins[metadata.pluginId()] = metadata; } @@ -70,15 +69,14 @@ KdeConnectPlugin *PluginLoader::instantiatePluginForDevice(const QString &plugin #ifdef SAILFISHOS KPluginFactory *factory = pluginsFactories.value(pluginName); #else - 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; } + KPluginFactory *factory = factoryResult.plugin; #endif - - const QStringList outgoingInterfaces = KPluginMetaData::readStringList(service.rawData(), QStringLiteral("X-KdeConnect-OutgoingPacketType")); + const QStringList outgoingInterfaces = service.rawData().value(QStringLiteral("X-KdeConnect-OutgoingPacketType")).toVariant().toStringList(); QVariant deviceVariant = QVariant::fromValue(device); @@ -119,33 +117,32 @@ QSet PluginLoader::pluginsForCapabilities(const QSet &incoming QString myDeviceType = KdeConnectConfig::instance().deviceType(); 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 << "is not supported. Supports:" << supportedDeviceTypes.toList().join(QStringLiteral(", ")); + qCDebug(KDECONNECT_CORE) << "Not loading plugin" << service.pluginId() << "because this device of type" << myDeviceType + << "is not supported. Supports:" << supportedDeviceTypes.toList().join(QStringLiteral(", ")); continue; } } // 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 +#if (QT_VERSION >= QT_VERSION_CHECK(5, 6, 0)) + bool capabilitiesIntersect = (outgoing.intersects(QSet(pluginIncomingCapabilities.begin(), pluginIncomingCapabilities.end())) + || incoming.intersects(QSet(pluginOutgoingCapabilities.begin(), pluginOutgoingCapabilities.end()))); +#else QSet commonIncoming = incoming; - commonIncoming.intersect(pluginOutgoingCapabilities); + commonIncoming.intersect(pluginOutgoingCapabilities.toSet()); QSet commonOutgoing = outgoing; - commonOutgoing.intersect(pluginIncomingCapabilities); + commonOutgoing.intersect(pluginIncomingCapabilities.toSet()); bool capabilitiesIntersect = (!commonIncoming.isEmpty() || !commonOutgoing.isEmpty()); - #endif +#endif if (!capabilitiesIntersect) { qCDebug(KDECONNECT_CORE) << "Not loading plugin" << service.pluginId() << "because device doesn't support it"; @@ -155,7 +152,6 @@ QSet PluginLoader::pluginsForCapabilities(const QSet &incoming // If we get here, the plugin can be loaded ret += service.pluginId(); - } return ret; diff --git a/core/pluginloader.h b/core/pluginloader.h index 53093dbc4..5d56e3c00 100644 --- a/core/pluginloader.h +++ b/core/pluginloader.h @@ -25,6 +25,15 @@ public: static PluginLoader *instance(); QStringList getPluginList() const; + QSet getPluginSet() const + { +#if QT_VERSION < QT_VERSION_CHECK(5, 14, 0) + return getPluginList().toSet(); +#else + const QStringList pluginList = getPluginList(); + return QSet(pluginList.begin(), pluginList.end()); +#endif + } KPluginMetaData getPluginInfo(const QString &name) const; KdeConnectPlugin *instantiatePluginForDevice(const QString &name, Device *device) const; 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(); }