diff --git a/scriptengines/javascript/plasmoid/declarativeappletscript.cpp b/scriptengines/javascript/plasmoid/declarativeappletscript.cpp index 94361473d..4bb8be07c 100644 --- a/scriptengines/javascript/plasmoid/declarativeappletscript.cpp +++ b/scriptengines/javascript/plasmoid/declarativeappletscript.cpp @@ -368,6 +368,7 @@ void DeclarativeAppletScript::setupObjects() bindI18N(m_engine); global.setProperty("dataEngine", m_engine->newFunction(DeclarativeAppletScript::dataEngine)); global.setProperty("service", m_engine->newFunction(DeclarativeAppletScript::service)); + global.setProperty("loadService", m_engine->newFunction(DeclarativeAppletScript::loadService)); //Add stuff from Qt ByteArrayClass *baClass = new ByteArrayClass(m_engine); @@ -423,6 +424,25 @@ QScriptValue DeclarativeAppletScript::service(QScriptContext *context, QScriptEn return engine->newQObject(service, QScriptEngine::AutoOwnership); } +QScriptValue DeclarativeAppletScript::loadService(QScriptContext *context, QScriptEngine *engine) +{ + if (context->argumentCount() != 1) { + return context->throwError(i18n("service() takes one argument")); + } + + QString pluginName = context->argument(0).toString(); + + AppletInterface *interface = AppletInterface::extract(engine); + if (!interface) { + return context->throwError(i18n("Could not extract the Applet")); + } + + Plasma::Service *service = Plasma::Service::load(pluginName, interface); + + //kDebug( )<< "lets try to get" << source << "from" << dataEngine; + return engine->newQObject(service, QScriptEngine::AutoOwnership); +} + void DeclarativeAppletScript::setEngine(QScriptValue &val) { if (val.engine() == m_engine) { diff --git a/scriptengines/javascript/plasmoid/declarativeappletscript.h b/scriptengines/javascript/plasmoid/declarativeappletscript.h index a38d5efd8..7de9ee8c4 100644 --- a/scriptengines/javascript/plasmoid/declarativeappletscript.h +++ b/scriptengines/javascript/plasmoid/declarativeappletscript.h @@ -67,6 +67,7 @@ public: static QScriptValue newPlasmaExtenderItem(QScriptContext *context, QScriptEngine *engine); static QScriptValue dataEngine(QScriptContext *context, QScriptEngine *engine); static QScriptValue service(QScriptContext *context, QScriptEngine *engine); + static QScriptValue loadService(QScriptContext *context, QScriptEngine *engine); public Q_SLOTS: void dataUpdated(const QString &name, const Plasma::DataEngine::Data &data);