plasma-framework/tests/kplugins/plugintest.cpp

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

172 lines
5.6 KiB
C++
Raw Normal View History

/*
SPDX-FileCopyrightText: 2013 Sebastian Kügler <sebas@kde.org>
SPDX-License-Identifier: LGPL-2.0-or-later
*/
#include "plugintest.h"
2020-07-08 07:44:43 +02:00
#include <KPluginFactory>
#include <KLocalizedString>
2020-07-08 07:44:43 +02:00
#include <KService>
#include <KServiceTypeTrader>
#include <KShell>
#include <KSycoca>
#include <QDebug>
#include <KJob>
#include <plasma/applet.h>
#include <plasma/dataengine.h>
#include <plasma/package.h>
#include <plasma/packagestructure.h>
#include <plasma/pluginloader.h>
2020-07-08 07:44:43 +02:00
#include <QCommandLineParser>
#include <QDBusInterface>
#include <QDir>
#include <QFileInfo>
#include <QJsonObject>
#include <QMap>
#include <QStandardPaths>
#include <QStringList>
#include <QTimer>
#include <iomanip>
#include <iostream>
namespace Plasma
{
2014-04-26 01:45:47 +02:00
class PluginTestPrivate
{
public:
QString pluginName;
QCommandLineParser *parser;
};
PluginTest::PluginTest(int &argc, char **argv, QCommandLineParser *parser)
: QApplication(argc, argv) // QApp needed for CursorNotificationHandler (QWidget)
{
d = new PluginTestPrivate;
d->parser = parser;
2019-08-30 17:26:54 +02:00
QTimer::singleShot(0, this, &PluginTest::runMain);
}
PluginTest::~PluginTest()
{
delete d;
}
void PluginTest::runMain()
{
qDebug() << "plugin test runs: ";
// loadDataEngine();
// qDebug() << " - - - -- - - - - ------------------------------------\n";
// qDebug() << " libs are in: " << QCoreApplication::libraryPaths();
// //loadKQPlugin();
2013-07-23 03:28:37 +02:00
qDebug() << "::: loadKPlugin() == " << loadKPlugin();
//
2013-07-23 03:28:37 +02:00
qDebug() << " - - - -- - - - - ------------------------------------\n";
2016-06-12 15:50:26 +02:00
qDebug() << "::: loadFromPlasma() == " << loadFromPlasma();
exit(0);
return;
}
2013-07-23 03:28:37 +02:00
bool PluginTest::loadKPlugin()
2013-06-28 05:09:27 +02:00
{
2013-07-23 03:28:37 +02:00
bool ok = false;
2013-06-28 05:09:27 +02:00
qDebug() << "Load KPlugin";
QString pluginPath = QStringLiteral("/home/sebas/kf5/install/lib/x86_64-linux-gnu/kplugins/");
2013-06-28 05:09:27 +02:00
QCoreApplication::addLibraryPath(pluginPath);
// QPluginLoader loader("/home/sebas/kf5/install/lib/x86_64-linux-gnu/kplugins/libkqpluginfactory.so", this);
QPluginLoader loader(QStringLiteral("/home/sebas/kf5/install/lib/x86_64-linux-gnu/plugins/kf5/kplugins/libplasma_engine_time.so"), this);
2014-04-26 01:45:47 +02:00
KPluginFactory *factory = qobject_cast<KPluginFactory *>(loader.instance());
// QObject *factory = loader.instance();
2013-06-28 05:09:27 +02:00
if (factory) {
qDebug() << "loaded successfully and cast";
qDebug() << "metadata: " << loader.metaData();
// QObject *o = factory->createPlugin("time");
// qDebug() << " objec name:" << o->objectName();
// Plasma::DataEngine *time_engine = qobject_cast<Plasma::DataEngine*>(factory->create(this, QVariantList()));
2018-07-02 00:16:21 +02:00
Plasma::DataEngine *time_engine = nullptr;
// Plasma::DataEngine *time_engine = factory->create(this, QVariantList());
2013-06-28 05:09:27 +02:00
time_engine = factory->create<Plasma::DataEngine>(this, QVariantList());
if (time_engine) {
qDebug() << "Successfully loaded timeengine";
time_engine->connectSource(QStringLiteral("Europe/Amsterdam"), this);
2013-06-28 05:09:27 +02:00
qDebug() << "SOURCE: " << time_engine->sources();
2013-07-23 03:28:37 +02:00
ok = true;
2013-06-28 05:09:27 +02:00
} else {
qDebug() << "Timeengine failed to load. :(";
}
} else {
qDebug() << "loading failed somehow";
}
// KQPluginFactory* factory = new KQPluginFactory(KPluginInfo(), this);
2013-07-23 03:28:37 +02:00
return ok;
2013-06-28 05:09:27 +02:00
}
2013-07-23 03:28:37 +02:00
bool PluginTest::loadFromPlasma()
{
bool ok = false;
const QStringList allEngines = Plasma::PluginLoader::self()->listAllEngines();
qDebug() << "All engines: " << allEngines;
for (const QString &e : allEngines) {
2013-07-23 03:28:37 +02:00
Plasma::DataEngine *engine = Plasma::PluginLoader::self()->loadDataEngine(e);
if (engine) {
engine->connectSource(QStringLiteral("Europe/Amsterdam"), this);
engine->connectSource(QStringLiteral("Battery"), this);
2013-07-23 03:28:37 +02:00
engine->connectAllSources(this);
qDebug() << "SOURCE: " << engine->sources();
ok = true;
}
}
return ok;
}
void PluginTest::loadKQPlugin()
{
qDebug() << "Load KQPlugin";
2013-06-28 05:09:27 +02:00
#if 0
QString pluginPath = "/home/sebas/kf5/install/lib/x86_64-linux-gnu/kplugins/";
QCoreApplication::addLibraryPath(pluginPath);
//QPluginLoader loader("/home/sebas/kf5/install/lib/x86_64-linux-gnu/kplugins/libkqpluginfactory.so", this);
QPluginLoader loader("/home/sebas/kf5/install/lib/x86_64-linux-gnu/plugins/kf5/kplugins/libplasma_engine_time.so", this);
2014-04-26 01:45:47 +02:00
KPluginFactory *factory = qobject_cast<KPluginFactory *>(loader.instance());
//QObject *factory = loader.instance();
if (factory) {
qDebug() << "loaded successfully and cast";
qDebug() << "metadata: " << loader.metaData();
2013-06-27 04:35:57 +02:00
//QObject *o = factory->createPlugin("time");
//qDebug() << " objec name:" << o->objectName();
2013-06-28 05:08:45 +02:00
//Plasma::DataEngine *time_engine = qobject_cast<Plasma::DataEngine*>(factory->create(this, QVariantList()));
//Plasma::DataEngine *time_engine = factory->create(this, QVariantList());
2013-06-28 05:09:27 +02:00
Plasma::DataEngine *time_engine = factory->createInstance<Plasma::DataEngine>(0, this, QVariantList());
2013-06-27 04:35:57 +02:00
if (time_engine) {
qDebug() << "Successfully loaded timeengine";
time_engine->connectSource("Europe/Amsterdam", this);
qDebug() << "SOURCE: " << time_engine->sources();
} else {
qDebug() << "Timeengine failed to load. :(";
}
} else {
qDebug() << "loading failed somehow";
}
//KQPluginFactory* factory = new KQPluginFactory(KPluginInfo(), this);
2013-06-28 05:09:27 +02:00
#endif
}
void PluginTest::dataUpdated(QString s, Plasma::DataEngine::Data d)
{
qDebug() << "new data for source:" << s << d;
}
} // namespace Plasma
#include "moc_plugintest.cpp"