Port deprecated KPluginLoader usage
This commit is contained in:
parent
c5bfc4a5b0
commit
a9292f651f
2 changed files with 18 additions and 23 deletions
|
@ -7,7 +7,6 @@
|
||||||
#include "pluginloader.h"
|
#include "pluginloader.h"
|
||||||
|
|
||||||
#include <KPluginFactory>
|
#include <KPluginFactory>
|
||||||
#include <KPluginLoader>
|
|
||||||
#include <KPluginMetaData>
|
#include <KPluginMetaData>
|
||||||
#include <QPluginLoader>
|
#include <QPluginLoader>
|
||||||
#include <QStaticPlugin>
|
#include <QStaticPlugin>
|
||||||
|
@ -26,7 +25,7 @@ PluginLoader *PluginLoader::instance()
|
||||||
|
|
||||||
PluginLoader::PluginLoader()
|
PluginLoader::PluginLoader()
|
||||||
{
|
{
|
||||||
const QVector<KPluginMetaData> data = KPluginLoader::findPlugins(QStringLiteral("kdeconnect/"));
|
const QVector<KPluginMetaData> data = KPluginMetaData::findPlugins(QStringLiteral("kdeconnect/"));
|
||||||
for (const KPluginMetaData &metadata : data) {
|
for (const KPluginMetaData &metadata : data) {
|
||||||
plugins[metadata.pluginId()] = metadata;
|
plugins[metadata.pluginId()] = metadata;
|
||||||
}
|
}
|
||||||
|
@ -57,18 +56,17 @@ KdeConnectPlugin *PluginLoader::instantiatePluginForDevice(const QString &plugin
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
KPluginLoader loader(service.fileName());
|
auto factoryResult = KPluginFactory::loadFactory(service);
|
||||||
KPluginFactory *factory = loader.factory();
|
if (!factoryResult) {
|
||||||
if (!factory) {
|
qCDebug(KDECONNECT_CORE) << "KPluginFactory could not load the plugin:" << service.pluginId() << factoryResult.errorString;
|
||||||
qCDebug(KDECONNECT_CORE) << "KPluginFactory could not load the plugin:" << service.pluginId() << loader.errorString();
|
|
||||||
return ret;
|
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 *>(device);
|
QVariant deviceVariant = QVariant::fromValue<Device *>(device);
|
||||||
|
|
||||||
ret = factory->create<KdeConnectPlugin>(device, QVariantList() << deviceVariant << pluginName << outgoingInterfaces << service.iconName());
|
ret = factoryResult.plugin->create<KdeConnectPlugin>(device, QVariantList() << deviceVariant << pluginName << outgoingInterfaces << service.iconName());
|
||||||
if (!ret) {
|
if (!ret) {
|
||||||
qCDebug(KDECONNECT_CORE) << "Error loading plugin";
|
qCDebug(KDECONNECT_CORE) << "Error loading plugin";
|
||||||
return ret;
|
return ret;
|
||||||
|
@ -106,8 +104,7 @@ QSet<QString> PluginLoader::pluginsForCapabilities(const QSet<QString> &incoming
|
||||||
|
|
||||||
for (const KPluginMetaData &service : qAsConst(plugins)) {
|
for (const KPluginMetaData &service : qAsConst(plugins)) {
|
||||||
// Check if the plugin support this device type
|
// Check if the plugin support this device type
|
||||||
const QSet<QString> supportedDeviceTypes =
|
const QStringList supportedDeviceTypes = service.rawData().value(QStringLiteral("X-KdeConnect-SupportedDeviceTypes")).toVariant().toStringList();
|
||||||
KPluginMetaData::readStringList(service.rawData(), QStringLiteral("X-KdeConnect-SupportedDeviceTypes")).toSet();
|
|
||||||
if (!supportedDeviceTypes.isEmpty()) {
|
if (!supportedDeviceTypes.isEmpty()) {
|
||||||
if (!supportedDeviceTypes.contains(myDeviceType)) {
|
if (!supportedDeviceTypes.contains(myDeviceType)) {
|
||||||
qCDebug(KDECONNECT_CORE) << "Not loading plugin" << service.pluginId() << "because this device of type" << myDeviceType
|
qCDebug(KDECONNECT_CORE) << "Not loading plugin" << service.pluginId() << "because this device of type" << myDeviceType
|
||||||
|
@ -117,22 +114,13 @@ QSet<QString> PluginLoader::pluginsForCapabilities(const QSet<QString> &incoming
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if capbilites intersect with the remote device
|
// Check if capbilites intersect with the remote device
|
||||||
const QSet<QString> pluginIncomingCapabilities =
|
const QStringList pluginIncomingCapabilities = service.rawData().value(QStringLiteral("X-KdeConnect-SupportedPacketType")).toVariant().toStringList();
|
||||||
KPluginMetaData::readStringList(service.rawData(), QStringLiteral("X-KdeConnect-SupportedPacketType")).toSet();
|
const QStringList pluginOutgoingCapabilities = service.rawData().value(QStringLiteral("X-KdeConnect-OutgoingPacketType")).toVariant().toStringList();
|
||||||
const QSet<QString> pluginOutgoingCapabilities =
|
|
||||||
KPluginMetaData::readStringList(service.rawData(), QStringLiteral("X-KdeConnect-OutgoingPacketType")).toSet();
|
|
||||||
|
|
||||||
bool capabilitiesEmpty = (pluginIncomingCapabilities.isEmpty() && pluginOutgoingCapabilities.isEmpty());
|
bool capabilitiesEmpty = (pluginIncomingCapabilities.isEmpty() && pluginOutgoingCapabilities.isEmpty());
|
||||||
if (!capabilitiesEmpty) {
|
if (!capabilitiesEmpty) {
|
||||||
#if (QT_VERSION >= QT_VERSION_CHECK(5, 6, 0))
|
bool capabilitiesIntersect = (outgoing.intersects(QSet(pluginIncomingCapabilities.begin(), pluginIncomingCapabilities.end()))
|
||||||
bool capabilitiesIntersect = (outgoing.intersects(pluginIncomingCapabilities) || incoming.intersects(pluginOutgoingCapabilities));
|
|| incoming.intersects(QSet(pluginIncomingCapabilities.begin(), pluginIncomingCapabilities.end())));
|
||||||
#else
|
|
||||||
QSet<QString> commonIncoming = incoming;
|
|
||||||
commonIncoming.intersect(pluginOutgoingCapabilities);
|
|
||||||
QSet<QString> commonOutgoing = outgoing;
|
|
||||||
commonOutgoing.intersect(pluginIncomingCapabilities);
|
|
||||||
bool capabilitiesIntersect = (!commonIncoming.isEmpty() || !commonOutgoing.isEmpty());
|
|
||||||
#endif
|
|
||||||
|
|
||||||
if (!capabilitiesIntersect) {
|
if (!capabilitiesIntersect) {
|
||||||
qCDebug(KDECONNECT_CORE) << "Not loading plugin" << service.pluginId() << "because device doesn't support it";
|
qCDebug(KDECONNECT_CORE) << "Not loading plugin" << service.pluginId() << "because device doesn't support it";
|
||||||
|
|
|
@ -8,8 +8,11 @@
|
||||||
|
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
|
|
||||||
|
#include "kcoreaddons_version.h"
|
||||||
#include <KConfigGroup>
|
#include <KConfigGroup>
|
||||||
|
#if KCOREADDONS_VERSION < QT_VERSION_CHECK(5, 86, 0)
|
||||||
#include <KPluginLoader>
|
#include <KPluginLoader>
|
||||||
|
#endif
|
||||||
|
|
||||||
PluginModel::PluginModel(QObject *parent)
|
PluginModel::PluginModel(QObject *parent)
|
||||||
: QAbstractListModel(parent)
|
: QAbstractListModel(parent)
|
||||||
|
@ -18,7 +21,11 @@ PluginModel::PluginModel(QObject *parent)
|
||||||
connect(this, &QAbstractItemModel::rowsRemoved, this, &PluginModel::rowsChanged);
|
connect(this, &QAbstractItemModel::rowsRemoved, this, &PluginModel::rowsChanged);
|
||||||
|
|
||||||
beginResetModel();
|
beginResetModel();
|
||||||
|
#if KCOREADDONS_VERSION < QT_VERSION_CHECK(5, 84, 0)
|
||||||
m_plugins = KPluginLoader::findPlugins(QStringLiteral("kdeconnect/"));
|
m_plugins = KPluginLoader::findPlugins(QStringLiteral("kdeconnect/"));
|
||||||
|
#else
|
||||||
|
m_plugins = KPluginMetaData::findPlugins(QStringLiteral("kdeconnect/"));
|
||||||
|
#endif
|
||||||
endResetModel();
|
endResetModel();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue