2020-08-13 21:08:54 +02:00
|
|
|
/*
|
|
|
|
SPDX-FileCopyrightText: 2013 Sebastian Kügler <sebas@kde.org>
|
|
|
|
|
|
|
|
SPDX-License-Identifier: LGPL-2.0-or-later
|
|
|
|
*/
|
2013-06-24 15:23:45 +02:00
|
|
|
|
|
|
|
#include "plugintest.h"
|
|
|
|
|
2020-07-08 07:44:43 +02:00
|
|
|
#include <KPluginFactory>
|
2013-06-27 04:01:34 +02:00
|
|
|
|
2021-03-05 19:15:32 +01:00
|
|
|
#include <KLocalizedString>
|
2020-07-08 07:44:43 +02:00
|
|
|
#include <KService>
|
|
|
|
#include <KServiceTypeTrader>
|
|
|
|
#include <KShell>
|
|
|
|
#include <KSycoca>
|
2021-03-05 19:15:32 +01:00
|
|
|
#include <QDebug>
|
2013-06-24 15:23:45 +02:00
|
|
|
|
2021-03-05 19:15:32 +01:00
|
|
|
#include <KJob>
|
2013-06-24 15:23:45 +02:00
|
|
|
#include <plasma/applet.h>
|
2021-03-05 19:15:32 +01:00
|
|
|
#include <plasma/dataengine.h>
|
2013-06-24 15:23:45 +02:00
|
|
|
#include <plasma/package.h>
|
2021-03-05 19:15:32 +01:00
|
|
|
#include <plasma/packagestructure.h>
|
2013-06-24 15:23:45 +02:00
|
|
|
#include <plasma/pluginloader.h>
|
|
|
|
|
2020-07-08 07:44:43 +02:00
|
|
|
#include <QCommandLineParser>
|
2013-06-24 15:23:45 +02:00
|
|
|
#include <QDBusInterface>
|
2021-03-05 19:15:32 +01:00
|
|
|
#include <QDir>
|
2013-06-24 15:23:45 +02:00
|
|
|
#include <QFileInfo>
|
2021-03-05 19:15:32 +01:00
|
|
|
#include <QJsonObject>
|
2013-06-24 15:23:45 +02:00
|
|
|
#include <QMap>
|
|
|
|
#include <QStandardPaths>
|
|
|
|
#include <QStringList>
|
|
|
|
#include <QTimer>
|
|
|
|
|
|
|
|
#include <iomanip>
|
2021-03-05 19:15:32 +01:00
|
|
|
#include <iostream>
|
2013-06-24 15:23:45 +02:00
|
|
|
|
|
|
|
namespace Plasma
|
|
|
|
{
|
2014-04-26 01:45:47 +02:00
|
|
|
class PluginTestPrivate
|
|
|
|
{
|
2013-06-24 15:23:45 +02:00
|
|
|
public:
|
|
|
|
QString pluginName;
|
|
|
|
QCommandLineParser *parser;
|
|
|
|
};
|
|
|
|
|
2021-03-05 19:15:32 +01:00
|
|
|
PluginTest::PluginTest(int &argc, char **argv, QCommandLineParser *parser)
|
|
|
|
: QApplication(argc, argv) // QApp needed for CursorNotificationHandler (QWidget)
|
2013-06-24 15:23:45 +02:00
|
|
|
{
|
|
|
|
d = new PluginTestPrivate;
|
|
|
|
d->parser = parser;
|
2019-08-30 17:26:54 +02:00
|
|
|
QTimer::singleShot(0, this, &PluginTest::runMain);
|
2013-06-24 15:23:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
PluginTest::~PluginTest()
|
|
|
|
{
|
|
|
|
delete d;
|
|
|
|
}
|
|
|
|
|
|
|
|
void PluginTest::runMain()
|
|
|
|
{
|
|
|
|
qDebug() << "plugin test runs: ";
|
2021-03-05 19:15:32 +01:00
|
|
|
// loadDataEngine();
|
|
|
|
// qDebug() << " - - - -- - - - - ------------------------------------\n";
|
|
|
|
// qDebug() << " libs are in: " << QCoreApplication::libraryPaths();
|
|
|
|
// //loadKQPlugin();
|
2013-07-23 03:28:37 +02:00
|
|
|
qDebug() << "::: loadKPlugin() == " << loadKPlugin();
|
2021-03-05 19:15:32 +01:00
|
|
|
//
|
2013-07-23 03:28:37 +02:00
|
|
|
qDebug() << " - - - -- - - - - ------------------------------------\n";
|
2016-06-12 15:50:26 +02:00
|
|
|
qDebug() << "::: loadFromPlasma() == " << loadFromPlasma();
|
2013-06-24 15:23:45 +02:00
|
|
|
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";
|
2016-02-29 00:08:05 +01:00
|
|
|
QString pluginPath = QStringLiteral("/home/sebas/kf5/install/lib/x86_64-linux-gnu/kplugins/");
|
2013-06-28 05:09:27 +02:00
|
|
|
QCoreApplication::addLibraryPath(pluginPath);
|
2021-03-05 19:15:32 +01:00
|
|
|
// QPluginLoader loader("/home/sebas/kf5/install/lib/x86_64-linux-gnu/kplugins/libkqpluginfactory.so", this);
|
2016-02-29 00:08:05 +01:00
|
|
|
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());
|
2021-03-05 19:15:32 +01:00
|
|
|
// QObject *factory = loader.instance();
|
2013-06-28 05:09:27 +02:00
|
|
|
if (factory) {
|
|
|
|
qDebug() << "loaded successfully and cast";
|
|
|
|
qDebug() << "metadata: " << loader.metaData();
|
2021-03-05 19:15:32 +01:00
|
|
|
// 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;
|
2021-03-05 19:15:32 +01:00
|
|
|
// 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";
|
2016-02-29 00:08:05 +01:00
|
|
|
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";
|
|
|
|
}
|
2021-03-05 19:15:32 +01:00
|
|
|
// 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;
|
2019-03-20 07:12:03 +01:00
|
|
|
for (const QString &e : allEngines) {
|
2013-07-23 03:28:37 +02:00
|
|
|
Plasma::DataEngine *engine = Plasma::PluginLoader::self()->loadDataEngine(e);
|
|
|
|
if (engine) {
|
2016-02-29 00:08:05 +01:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2013-06-27 04:01:34 +02:00
|
|
|
void PluginTest::loadKQPlugin()
|
|
|
|
{
|
|
|
|
qDebug() << "Load KQPlugin";
|
2013-06-28 05:09:27 +02:00
|
|
|
#if 0
|
2013-06-27 04:01:34 +02:00
|
|
|
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());
|
2013-06-27 04:01:34 +02:00
|
|
|
//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
|
|
|
|
2013-06-27 04:01:34 +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
|
2013-06-27 04:01:34 +02:00
|
|
|
}
|
|
|
|
|
2013-06-24 15:23:45 +02:00
|
|
|
void PluginTest::dataUpdated(QString s, Plasma::DataEngine::Data d)
|
|
|
|
{
|
2016-06-12 15:14:35 +02:00
|
|
|
qDebug() << "new data for source:" << s << d;
|
2013-06-24 15:23:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace Plasma
|
|
|
|
|
|
|
|
#include "moc_plugintest.cpp"
|