diff --git a/src/daemon/daemon.cpp b/src/daemon/daemon.cpp --- a/src/daemon/daemon.cpp +++ b/src/daemon/daemon.cpp @@ -21,6 +21,8 @@ #include #include +#include +#include #include #include @@ -36,50 +38,34 @@ AccountsDaemon::AccountsDaemon(QObject *parent, const QList&) : 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 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(this, {}); + if (!plugin) { + qDebug() << "Error loading plugin" << metadata.name() << loader.errorString(); continue; } - QObject *obj = loader.instance(); - if (obj) { - KAccountsDPlugin *plugin = qobject_cast(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; } } diff --git a/src/lib/kaccountsdplugin.h b/src/lib/kaccountsdplugin.h --- a/src/lib/kaccountsdplugin.h +++ b/src/lib/kaccountsdplugin.h @@ -54,7 +54,7 @@ Q_OBJECT public: - KAccountsDPlugin(QObject *parent = nullptr); + KAccountsDPlugin(QObject *parent, const QVariantList& args); virtual ~KAccountsDPlugin(); public Q_SLOTS: @@ -90,6 +90,4 @@ virtual void onServiceDisabled(const Accounts::AccountId accountId, const Accounts::Service &service) = 0; }; -Q_DECLARE_INTERFACE(KAccountsDPlugin, "org.kde.kaccounts.DPlugin") - #endif // KACCOUNTSDPLUGIN_H diff --git a/src/lib/kaccountsdplugin.cpp b/src/lib/kaccountsdplugin.cpp --- a/src/lib/kaccountsdplugin.cpp +++ b/src/lib/kaccountsdplugin.cpp @@ -21,7 +21,7 @@ #include "kaccountsdplugin.h" -KAccountsDPlugin::KAccountsDPlugin(QObject *parent) +KAccountsDPlugin::KAccountsDPlugin(QObject *parent, const QVariantList& args) : QObject(parent) { }