plasma-framework/tests/kplugins/plugintest.cpp

189 lines
6.9 KiB
C++
Raw Normal View History

/******************************************************************************
* Copyright 2013 Sebastian Kügler <sebas@kde.org> *
* *
* This library is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Library General Public *
* License as published by the Free Software Foundation; either *
* version 2 of the License, or (at your option) any later version. *
* *
* This library is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
* Library General Public License for more details. *
* *
* You should have received a copy of the GNU Library General Public License *
* along with this library; see the file COPYING.LIB. If not, write to *
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, *
* Boston, MA 02110-1301, USA. *
*******************************************************************************/
#include "plugintest.h"
2013-06-28 05:09:27 +02:00
#include <kpluginfactory.h>
2013-08-09 04:14:26 +02:00
#include <QDebug>
#include <kservice.h>
#include <kservicetypetrader.h>
#include <kshell.h>
2013-10-05 04:30:19 +02:00
#include <ksycoca.h>
#include <klocalizedstring.h>
#include <plasma/applet.h>
#include <plasma/packagestructure.h>
#include <plasma/package.h>
#include <plasma/pluginloader.h>
#include <plasma/dataengine.h>
#include <kjob.h>
#include <qcommandlineparser.h>
#include <QDir>
#include <QDBusInterface>
#include <QFileInfo>
#include <QMap>
#include <QStandardPaths>
#include <QStringList>
#include <QTimer>
#include <QJsonObject>
#include <iostream>
#include <iomanip>
namespace Plasma
{
2014-04-26 01:45:47 +02:00
class PluginTestPrivate
{
public:
QString pluginName;
QCommandLineParser *parser;
};
2014-04-26 01:45:47 +02:00
PluginTest::PluginTest(int &argc, char **argv, QCommandLineParser *parser) :
QApplication(argc, argv) // QApp needed for CursorNotificationHandler (QWidget)
{
d = new PluginTestPrivate;
d->parser = parser;
QTimer::singleShot(0, this, SLOT(runMain()));
}
PluginTest::~PluginTest()
{
delete d;
}
void PluginTest::runMain()
{
qDebug() << "plugin test runs: ";
//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();
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());
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";
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;
foreach (const QString &e, allEngines) {
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"