add setCurrentActivity to scripting
This commit is contained in:
parent
4b7b2356e0
commit
5cfa48062e
@ -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<bool> task = controller.setCurrentActivity(id);
|
||||
QEventLoop loop;
|
||||
|
||||
QFutureWatcher<bool> *watcher = new QFutureWatcher<bool>();
|
||||
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));
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user