2010-03-17 19:00:07 +01:00
|
|
|
/*
|
|
|
|
* Copyright 2009 Aaron Seigo <aseigo@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
|
|
|
|
* published by the Free Software Foundation; either version 2, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Library General Public
|
|
|
|
* License along with this program; if not, write to the
|
|
|
|
* Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef SCRIPTENGINE
|
|
|
|
#define SCRIPTENGINE
|
|
|
|
|
|
|
|
#include <QScriptEngine>
|
|
|
|
#include <QScriptValue>
|
|
|
|
|
|
|
|
#include "../plasmagenericshell_export.h"
|
|
|
|
|
|
|
|
namespace Plasma
|
|
|
|
{
|
|
|
|
class Applet;
|
|
|
|
class Containment;
|
|
|
|
class Corona;
|
|
|
|
} // namespace Plasma
|
|
|
|
|
2010-05-19 19:13:29 +02:00
|
|
|
namespace WorkspaceScripting
|
|
|
|
{
|
|
|
|
|
2010-03-17 19:00:07 +01:00
|
|
|
class Containment;
|
|
|
|
|
|
|
|
class PLASMAGENERICSHELL_EXPORT ScriptEngine : public QScriptEngine
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
|
|
|
ScriptEngine(Plasma::Corona *corona, QObject *parent = 0);
|
|
|
|
~ScriptEngine();
|
|
|
|
|
2010-03-19 19:07:53 +01:00
|
|
|
static QStringList pendingUpdateScripts();
|
|
|
|
static QStringList defaultLayoutScripts();
|
|
|
|
|
2010-04-09 03:03:05 +02:00
|
|
|
bool evaluateScript(const QString &script, const QString &path = QString());
|
2010-03-17 19:00:07 +01:00
|
|
|
static bool isPanel(const Plasma::Containment *c);
|
2010-04-27 21:41:40 +02:00
|
|
|
QScriptValue wrap(Plasma::Applet *w);
|
|
|
|
virtual QScriptValue wrap(Plasma::Containment *c);
|
|
|
|
QScriptValue wrap(Containment *c);
|
2010-03-17 19:00:07 +01:00
|
|
|
|
|
|
|
static ScriptEngine *envFor(QScriptEngine *engine);
|
|
|
|
|
|
|
|
Q_SIGNALS:
|
|
|
|
void print(const QString &string);
|
|
|
|
void printError(const QString &string);
|
|
|
|
void createPendingPanelViews();
|
|
|
|
|
|
|
|
private:
|
|
|
|
void setupEngine();
|
|
|
|
|
|
|
|
// containment accessors
|
2010-04-27 22:51:38 +02:00
|
|
|
static QStringList availableContainments(const QString &type);
|
2010-03-17 19:00:07 +01:00
|
|
|
static QScriptValue newActivity(QScriptContext *context, QScriptEngine *engine);
|
|
|
|
static QScriptValue newPanel(QScriptContext *context, QScriptEngine *engine);
|
2010-04-27 21:52:56 +02:00
|
|
|
static QScriptValue activities(QScriptContext *context, QScriptEngine *engine);
|
2010-03-17 19:00:07 +01:00
|
|
|
static QScriptValue activityById(QScriptContext *context, QScriptEngine *engine);
|
|
|
|
static QScriptValue activityForScreen(QScriptContext *context, QScriptEngine *engine);
|
|
|
|
static QScriptValue panelById(QScriptContext *context, QScriptEngine *engine);
|
2010-04-27 21:44:53 +02:00
|
|
|
static QScriptValue panels(QScriptContext *context, QScriptEngine *engine);
|
2010-03-17 19:00:07 +01:00
|
|
|
static QScriptValue fileExists(QScriptContext *context, QScriptEngine *engine);
|
2010-04-09 03:03:05 +02:00
|
|
|
static QScriptValue loadTemplate(QScriptContext *context, QScriptEngine *engine);
|
2010-03-17 19:00:07 +01:00
|
|
|
|
|
|
|
// helpers
|
|
|
|
static QScriptValue createContainment(const QString &type, const QString &defautPlugin,
|
|
|
|
QScriptContext *context, QScriptEngine *engine);
|
|
|
|
|
|
|
|
private Q_SLOTS:
|
|
|
|
void exception(const QScriptValue &value);
|
|
|
|
|
|
|
|
private:
|
|
|
|
Plasma::Corona *m_corona;
|
|
|
|
QScriptValue m_scriptSelf;
|
|
|
|
};
|
|
|
|
|
2010-05-19 19:13:29 +02:00
|
|
|
}
|
|
|
|
|
2010-03-17 19:00:07 +01:00
|
|
|
#endif
|
|
|
|
|