From 7830cad43c7e6b9443ca4e87fad56875efc04536 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20K=C3=BCgler?= Date: Mon, 24 Jun 2013 15:23:45 +0200 Subject: [PATCH] small test app for plugin loading Loads a dataengine right now, for testing purposes of KPlugin* --- src/plasma/tests/testplugins/CMakeLists.txt | 13 ++ src/plasma/tests/testplugins/main.cpp | 43 ++++++ src/plasma/tests/testplugins/plugintest.cpp | 159 ++++++++++++++++++++ src/plasma/tests/testplugins/plugintest.h | 57 +++++++ 4 files changed, 272 insertions(+) create mode 100644 src/plasma/tests/testplugins/CMakeLists.txt create mode 100644 src/plasma/tests/testplugins/main.cpp create mode 100644 src/plasma/tests/testplugins/plugintest.cpp create mode 100644 src/plasma/tests/testplugins/plugintest.h diff --git a/src/plasma/tests/testplugins/CMakeLists.txt b/src/plasma/tests/testplugins/CMakeLists.txt new file mode 100644 index 000000000..5e69e6eec --- /dev/null +++ b/src/plasma/tests/testplugins/CMakeLists.txt @@ -0,0 +1,13 @@ +project("plugintest") + +add_executable(plugintest + main.cpp + plugintest.cpp +) + +target_link_libraries(plugintest kdeqt5staging plasma) + +message("INSTALL_TARGETS_DEFAULT_ARGS ${INSTALL_TARGETS_DEFAULT_ARGS}") + +#install(TARGETS plugintest ${INSTALL_TARGETS_DEFAULT_ARGS}) + diff --git a/src/plasma/tests/testplugins/main.cpp b/src/plasma/tests/testplugins/main.cpp new file mode 100644 index 000000000..ced488268 --- /dev/null +++ b/src/plasma/tests/testplugins/main.cpp @@ -0,0 +1,43 @@ +/* + * Copyright 2008 Aaron Seigo + * Copyright 2013 Sebastian Kügler + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2, + * or (at your option) any later version. + * + * This program 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 General Public License for more details + * + * You should have received a copy of the GNU Library General Public + * License along with this program; if not, write to the + * Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#include +#include +#include + +#include "plugintest.h" + +int main(int argc, char **argv) +{ + QCommandLineParser *parser = new QCommandLineParser; + Plasma::PluginTest app(argc, argv, parser); + + const QString description = i18n("Plugin test app"); + const char version[] = "2.0"; + + app.setApplicationVersion(version); + parser->addVersionOption(); + parser->addHelpOption(description); + + parser->addOption(QCommandLineOption(QStringList() << "s" << "show", i18nc("Do not translate ", "Show plugins"), "name")); + + return app.exec(); +} + diff --git a/src/plasma/tests/testplugins/plugintest.cpp b/src/plasma/tests/testplugins/plugintest.cpp new file mode 100644 index 000000000..d879bfc52 --- /dev/null +++ b/src/plasma/tests/testplugins/plugintest.cpp @@ -0,0 +1,159 @@ +/****************************************************************************** +* Copyright 2013 Sebastian Kügler * +* * +* 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" + +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include + + +namespace Plasma +{ +class PluginTestPrivate { +public: + QString pluginName; + QCommandLineParser *parser; +}; + +PluginTest::PluginTest(int& argc, char** argv, QCommandLineParser *parser) : + QApplication(argc, argv) +{ + d = new PluginTestPrivate; + d->parser = parser; + QTimer::singleShot(0, this, SLOT(runMain())); +} + +PluginTest::~PluginTest() +{ + delete d; +} + +void PluginTest::runMain() +{ + qDebug() << "plugin test runs: "; + loadDataEngine(); + exit(0); + return; +} + +void PluginTest::loadDataEngine(const QString &name) +{ +// DataEngine *engine = d->isDefaultLoader ? 0 : internalLoadDataEngine(name); +// if (engine) { +// return engine; +// } + + DataEngine *engine = 0; + // load the engine, add it to the engines + QString constraint = QString("[X-KDE-PluginInfo-Name] == '%1'").arg(name); + constraint = QString(); + KService::List offers = KServiceTypeTrader::self()->query("Plasma/DataEngine", + constraint); + QString error; + + if (offers.isEmpty()) { + qDebug() << "offers are empty for " << name << " with constraint " << constraint; + } else { + qDebug() << "Found a bunch of stuff"; + + QVariantList allArgs; + allArgs << offers.first()->storageId(); + QString api = offers.first()->property("X-Plasma-API").toString(); + if (api.isEmpty()) { + if (offers.first()) { + KPluginLoader plugin(*offers.first()); + if (Plasma::isPluginVersionCompatible(plugin.pluginVersion())) { + //KPluginInfo::List infos = KPluginInfo::fromServices(offers.first()); + //qDebug() << " plugininfo:" << info.name(); + engine = offers.first()->createInstance(0, allArgs, &error); + qDebug() << "DE"; + engine->connectSource("Europe/Amsterdam", this); + qDebug() << "SOURCE: " << engine->sources(); + //qDebug() << "DataEngine ID: " << engine->pluginInfo().name(); + } else { + qDebug() << "Plugin version incompatible" << plugin.pluginVersion(); + } + } + } else { + engine = new DataEngine(KPluginInfo(offers.first()), 0); + qDebug() << "DataEngine ID (from KPluginINfo): " << engine << engine->pluginInfo().icon() << engine->pluginInfo().name(); + } + QStringList result; + foreach (const KService::Ptr &service, offers) { + const QString _plugin = service->property("X-KDE-PluginInfo-Name", QVariant::String).toString(); + qDebug() << "Found plugin: " << _plugin; + if (!result.contains(_plugin)) { + result << _plugin; + //engine = PluginLoader::self()->loadDataEngine(_plugin); + //engine = PluginLoader::self()->loadDataEngine(name); + //qDebug() << "SOURCE: " << engine->sources(); + + //engine->setPluginInfo(service->pluginInfo()); + //qDebug() << engine->pluginInfo().name(); + } + } + + } + + if (!engine) { + qDebug() << "Couldn't load engine \"" << name << "\". Error given: " << error; + } + + //return engine; +} + +void PluginTest::dataUpdated(QString s, Plasma::DataEngine::Data d) +{ + qDebug() << "new data for source: " << s << d; + + + + + +} + +} // namespace Plasma + +#include "moc_plugintest.cpp" + diff --git a/src/plasma/tests/testplugins/plugintest.h b/src/plasma/tests/testplugins/plugintest.h new file mode 100644 index 000000000..232d50726 --- /dev/null +++ b/src/plasma/tests/testplugins/plugintest.h @@ -0,0 +1,57 @@ +/****************************************************************************** +* Copyright 2012 Sebastian Kügler * +* * +* 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. * +*******************************************************************************/ + +#ifndef PLUGINTEST_H +#define PLUGINTEST_H + +#include +#include + +#include + +class QCommandLineParser; +class KJob; + +namespace Plasma +{ + +class PluginTestPrivate; + +class PluginTest : public QApplication +{ + Q_OBJECT + + public: + PluginTest(int& argc, char** argv, QCommandLineParser *parser); + virtual ~PluginTest(); + + void showPackageInfo(const QString &pluginName); + + public Q_SLOTS: + void runMain(); + void loadDataEngine(const QString &name = QString()); + void dataUpdated(QString s, Plasma::DataEngine::Data d); + + private: + PluginTestPrivate* d; +}; + +} + +#endif