From 5cfa48062ea9504a512d8e9462ad9b899ad3e0ab Mon Sep 17 00:00:00 2001 From: Marco Martin Date: Fri, 28 Mar 2014 11:02:49 +0100 Subject: [PATCH] add setCurrentActivity to scripting --- src/shell/scripting/scriptengine.cpp | 26 ++++++++++++++++++++++++-- src/shell/scripting/scriptengine.h | 1 + src/shell/shellcorona.h | 1 + 3 files changed, 26 insertions(+), 2 deletions(-) diff --git a/src/shell/scripting/scriptengine.cpp b/src/shell/scripting/scriptengine.cpp index 1c532a027..80f9ed3c1 100644 --- a/src/shell/scripting/scriptengine.cpp +++ b/src/shell/scripting/scriptengine.cpp @@ -129,8 +129,6 @@ QScriptValue ScriptEngine::desktopForScreen(QScriptContext *context, QScriptEngi QScriptValue ScriptEngine::createActivity(QScriptContext *context, QScriptEngine *engine) { - //return createContainment("Desktop", "org.kde.desktopcontainment", context, engine); - if (context->argumentCount() < 0) { return context->throwError(i18n("createActivity required the activity name")); } @@ -160,6 +158,29 @@ QScriptValue ScriptEngine::createActivity(QScriptContext *context, QScriptEngine return QScriptValue(id.result()); } +QScriptValue ScriptEngine::setCurrentActivity(QScriptContext *context, QScriptEngine *engine) +{ + if (context->argumentCount() < 0) { + return context->throwError(i18n("setCurrentActivity required the activity id")); + } + + const QString id = context->argument(0).toString(); + + KActivities::Controller controller; + + QFuture task = controller.setCurrentActivity(id); + QEventLoop loop; + + QFutureWatcher *watcher = new QFutureWatcher(); + connect(watcher, &QFutureWatcherBase::finished, &loop, &QEventLoop::quit); + + watcher->setFuture(task); + + loop.exec(); + + return QScriptValue(task.result()); +} + QScriptValue ScriptEngine::newPanel(QScriptContext *context, QScriptEngine *engine) { return createContainment("Panel", "org.kde.panel", context, engine); @@ -657,6 +678,7 @@ void ScriptEngine::setupEngine() m_scriptSelf.setProperty("QRectF", constructQRectFClass(this)); m_scriptSelf.setProperty("createActivity", newFunction(ScriptEngine::createActivity)); + m_scriptSelf.setProperty("setCurrentActivity", newFunction(ScriptEngine::setCurrentActivity)); m_scriptSelf.setProperty("Panel", newFunction(ScriptEngine::newPanel, newObject())); m_scriptSelf.setProperty("desktopsForActivity", newFunction(ScriptEngine::desktopsForActivity)); m_scriptSelf.setProperty("desktops", newFunction(ScriptEngine::desktops)); diff --git a/src/shell/scripting/scriptengine.h b/src/shell/scripting/scriptengine.h index 22b7f7a4b..578306d3e 100644 --- a/src/shell/scripting/scriptengine.h +++ b/src/shell/scripting/scriptengine.h @@ -70,6 +70,7 @@ private: // containment accessors static QStringList availableContainments(const QString &type); static QScriptValue createActivity(QScriptContext *context, QScriptEngine *engine); + static QScriptValue setCurrentActivity(QScriptContext *context, QScriptEngine *engine); static QScriptValue newPanel(QScriptContext *context, QScriptEngine *engine); static QScriptValue desktopsForActivity(QScriptContext *context, QScriptEngine *engine); static QScriptValue desktops(QScriptContext *context, QScriptEngine *engine); diff --git a/src/shell/shellcorona.h b/src/shell/shellcorona.h index 37842f77a..b26825357 100644 --- a/src/shell/shellcorona.h +++ b/src/shell/shellcorona.h @@ -72,6 +72,7 @@ public: Plasma::Package lookAndFeelPackage() const; + //Those two are a bit of an hack but are just for desktop scripting Activity *activity(const QString &id); void insertActivity(const QString &id, Activity *activity);