Commit 951a3fd5 authored by Laurent Montel's avatar Laurent Montel 😁
Browse files

Port to KPluginLoader::findPlugins

parent cb509c5b
Pipeline #75633 passed with stage
in 4 minutes and 17 seconds
......@@ -7,6 +7,7 @@
*/
#include "kcmkontact.h"
#include "kcoreaddons_version.h"
#include "prefs.h"
using namespace Kontact;
......@@ -62,10 +63,15 @@ KcmKontact::KcmKontact(QWidget *parent, const QVariantList &args)
void KcmKontact::load()
{
const KConfigGroup grp(Prefs::self()->config(), "Plugins");
#if KCOREADDONS_VERSION < QT_VERSION_CHECK(5, 86, 0)
const QVector<KPluginMetaData> pluginMetaDatas = KPluginLoader::findPlugins(QStringLiteral("kontact5"), [](const KPluginMetaData &data) {
return data.rawData().value(QStringLiteral("X-KDE-KontactPluginVersion")).toInt() == KONTACT_PLUGIN_VERSION;
});
#else
const QVector<KPluginMetaData> pluginMetaDatas = KPluginMetaData::findPlugins(QStringLiteral("kontact5"), [](const KPluginMetaData &data) {
return data.rawData().value(QStringLiteral("X-KDE-KontactPluginVersion")).toInt() == KONTACT_PLUGIN_VERSION;
});
#endif
int activeComponent = 0;
mPluginCombo->clear();
......
......@@ -10,6 +10,7 @@
// Use the kdepim version
#include "kontact-version.h"
#include "kcoreaddons_version.h"
#include "kontact_debug.h"
#include "mainwindow.h"
#include "prefs.h"
......@@ -74,9 +75,15 @@ private:
static void listPlugins()
{
#if KCOREADDONS_VERSION < QT_VERSION_CHECK(5, 86, 0)
const QVector<KPluginMetaData> pluginMetaDatas = KPluginLoader::findPlugins(QStringLiteral("kontact5"), [](const KPluginMetaData &data) {
return data.rawData().value(QStringLiteral("X-KDE-KontactPluginVersion")).toInt() == KONTACT_PLUGIN_VERSION;
});
#else
const QVector<KPluginMetaData> pluginMetaDatas = KPluginMetaData::findPlugins(QStringLiteral("kontact5"), [](const KPluginMetaData &data) {
return data.rawData().value(QStringLiteral("X-KDE-KontactPluginVersion")).toInt() == KONTACT_PLUGIN_VERSION;
});
#endif
for (const KPluginMetaData &plugin : pluginMetaDatas) {
// skip summary only plugins
......
......@@ -12,8 +12,8 @@
#include "mainwindow.h"
#include "aboutdialog.h"
#include "iconsidepane.h"
#include "kcoreaddons_version.h"
#include "prefs.h"
#include "webengine/introductionwebenginepage.h"
#include "webengine/introductionwebengineview.h"
......@@ -133,10 +133,15 @@ void MainWindow::initObject()
qFatal("KSycoca unavailable. Kontact will be unable to find plugins.");
}
}
#if KCOREADDONS_VERSION < QT_VERSION_CHECK(5, 86, 0)
mPluginMetaData = KPluginLoader::findPlugins(QStringLiteral("kontact5"), [](const KPluginMetaData &data) {
return data.rawData().value(QStringLiteral("X-KDE-KontactPluginVersion")).toInt() == KONTACT_PLUGIN_VERSION;
});
#else
mPluginMetaData = KPluginMetaData::findPlugins(QStringLiteral("kontact5"), [](const KPluginMetaData &data) {
return data.rawData().value(QStringLiteral("X-KDE-KontactPluginVersion")).toInt() == KONTACT_PLUGIN_VERSION;
});
#endif
// prepare the part manager
mPartManager = new KParts::PartManager(this);
......@@ -334,6 +339,7 @@ void MainWindow::loadPlugins()
}
qCDebug(KONTACT_LOG) << "Loading Plugin:" << pluginMetaData.name();
#if KCOREADDONS_VERSION < QT_VERSION_CHECK(5, 86, 0)
KPluginLoader loader(pluginMetaData.fileName());
KPluginFactory *factory = loader.factory();
if (!factory) {
......@@ -346,7 +352,19 @@ void MainWindow::loadPlugins()
continue;
}
}
#else
const auto loadResult = KPluginFactory::instantiatePlugin<KontactInterface::Plugin>(pluginMetaData, this);
if (!loadResult) {
qCWarning(KONTACT_LOG) << "Error loading plugin" << pluginMetaData.fileName() << loadResult.errorString;
continue;
} else {
plugin = loadResult.plugin;
if (!plugin) {
qCWarning(KONTACT_LOG) << "Unable to create plugin for" << pluginMetaData.fileName();
continue;
}
}
#endif
plugin->setIdentifier(pluginMetaData.fileName());
plugin->setTitle(pluginMetaData.name());
plugin->setIcon(pluginMetaData.iconName());
......@@ -729,7 +747,11 @@ void MainWindow::slotPreferences()
for (const KPluginMetaData &metaData : std::as_const(mPluginMetaData)) {
const QString pluginNamespace = metaData.value(QStringLiteral("X-KDE-ConfigModuleNamespace"));
if (!pluginNamespace.isEmpty()) {
#if KCOREADDONS_VERSION < QT_VERSION_CHECK(5, 86, 0)
auto plugins = KPluginLoader::findPlugins(pluginNamespace);
#else
auto plugins = KPluginMetaData::findPlugins(pluginNamespace);
#endif
std::sort(plugins.begin(), plugins.end(), sortByWeight);
dlg->addPluginComponent(metaData, plugins);
}
......
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