Modernize plugin loading code
Use the new utility-methods and improve the logging.
This commit is contained in:
parent
6d4b19c07b
commit
aeb1d7f4cc
2 changed files with 14 additions and 25 deletions
|
@ -12,7 +12,7 @@ struct KdeConnectPluginPrivate {
|
||||||
Device *m_device;
|
Device *m_device;
|
||||||
QString m_pluginName;
|
QString m_pluginName;
|
||||||
QSet<QString> m_outgoingCapabilties;
|
QSet<QString> m_outgoingCapabilties;
|
||||||
KdeConnectPluginConfig *m_config;
|
KdeConnectPluginConfig *m_config = nullptr;
|
||||||
QString iconName;
|
QString iconName;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -20,13 +20,12 @@ KdeConnectPlugin::KdeConnectPlugin(QObject *parent, const QVariantList &args)
|
||||||
: QObject(parent)
|
: QObject(parent)
|
||||||
, d(new KdeConnectPluginPrivate)
|
, d(new KdeConnectPluginPrivate)
|
||||||
{
|
{
|
||||||
|
Q_ASSERT(args.length() == 4);
|
||||||
d->m_device = qvariant_cast<Device *>(args.at(0));
|
d->m_device = qvariant_cast<Device *>(args.at(0));
|
||||||
d->m_pluginName = args.at(1).toString();
|
d->m_pluginName = args.at(1).toString();
|
||||||
|
|
||||||
const QStringList cap = args.at(2).toStringList();
|
const QStringList cap = args.at(2).toStringList();
|
||||||
d->m_outgoingCapabilties = QSet(cap.begin(), cap.end());
|
d->m_outgoingCapabilties = QSet(cap.begin(), cap.end());
|
||||||
|
|
||||||
d->m_config = nullptr;
|
|
||||||
d->iconName = args.at(3).toString();
|
d->iconName = args.at(3).toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -48,32 +48,22 @@ KPluginMetaData PluginLoader::getPluginInfo(const QString &name) const
|
||||||
|
|
||||||
KdeConnectPlugin *PluginLoader::instantiatePluginForDevice(const QString &pluginName, Device *device) const
|
KdeConnectPlugin *PluginLoader::instantiatePluginForDevice(const QString &pluginName, Device *device) const
|
||||||
{
|
{
|
||||||
KdeConnectPlugin *ret = nullptr;
|
const KPluginMetaData data = plugins.value(pluginName);
|
||||||
|
if (!data.isValid()) {
|
||||||
KPluginMetaData service = plugins.value(pluginName);
|
|
||||||
if (!service.isValid()) {
|
|
||||||
qCDebug(KDECONNECT_CORE) << "Plugin unknown" << pluginName;
|
qCDebug(KDECONNECT_CORE) << "Plugin unknown" << pluginName;
|
||||||
return ret;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto factoryResult = KPluginFactory::loadFactory(service);
|
const QStringList outgoingInterfaces = data.value(QStringLiteral("X-KdeConnect-OutgoingPacketType"), QStringList());
|
||||||
if (!factoryResult) {
|
const QVariantList args{QVariant::fromValue<Device *>(device), pluginName, outgoingInterfaces, data.iconName()};
|
||||||
qCDebug(KDECONNECT_CORE) << "KPluginFactory could not load the plugin:" << service.pluginId() << factoryResult.errorString;
|
|
||||||
return ret;
|
if (auto result = KPluginFactory::instantiatePlugin<KdeConnectPlugin>(data, device, args)) {
|
||||||
|
qCDebug(KDECONNECT_CORE) << "Loaded plugin:" << data.pluginId();
|
||||||
|
return result.plugin;
|
||||||
|
} else {
|
||||||
|
qCDebug(KDECONNECT_CORE) << "Error loading plugin" << result.errorText;
|
||||||
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
const QStringList outgoingInterfaces = service.value(QStringLiteral("X-KdeConnect-OutgoingPacketType"), QStringList());
|
|
||||||
|
|
||||||
QVariant deviceVariant = QVariant::fromValue<Device *>(device);
|
|
||||||
|
|
||||||
ret = factoryResult.plugin->create<KdeConnectPlugin>(device, QVariantList() << deviceVariant << pluginName << outgoingInterfaces << service.iconName());
|
|
||||||
if (!ret) {
|
|
||||||
qCDebug(KDECONNECT_CORE) << "Error loading plugin";
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
// qCDebug(KDECONNECT_CORE) << "Loaded plugin:" << service.pluginId();
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QStringList PluginLoader::incomingCapabilities() const
|
QStringList PluginLoader::incomingCapabilities() const
|
||||||
|
|
Loading…
Reference in a new issue