make Service work by introducing service("engine", "source")
svn path=/trunk/KDE/kdebase/workspace/plasma/scriptengines/javascript/; revision=906276
This commit is contained in:
parent
4d64a905ce
commit
6a930aea43
@ -63,9 +63,11 @@ QScriptValue constructQSizeFClass(QScriptEngine *engine);
|
|||||||
|
|
||||||
class DummyService : public Service
|
class DummyService : public Service
|
||||||
{
|
{
|
||||||
ServiceJob *createJob(const QString &operation,
|
public:
|
||||||
QMap<QString, QVariant> ¶meters)
|
ServiceJob *createJob(const QString &operation, QMap<QString, QVariant> ¶meters)
|
||||||
{
|
{
|
||||||
|
Q_UNUSED(operation)
|
||||||
|
Q_UNUSED(parameters)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -373,15 +375,9 @@ void SimpleJavaScriptApplet::setupObjects()
|
|||||||
m_engine->setDefaultPrototype(qMetaTypeId<DataEngine*>(), m_engine->newQObject(new DataEngine()));
|
m_engine->setDefaultPrototype(qMetaTypeId<DataEngine*>(), m_engine->newQObject(new DataEngine()));
|
||||||
m_engine->setDefaultPrototype(qMetaTypeId<Service*>(), m_engine->newQObject(new DummyService()));
|
m_engine->setDefaultPrototype(qMetaTypeId<Service*>(), m_engine->newQObject(new DummyService()));
|
||||||
m_engine->setDefaultPrototype(qMetaTypeId<ServiceJob*>(), m_engine->newQObject(new ServiceJob(QString(), QString(), QMap<QString, QVariant>())));
|
m_engine->setDefaultPrototype(qMetaTypeId<ServiceJob*>(), m_engine->newQObject(new ServiceJob(QString(), QString(), QMap<QString, QVariant>())));
|
||||||
#if 0
|
|
||||||
fun = m_engine->newFunction(SimpleJavaScriptApplet::dataEngine);
|
|
||||||
m_self.setProperty("dataEngine", fun);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
global.setProperty("dataEngine", m_engine->newFunction(SimpleJavaScriptApplet::dataEngine));
|
global.setProperty("dataEngine", m_engine->newFunction(SimpleJavaScriptApplet::dataEngine));
|
||||||
// qScriptRegisterMapMetaType<QMap<QString, QVariant> >(m_engine);
|
global.setProperty("service", m_engine->newFunction(SimpleJavaScriptApplet::service));
|
||||||
// qScriptRegisterMapMetaType<DataEngine::Dict>(m_engine);
|
|
||||||
// qScriptRegisterMapMetaType<DataEngine::Data>(m_engine);
|
|
||||||
qScriptRegisterMetaType<DataEngine::Data>(m_engine, qScriptValueFromData, 0, QScriptValue());
|
qScriptRegisterMetaType<DataEngine::Data>(m_engine, qScriptValueFromData, 0, QScriptValue());
|
||||||
qScriptRegisterMetaType<KConfigGroup>(m_engine, qScriptValueFromKConfigGroup, kConfigGroupFromScriptValue, QScriptValue());
|
qScriptRegisterMetaType<KConfigGroup>(m_engine, qScriptValueFromKConfigGroup, kConfigGroupFromScriptValue, QScriptValue());
|
||||||
|
|
||||||
@ -402,12 +398,6 @@ void SimpleJavaScriptApplet::setupObjects()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// global.setProperty("Planar", QScriptValue(m_engine, Plasma::Planar));
|
|
||||||
// m_metaObject = m_engine->newQMetaObject(&AppletInterface::staticMetaObject);
|
|
||||||
// m_metaObject.setScope(global);
|
|
||||||
// global.setProperty("meta", m_metaObject);
|
|
||||||
|
|
||||||
|
|
||||||
// Add a global loadui method for ui files
|
// Add a global loadui method for ui files
|
||||||
QScriptValue fun = m_engine->newFunction(SimpleJavaScriptApplet::loadui);
|
QScriptValue fun = m_engine->newFunction(SimpleJavaScriptApplet::loadui);
|
||||||
global.setProperty("loadui", fun);
|
global.setProperty("loadui", fun);
|
||||||
@ -433,7 +423,6 @@ void SimpleJavaScriptApplet::setupObjects()
|
|||||||
global.setProperty("QPoint", constructQPointClass(m_engine));
|
global.setProperty("QPoint", constructQPointClass(m_engine));
|
||||||
global.setProperty("LinearLayout", constructLinearLayoutClass(m_engine));
|
global.setProperty("LinearLayout", constructLinearLayoutClass(m_engine));
|
||||||
|
|
||||||
|
|
||||||
installWidgets(m_engine);
|
installWidgets(m_engine);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -488,6 +477,34 @@ QScriptValue SimpleJavaScriptApplet::dataEngine(QScriptContext *context, QScript
|
|||||||
return engine->newQObject(data);
|
return engine->newQObject(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QScriptValue SimpleJavaScriptApplet::service(QScriptContext *context, QScriptEngine *engine)
|
||||||
|
{
|
||||||
|
if (context->argumentCount() != 2) {
|
||||||
|
return context->throwError("service takes two arguments");
|
||||||
|
}
|
||||||
|
|
||||||
|
QString dataEngine = context->argument(0).toString();
|
||||||
|
|
||||||
|
QScriptValue appletValue = engine->globalObject().property("plasmoid");
|
||||||
|
//kDebug() << "appletValue is " << appletValue.toString();
|
||||||
|
|
||||||
|
QObject *appletObject = appletValue.toQObject();
|
||||||
|
if (!appletObject) {
|
||||||
|
return context->throwError(i18n("Could not extract the AppletObject"));
|
||||||
|
}
|
||||||
|
|
||||||
|
AppletInterface *interface = qobject_cast<AppletInterface*>(appletObject);
|
||||||
|
if (!interface) {
|
||||||
|
return context->throwError(i18n("Could not extract the Applet"));
|
||||||
|
}
|
||||||
|
|
||||||
|
DataEngine *data = interface->dataEngine(dataEngine);
|
||||||
|
QString source = context->argument(1).toString();
|
||||||
|
Service *service = data->serviceForSource(source);
|
||||||
|
kDebug( )<< "lets try to get" << source << "from" << dataEngine;
|
||||||
|
return engine->newQObject(service);
|
||||||
|
}
|
||||||
|
|
||||||
QScriptValue SimpleJavaScriptApplet::loadui(QScriptContext *context, QScriptEngine *engine)
|
QScriptValue SimpleJavaScriptApplet::loadui(QScriptContext *context, QScriptEngine *engine)
|
||||||
{
|
{
|
||||||
if (context->argumentCount() != 1) {
|
if (context->argumentCount() != 1) {
|
||||||
|
@ -60,6 +60,7 @@ private:
|
|||||||
|
|
||||||
static QString findSvg(QScriptEngine *engine, const QString &file);
|
static QString findSvg(QScriptEngine *engine, const QString &file);
|
||||||
static QScriptValue dataEngine(QScriptContext *context, QScriptEngine *engine);
|
static QScriptValue dataEngine(QScriptContext *context, QScriptEngine *engine);
|
||||||
|
static QScriptValue service(QScriptContext *context, QScriptEngine *engine);
|
||||||
static QScriptValue loadui(QScriptContext *context, QScriptEngine *engine);
|
static QScriptValue loadui(QScriptContext *context, QScriptEngine *engine);
|
||||||
static QScriptValue newPlasmaSvg(QScriptContext *context, QScriptEngine *engine);
|
static QScriptValue newPlasmaSvg(QScriptContext *context, QScriptEngine *engine);
|
||||||
static QScriptValue newPlasmaFrameSvg(QScriptContext *context, QScriptEngine *engine);
|
static QScriptValue newPlasmaFrameSvg(QScriptContext *context, QScriptEngine *engine);
|
||||||
|
Loading…
Reference in New Issue
Block a user