extenders
svn path=/branches/KDE/4.4/kdebase/runtime/; revision=1077723
This commit is contained in:
parent
3f5f41d784
commit
d8b8c51c6a
@ -32,7 +32,6 @@
|
||||
#include <Plasma/Plasma>
|
||||
#include <Plasma/Applet>
|
||||
#include <Plasma/Context>
|
||||
#include <Plasma/DataEngine>
|
||||
#include <Plasma/Package>
|
||||
|
||||
AppletInterface::AppletInterface(SimpleJavaScriptApplet *parent)
|
||||
@ -365,6 +364,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()));
|
||||
|
@ -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;
|
||||
|
@ -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::DataEngine::Data>(engine, qScriptValueFromData, 0, QScriptValue());
|
||||
qScriptRegisterMetaType<Plasma::Extender *>(engine, qScriptValueFromExtender , extenderFromQScriptValue);
|
||||
qScriptRegisterMetaType<Plasma::VideoWidget::Controls>(engine, qScriptValueFromControls, controlsFromScriptValue, QScriptValue());
|
||||
}
|
||||
|
@ -42,10 +42,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 "simplebindings/animationgroup.h"
|
||||
@ -315,6 +317,8 @@ void SimpleJavaScriptApplet::populateAnimationsHash()
|
||||
|
||||
bool SimpleJavaScriptApplet::init()
|
||||
{
|
||||
connect(applet(), SIGNAL(extenderItemRestored(Plasma::ExtenderItem*)),
|
||||
this, SLOT(extenderItemRestored(Plasma::ExtenderItem*)));
|
||||
setupObjects();
|
||||
|
||||
if (!importExtensions()) {
|
||||
@ -327,6 +331,13 @@ bool SimpleJavaScriptApplet::init()
|
||||
return include(mainScript());
|
||||
}
|
||||
|
||||
void SimpleJavaScriptApplet::extenderItemRestored(Plasma::ExtenderItem* item)
|
||||
{
|
||||
QScriptValueList args;
|
||||
args << m_engine->newQObject(item, QScriptEngine::AutoOwnership, QScriptEngine::PreferExistingWrapperObject);
|
||||
callFunction("initExtenderItem", args);
|
||||
}
|
||||
|
||||
QScriptValue SimpleJavaScriptApplet::runApplication(QScriptContext *context, QScriptEngine *engine)
|
||||
{
|
||||
Q_UNUSED(engine)
|
||||
@ -589,6 +600,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);
|
||||
@ -774,6 +786,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);
|
||||
registerEnums(engine, fun, *extenderItem->metaObject());
|
||||
return fun;
|
||||
}
|
||||
|
||||
QScriptValue SimpleJavaScriptApplet::widgetAdjustSize(QScriptContext *context, QScriptEngine *engine)
|
||||
{
|
||||
QGraphicsWidget *widget = qobject_cast<QGraphicsWidget*>(context->thisObject().toQObject());
|
||||
|
@ -32,6 +32,11 @@ class QScriptContext;
|
||||
|
||||
class AppletInterface;
|
||||
|
||||
namespace Plasma
|
||||
{
|
||||
class ExtenderItem;
|
||||
} // namespace Plasma
|
||||
|
||||
class SimpleJavaScriptApplet : public Plasma::AppletScript
|
||||
{
|
||||
Q_OBJECT
|
||||
@ -63,6 +68,7 @@ public slots:
|
||||
void configChanged();
|
||||
void executeAction(const QString &name);
|
||||
void collectGarbage();
|
||||
void extenderItemRestored(Plasma::ExtenderItem* item);
|
||||
|
||||
private:
|
||||
void registerGetUrl();
|
||||
@ -85,6 +91,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);
|
||||
|
Loading…
Reference in New Issue
Block a user