diff --git a/scriptengines/javascript/plasmoid/abstractjsappletscript.h b/scriptengines/javascript/plasmoid/abstractjsappletscript.h index fde888ae8..2eb4dde1f 100644 --- a/scriptengines/javascript/plasmoid/abstractjsappletscript.h +++ b/scriptengines/javascript/plasmoid/abstractjsappletscript.h @@ -32,6 +32,7 @@ public: AbstractJsAppletScript(QObject *parent, const QVariantList &args = QVariantList()); ~AbstractJsAppletScript(); + virtual QScriptEngine *engine() const = 0; virtual bool include(const QString &path) = 0; virtual QString filePath(const QString &type, const QString &file) const = 0; virtual QScriptValue variantToScriptValue(QVariant var) = 0; diff --git a/scriptengines/javascript/plasmoid/appletinterface.cpp b/scriptengines/javascript/plasmoid/appletinterface.cpp index 0d57675c0..c25c5b65f 100644 --- a/scriptengines/javascript/plasmoid/appletinterface.cpp +++ b/scriptengines/javascript/plasmoid/appletinterface.cpp @@ -375,7 +375,7 @@ void AppletInterface::gc() PopupAppletInterface::PopupAppletInterface(AbstractJsAppletScript *parent) - : POPUPAPPLETSUPERCLASS(parent) + : APPLETSUPERCLASS(parent) { } @@ -429,6 +429,35 @@ QGraphicsWidget *PopupAppletInterface::popupWidget() return popupApplet()->graphicsWidget(); } +ContainmentInterface::ContainmentInterface(AbstractJsAppletScript *parent) + : APPLETSUPERCLASS(parent) +{ + connect(containment(), SIGNAL(appletRemoved(Plasma::Applet *)), this, SLOT(appletRemovedForward(Plasma::Applet *))); + + connect(containment(), SIGNAL(appletAdded(Plasma::Applet *, const QPointF &)), this, SLOT(appletAddedForward(Plasma::Applet *, const QPointF &))); +} + +QScriptValue ContainmentInterface::applets() +{ + QScriptValue list = m_appletScriptEngine->engine()->newArray(containment()->applets().size()); + int i = 0; + foreach (Plasma::Applet *applet, containment()->applets()) { + list.setProperty(i, m_appletScriptEngine->engine()->newQObject(applet)); + ++i; + } + return list; +} + +void ContainmentInterface::appletAddedForward(Plasma::Applet *applet, const QPointF &pos) +{ + emit appletAdded(applet, pos); +} + +void ContainmentInterface::appletRemovedForward(Plasma::Applet *applet) +{ + emit appletRemoved(applet); +} + #ifndef USE_JS_SCRIPTENGINE #include "appletinterface.moc" #endif diff --git a/scriptengines/javascript/plasmoid/appletinterface.h b/scriptengines/javascript/plasmoid/appletinterface.h index cd987e6e9..da7c810dc 100644 --- a/scriptengines/javascript/plasmoid/appletinterface.h +++ b/scriptengines/javascript/plasmoid/appletinterface.h @@ -28,6 +28,7 @@ #include #include +#include #include #include #include @@ -319,11 +320,11 @@ public: }; #ifdef USE_JS_SCRIPTENGINE -#define POPUPAPPLETSUPERCLASS JsAppletInterface +#define APPLETSUPERCLASS JsAppletInterface #else -#define POPUPAPPLETSUPERCLASS AppletInterface +#define APPLETSUPERCLASS AppletInterface #endif -class PopupAppletInterface : public POPUPAPPLETSUPERCLASS +class PopupAppletInterface : public APPLETSUPERCLASS { Q_OBJECT Q_PROPERTY(QIcon popupIcon READ popupIcon WRITE setPopupIcon) @@ -351,4 +352,26 @@ public Q_SLOTS: void showPopup(); }; + +class ContainmentInterface : public APPLETSUPERCLASS +{ + Q_OBJECT + Q_PROPERTY(QScriptValue applets READ applets) + +public: + ContainmentInterface(AbstractJsAppletScript *parent); + + inline Plasma::Containment *containment() const { return static_cast(m_appletScriptEngine->applet()); } + + QScriptValue applets() ; + +Q_SIGNALS: + void appletAdded(QGraphicsWidget *applet, const QPointF &pos); + void appletRemoved(QGraphicsWidget *applet); + +protected Q_SLOTS: + void appletAddedForward(Plasma::Applet *applet, const QPointF &pos); + void appletRemovedForward(Plasma::Applet *applet); +}; + #endif diff --git a/scriptengines/javascript/plasmoid/declarativeappletscript.cpp b/scriptengines/javascript/plasmoid/declarativeappletscript.cpp index 43daf0b76..38e6055cc 100644 --- a/scriptengines/javascript/plasmoid/declarativeappletscript.cpp +++ b/scriptengines/javascript/plasmoid/declarativeappletscript.cpp @@ -102,6 +102,7 @@ bool DeclarativeAppletScript::init() Plasma::Applet *a = applet(); Plasma::PopupApplet *pa = qobject_cast(a); + Plasma::Containment *cont = qobject_cast(a); if (pa) { pa->setPopupIcon(a->icon()); @@ -112,7 +113,15 @@ bool DeclarativeAppletScript::init() lay->addItem(m_declarativeWidget); } - m_interface = pa ? new PopupAppletInterface(this) : new AppletInterface(this); + m_interface = 0; + if (pa) { + m_interface = new PopupAppletInterface(this); + } else if (cont) { + m_interface = new ContainmentInterface(this); + //fail? so it's a normal Applet + } else { + m_interface = new AppletInterface(this); + } m_engineAccess = new EngineAccess(this); m_declarativeWidget->engine()->rootContext()->setContextProperty("__engineAccess", m_engineAccess); @@ -443,6 +452,11 @@ QScriptValue DeclarativeAppletScript::loadService(QScriptContext *context, QScri return engine->newQObject(service, QScriptEngine::AutoOwnership); } +QScriptEngine *DeclarativeAppletScript::engine() const +{ + return m_engine; +} + void DeclarativeAppletScript::setEngine(QScriptValue &val) { if (val.engine() == m_engine) { diff --git a/scriptengines/javascript/plasmoid/declarativeappletscript.h b/scriptengines/javascript/plasmoid/declarativeappletscript.h index 7de9ee8c4..8466b1832 100644 --- a/scriptengines/javascript/plasmoid/declarativeappletscript.h +++ b/scriptengines/javascript/plasmoid/declarativeappletscript.h @@ -59,6 +59,8 @@ public: ScriptEnv *scriptEnv(); + QScriptEngine *engine() const; + QScriptValue variantToScriptValue(QVariant var); static QScriptValue loadui(QScriptContext *context, QScriptEngine *engine); diff --git a/scriptengines/javascript/plasmoid/simplejavascriptapplet.cpp b/scriptengines/javascript/plasmoid/simplejavascriptapplet.cpp index 6a7653a92..f39eb6ecb 100644 --- a/scriptengines/javascript/plasmoid/simplejavascriptapplet.cpp +++ b/scriptengines/javascript/plasmoid/simplejavascriptapplet.cpp @@ -808,6 +808,11 @@ void SimpleJavaScriptApplet::installWidgets(QScriptEngine *engine) } } +QScriptEngine *SimpleJavaScriptApplet::engine() const +{ + return m_engine; +} + QGraphicsWidget *SimpleJavaScriptApplet::extractParent(QScriptContext *context, QScriptEngine *engine, int argIndex, bool *parentedToApplet) { diff --git a/scriptengines/javascript/plasmoid/simplejavascriptapplet.h b/scriptengines/javascript/plasmoid/simplejavascriptapplet.h index 5e89e16fd..29929dcf7 100644 --- a/scriptengines/javascript/plasmoid/simplejavascriptapplet.h +++ b/scriptengines/javascript/plasmoid/simplejavascriptapplet.h @@ -58,6 +58,8 @@ public: bool eventFilter(QObject *watched, QEvent *event); + QScriptEngine *engine() const; + public Q_SLOTS: void dataUpdated(const QString &name, const Plasma::DataEngine::Data &data); void configChanged();