first important part for the ml bindings merge:

make appletInterface more generic it could work with QML too
simplejavascriptapplet inherits from an abstract ckass that provides just the virtuals of functions needed by appletinterface so a different scriptengine implementation can be used as well.

The behaviour of the current js bindings should be completely unchanged.

svn path=/trunk/KDE/kdebase/runtime/; revision=1185532
This commit is contained in:
Marco Martin 2010-10-13 16:12:43 +00:00
parent c90b506d8e
commit ac8de83bbd
9 changed files with 153 additions and 34 deletions

View File

@ -0,0 +1,32 @@
/*
* Copyright 2010 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
* 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()
{
}

View File

@ -0,0 +1,40 @@
/*
* Copyright 2010 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
* 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 <QScriptValue>
#include <Plasma/AppletScript>
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

View File

@ -19,9 +19,10 @@
#include <KAuthorized> #include <KAuthorized>
#include "appletauthorization.h" #include "appletauthorization.h"
#include "simplejavascriptapplet.h" #include <Plasma/AppletScript>
#include <Plasma/Applet>
AppletAuthorization::AppletAuthorization(SimpleJavaScriptApplet *scriptEngine) AppletAuthorization::AppletAuthorization(Plasma::AppletScript *scriptEngine)
: Authorization(), : Authorization(),
m_scriptEngine(scriptEngine) m_scriptEngine(scriptEngine)
{ {

View File

@ -21,19 +21,23 @@
#include "authorization.h" #include "authorization.h"
namespace Plasma {
class AppletScript;
}
class SimpleJavaScriptApplet; class SimpleJavaScriptApplet;
class AppletAuthorization : public Authorization class AppletAuthorization : public Authorization
{ {
public: public:
AppletAuthorization(SimpleJavaScriptApplet *scriptEngine); AppletAuthorization(Plasma::AppletScript *scriptEngine);
bool authorizeRequiredExtension(const QString &extension); bool authorizeRequiredExtension(const QString &extension);
bool authorizeOptionalExtension(const QString &extension); bool authorizeOptionalExtension(const QString &extension);
bool authorizeExternalExtensions(); bool authorizeExternalExtensions();
private: private:
SimpleJavaScriptApplet *m_scriptEngine; Plasma::AppletScript *m_scriptEngine;
}; };
#endif #endif

View File

@ -1,5 +1,7 @@
/* /*
* Copyright 2008 Chani Armitage <chani@kde.org> * Copyright 2008 Chani Armitage <chani@kde.org>
* Copyright 2008, 2009 Aaron Seigo <aseigo@kde.org>
* Copyright 2010 Marco Martin <mart@kde.org>
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Library General Public License as * it under the terms of the GNU Library General Public License as
@ -36,13 +38,14 @@
Q_DECLARE_METATYPE(AppletInterface*) Q_DECLARE_METATYPE(AppletInterface*)
AppletInterface::AppletInterface(SimpleJavaScriptApplet *parent) AppletInterface::AppletInterface(AbstractJsAppletScript *parent)
: QObject(parent), : QObject(parent),
m_appletScriptEngine(parent), m_appletScriptEngine(parent),
m_actionSignals(0) m_actionSignals(0)
{ {
connect(this, SIGNAL(releaseVisualFocus()), applet(), SIGNAL(releaseVisualFocus())); connect(this, SIGNAL(releaseVisualFocus()), applet(), SIGNAL(releaseVisualFocus()));
connect(this, SIGNAL(configNeedsSaving()), applet(), SIGNAL(configNeedsSaving())); connect(this, SIGNAL(configNeedsSaving()), applet(), SIGNAL(configNeedsSaving()));
connect(applet(), SIGNAL(immutabilityChanged(Plasma::ImmutabilityType)), this, SIGNAL(immutableChanged()));
} }
AppletInterface::~AppletInterface() AppletInterface::~AppletInterface()
@ -120,11 +123,25 @@ void AppletInterface::setConfigurationRequired(bool needsConfiguring, const QStr
m_appletScriptEngine->setConfigurationRequired(needsConfiguring, reason); m_appletScriptEngine->setConfigurationRequired(needsConfiguring, reason);
} }
#ifdef USE_JS_SCRIPTENGINE
void AppletInterface::update(const QRectF &rect) void AppletInterface::update(const QRectF &rect)
{ {
applet()->update(rect); applet()->update(rect);
} }
QGraphicsLayout *AppletInterface::layout() const
{
return applet()->layout();
}
void AppletInterface::setLayout(QGraphicsLayout *layout)
{
applet()->setLayout(layout);
}
#endif
QString AppletInterface::activeConfig() const QString AppletInterface::activeConfig() const
{ {
return m_currentConfig.isEmpty() ? "main" : m_currentConfig; return m_currentConfig.isEmpty() ? "main" : m_currentConfig;
@ -295,16 +312,6 @@ void AppletInterface::setPreferredSize(qreal w, qreal h)
applet()->setPreferredSize(w,h); applet()->setPreferredSize(w,h);
} }
QGraphicsLayout *AppletInterface::layout() const
{
return applet()->layout();
}
void AppletInterface::setLayout(QGraphicsLayout *layout)
{
applet()->setLayout(layout);
}
bool AppletInterface::immutable() const bool AppletInterface::immutable() const
{ {
return applet()->immutability() != Plasma::Mutable; return applet()->immutability() != Plasma::Mutable;
@ -363,13 +370,14 @@ Plasma::Extender *AppletInterface::extender() const
return m_appletScriptEngine->extender(); return m_appletScriptEngine->extender();
} }
void AppletInterface::gc() void AppletInterface::gc()
{ {
QTimer::singleShot(0, m_appletScriptEngine, SLOT(collectGarbage())); QTimer::singleShot(0, m_appletScriptEngine, SLOT(collectGarbage()));
} }
PopupAppletInterface::PopupAppletInterface(SimpleJavaScriptApplet *parent) PopupAppletInterface::PopupAppletInterface(AbstractJsAppletScript *parent)
: AppletInterface(parent) : AppletInterface(parent)
{ {
} }
@ -424,4 +432,6 @@ QGraphicsWidget *PopupAppletInterface::popupWidget()
return popupApplet()->graphicsWidget(); return popupApplet()->graphicsWidget();
} }
#ifndef USE_JS_SCRIPTENGINE
#include "appletinterface.moc" #include "appletinterface.moc"
#endif

View File

@ -1,6 +1,7 @@
/* /*
* Copyright 2008 Chani Armitage <chani@kde.org> * Copyright 2008 Chani Armitage <chani@kde.org>
* Copyright 2008, 2009 Aaron Seigo <aseigo@kde.org> * Copyright 2008, 2009 Aaron Seigo <aseigo@kde.org>
* Copyright 2010 Marco Martin <mart@kde.org>
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Library General Public License as * it under the terms of the GNU Library General Public License as
@ -31,10 +32,10 @@
#include <Plasma/DataEngine> #include <Plasma/DataEngine>
#include <Plasma/Theme> #include <Plasma/Theme>
#include "simplejavascriptapplet.h" #include "abstractjsappletscript.h"
class QAction; class QAction;
class SimpleJavaScriptApplet; class QmlAppletScript;
class QSignalMapper; class QSignalMapper;
class QSizeF; class QSizeF;
@ -63,23 +64,25 @@ class AppletInterface : public QObject
Q_ENUMS(IntervalAlignment) Q_ENUMS(IntervalAlignment)
Q_ENUMS(ThemeColors) Q_ENUMS(ThemeColors)
Q_PROPERTY(AspectRatioMode aspectRatioMode READ aspectRatioMode WRITE setAspectRatioMode) Q_PROPERTY(AspectRatioMode aspectRatioMode READ aspectRatioMode WRITE setAspectRatioMode)
Q_PROPERTY(FormFactor formFactor READ formFactor) Q_PROPERTY(FormFactor formFactor READ formFactor NOTIFY formFactorChanged)
Q_PROPERTY(Location location READ location) Q_PROPERTY(Location location READ location NOTIFY locationChanged)
Q_PROPERTY(QString currentActivity READ currentActivity) Q_PROPERTY(QString currentActivity READ currentActivity NOTIFY contextChanged)
Q_PROPERTY(bool shouldConserveResources READ shouldConserveResources) Q_PROPERTY(bool shouldConserveResources READ shouldConserveResources)
Q_PROPERTY(QString activeConfig WRITE setActiveConfig READ activeConfig) Q_PROPERTY(QString activeConfig WRITE setActiveConfig READ activeConfig)
Q_PROPERTY(bool busy WRITE setBusy READ isBusy) Q_PROPERTY(bool busy WRITE setBusy READ isBusy)
Q_PROPERTY(BackgroundHints backgroundHints WRITE setBackgroundHints READ backgroundHints) Q_PROPERTY(BackgroundHints backgroundHints WRITE setBackgroundHints READ backgroundHints)
Q_PROPERTY(QGraphicsLayout *layout WRITE setLayout READ layout) Q_PROPERTY(bool immutable READ immutable NOTIFY immutableChanged)
Q_PROPERTY(bool immutable READ immutable)
Q_PROPERTY(bool userConfiguring READ userConfiguring) // @since 4.5 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(QRectF rect READ rect)
Q_PROPERTY(QSizeF size READ size) Q_PROPERTY(QSizeF size READ size)
#ifdef USE_JS_SCRIPTENGINE
Q_PROPERTY(QGraphicsLayout *layout WRITE setLayout READ layout)
Q_PROPERTY(QObject *sender READ sender) Q_PROPERTY(QObject *sender READ sender)
#endif
public: public:
AppletInterface(SimpleJavaScriptApplet *parent); AppletInterface(AbstractJsAppletScript *parent);
~AppletInterface(); ~AppletInterface();
//------------------------------------------------------------------ //------------------------------------------------------------------
@ -255,8 +258,6 @@ enum IntervalAlignment {
Q_INVOKABLE void setPreferredSize(qreal w, qreal h); Q_INVOKABLE void setPreferredSize(qreal w, qreal h);
Q_INVOKABLE void update(const QRectF &rect = QRectF());
Q_INVOKABLE QString activeConfig() const; Q_INVOKABLE QString activeConfig() const;
Q_INVOKABLE void setActiveConfig(const QString &name); Q_INVOKABLE void setActiveConfig(const QString &name);
@ -275,11 +276,15 @@ enum IntervalAlignment {
Q_INVOKABLE Plasma::Extender *extender() const; 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); Plasma::DataEngine *dataEngine(const QString &name);
QList<QAction*> contextualActions() const; QList<QAction*> contextualActions() const;
QGraphicsLayout *layout() const;
void setLayout(QGraphicsLayout *);
bool immutable() const; bool immutable() const;
bool userConfiguring() const; bool userConfiguring() const;
int apiVersion() const; int apiVersion() const;
@ -291,8 +296,13 @@ Q_SIGNALS:
void releaseVisualFocus(); void releaseVisualFocus();
void configNeedsSaving(); void configNeedsSaving();
void formFactorChanged();
void locationChanged();
void contextChanged();
void immutableChanged();
protected: protected:
SimpleJavaScriptApplet *m_appletScriptEngine; AbstractJsAppletScript *m_appletScriptEngine;
private: private:
QSet<QString> m_actions; QSet<QString> m_actions;
@ -309,7 +319,7 @@ class PopupAppletInterface : public AppletInterface
Q_PROPERTY(QGraphicsWidget *popupWidget READ popupWidget WRITE setPopupWidget) Q_PROPERTY(QGraphicsWidget *popupWidget READ popupWidget WRITE setPopupWidget)
public: public:
PopupAppletInterface(SimpleJavaScriptApplet *parent); PopupAppletInterface(AbstractJsAppletScript *parent);
void setPopupIcon(const QIcon &icon); void setPopupIcon(const QIcon &icon);
QIcon popupIcon(); QIcon popupIcon();

View File

@ -0,0 +1,22 @@
/*
* Copyright 2010 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 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"

View File

@ -98,7 +98,7 @@ KSharedPtr<UiLoader> SimpleJavaScriptApplet::s_widgetLoader;
QHash<QString, Plasma::Animator::Animation> SimpleJavaScriptApplet::s_animationDefs; QHash<QString, Plasma::Animator::Animation> SimpleJavaScriptApplet::s_animationDefs;
SimpleJavaScriptApplet::SimpleJavaScriptApplet(QObject *parent, const QVariantList &args) SimpleJavaScriptApplet::SimpleJavaScriptApplet(QObject *parent, const QVariantList &args)
: Plasma::AppletScript(parent) : AbstractJsAppletScript(parent)
{ {
Q_UNUSED(args); Q_UNUSED(args);
// kDebug() << "Script applet launched, args" << applet()->startupArguments(); // kDebug() << "Script applet launched, args" << applet()->startupArguments();

View File

@ -22,10 +22,10 @@
#include <QScriptValue> #include <QScriptValue>
#include <Plasma/Animator> #include <Plasma/Animator>
#include <Plasma/AppletScript>
#include <Plasma/DataEngine> #include <Plasma/DataEngine>
#include "simplebindings/uiloader.h" #include "simplebindings/uiloader.h"
#include "abstractjsappletscript.h"
class QScriptContext; class QScriptContext;
class QScriptEngine; class QScriptEngine;
@ -38,7 +38,7 @@ namespace Plasma
class ExtenderItem; class ExtenderItem;
} // namespace Plasma } // namespace Plasma
class SimpleJavaScriptApplet : public Plasma::AppletScript class SimpleJavaScriptApplet : public AbstractJsAppletScript
{ {
Q_OBJECT Q_OBJECT