2009-05-13 02:55:25 +02:00
|
|
|
/*
|
|
|
|
* Copyright 2007 Richard J. Moore <rich@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 version 2 as
|
|
|
|
* published by the Free Software Foundation
|
|
|
|
*
|
|
|
|
* 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 SCRIPT_H
|
|
|
|
#define SCRIPT_H
|
|
|
|
|
|
|
|
#include <QScriptValue>
|
|
|
|
|
2009-10-21 04:26:44 +02:00
|
|
|
#include <Plasma/Animator>
|
2009-05-13 02:55:25 +02:00
|
|
|
#include <Plasma/AppletScript>
|
|
|
|
#include <Plasma/DataEngine>
|
|
|
|
|
2009-11-27 04:12:43 +01:00
|
|
|
#include "simplebindings/uiloader.h"
|
2009-05-13 02:55:25 +02:00
|
|
|
|
|
|
|
class QScriptEngine;
|
|
|
|
class QScriptContext;
|
|
|
|
|
|
|
|
class AppletInterface;
|
|
|
|
|
2010-01-20 20:08:44 +01:00
|
|
|
namespace Plasma
|
|
|
|
{
|
|
|
|
class ExtenderItem;
|
|
|
|
} // namespace Plasma
|
|
|
|
|
2009-05-13 02:55:25 +02:00
|
|
|
class SimpleJavaScriptApplet : public Plasma::AppletScript
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
2009-12-16 23:05:46 +01:00
|
|
|
enum AllowedUrl { NoUrls = 0,
|
|
|
|
HttpUrls = 1,
|
|
|
|
NetworkUrls = 2,
|
|
|
|
LocalUrls = 4 };
|
|
|
|
Q_DECLARE_FLAGS(AllowedUrls, AllowedUrl)
|
|
|
|
|
|
|
|
SimpleJavaScriptApplet(QObject *parent, const QVariantList &args);
|
2009-05-13 02:55:25 +02:00
|
|
|
~SimpleJavaScriptApplet();
|
|
|
|
bool init();
|
|
|
|
|
2009-11-11 03:09:25 +01:00
|
|
|
static void reportError(QScriptEngine *error, bool fatal = false);
|
2009-05-13 02:55:25 +02:00
|
|
|
|
|
|
|
void paintInterface(QPainter *painter, const QStyleOptionGraphicsItem *option, const QRect &contentsRect);
|
|
|
|
QList<QAction*> contextualActions();
|
|
|
|
void constraintsEvent(Plasma::Constraints constraints);
|
2009-11-14 06:19:19 +01:00
|
|
|
bool include(const QString &path);
|
2009-11-14 08:32:00 +01:00
|
|
|
QSet<QString> loadedExtensions() const;
|
2009-05-13 02:55:25 +02:00
|
|
|
QScriptValue variantToScriptValue(QVariant var);
|
|
|
|
|
2009-10-21 01:15:33 +02:00
|
|
|
static QString findImageFile(QScriptEngine *engine, const QString &file);
|
|
|
|
|
2009-05-13 02:55:25 +02:00
|
|
|
public slots:
|
|
|
|
void dataUpdated( const QString &name, const Plasma::DataEngine::Data &data );
|
|
|
|
void configChanged();
|
|
|
|
void executeAction(const QString &name);
|
2009-11-18 23:40:38 +01:00
|
|
|
void collectGarbage();
|
2010-01-20 20:08:44 +01:00
|
|
|
void extenderItemRestored(Plasma::ExtenderItem* item);
|
2009-05-13 02:55:25 +02:00
|
|
|
|
|
|
|
private:
|
2009-12-16 23:05:46 +01:00
|
|
|
void registerGetUrl();
|
2009-11-11 03:09:25 +01:00
|
|
|
bool importExtensions();
|
2009-11-14 08:28:16 +01:00
|
|
|
bool importBuiltinExtesion(const QString &extension);
|
2009-05-13 02:55:25 +02:00
|
|
|
void setupObjects();
|
|
|
|
void callFunction(const QString &functionName, const QScriptValueList &args = QScriptValueList());
|
2009-10-21 04:26:44 +02:00
|
|
|
static void populateAnimationsHash();
|
2009-05-13 02:55:25 +02:00
|
|
|
|
|
|
|
static QString findSvg(QScriptEngine *engine, const QString &file);
|
2009-10-21 04:26:44 +02:00
|
|
|
static QScriptValue animation(QScriptContext *context, QScriptEngine *engine);
|
2009-10-21 09:53:49 +02:00
|
|
|
static QScriptValue animationGroup(QScriptContext *context, QScriptEngine *engine);
|
2009-12-06 16:34:41 +01:00
|
|
|
static QScriptValue parallelAnimationGroup(QScriptContext *context, QScriptEngine *engine);
|
2009-05-13 02:55:25 +02:00
|
|
|
static QScriptValue jsi18n(QScriptContext *context, QScriptEngine *engine);
|
|
|
|
static QScriptValue jsi18nc(QScriptContext *context, QScriptEngine *engine);
|
|
|
|
static QScriptValue jsi18np(QScriptContext *context, QScriptEngine *engine);
|
|
|
|
static QScriptValue jsi18ncp(QScriptContext *context, QScriptEngine *engine);
|
|
|
|
static QScriptValue dataEngine(QScriptContext *context, QScriptEngine *engine);
|
|
|
|
static QScriptValue service(QScriptContext *context, QScriptEngine *engine);
|
|
|
|
static QScriptValue loadui(QScriptContext *context, QScriptEngine *engine);
|
|
|
|
static QScriptValue newPlasmaSvg(QScriptContext *context, QScriptEngine *engine);
|
|
|
|
static QScriptValue newPlasmaFrameSvg(QScriptContext *context, QScriptEngine *engine);
|
2010-01-20 20:08:44 +01:00
|
|
|
static QScriptValue newPlasmaExtenderItem(QScriptContext *context, QScriptEngine *engine);
|
2009-05-13 02:55:25 +02:00
|
|
|
|
2009-12-16 23:05:46 +01:00
|
|
|
void installWidgets(QScriptEngine *engine);
|
2009-05-13 02:55:25 +02:00
|
|
|
static QScriptValue createWidget(QScriptContext *context, QScriptEngine *engine);
|
|
|
|
static QScriptValue notSupported(QScriptContext *context, QScriptEngine *engine);
|
|
|
|
static QScriptValue print(QScriptContext *context, QScriptEngine *engine);
|
2009-11-27 21:47:31 +01:00
|
|
|
static QScriptValue widgetAdjustSize(QScriptContext *context, QScriptEngine *engine);
|
2009-05-13 02:55:25 +02:00
|
|
|
|
2009-11-28 01:42:22 +01:00
|
|
|
// run extension
|
|
|
|
static QScriptValue runApplication(QScriptContext *context, QScriptEngine *engine);
|
|
|
|
static QScriptValue runCommand(QScriptContext *context, QScriptEngine *engine);
|
|
|
|
static QScriptValue openUrl(QScriptContext *context, QScriptEngine *engine);
|
|
|
|
|
2009-12-16 23:05:46 +01:00
|
|
|
// file io extensions
|
|
|
|
static QScriptValue getUrl(QScriptContext *context, QScriptEngine *engine);
|
|
|
|
|
|
|
|
static AppletInterface *extractAppletInterface(QScriptEngine *engine);
|
2009-12-06 16:34:41 +01:00
|
|
|
static QGraphicsWidget *extractParent(QScriptContext *context,
|
|
|
|
QScriptEngine *engine,
|
|
|
|
int parentIndex = 0,
|
|
|
|
bool *parentedToApplet = 0);
|
|
|
|
|
2009-05-13 02:55:25 +02:00
|
|
|
private:
|
|
|
|
static KSharedPtr<UiLoader> s_widgetLoader;
|
2009-10-21 04:26:44 +02:00
|
|
|
static QHash<QString, Plasma::Animator::Animation> s_animationDefs;
|
2009-05-13 02:55:25 +02:00
|
|
|
QScriptEngine *m_engine;
|
|
|
|
QScriptValue m_self;
|
|
|
|
QVariantList m_args;
|
2009-11-14 08:28:16 +01:00
|
|
|
QSet<QString> m_extensions;
|
2009-05-13 02:55:25 +02:00
|
|
|
AppletInterface *m_interface;
|
|
|
|
friend class AppletInterface;
|
|
|
|
};
|
|
|
|
|
2009-12-16 23:05:46 +01:00
|
|
|
Q_DECLARE_OPERATORS_FOR_FLAGS(SimpleJavaScriptApplet::AllowedUrls)
|
2009-05-13 02:55:25 +02:00
|
|
|
|
|
|
|
#endif // SCRIPT_H
|
|
|
|
|