Make the desktop scripting activity aware:
adapt the desktop scripting from the time when Containment == activity to creating actual activities * activities() -> desktops() * activityById() -> desktopById() * activityForScreen() -> desktopForScreen() To create a new activity, there is the new global function createActivity(activtyName, containmentPlugin (optional)) when you want to access the actual containments created by the activity, you do Array[containments] = desktopsForActivity(activityId)
This commit is contained in:
parent
04bf0ddaed
commit
abdca6f189
@ -161,6 +161,11 @@ void Activity::setDefaultPlugin(const QString &plugin)
|
||||
//FIXME save&restore this setting
|
||||
}
|
||||
|
||||
QString Activity::defaultPlugin() const
|
||||
{
|
||||
return m_plugin;
|
||||
}
|
||||
|
||||
const KActivities::Info * Activity::info() const
|
||||
{
|
||||
return m_info;
|
||||
|
@ -87,6 +87,11 @@ public:
|
||||
*/
|
||||
void setDefaultPlugin(const QString &plugin);
|
||||
|
||||
/**
|
||||
* The plugin to use when creating new containments
|
||||
*/
|
||||
QString defaultPlugin() const;
|
||||
|
||||
/**
|
||||
* @returns the info object for this activity
|
||||
*/
|
||||
|
@ -47,18 +47,18 @@
|
||||
#include <KTextEditor/View>
|
||||
#include <KToolBar>
|
||||
|
||||
#include <Plasma/Corona>
|
||||
#include <Plasma/Package>
|
||||
|
||||
#include "scripting/desktopscriptengine.h"
|
||||
#include "shellpluginloader.h"
|
||||
#include "shellcorona.h"
|
||||
|
||||
//TODO:
|
||||
// interative help?
|
||||
static const QString s_autosaveFileName("interactiveconsoleautosave.js");
|
||||
static const QString s_kwinService = "org.kde.kwin.Scripting";
|
||||
|
||||
InteractiveConsole::InteractiveConsole(Plasma::Corona *corona, QWidget *parent)
|
||||
InteractiveConsole::InteractiveConsole(ShellCorona *corona, QWidget *parent)
|
||||
: QDialog(parent),
|
||||
m_corona(corona),
|
||||
m_splitter(new QSplitter(Qt::Vertical, this)),
|
||||
|
@ -36,6 +36,8 @@ class QMenu;
|
||||
class KTextEdit;
|
||||
class QTextBrowser;
|
||||
|
||||
class ShellCorona;
|
||||
|
||||
namespace KTextEditor
|
||||
{
|
||||
class Document;
|
||||
@ -53,7 +55,7 @@ class InteractiveConsole : public QDialog
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
InteractiveConsole(Plasma::Corona *corona, QWidget *parent = 0);
|
||||
InteractiveConsole(ShellCorona *corona, QWidget *parent = 0);
|
||||
~InteractiveConsole();
|
||||
|
||||
void loadScript(const QString &path);
|
||||
@ -93,7 +95,7 @@ private:
|
||||
void onClose();
|
||||
void saveScript(const QUrl &url);
|
||||
|
||||
Plasma::Corona *m_corona;
|
||||
ShellCorona *m_corona;
|
||||
QSplitter *m_splitter;
|
||||
KTextEditor::Document *m_editorPart;
|
||||
KTextEdit *m_editor;
|
||||
|
@ -31,7 +31,7 @@
|
||||
namespace WorkspaceScripting
|
||||
{
|
||||
|
||||
DesktopScriptEngine::DesktopScriptEngine(Plasma::Corona *corona, bool startup, QObject *parent)
|
||||
DesktopScriptEngine::DesktopScriptEngine(ShellCorona *corona, bool startup, QObject *parent)
|
||||
: ScriptEngine(corona, parent),
|
||||
m_startup(startup)
|
||||
{
|
||||
|
@ -22,6 +22,8 @@
|
||||
|
||||
#include "scriptengine.h"
|
||||
|
||||
class ShellCorona;
|
||||
|
||||
namespace WorkspaceScripting
|
||||
{
|
||||
|
||||
@ -30,7 +32,7 @@ class DesktopScriptEngine : public ScriptEngine
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
DesktopScriptEngine(Plasma::Corona *corona, bool isStartup = true, QObject *parent = 0);
|
||||
DesktopScriptEngine(ShellCorona *corona, bool isStartup = true, QObject *parent = 0);
|
||||
QScriptValue wrap(Plasma::Containment *c);
|
||||
QScriptValue wrap(Containment *c);
|
||||
int defaultPanelScreen() const;
|
||||
|
@ -27,6 +27,7 @@
|
||||
#include <QFileInfo>
|
||||
#include <QScriptValueIterator>
|
||||
#include <QStandardPaths>
|
||||
#include <QFutureWatcher>
|
||||
|
||||
#include <QDebug>
|
||||
#include <klocalizedstring.h>
|
||||
@ -39,7 +40,6 @@
|
||||
|
||||
#include <Plasma/Applet>
|
||||
#include <Plasma/Containment>
|
||||
#include <Plasma/Corona>
|
||||
#include <Plasma/Package>
|
||||
#include <Plasma/PluginLoader>
|
||||
#include <qstandardpaths.h>
|
||||
@ -50,13 +50,15 @@
|
||||
#include "i18n.h"
|
||||
//#include "packages.h"
|
||||
#include "widget.h"
|
||||
#include "../activity.h"
|
||||
#include "../shellcorona.h"
|
||||
|
||||
QScriptValue constructQRectFClass(QScriptEngine *engine);
|
||||
|
||||
namespace WorkspaceScripting
|
||||
{
|
||||
|
||||
ScriptEngine::ScriptEngine(Plasma::Corona *corona, QObject *parent)
|
||||
ScriptEngine::ScriptEngine(ShellCorona *corona, QObject *parent)
|
||||
: QScriptEngine(parent),
|
||||
m_corona(corona)
|
||||
{
|
||||
@ -75,7 +77,7 @@ ScriptEngine::~ScriptEngine()
|
||||
{
|
||||
}
|
||||
|
||||
QScriptValue ScriptEngine::activityById(QScriptContext *context, QScriptEngine *engine)
|
||||
QScriptValue ScriptEngine::desktopById(QScriptContext *context, QScriptEngine *engine)
|
||||
{
|
||||
if (context->argumentCount() == 0) {
|
||||
return context->throwError(i18n("activityById requires an id"));
|
||||
@ -92,7 +94,29 @@ QScriptValue ScriptEngine::activityById(QScriptContext *context, QScriptEngine *
|
||||
return engine->undefinedValue();
|
||||
}
|
||||
|
||||
QScriptValue ScriptEngine::activityForScreen(QScriptContext *context, QScriptEngine *engine)
|
||||
QScriptValue ScriptEngine::desktopsForActivity(QScriptContext *context, QScriptEngine *engine)
|
||||
{
|
||||
if (context->argumentCount() == 0) {
|
||||
return context->throwError(i18n("containmentsByActivity requires an id"));
|
||||
}
|
||||
|
||||
QScriptValue containments = engine->newArray();
|
||||
int count = 0;
|
||||
|
||||
const QString id = context->argument(0).toString();
|
||||
ScriptEngine *env = envFor(engine);
|
||||
foreach (Plasma::Containment *c, env->m_corona->containments()) {
|
||||
if (c->activity() == id && !isPanel(c)) {
|
||||
containments.setProperty(count, env->wrap(c));
|
||||
++count;
|
||||
}
|
||||
}
|
||||
|
||||
containments.setProperty("length", count);
|
||||
return containments;
|
||||
}
|
||||
|
||||
QScriptValue ScriptEngine::desktopForScreen(QScriptContext *context, QScriptEngine *engine)
|
||||
{
|
||||
if (context->argumentCount() == 0) {
|
||||
return context->throwError(i18n("activityForScreen requires a screen id"));
|
||||
@ -103,9 +127,37 @@ QScriptValue ScriptEngine::activityForScreen(QScriptContext *context, QScriptEng
|
||||
return env->wrap(env->m_corona->containmentForScreen(screen));
|
||||
}
|
||||
|
||||
QScriptValue ScriptEngine::newActivity(QScriptContext *context, QScriptEngine *engine)
|
||||
QScriptValue ScriptEngine::createActivity(QScriptContext *context, QScriptEngine *engine)
|
||||
{
|
||||
return createContainment("Desktop", "org.kde.desktopcontainment", context, engine);
|
||||
//return createContainment("Desktop", "org.kde.desktopcontainment", context, engine);
|
||||
|
||||
if (context->argumentCount() < 0) {
|
||||
return context->throwError(i18n("createActivity required the activity name"));
|
||||
}
|
||||
|
||||
const QString name = context->argument(0).toString();
|
||||
const QString plugin = context->argument(1).toString();
|
||||
|
||||
KActivities::Controller controller;
|
||||
|
||||
QFuture<QString> id = controller.addActivity(name);
|
||||
QEventLoop loop;
|
||||
|
||||
QFutureWatcher<QString> *watcher = new QFutureWatcher<QString>();
|
||||
connect(watcher, &QFutureWatcherBase::finished, &loop, &QEventLoop::quit);
|
||||
|
||||
watcher->setFuture(id);
|
||||
|
||||
loop.exec();
|
||||
|
||||
ScriptEngine *env = envFor(engine);
|
||||
Activity *a = new Activity(id, env->m_corona);
|
||||
if (!plugin.isEmpty()) {
|
||||
a->setDefaultPlugin(plugin);
|
||||
}
|
||||
env->m_corona->insertActivity(id, a);
|
||||
|
||||
return QScriptValue(id.result());
|
||||
}
|
||||
|
||||
QScriptValue ScriptEngine::newPanel(QScriptContext *context, QScriptEngine *engine)
|
||||
@ -197,7 +249,7 @@ ScriptEngine *ScriptEngine::envFor(QScriptEngine *engine)
|
||||
QScriptValue ScriptEngine::panelById(QScriptContext *context, QScriptEngine *engine)
|
||||
{
|
||||
if (context->argumentCount() == 0) {
|
||||
return context->throwError(i18n("activityById requires an id"));
|
||||
return context->throwError(i18n("panelById requires an id"));
|
||||
}
|
||||
|
||||
const uint id = context->argument(0).toInt32();
|
||||
@ -604,11 +656,12 @@ void ScriptEngine::setupEngine()
|
||||
}
|
||||
|
||||
m_scriptSelf.setProperty("QRectF", constructQRectFClass(this));
|
||||
m_scriptSelf.setProperty("Activity", newFunction(ScriptEngine::newActivity));
|
||||
m_scriptSelf.setProperty("createActivity", newFunction(ScriptEngine::createActivity));
|
||||
m_scriptSelf.setProperty("Panel", newFunction(ScriptEngine::newPanel, newObject()));
|
||||
m_scriptSelf.setProperty("activities", newFunction(ScriptEngine::activities));
|
||||
m_scriptSelf.setProperty("activityById", newFunction(ScriptEngine::activityById));
|
||||
m_scriptSelf.setProperty("activityForScreen", newFunction(ScriptEngine::activityForScreen));
|
||||
m_scriptSelf.setProperty("desktopsForActivity", newFunction(ScriptEngine::desktopsForActivity));
|
||||
m_scriptSelf.setProperty("desktops", newFunction(ScriptEngine::desktops));
|
||||
m_scriptSelf.setProperty("desktopById", newFunction(ScriptEngine::desktopById));
|
||||
m_scriptSelf.setProperty("desktopForScreen", newFunction(ScriptEngine::desktopForScreen));
|
||||
m_scriptSelf.setProperty("panelById", newFunction(ScriptEngine::panelById));
|
||||
m_scriptSelf.setProperty("panels", newFunction(ScriptEngine::panels));
|
||||
m_scriptSelf.setProperty("fileExists", newFunction(ScriptEngine::fileExists));
|
||||
@ -633,7 +686,7 @@ bool ScriptEngine::isPanel(const Plasma::Containment *c)
|
||||
c->containmentType() == Plasma::Types::CustomPanelContainment;
|
||||
}
|
||||
|
||||
QScriptValue ScriptEngine::activities(QScriptContext *context, QScriptEngine *engine)
|
||||
QScriptValue ScriptEngine::desktops(QScriptContext *context, QScriptEngine *engine)
|
||||
{
|
||||
Q_UNUSED(context)
|
||||
|
||||
@ -652,7 +705,7 @@ QScriptValue ScriptEngine::activities(QScriptContext *context, QScriptEngine *en
|
||||
return containments;
|
||||
}
|
||||
|
||||
Plasma::Corona *ScriptEngine::corona() const
|
||||
ShellCorona *ScriptEngine::corona() const
|
||||
{
|
||||
return m_corona;
|
||||
}
|
||||
@ -680,7 +733,7 @@ void ScriptEngine::exception(const QScriptValue &value)
|
||||
emit printError(value.toVariant().toString());
|
||||
}
|
||||
|
||||
QStringList ScriptEngine::pendingUpdateScripts(Plasma::Corona *corona)
|
||||
QStringList ScriptEngine::pendingUpdateScripts(ShellCorona *corona)
|
||||
{
|
||||
if (!corona->package().metadata().isValid()) {
|
||||
qWarning() << "Warning: corona package invalid";
|
||||
|
@ -23,13 +23,17 @@
|
||||
#include <QScriptEngine>
|
||||
#include <QScriptValue>
|
||||
|
||||
#include <kactivities/controller.h>
|
||||
|
||||
#include "../shellcorona.h"
|
||||
|
||||
namespace Plasma
|
||||
{
|
||||
class Applet;
|
||||
class Containment;
|
||||
class Corona;
|
||||
} // namespace Plasma
|
||||
|
||||
|
||||
namespace WorkspaceScripting
|
||||
{
|
||||
|
||||
@ -40,12 +44,12 @@ class ScriptEngine : public QScriptEngine
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
ScriptEngine(Plasma::Corona *corona, QObject *parent = 0);
|
||||
ScriptEngine(ShellCorona *corona, QObject *parent = 0);
|
||||
~ScriptEngine();
|
||||
|
||||
static QStringList pendingUpdateScripts(Plasma::Corona *corona);
|
||||
static QStringList pendingUpdateScripts(ShellCorona *corona);
|
||||
|
||||
Plasma::Corona *corona() const;
|
||||
ShellCorona *corona() const;
|
||||
bool evaluateScript(const QString &script, const QString &path = QString());
|
||||
QScriptValue wrap(Plasma::Applet *w);
|
||||
virtual QScriptValue wrap(Plasma::Containment *c);
|
||||
@ -65,11 +69,12 @@ private:
|
||||
|
||||
// containment accessors
|
||||
static QStringList availableContainments(const QString &type);
|
||||
static QScriptValue newActivity(QScriptContext *context, QScriptEngine *engine);
|
||||
static QScriptValue createActivity(QScriptContext *context, QScriptEngine *engine);
|
||||
static QScriptValue newPanel(QScriptContext *context, QScriptEngine *engine);
|
||||
static QScriptValue activities(QScriptContext *context, QScriptEngine *engine);
|
||||
static QScriptValue activityById(QScriptContext *context, QScriptEngine *engine);
|
||||
static QScriptValue activityForScreen(QScriptContext *context, QScriptEngine *engine);
|
||||
static QScriptValue desktopsForActivity(QScriptContext *context, QScriptEngine *engine);
|
||||
static QScriptValue desktops(QScriptContext *context, QScriptEngine *engine);
|
||||
static QScriptValue desktopById(QScriptContext *context, QScriptEngine *engine);
|
||||
static QScriptValue desktopForScreen(QScriptContext *context, QScriptEngine *engine);
|
||||
static QScriptValue panelById(QScriptContext *context, QScriptEngine *engine);
|
||||
static QScriptValue panels(QScriptContext *context, QScriptEngine *engine);
|
||||
static QScriptValue fileExists(QScriptContext *context, QScriptEngine *engine);
|
||||
@ -89,7 +94,7 @@ private Q_SLOTS:
|
||||
void exception(const QScriptValue &value);
|
||||
|
||||
private:
|
||||
Plasma::Corona *m_corona;
|
||||
ShellCorona *m_corona;
|
||||
QScriptValue m_scriptSelf;
|
||||
};
|
||||
|
||||
|
@ -2,6 +2,7 @@
|
||||
* Copyright 2008 Aaron Seigo <aseigo@kde.org>
|
||||
* Copyright 2013 Sebastian Kügler <sebas@kde.org>
|
||||
* Copyright 2013 Ivan Cukic <ivan.cukic@kde.org>
|
||||
* Copyright 2013 Marco Martin <mart@kde.org>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Library General Public License as
|
||||
@ -58,6 +59,8 @@
|
||||
|
||||
#include "plasmashelladaptor.h"
|
||||
|
||||
|
||||
|
||||
static const int s_configSyncDelay = 10000; // 10 seconds
|
||||
|
||||
class ShellCorona::Private {
|
||||
@ -100,6 +103,7 @@ public:
|
||||
QTimer appConfigSyncTimer;
|
||||
};
|
||||
|
||||
|
||||
WorkspaceScripting::DesktopScriptEngine * ShellCorona::scriptEngine() const
|
||||
{
|
||||
return d->scriptEngine;
|
||||
@ -388,7 +392,18 @@ void ShellCorona::screenAdded(QScreen *screen)
|
||||
|
||||
Plasma::Containment* ShellCorona::createContainmentForActivity(const QString& activity, int screenNum)
|
||||
{
|
||||
Plasma::Containment* containment = createContainment(d->desktopDefaultsConfig.readEntry("Containment", "org.kde.desktopcontainment"));
|
||||
if (d->desktopContainments.contains(activity) &&
|
||||
d->desktopContainments[activity].contains(screenNum) &&
|
||||
d->desktopContainments.value(activity).value(screenNum)) {
|
||||
return d->desktopContainments[activity][screenNum];
|
||||
}
|
||||
|
||||
QString plugin = "org.kde.desktopcontainment";
|
||||
if (d->activities.contains(activity)) {
|
||||
// plugin = d->activities.value(activity)->defaultPlugin();
|
||||
}
|
||||
|
||||
Plasma::Containment* containment = createContainment(d->desktopDefaultsConfig.readEntry("Containment", plugin));
|
||||
containment->setActivity(activity);
|
||||
insertContainment(activity, screenNum, containment);
|
||||
|
||||
@ -583,6 +598,7 @@ void ShellCorona::activityAdded(const QString &id)
|
||||
|
||||
Activity *a = new Activity(id, this);
|
||||
d->activities.insert(id, a);
|
||||
createContainmentForActivity(id, -1);
|
||||
}
|
||||
|
||||
void ShellCorona::activityRemoved(const QString &id)
|
||||
@ -591,6 +607,17 @@ void ShellCorona::activityRemoved(const QString &id)
|
||||
a->deleteLater();
|
||||
}
|
||||
|
||||
Activity *ShellCorona::activity(const QString &id)
|
||||
{
|
||||
return d->activities.value(id);
|
||||
}
|
||||
|
||||
void ShellCorona::insertActivity(const QString &id, Activity *activity)
|
||||
{
|
||||
d->activities.insert(id, activity);
|
||||
createContainmentForActivity(id, -1);
|
||||
}
|
||||
|
||||
void ShellCorona::checkAddPanelAction(const QStringList &sycocaChanges)
|
||||
{
|
||||
if (!sycocaChanges.isEmpty() && !sycocaChanges.contains("services")) {
|
||||
|
@ -1,5 +1,7 @@
|
||||
/*
|
||||
* Copyright 2008 Aaron Seigo <aseigo@kde.org>
|
||||
* Copyright 2013 Sebastian Kügler <sebas@kde.org>
|
||||
* Copyright 2013 Ivan Cukic <ivan.cukic@kde.org>
|
||||
* Copyright 2013 Marco Martin <mart@kde.org>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
@ -25,6 +27,7 @@
|
||||
|
||||
#include <Plasma/Package>
|
||||
|
||||
|
||||
namespace Plasma
|
||||
{
|
||||
class Applet;
|
||||
@ -69,6 +72,9 @@ public:
|
||||
|
||||
Plasma::Package lookAndFeelPackage() const;
|
||||
|
||||
Activity *activity(const QString &id);
|
||||
void insertActivity(const QString &id, Activity *activity);
|
||||
|
||||
public Q_SLOTS:
|
||||
/**
|
||||
* Request saving applicationConfig on disk, it's event compressed, not immediate
|
||||
|
Loading…
Reference in New Issue
Block a user