Commit edfafd86 authored by Laurent Montel's avatar Laurent Montel 😁
Browse files

Port to new plugin support

parent 289786c0
......@@ -47,7 +47,7 @@ find_package(KF5KDEGames 7.3.0 REQUIRED)
add_definitions(
-DQT_DISABLE_DEPRECATED_BEFORE=0x050F00
-DQT_DEPRECATED_WARNINGS_SINCE=0x060000
-DKF_DISABLE_DEPRECATED_BEFORE_AND_AT=0x055400
-DKF_DISABLE_DEPRECATED_BEFORE_AND_AT=0x055600
-DKF_DEPRECATED_WARNINGS_SINCE=0x060000
)
......
......@@ -5,7 +5,7 @@
*/
#include "slicerselector.h"
#include "kcoreaddons_version.h"
#include <Pala/Slicer>
#include <Pala/SlicerJob>
#include <Pala/SlicerMode>
......@@ -22,17 +22,32 @@ Palapeli::SlicerSelector::SlicerSelector(QWidget* parent)
setSelectionBehavior(QAbstractItemView::SelectItems);
setSelectionMode(QAbstractItemView::SingleSelection);
connect(this, &SlicerSelector::itemSelectionChanged, this, &SlicerSelector::slotSelectionChanged);
//load slicer plugins
const QVector<KPluginMetaData> offers = KPluginLoader::findPlugins(QStringLiteral("palapelislicers"));
//load slicer plugins
#if KCOREADDONS_VERSION < QT_VERSION_CHECK(5, 86, 0)
const QVector<KPluginMetaData> offers = KPluginLoader::findPlugins(QStringLiteral("palapelislicers"));
#else
const QVector<KPluginMetaData> offers = KPluginMetaData::findPlugins(QStringLiteral("palapelislicers"));
#endif
for (const KPluginMetaData &offer : offers)
{
const QString pluginName = offer.pluginId(), slicerName = offer.name();
{
const QString pluginName = offer.pluginId();
const QString slicerName = offer.name();
#if KCOREADDONS_VERSION < QT_VERSION_CHECK(5, 86, 0)
//create slicer object
KPluginLoader loader(offer.fileName());
KPluginFactory *factory = loader.factory();
Pala::Slicer* slicer = factory->create<Pala::Slicer>(nullptr, QVariantList());
if (!slicer)
continue;
continue;
#else
Pala::Slicer* slicer = nullptr;
if (auto plugin = KPluginFactory::instantiatePlugin<Pala::Slicer>({}, nullptr).plugin) {
slicer = plugin;
} else {
continue;
}
#endif
m_slicerInstances << slicer;
//create item for this slicer
QTreeWidgetItem* slicerItem = new QTreeWidgetItem(this);
......
......@@ -5,7 +5,7 @@
*/
#include "components.h"
#include "kcoreaddons_version.h"
#include <Pala/Slicer>
#include <Pala/SlicerJob>
#include <Pala/SlicerMode>
......@@ -34,15 +34,22 @@ Palapeli::PuzzleComponent* Palapeli::CreationContextComponent::cast(Type type) c
//TODO: move slicer instantiation to a location that is shared between
// puzzle creator dialog and this function
//find slicer
const QVector<KPluginMetaData> offers = KPluginLoader::findPlugins(QStringLiteral("palapelislicers"), [cc](const KPluginMetaData &m) {
return m.pluginId() == cc.slicer;
});
#if KCOREADDONS_VERSION < QT_VERSION_CHECK(5, 86, 0)
const QVector<KPluginMetaData> offers = KPluginLoader::findPlugins(QStringLiteral("palapelislicers"), [cc](const KPluginMetaData &m) {
return m.pluginId() == cc.slicer;
});
#else
const QVector<KPluginMetaData> offers = KPluginMetaData::findPlugins(QStringLiteral("palapelislicers"), [cc](const KPluginMetaData &m) {
return m.pluginId() == cc.slicer;
});
#endif
if (offers.isEmpty())
{
CAST_ERROR(QString::fromLatin1("Could not find slicer \"%1\".").arg(cc.slicer));
return nullptr;
}
//initialize requested slicer plugin
#if KCOREADDONS_VERSION < QT_VERSION_CHECK(5, 86, 0)
KPluginLoader loader(offers.first().fileName());
KPluginFactory *factory = loader.factory();
QScopedPointer<Pala::Slicer> slicer(factory->create<Pala::Slicer>(nullptr, QVariantList()));
......@@ -50,7 +57,15 @@ Palapeli::PuzzleComponent* Palapeli::CreationContextComponent::cast(Type type) c
{
CAST_ERROR(QString::fromLatin1("Could not load slicer \"%1\": %2").arg(cc.slicer).arg(loader.errorString()));
return nullptr;
}
}
#else
QScopedPointer<Pala::Slicer> slicer;
if (auto plugin = KPluginFactory::instantiatePlugin<Pala::Slicer>({}, nullptr).plugin) {
slicer.reset(plugin);
} else {
return nullptr;
}
#endif
//create job
Pala::SlicerJob job(cc.image, cc.slicerArgs);
if (!cc.slicerMode.isEmpty())
......
Supports Markdown
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