Commit 27487ab9 authored by Nicolas Fella's avatar Nicolas Fella
Browse files

Port to KPluginLoader

Summary: Make it consistent with our plugin systems elsewehere

Reviewers: bshah, leinir, #frameworks, apol

Reviewed By: apol

Differential Revision: https://phabricator.kde.org/D27633
parent 71e63ecc
......@@ -21,6 +21,8 @@
#include <core.h>
#include <KPluginFactory>
#include <KPluginMetaData>
#include <KPluginLoader>
#include <QDebug>
#include <QDir>
......@@ -36,50 +38,34 @@ K_PLUGIN_FACTORY_WITH_JSON(AccountsDaemonFactory, "accounts.json", registerPlugi
AccountsDaemon::AccountsDaemon(QObject *parent, const QList<QVariant>&)
: KDEDModule(parent)
{
QMetaObject::invokeMethod(this, "startDaemon", Qt::QueuedConnection);
connect(KAccounts::accountsManager(), &Accounts::Manager::accountCreated, this, &AccountsDaemon::accountCreated);
connect(KAccounts::accountsManager(), &Accounts::Manager::accountRemoved, this, &AccountsDaemon::accountRemoved);
QStringList pluginPaths;
const QStringList paths = QCoreApplication::libraryPaths();
for (const QString &libraryPath : paths) {
QString path(libraryPath + QStringLiteral("/kaccounts/daemonplugins"));
QDir dir(path);
const QVector<KPluginMetaData> data = KPluginLoader::findPlugins(QStringLiteral("kaccounts/daemonplugins"));
for (const KPluginMetaData& metadata : data) {
if (!dir.exists()) {
if (!metadata.isValid()) {
qDebug() << "Invalid metadata" << metadata.name();
continue;
}
const QStringList dirEntries = dir.entryList(QDir::Files | QDir::NoDotAndDotDot);
KPluginLoader loader(metadata.fileName());
KPluginFactory* factory = loader.factory();
for (const QString &file : dirEntries) {
pluginPaths.append(path + '/' + file);
if (!factory) {
qDebug() << "KPluginFactory could not load the plugin:" << metadata.pluginId() << loader.errorString();
continue;
}
}
for (const QString &pluginPath : qAsConst(pluginPaths)) {
QPluginLoader loader(pluginPath);
if (!loader.load()) {
qWarning() << "Could not create KAccounts daemon plugin: " << pluginPath;
qWarning() << loader.errorString();
KAccountsDPlugin* plugin = factory->create<KAccountsDPlugin>(this, {});
if (!plugin) {
qDebug() << "Error loading plugin" << metadata.name() << loader.errorString();
continue;
}
QObject *obj = loader.instance();
if (obj) {
KAccountsDPlugin *plugin = qobject_cast<KAccountsDPlugin*>(obj);
if (!plugin) {
qDebug() << "Plugin could not be converted to an KAccountsDPlugin";
qDebug() << pluginPath;
continue;
}
qDebug() << "Loaded KAccounts plugin" << pluginPath;
m_plugins << plugin;
} else {
qDebug() << "Plugin could not creaate instance" << pluginPath;
}
m_plugins << plugin;
}
}
......
......@@ -21,7 +21,7 @@
#include "kaccountsdplugin.h"
KAccountsDPlugin::KAccountsDPlugin(QObject *parent)
KAccountsDPlugin::KAccountsDPlugin(QObject *parent, const QVariantList& args)
: QObject(parent)
{
}
......
......@@ -54,7 +54,7 @@ class KACCOUNTS_EXPORT KAccountsDPlugin : public QObject
Q_OBJECT
public:
KAccountsDPlugin(QObject *parent = nullptr);
KAccountsDPlugin(QObject *parent, const QVariantList& args);
virtual ~KAccountsDPlugin();
public Q_SLOTS:
......@@ -90,6 +90,4 @@ public Q_SLOTS:
virtual void onServiceDisabled(const Accounts::AccountId accountId, const Accounts::Service &service) = 0;
};
Q_DECLARE_INTERFACE(KAccountsDPlugin, "org.kde.kaccounts.DPlugin")
#endif // KACCOUNTSDPLUGIN_H
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment