extenders

svn path=/trunk/KDE/kdebase/runtime/; revision=1077776
This commit is contained in:
Aaron J. Seigo 2010-01-20 21:40:55 +00:00
parent 95663c101d
commit 59ca56a770
5 changed files with 80 additions and 12 deletions

View File

@ -32,7 +32,6 @@
#include <Plasma/Plasma>
#include <Plasma/Applet>
#include <Plasma/Context>
#include <Plasma/DataEngine>
#include <Plasma/Package>
AppletInterface::AppletInterface(SimpleJavaScriptApplet *parent)
@ -354,6 +353,11 @@ QObject *AppletInterface::findChild(const QString &name) const
return 0;
}
Plasma::Extender *AppletInterface::extender() const
{
return m_appletScriptEngine->extender();
}
void AppletInterface::gc()
{
QTimer::singleShot(0, m_appletScriptEngine, SLOT(collectGarbage()));

View File

@ -41,6 +41,7 @@ class QSizeF;
namespace Plasma
{
class ConfigLoader;
class Extender;
} // namespace Plasa
class AppletInterface : public QObject
@ -233,6 +234,8 @@ enum AnimationDirection {
Q_INVOKABLE void debug(const QString &msg);
Q_INVOKABLE QObject *findChild(const QString &name) const;
Q_INVOKABLE Plasma::Extender *extender() const;
Plasma::DataEngine *dataEngine(const QString &name);
const Plasma::Package *package() const;

View File

@ -20,26 +20,31 @@
#include <QGraphicsWidget>
#include <QScriptEngine>
#include <Plasma/Applet>
#include <Plasma/Animation>
#include <Plasma/VideoWidget>
#include <KConfigGroup>
#include <KIO/Job>
#include <Plasma/Applet>
#include <Plasma/Animation>
#include <Plasma/Extender>
#include <Plasma/VideoWidget>
#include "appletinterface.h"
#include "dataengine.h"
#include "variant.h"
//Q_DECLARE_METATYPE(SimpleJavaScriptApplet*)
Q_DECLARE_METATYPE(AppletInterface*)
Q_DECLARE_METATYPE(Plasma::Applet*)
Q_DECLARE_METATYPE(QGraphicsWidget*)
Q_DECLARE_METATYPE(QGraphicsLayout*)
Q_DECLARE_METATYPE(KConfigGroup)
Q_DECLARE_METATYPE(Plasma::Animation*)
Q_DECLARE_METATYPE(Plasma::Applet*)
Q_DECLARE_METATYPE(Plasma::Extender*)
Q_DECLARE_METATYPE(Plasma::VideoWidget::Controls)
Q_DECLARE_METATYPE(AppletInterface*)
//Q_SCRIPT_DECLARE_QMETAOBJECT(AppletInterface, SimpleJavaScriptApplet*)
@ -168,13 +173,28 @@ void qGraphicsWidgetFromQScriptValue(const QScriptValue &scriptValue, QGraphicsW
anim = static_cast<QGraphicsWidget *>(obj);
}
typedef Plasma::Extender *ExtenderPtr;
QScriptValue qScriptValueFromExtender(QScriptEngine *engine, const ExtenderPtr &extender)
{
return engine->newQObject(const_cast<Plasma::Extender *>(extender), QScriptEngine::AutoOwnership, QScriptEngine::PreferExistingWrapperObject);
}
void extenderFromQScriptValue(const QScriptValue &scriptValue, ExtenderPtr &extender)
{
QObject *obj = scriptValue.toQObject();
extender = static_cast<Plasma::Extender *>(obj);
}
void registerSimpleAppletMetaTypes(QScriptEngine *engine)
{
qScriptRegisterMetaType<Plasma::DataEngine::Data>(engine, qScriptValueFromData, 0, QScriptValue());
qScriptRegisterMetaType<QGraphicsWidget*>(engine, qScriptValueFromQGraphicsWidget, qGraphicsWidgetFromQScriptValue);
qScriptRegisterMetaType<KConfigGroup>(engine, qScriptValueFromKConfigGroup, kConfigGroupFromScriptValue, QScriptValue());
qScriptRegisterMetaType<Plasma::VideoWidget::Controls>(engine, qScriptValueFromControls, controlsFromScriptValue, QScriptValue());
qScriptRegisterMetaType<KJob *>(engine, qScriptValueFromKJob, qKJobFromQScriptValue);
qScriptRegisterMetaType<KIO::Job *>(engine, qScriptValueFromKIOJob, qKIOJobFromQScriptValue);
qScriptRegisterMetaType<Plasma::Animation*>(engine, qScriptValueFromAnimation, abstractAnimationFromQScriptValue);
qScriptRegisterMetaType<QGraphicsWidget*>(engine, qScriptValueFromQGraphicsWidget, qGraphicsWidgetFromQScriptValue);
qScriptRegisterMetaType<Plasma::Animation *>(engine, qScriptValueFromAnimation, abstractAnimationFromQScriptValue);
qScriptRegisterMetaType<Plasma::DataEngine::Data>(engine, qScriptValueFromData, 0, QScriptValue());
qScriptRegisterMetaType<Plasma::Extender *>(engine, qScriptValueFromExtender , extenderFromQScriptValue);
qScriptRegisterMetaType<Plasma::VideoWidget::Controls>(engine, qScriptValueFromControls, controlsFromScriptValue, QScriptValue());
}

View File

@ -41,10 +41,12 @@
#include <Plasma/Animation>
#include <Plasma/Applet>
#include <Plasma/Svg>
#include <Plasma/Extender>
#include <Plasma/ExtenderItem>
#include <Plasma/FrameSvg>
#include <Plasma/Package>
#include <Plasma/PopupApplet>
#include <Plasma/Svg>
#include <Plasma/VideoWidget>
#include "appletauthorization.h"
@ -173,6 +175,13 @@ void SimpleJavaScriptApplet::dataUpdated(const QString &name, const DataEngine::
}
}
void SimpleJavaScriptApplet::extenderItemRestored(Plasma::ExtenderItem* item)
{
QScriptValueList args;
args << m_engine->newQObject(item, QScriptEngine::AutoOwnership, QScriptEngine::PreferExistingWrapperObject);
callFunction("initExtenderItem", args);
}
void SimpleJavaScriptApplet::executeAction(const QString &name)
{
//callFunction("action_" + name);
@ -283,6 +292,8 @@ void SimpleJavaScriptApplet::populateAnimationsHash()
bool SimpleJavaScriptApplet::init()
{
connect(applet(), SIGNAL(extenderItemRestored(Plasma::ExtenderItem*)),
this, SLOT(extenderItemRestored(Plasma::ExtenderItem*)));
setupObjects();
AppletAuthorization auth(this);
@ -368,6 +379,7 @@ void SimpleJavaScriptApplet::setupObjects()
global.setProperty("PlasmaFrameSvg", m_engine->newFunction(SimpleJavaScriptApplet::newPlasmaFrameSvg));
global.setProperty("Svg", m_engine->newFunction(SimpleJavaScriptApplet::newPlasmaSvg));
global.setProperty("FrameSvg", m_engine->newFunction(SimpleJavaScriptApplet::newPlasmaFrameSvg));
global.setProperty("ExtenderItem", m_engine->newFunction(SimpleJavaScriptApplet::newPlasmaExtenderItem));
registerSimpleAppletMetaTypes(m_engine);
installWidgets(m_engine);
@ -553,6 +565,28 @@ QScriptValue SimpleJavaScriptApplet::newPlasmaFrameSvg(QScriptContext *context,
return fun;
}
QScriptValue SimpleJavaScriptApplet::newPlasmaExtenderItem(QScriptContext *context, QScriptEngine *engine)
{
Plasma::Extender *extender = 0;
if (context->argumentCount() > 0) {
extender = qobject_cast<Plasma::Extender *>(context->argument(0).toQObject());
}
if (!extender) {
AppletInterface *interface = extractAppletInterface(engine);
if (!interface) {
engine->undefinedValue();
}
extender = interface->extender();
}
Plasma::ExtenderItem *extenderItem = new Plasma::ExtenderItem(extender);
QScriptValue fun = engine->newQObject(extenderItem);
static_cast<ScriptEnv*>(engine)->registerEnums(fun, *extenderItem->metaObject());
return fun;
}
QScriptValue SimpleJavaScriptApplet::widgetAdjustSize(QScriptContext *context, QScriptEngine *engine)
{
QGraphicsWidget *widget = qobject_cast<QGraphicsWidget*>(context->thisObject().toQObject());

View File

@ -32,6 +32,11 @@ class QScriptContext;
class AppletInterface;
class ScriptEnv;
namespace Plasma
{
class ExtenderItem;
} // namespace Plasma
class SimpleJavaScriptApplet : public Plasma::AppletScript
{
Q_OBJECT
@ -57,6 +62,7 @@ public Q_SLOTS:
void configChanged();
void executeAction(const QString &name);
void collectGarbage();
void extenderItemRestored(Plasma::ExtenderItem* item);
private Q_SLOTS:
void engineReportsError(ScriptEnv *engine, bool fatal);
@ -81,6 +87,7 @@ private:
static QScriptValue loadui(QScriptContext *context, QScriptEngine *engine);
static QScriptValue newPlasmaSvg(QScriptContext *context, QScriptEngine *engine);
static QScriptValue newPlasmaFrameSvg(QScriptContext *context, QScriptEngine *engine);
static QScriptValue newPlasmaExtenderItem(QScriptContext *context, QScriptEngine *engine);
void installWidgets(QScriptEngine *engine);
static QScriptValue createWidget(QScriptContext *context, QScriptEngine *engine);