diff --git a/scriptengines/javascript/plasmoid/abstractjsappletscript.cpp b/scriptengines/javascript/plasmoid/abstractjsappletscript.cpp new file mode 100644 index 000000000..04cf6cdaf --- /dev/null +++ b/scriptengines/javascript/plasmoid/abstractjsappletscript.cpp @@ -0,0 +1,32 @@ +/* + * Copyright 2010 Marco Martin + + * 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. + */ + +#include "plasmoid/abstractjsappletscript.h" + + +AbstractJsAppletScript::AbstractJsAppletScript(QObject *parent, const QVariantList &args) + : Plasma::AppletScript(parent) +{ + Q_UNUSED(args); +} + +AbstractJsAppletScript::~AbstractJsAppletScript() +{ +} + diff --git a/scriptengines/javascript/plasmoid/abstractjsappletscript.h b/scriptengines/javascript/plasmoid/abstractjsappletscript.h new file mode 100644 index 000000000..fde888ae8 --- /dev/null +++ b/scriptengines/javascript/plasmoid/abstractjsappletscript.h @@ -0,0 +1,40 @@ +/* + * Copyright 2010 Marco Martin + + * 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 ABSTRACTJS_APPLETSCRIPT_H +#define ABSTRACTJS_APPLETSCRIPT_H + +#include + +#include + +class AbstractJsAppletScript : public Plasma::AppletScript +{ +Q_OBJECT + +public: + AbstractJsAppletScript(QObject *parent, const QVariantList &args = QVariantList()); + ~AbstractJsAppletScript(); + + virtual bool include(const QString &path) = 0; + virtual QString filePath(const QString &type, const QString &file) const = 0; + virtual QScriptValue variantToScriptValue(QVariant var) = 0; +}; + +#endif diff --git a/scriptengines/javascript/plasmoid/appletauthorization.cpp b/scriptengines/javascript/plasmoid/appletauthorization.cpp index 8cb833458..c0b1571e5 100644 --- a/scriptengines/javascript/plasmoid/appletauthorization.cpp +++ b/scriptengines/javascript/plasmoid/appletauthorization.cpp @@ -19,9 +19,10 @@ #include #include "appletauthorization.h" -#include "simplejavascriptapplet.h" +#include +#include -AppletAuthorization::AppletAuthorization(SimpleJavaScriptApplet *scriptEngine) +AppletAuthorization::AppletAuthorization(Plasma::AppletScript *scriptEngine) : Authorization(), m_scriptEngine(scriptEngine) { diff --git a/scriptengines/javascript/plasmoid/appletauthorization.h b/scriptengines/javascript/plasmoid/appletauthorization.h index 3b83ac5e6..f0a7fa29f 100644 --- a/scriptengines/javascript/plasmoid/appletauthorization.h +++ b/scriptengines/javascript/plasmoid/appletauthorization.h @@ -21,19 +21,23 @@ #include "authorization.h" +namespace Plasma { + class AppletScript; +} + class SimpleJavaScriptApplet; class AppletAuthorization : public Authorization { public: - AppletAuthorization(SimpleJavaScriptApplet *scriptEngine); + AppletAuthorization(Plasma::AppletScript *scriptEngine); bool authorizeRequiredExtension(const QString &extension); bool authorizeOptionalExtension(const QString &extension); bool authorizeExternalExtensions(); private: - SimpleJavaScriptApplet *m_scriptEngine; + Plasma::AppletScript *m_scriptEngine; }; #endif diff --git a/scriptengines/javascript/plasmoid/appletinterface.cpp b/scriptengines/javascript/plasmoid/appletinterface.cpp index fbb82a615..55ca3bd99 100644 --- a/scriptengines/javascript/plasmoid/appletinterface.cpp +++ b/scriptengines/javascript/plasmoid/appletinterface.cpp @@ -1,5 +1,7 @@ /* * Copyright 2008 Chani Armitage + * Copyright 2008, 2009 Aaron Seigo + * Copyright 2010 Marco Martin * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Library General Public License as @@ -36,13 +38,14 @@ Q_DECLARE_METATYPE(AppletInterface*) -AppletInterface::AppletInterface(SimpleJavaScriptApplet *parent) +AppletInterface::AppletInterface(AbstractJsAppletScript *parent) : QObject(parent), m_appletScriptEngine(parent), m_actionSignals(0) { connect(this, SIGNAL(releaseVisualFocus()), applet(), SIGNAL(releaseVisualFocus())); connect(this, SIGNAL(configNeedsSaving()), applet(), SIGNAL(configNeedsSaving())); + connect(applet(), SIGNAL(immutabilityChanged(Plasma::ImmutabilityType)), this, SIGNAL(immutableChanged())); } AppletInterface::~AppletInterface() @@ -120,11 +123,25 @@ void AppletInterface::setConfigurationRequired(bool needsConfiguring, const QStr m_appletScriptEngine->setConfigurationRequired(needsConfiguring, reason); } +#ifdef USE_JS_SCRIPTENGINE + void AppletInterface::update(const QRectF &rect) { applet()->update(rect); } +QGraphicsLayout *AppletInterface::layout() const +{ + return applet()->layout(); +} + +void AppletInterface::setLayout(QGraphicsLayout *layout) +{ + applet()->setLayout(layout); +} + +#endif + QString AppletInterface::activeConfig() const { return m_currentConfig.isEmpty() ? "main" : m_currentConfig; @@ -295,16 +312,6 @@ void AppletInterface::setPreferredSize(qreal w, qreal h) applet()->setPreferredSize(w,h); } -QGraphicsLayout *AppletInterface::layout() const -{ - return applet()->layout(); -} - -void AppletInterface::setLayout(QGraphicsLayout *layout) -{ - applet()->setLayout(layout); -} - bool AppletInterface::immutable() const { return applet()->immutability() != Plasma::Mutable; @@ -363,13 +370,14 @@ Plasma::Extender *AppletInterface::extender() const return m_appletScriptEngine->extender(); } + void AppletInterface::gc() { QTimer::singleShot(0, m_appletScriptEngine, SLOT(collectGarbage())); } -PopupAppletInterface::PopupAppletInterface(SimpleJavaScriptApplet *parent) +PopupAppletInterface::PopupAppletInterface(AbstractJsAppletScript *parent) : AppletInterface(parent) { } @@ -424,4 +432,6 @@ QGraphicsWidget *PopupAppletInterface::popupWidget() return popupApplet()->graphicsWidget(); } +#ifndef USE_JS_SCRIPTENGINE #include "appletinterface.moc" +#endif diff --git a/scriptengines/javascript/plasmoid/appletinterface.h b/scriptengines/javascript/plasmoid/appletinterface.h index 2569b43de..e6e84c00b 100644 --- a/scriptengines/javascript/plasmoid/appletinterface.h +++ b/scriptengines/javascript/plasmoid/appletinterface.h @@ -1,6 +1,7 @@ /* * Copyright 2008 Chani Armitage * Copyright 2008, 2009 Aaron Seigo + * Copyright 2010 Marco Martin * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Library General Public License as @@ -31,10 +32,10 @@ #include #include -#include "simplejavascriptapplet.h" +#include "abstractjsappletscript.h" class QAction; -class SimpleJavaScriptApplet; +class QmlAppletScript; class QSignalMapper; class QSizeF; @@ -63,23 +64,25 @@ class AppletInterface : public QObject Q_ENUMS(IntervalAlignment) Q_ENUMS(ThemeColors) Q_PROPERTY(AspectRatioMode aspectRatioMode READ aspectRatioMode WRITE setAspectRatioMode) - Q_PROPERTY(FormFactor formFactor READ formFactor) - Q_PROPERTY(Location location READ location) - Q_PROPERTY(QString currentActivity READ currentActivity) + Q_PROPERTY(FormFactor formFactor READ formFactor NOTIFY formFactorChanged) + Q_PROPERTY(Location location READ location NOTIFY locationChanged) + Q_PROPERTY(QString currentActivity READ currentActivity NOTIFY contextChanged) Q_PROPERTY(bool shouldConserveResources READ shouldConserveResources) Q_PROPERTY(QString activeConfig WRITE setActiveConfig READ activeConfig) Q_PROPERTY(bool busy WRITE setBusy READ isBusy) Q_PROPERTY(BackgroundHints backgroundHints WRITE setBackgroundHints READ backgroundHints) - Q_PROPERTY(QGraphicsLayout *layout WRITE setLayout READ layout) - Q_PROPERTY(bool immutable READ immutable) + Q_PROPERTY(bool immutable READ immutable NOTIFY immutableChanged) Q_PROPERTY(bool userConfiguring READ userConfiguring) // @since 4.5 - Q_PROPERTY(int apiVersion READ apiVersion) + Q_PROPERTY(int apiVersion READ apiVersion CONSTANT) Q_PROPERTY(QRectF rect READ rect) Q_PROPERTY(QSizeF size READ size) +#ifdef USE_JS_SCRIPTENGINE + Q_PROPERTY(QGraphicsLayout *layout WRITE setLayout READ layout) Q_PROPERTY(QObject *sender READ sender) +#endif public: - AppletInterface(SimpleJavaScriptApplet *parent); + AppletInterface(AbstractJsAppletScript *parent); ~AppletInterface(); //------------------------------------------------------------------ @@ -255,8 +258,6 @@ enum IntervalAlignment { Q_INVOKABLE void setPreferredSize(qreal w, qreal h); - Q_INVOKABLE void update(const QRectF &rect = QRectF()); - Q_INVOKABLE QString activeConfig() const; Q_INVOKABLE void setActiveConfig(const QString &name); @@ -275,11 +276,15 @@ enum IntervalAlignment { Q_INVOKABLE Plasma::Extender *extender() const; +#ifdef USE_JS_SCRIPTENGINE + Q_INVOKABLE void update(const QRectF &rect = QRectF()); + QGraphicsLayout *layout() const; + void setLayout(QGraphicsLayout *); +#endif + Plasma::DataEngine *dataEngine(const QString &name); QList contextualActions() const; - QGraphicsLayout *layout() const; - void setLayout(QGraphicsLayout *); bool immutable() const; bool userConfiguring() const; int apiVersion() const; @@ -291,8 +296,13 @@ Q_SIGNALS: void releaseVisualFocus(); void configNeedsSaving(); + void formFactorChanged(); + void locationChanged(); + void contextChanged(); + void immutableChanged(); + protected: - SimpleJavaScriptApplet *m_appletScriptEngine; + AbstractJsAppletScript *m_appletScriptEngine; private: QSet m_actions; @@ -309,7 +319,7 @@ class PopupAppletInterface : public AppletInterface Q_PROPERTY(QGraphicsWidget *popupWidget READ popupWidget WRITE setPopupWidget) public: - PopupAppletInterface(SimpleJavaScriptApplet *parent); + PopupAppletInterface(AbstractJsAppletScript *parent); void setPopupIcon(const QIcon &icon); QIcon popupIcon(); diff --git a/scriptengines/javascript/plasmoid/jsappletinterface.cpp b/scriptengines/javascript/plasmoid/jsappletinterface.cpp new file mode 100644 index 000000000..8cb20d205 --- /dev/null +++ b/scriptengines/javascript/plasmoid/jsappletinterface.cpp @@ -0,0 +1,22 @@ +/* + * Copyright 2010 Marco Martin + * + * 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. + */ + +#define USE_JS_SCRIPTENGINE +#include "appletinterface.cpp" +#include "appletinterface.moc" + diff --git a/scriptengines/javascript/plasmoid/simplejavascriptapplet.cpp b/scriptengines/javascript/plasmoid/simplejavascriptapplet.cpp index 008b2f291..5028fbd64 100644 --- a/scriptengines/javascript/plasmoid/simplejavascriptapplet.cpp +++ b/scriptengines/javascript/plasmoid/simplejavascriptapplet.cpp @@ -98,7 +98,7 @@ KSharedPtr SimpleJavaScriptApplet::s_widgetLoader; QHash SimpleJavaScriptApplet::s_animationDefs; SimpleJavaScriptApplet::SimpleJavaScriptApplet(QObject *parent, const QVariantList &args) - : Plasma::AppletScript(parent) + : AbstractJsAppletScript(parent) { Q_UNUSED(args); // kDebug() << "Script applet launched, args" << applet()->startupArguments(); diff --git a/scriptengines/javascript/plasmoid/simplejavascriptapplet.h b/scriptengines/javascript/plasmoid/simplejavascriptapplet.h index 2f93c72f1..1c82cf64f 100644 --- a/scriptengines/javascript/plasmoid/simplejavascriptapplet.h +++ b/scriptengines/javascript/plasmoid/simplejavascriptapplet.h @@ -22,10 +22,10 @@ #include #include -#include #include #include "simplebindings/uiloader.h" +#include "abstractjsappletscript.h" class QScriptContext; class QScriptEngine; @@ -38,7 +38,7 @@ namespace Plasma class ExtenderItem; } // namespace Plasma -class SimpleJavaScriptApplet : public Plasma::AppletScript +class SimpleJavaScriptApplet : public AbstractJsAppletScript { Q_OBJECT