Load the time engine from the KService

This commit is contained in:
Sebastian Kügler 2013-06-28 05:09:27 +02:00
parent 9035691567
commit a21400096a
4 changed files with 66 additions and 14 deletions

View File

@ -62,6 +62,12 @@ DataEngine::DataEngine(const KPluginInfo &plugin, QObject *parent)
} }
} }
DataEngine::DataEngine(QObject* parent, const QVariantList &args)
: Plasma::DataEngine(KPluginInfo(), parent)
{
qDebug() << "wrong constructor for timeengine :(";
}
DataEngine::~DataEngine() DataEngine::~DataEngine()
{ {
//kDebug() << objectName() << ": bye bye birdy! "; //kDebug() << objectName() << ": bye bye birdy! ";

View File

@ -73,6 +73,8 @@ class PLASMA_EXPORT DataEngine : public QObject
**/ **/
explicit DataEngine(const KPluginInfo &plugin, QObject *parent = 0); explicit DataEngine(const KPluginInfo &plugin, QObject *parent = 0);
explicit DataEngine(QObject* parent = 0, const QVariantList& args = QVariantList());
~DataEngine(); ~DataEngine();
/** /**

View File

@ -19,7 +19,7 @@
#include "plugintest.h" #include "plugintest.h"
#include <kqpluginfactory.h> #include <kpluginfactory.h>
#include <kdebug.h> #include <kdebug.h>
#include <kservice.h> #include <kservice.h>
@ -76,21 +76,24 @@ void PluginTest::runMain()
{ {
qDebug() << "plugin test runs: "; qDebug() << "plugin test runs: ";
//loadDataEngine(); //loadDataEngine();
qDebug() << " libs are in: " << QCoreApplication::libraryPaths();
qDebug() << " - - - -- - - - - ------------------------------------\n"; qDebug() << " - - - -- - - - - ------------------------------------\n";
loadKQPlugin(); qDebug() << " libs are in: " << QCoreApplication::libraryPaths();
//loadKQPlugin();
loadKPlugin();
qDebug() << " - - - -- - - - - ------------------------------------\n";
loadKService();
exit(0); exit(0);
return; return;
} }
void PluginTest::loadKQPlugin() void PluginTest::loadKPlugin()
{ {
qDebug() << "Load KQPlugin"; qDebug() << "Load KPlugin";
QString pluginPath = "/home/sebas/kf5/install/lib/x86_64-linux-gnu/kplugins/"; QString pluginPath = "/home/sebas/kf5/install/lib/x86_64-linux-gnu/kplugins/";
QCoreApplication::addLibraryPath(pluginPath); 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/kplugins/libkqpluginfactory.so", this);
QPluginLoader loader("/home/sebas/kf5/install/lib/x86_64-linux-gnu/plugins/kf5/kplugins/libplasma_engine_time.so", this); QPluginLoader loader("/home/sebas/kf5/install/lib/x86_64-linux-gnu/plugins/kf5/kplugins/libplasma_engine_time.so", this);
KQPluginFactory *factory = qobject_cast<KQPluginFactory*>(loader.instance()); KPluginFactory *factory = qobject_cast<KPluginFactory*>(loader.instance());
//QObject *factory = loader.instance(); //QObject *factory = loader.instance();
if (factory) { if (factory) {
qDebug() << "loaded successfully and cast"; qDebug() << "loaded successfully and cast";
@ -98,8 +101,9 @@ void PluginTest::loadKQPlugin()
//QObject *o = factory->createPlugin("time"); //QObject *o = factory->createPlugin("time");
//qDebug() << " objec name:" << o->objectName(); //qDebug() << " objec name:" << o->objectName();
//Plasma::DataEngine *time_engine = qobject_cast<Plasma::DataEngine*>(factory->create(this, QVariantList())); //Plasma::DataEngine *time_engine = qobject_cast<Plasma::DataEngine*>(factory->create(this, QVariantList()));
//Plasma::DataEngine *time_engine = factory->create(this, QVariantList()); Plasma::DataEngine *time_engine = 0;
Plasma::DataEngine *time_engine = factory->createInstance<Plasma::DataEngine>(this); // Plasma::DataEngine *time_engine = factory->create(this, QVariantList());
time_engine = factory->create<Plasma::DataEngine>(this, QVariantList());
if (time_engine) { if (time_engine) {
qDebug() << "Successfully loaded timeengine"; qDebug() << "Successfully loaded timeengine";
@ -117,13 +121,48 @@ void PluginTest::loadKQPlugin()
} }
void PluginTest::loadDataEngine(const QString &name) void PluginTest::loadKQPlugin()
{
qDebug() << "Load KQPlugin";
#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);
KPluginFactory *factory = qobject_cast<KPluginFactory*>(loader.instance());
//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()));
//Plasma::DataEngine *time_engine = factory->create(this, QVariantList());
Plasma::DataEngine *time_engine = factory->createInstance<Plasma::DataEngine>(0, this, QVariantList());
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);
#endif
}
void PluginTest::loadKService(const QString &name)
{ {
// DataEngine *engine = d->isDefaultLoader ? 0 : internalLoadDataEngine(name); // DataEngine *engine = d->isDefaultLoader ? 0 : internalLoadDataEngine(name);
// if (engine) { // if (engine) {
// return engine; // return engine;
// } // }
qDebug() << "Load KService";
DataEngine *engine = 0; DataEngine *engine = 0;
// load the engine, add it to the engines // load the engine, add it to the engines
QString constraint = QString("[X-KDE-PluginInfo-Name] == '%1'").arg(name); QString constraint = QString("[X-KDE-PluginInfo-Name] == '%1'").arg(name);
@ -148,9 +187,13 @@ void PluginTest::loadDataEngine(const QString &name)
//qDebug() << " plugininfo:" << info.name(); //qDebug() << " plugininfo:" << info.name();
engine = offers.first()->createInstance<Plasma::DataEngine>(0, allArgs, &error); engine = offers.first()->createInstance<Plasma::DataEngine>(0, allArgs, &error);
qDebug() << "DE"; qDebug() << "DE";
engine->connectSource("Europe/Amsterdam", this); if (engine) {
qDebug() << "SOURCE: " << engine->sources(); engine->connectSource("Europe/Amsterdam", this);
//qDebug() << "DataEngine ID: " << engine->pluginInfo().name(); qDebug() << "SOURCE: " << engine->sources();
//qDebug() << "DataEngine ID: " << engine->pluginInfo().name();
} else {
qDebug() << "Engine invalid";
}
} else { } else {
qDebug() << "Plugin version incompatible" << plugin.pluginVersion(); qDebug() << "Plugin version incompatible" << plugin.pluginVersion();
} }

View File

@ -45,8 +45,9 @@ class PluginTest : public QApplication
public Q_SLOTS: public Q_SLOTS:
void runMain(); void runMain();
void loadKPlugin();
void loadKQPlugin(); void loadKQPlugin();
void loadDataEngine(const QString &name = QString()); void loadKService(const QString &name = QString());
void dataUpdated(QString s, Plasma::DataEngine::Data d); void dataUpdated(QString s, Plasma::DataEngine::Data d);
private: private: