From 84d67b43c67df664e9b3a924bbef10c8a9fbeb91 Mon Sep 17 00:00:00 2001 From: Ivailo Monev Date: Sat, 2 Apr 2016 00:25:23 +0000 Subject: [PATCH] plasma: make share dataengine use QScriptEngine instead of Kross Signed-off-by: Ivailo Monev --- plasma/dataengines/share/CMakeLists.txt | 3 +- plasma/dataengines/share/shareservice.cpp | 121 +++++++++++++----------------- plasma/dataengines/share/shareservice.h | 8 +- 3 files changed, 56 insertions(+), 76 deletions(-) diff --git a/plasma/dataengines/share/CMakeLists.txt b/plasma/dataengines/share/CMakeLists.txt index e2e58a6b..c3849ef1 100644 --- a/plasma/dataengines/share/CMakeLists.txt +++ b/plasma/dataengines/share/CMakeLists.txt @@ -10,8 +10,7 @@ kde4_add_plugin(plasma_engine_share ${share_engine_SRCS}) target_link_libraries(plasma_engine_share ${KDE4_KDECORE_LIBS} ${KDE4_PLASMA_LIBS} - ${KDE4_KIO_LIBS} - ${KDE4_KROSSCORE_LIBS}) + ${KDE4_KIO_LIBS}) install(TARGETS plasma_engine_share DESTINATION ${PLUGIN_INSTALL_DIR}) diff --git a/plasma/dataengines/share/shareservice.cpp b/plasma/dataengines/share/shareservice.cpp index 1b71a86a..7f3dc59a 100644 --- a/plasma/dataengines/share/shareservice.cpp +++ b/plasma/dataengines/share/shareservice.cpp @@ -17,11 +17,6 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . * ***************************************************************************/ -#include - -#include -#include -#include #include #include @@ -45,13 +40,13 @@ Plasma::ServiceJob *ShareService::createJob(const QString &operation, ShareJob::ShareJob(const QString &destination, const QString &operation, QMap ¶meters, QObject *parent) : Plasma::ServiceJob(destination, operation, parameters, parent), - m_action(0), m_provider(0), m_package(0) + m_engine(0), m_provider(0), m_package(0) { } ShareJob::~ShareJob() { - delete m_action; + delete m_engine; delete m_provider; delete m_package; } @@ -82,77 +77,65 @@ void ShareJob::start() m_package->path() + m_package->structure()->contentsPrefixPaths().at(0) + m_package->structure()->path("mainscript"); - if (!QFile::exists(mainscript)) { + QFile mainfile(mainscript); + if (!mainfile.exists()) { showError(i18n("Selected provider does not have a valid script file")); return; } + mainfile.open(QIODevice::ReadOnly); + + QScriptEngine * m_engine = new QScriptEngine(parent()); + if (!m_engine) { + showError(i18n("Could not initialize engine")); + return; + } - const QString interpreter = - Kross::Manager::self().interpreternameForFile(mainscript); + m_provider = new ShareProvider(this); + connect(m_provider, SIGNAL(readyToPublish()), this, SLOT(publish())); + connect(m_provider, SIGNAL(finished(QString)), + this, SLOT(showResult(QString))); + connect(m_provider, SIGNAL(finishedError(QString)), + this, SLOT(showError(QString))); - if (interpreter.isEmpty()) { - showError(i18n("Selected provider does not provide a supported script file")); + QScriptValue provideproto = m_engine->newQObject(m_provider); + m_engine->globalObject().setProperty("provider", provideproto); + + QScriptValue maincode = m_engine->evaluate(mainfile.readAll(), mainscript); + + if(m_engine->hasUncaughtException()) { + showError(i18n("Error trying to execute script")); return; } - m_action = new Kross::Action(parent(), pluginName); - if (m_action) { - m_provider = new ShareProvider(this); - connect(m_provider, SIGNAL(readyToPublish()), this, SLOT(publish())); - connect(m_provider, SIGNAL(finished(QString)), - this, SLOT(showResult(QString))); - connect(m_provider, SIGNAL(finishedError(QString)), - this, SLOT(showError(QString))); - - // automatically connects signals and slots with the script - m_action->addObject(m_provider, "provider", - Kross::ChildrenInterface::AutoConnectSignals); - - // set the main script file and load it - m_action->setFile(mainscript); - m_action->trigger(); - - // check for any errors - if(m_action->hadError()) { - showError(i18n("Error trying to execute script")); - return; - } - - // do the work together with the loaded plugin - const QStringList functions = m_action->functionNames(); - if (!functions.contains("url") || !functions.contains("contentKey") || - !functions.contains("setup")) { - showError(i18n("Could not find all required functions")); - return; - } - - // call the methods from the plugin - const QString url = - m_action->callFunction("url", QVariantList()).toString(); - m_provider->setUrl(url); - - // setup the method (get/post) - QVariant vmethod; - if (functions.contains("method")) { - vmethod = - m_action->callFunction("method", QVariantList()).toString(); - } - - // default is POST (if the plugin does not specify one method) - const QString method = vmethod.isValid() ? vmethod.toString() : "POST"; - m_provider->setMethod(method); - - // setup the provider - QVariant setup = m_action->callFunction("setup", QVariantList()); - - // get the content from the parameters, set the url and add the file - // then we can wait the signal to publish the information - const QString contentKey = - m_action->callFunction("contentKey", QVariantList()).toString(); - - const QString content(parameters()["content"].toString()); - m_provider->addPostFile(contentKey, content); + QScriptValue mainobject = m_engine->globalObject(); + // do the work together with the loaded plugin + if (!mainobject.property("url").isFunction() + || !mainobject.property("contentKey").isFunction() + || !mainobject.property("setup").isFunction()) { + showError(i18n("Could not find all required functions")); + return; } + + // call the methods from the plugin + const QString url = mainobject.property("url").call().toString(); + m_provider->setUrl(url); + + // default is POST (if the plugin does not specify one method) + QVariant method = "POST"; + if (mainobject.property("method").isFunction()) { + method = mainobject.property("method").call().toString(); + } + m_provider->setMethod(method.toString()); + + // setup the provider + QScriptValue setup = mainobject.property("setup").call(); + + // get the content from the parameters, set the url and add the file + // then we can wait the signal to publish the information + const QString contentKey = mainobject.property("contentKey").call().toString(); + + const QString content(parameters()["content"].toString()); + m_provider->addPostFile(contentKey, content); } } diff --git a/plasma/dataengines/share/shareservice.h b/plasma/dataengines/share/shareservice.h index aa075911..fbdc04fa 100644 --- a/plasma/dataengines/share/shareservice.h +++ b/plasma/dataengines/share/shareservice.h @@ -22,6 +22,8 @@ #include "shareengine.h" +#include + #include #include @@ -32,10 +34,6 @@ namespace Plasma { class Package; } -namespace Kross { - class Action; -} - class ShareService : public Plasma::Service { Q_OBJECT @@ -62,7 +60,7 @@ public slots: void showError(const QString &msg); private: - Kross::Action *m_action; + QScriptEngine *m_engine; ShareProvider *m_provider; Plasma::Package *m_package; }; -- 2.11.0