make Service work by introducing service("engine", "source")

svn path=/trunk/KDE/kdebase/workspace/plasma/scriptengines/javascript/; revision=906276
This commit is contained in:
Aaron J. Seigo 2009-01-05 20:48:22 +00:00
parent 4d64a905ce
commit 6a930aea43
2 changed files with 34 additions and 16 deletions

View File

@ -63,9 +63,11 @@ QScriptValue constructQSizeFClass(QScriptEngine *engine);
class DummyService : public Service
{
ServiceJob *createJob(const QString &operation,
QMap<QString, QVariant> &parameters)
public:
ServiceJob *createJob(const QString &operation, QMap<QString, QVariant> &parameters)
{
Q_UNUSED(operation)
Q_UNUSED(parameters)
return 0;
}
};
@ -373,15 +375,9 @@ void SimpleJavaScriptApplet::setupObjects()
m_engine->setDefaultPrototype(qMetaTypeId<DataEngine*>(), m_engine->newQObject(new DataEngine()));
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>())));
#if 0
fun = m_engine->newFunction(SimpleJavaScriptApplet::dataEngine);
m_self.setProperty("dataEngine", fun);
#endif
global.setProperty("dataEngine", m_engine->newFunction(SimpleJavaScriptApplet::dataEngine));
// qScriptRegisterMapMetaType<QMap<QString, QVariant> >(m_engine);
// qScriptRegisterMapMetaType<DataEngine::Dict>(m_engine);
// qScriptRegisterMapMetaType<DataEngine::Data>(m_engine);
global.setProperty("service", m_engine->newFunction(SimpleJavaScriptApplet::service));
qScriptRegisterMetaType<DataEngine::Data>(m_engine, qScriptValueFromData, 0, 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
QScriptValue fun = m_engine->newFunction(SimpleJavaScriptApplet::loadui);
global.setProperty("loadui", fun);
@ -433,7 +423,6 @@ void SimpleJavaScriptApplet::setupObjects()
global.setProperty("QPoint", constructQPointClass(m_engine));
global.setProperty("LinearLayout", constructLinearLayoutClass(m_engine));
installWidgets(m_engine);
}
@ -488,6 +477,34 @@ QScriptValue SimpleJavaScriptApplet::dataEngine(QScriptContext *context, QScript
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)
{
if (context->argumentCount() != 1) {

View File

@ -60,6 +60,7 @@ private:
static QString findSvg(QScriptEngine *engine, const QString &file);
static QScriptValue dataEngine(QScriptContext *context, QScriptEngine *engine);
static QScriptValue service(QScriptContext *context, QScriptEngine *engine);
static QScriptValue loadui(QScriptContext *context, QScriptEngine *engine);
static QScriptValue newPlasmaSvg(QScriptContext *context, QScriptEngine *engine);
static QScriptValue newPlasmaFrameSvg(QScriptContext *context, QScriptEngine *engine);