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
|
|
|
|
2013-08-09 04:14:26 +02:00
|
|
|
#include <QDebug>
|
2020-07-08 07:44:43 +02:00
|
|
|
#include <KService>
|
|
|
|
#include <KServiceTypeTrader>
|
|
|
|
#include <KShell>
|
|
|
|
#include <KSycoca>
|
|
|
|
#include <KLocalizedString>
|
2013-06-24 15:23:45 +02:00
|
|
|
|
|
|
|
#include <plasma/applet.h>
|
|
|
|
#include <plasma/packagestructure.h>
|
|
|
|
#include <plasma/package.h>
|
|
|
|
#include <plasma/pluginloader.h>
|
|
|
|
#include <plasma/dataengine.h>
|
2020-07-08 07:44:43 +02:00
|
|
|
#include <KJob>
|
2013-06-24 15:23:45 +02:00
|
|
|
|
2020-07-08 07:44:43 +02:00
|
|
|
#include <QCommandLineParser>
|
2013-06-24 15:23:45 +02:00
|
|
|
#include <QDir>
|
|
|
|
#include <QDBusInterface>
|
|
|
|
#include <QFileInfo>
|
|
|
|
#include <QMap>
|
|
|
|
#include <QStandardPaths>
|
|
|
|
#include <QStringList>
|
|
|
|
#include <QTimer>
|
2013-06-27 04:01:34 +02:00
|
|
|
#include <QJsonObject>
|
2013-06-24 15:23:45 +02:00
|
|
|
|
|
|
|
#include <iostream>
|
|
|
|
#include <iomanip>
|
|
|
|
|
|
|
|
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;
|
|
|
|
};
|
|
|
|
|
2014-04-26 01:45:47 +02:00
|
|
|
PluginTest::PluginTest(int &argc, char **argv, QCommandLineParser *parser) :
|
2016-06-12 15:14:35 +02:00
|
|
|
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: ";
|
2013-06-27 04:01:34 +02:00
|
|
|
//loadDataEngine();
|
2013-07-30 21:26:47 +02:00
|
|
|
// qDebug() << " - - - -- - - - - ------------------------------------\n";
|
|
|
|
// qDebug() << " libs are in: " << QCoreApplication::libraryPaths();
|
|
|
|
// //loadKQPlugin();
|
2013-07-23 03:28:37 +02:00
|
|
|
qDebug() << "::: loadKPlugin() == " << loadKPlugin();
|
2013-07-30 21:26:47 +02: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);
|
|
|
|
//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());
|
2013-06-28 05:09:27 +02:00
|
|
|
//QObject *factory = loader.instance();
|
|
|
|
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;
|
2013-06-28 05:09:27 +02:00
|
|
|
// Plasma::DataEngine *time_engine = factory->create(this, QVariantList());
|
|
|
|
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";
|
|
|
|
}
|
|
|
|
//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"
|
|
|
|
|