share the dataengine bindings between applet and dataengine

svn path=/trunk/KDE/kdebase/runtime/; revision=1089372
This commit is contained in:
Aaron J. Seigo 2010-02-13 00:53:46 +00:00
parent 1072174a96
commit 58c8a6cc0a
6 changed files with 78 additions and 61 deletions

View File

@ -10,6 +10,7 @@ set(simple_javascript_engine_SRCS
simplebindings/bytearrayclass.cpp
simplebindings/bytearrayprototype.cpp
simplebindings/color.cpp
simplebindings/dataengine.cpp
simplebindings/easingcurve.cpp
simplebindings/font.cpp
simplebindings/filedialogproxy.cpp
@ -69,6 +70,7 @@ install(FILES plasma-scriptengine-runner-javascript.desktop DESTINATION ${SERVIC
set(javascript_dataengine_engine_SRCS
javascriptdataengine.cpp
scriptenv.cpp
simplebindings/dataengine.cpp
simplebindings/variant.cpp
)
kde4_add_plugin(plasma_dataenginescript_javascript ${javascript_dataengine_engine_SRCS})

View File

@ -49,13 +49,7 @@ bool JavaScriptDataEngine::init()
global.setProperty("removeData", m_qscriptEngine->newFunction(JavaScriptDataEngine::jsRemoveData));
global.setProperty("removeAllSources", m_qscriptEngine->newFunction(JavaScriptDataEngine::jsRemoveAllSources));
qRegisterMetaType<DataEngine::Data>("Plasma::DataEngine::Data");
qRegisterMetaType<DataEngine::Data>("DataEngine::Data");
qScriptRegisterMapMetaType<Plasma::DataEngine::Data>(m_qscriptEngine);
m_qscriptEngine->setDefaultPrototype(qMetaTypeId<Service*>(), m_qscriptEngine->newQObject(new DummyService(), QScriptEngine::ScriptOwnership));
m_qscriptEngine->setDefaultPrototype(qMetaTypeId<ServiceJob*>(),
m_qscriptEngine->newQObject(new ServiceJob(QString(), QString(), QMap<QString, QVariant>()),
QScriptEngine::ScriptOwnership ));
registerDataEngineMetaTypes(m_qscriptEngine);
Authorization auth;
if (!m_qscriptEngine->importExtensions(description(), iface, auth)) {

View File

@ -0,0 +1,66 @@
/*
* Copyright 2007 Richard J. Moore <rich@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.
*/
#include "dataengine.h"
typedef Plasma::Service *ServicePtr;
QScriptValue qScriptValueFromService(QScriptEngine *engine, const ServicePtr &service)
{
return engine->newQObject(const_cast<Plasma::Service *>(service), QScriptEngine::AutoOwnership, QScriptEngine::PreferExistingWrapperObject);
}
void serviceFromQScriptValue(const QScriptValue &scriptValue, ServicePtr &service)
{
QObject *obj = scriptValue.toQObject();
service = static_cast<Plasma::Service *>(obj);
}
typedef Plasma::DataEngine *DataEnginePtr;
QScriptValue qScriptValueFromDataEngine(QScriptEngine *engine, const DataEnginePtr &dataEngine)
{
return engine->newQObject(const_cast<Plasma::DataEngine *>(dataEngine), QScriptEngine::AutoOwnership, QScriptEngine::PreferExistingWrapperObject);
}
void dataEngineFromQScriptValue(const QScriptValue &scriptValue, DataEnginePtr &dataEngine)
{
QObject *obj = scriptValue.toQObject();
dataEngine = static_cast<Plasma::DataEngine *>(obj);
}
typedef Plasma::ServiceJob *ServiceJobPtr;
QScriptValue qScriptValueFromServiceJob(QScriptEngine *engine, const ServiceJobPtr &serviceJob)
{
return engine->newQObject(const_cast<Plasma::ServiceJob *>(serviceJob), QScriptEngine::AutoOwnership, QScriptEngine::PreferExistingWrapperObject);
}
void serviceJobFromQScriptValue(const QScriptValue &scriptValue, ServiceJobPtr &serviceJob)
{
QObject *obj = scriptValue.toQObject();
serviceJob = static_cast<Plasma::ServiceJob *>(obj);
}
void registerDataEngineMetaTypes(QScriptEngine *engine)
{
qRegisterMetaType<DataEngine::Data>("Plasma::DataEngine::Data");
qRegisterMetaType<DataEngine::Data>("DataEngine::Data");
qScriptRegisterMapMetaType<DataEngine::Data>(engine);
qScriptRegisterMetaType<Plasma::Service *>(engine, qScriptValueFromService, serviceFromQScriptValue);
qScriptRegisterMetaType<Plasma::DataEngine *>(engine, qScriptValueFromDataEngine, dataEngineFromQScriptValue);
qScriptRegisterMetaType<Plasma::ServiceJob *>(engine, qScriptValueFromServiceJob, serviceJobFromQScriptValue);
}

View File

@ -19,7 +19,9 @@
#ifndef DATAENGINE_H
#define DATAENGINE_H
#include <QtScript/QtScript>
#include <QScriptEngine>
#include <QScriptValue>
#include <QScriptValueIterator>
#include <KDebug>
#include <Plasma/DataEngine>
@ -75,16 +77,7 @@ int qScriptRegisterMapMetaType(
return qScriptRegisterMetaType<T>(engine, qScriptValueFromMap, qScriptValueToMap, prototype);
}
class DummyService : public Plasma::Service
{
public:
ServiceJob *createJob(const QString &operation, QMap<QString, QVariant> &parameters)
{
Q_UNUSED(operation)
Q_UNUSED(parameters)
return 0;
}
};
void registerDataEngineMetaTypes(QScriptEngine *engine);
#endif // DATAENGINE_H

View File

@ -185,45 +185,9 @@ void extenderFromQScriptValue(const QScriptValue &scriptValue, ExtenderPtr &exte
extender = static_cast<Plasma::Extender *>(obj);
}
typedef Plasma::Service *ServicePtr;
QScriptValue qScriptValueFromService(QScriptEngine *engine, const ServicePtr &service)
{
return engine->newQObject(const_cast<Plasma::Service *>(service), QScriptEngine::AutoOwnership, QScriptEngine::PreferExistingWrapperObject);
}
void serviceFromQScriptValue(const QScriptValue &scriptValue, ServicePtr &service)
{
QObject *obj = scriptValue.toQObject();
service = static_cast<Plasma::Service *>(obj);
}
typedef Plasma::DataEngine *DataEnginePtr;
QScriptValue qScriptValueFromDataEngine(QScriptEngine *engine, const DataEnginePtr &dataEngine)
{
return engine->newQObject(const_cast<Plasma::DataEngine *>(dataEngine), QScriptEngine::AutoOwnership, QScriptEngine::PreferExistingWrapperObject);
}
void dataEngineFromQScriptValue(const QScriptValue &scriptValue, DataEnginePtr &dataEngine)
{
QObject *obj = scriptValue.toQObject();
dataEngine = static_cast<Plasma::DataEngine *>(obj);
}
typedef Plasma::ServiceJob *ServiceJobPtr;
QScriptValue qScriptValueFromServiceJob(QScriptEngine *engine, const ServiceJobPtr &serviceJob)
{
return engine->newQObject(const_cast<Plasma::ServiceJob *>(serviceJob), QScriptEngine::AutoOwnership, QScriptEngine::PreferExistingWrapperObject);
}
void serviceJobFromQScriptValue(const QScriptValue &scriptValue, ServiceJobPtr &serviceJob)
{
QObject *obj = scriptValue.toQObject();
serviceJob = static_cast<Plasma::ServiceJob *>(obj);
}
using namespace Plasma;
void registerSimpleAppletMetaTypes(QScriptEngine *engine, bool includeUi)
void registerSimpleAppletMetaTypes(QScriptEngine *engine)
{
qScriptRegisterMetaType<QGraphicsWidget*>(engine, qScriptValueFromQGraphicsWidget, qGraphicsWidgetFromQScriptValue);
@ -232,12 +196,9 @@ void registerSimpleAppletMetaTypes(QScriptEngine *engine, bool includeUi)
qScriptRegisterMetaType<KIO::Job *>(engine, qScriptValueFromKIOJob, qKIOJobFromQScriptValue);
qScriptRegisterMetaType<Plasma::Animation *>(engine, qScriptValueFromAnimation, abstractAnimationFromQScriptValue);
qRegisterMetaType<DataEngine::Data>("Plasma::DataEngine::Data");
qRegisterMetaType<DataEngine::Data>("DataEngine::Data");
qScriptRegisterMapMetaType<DataEngine::Data>(engine);
qScriptRegisterMetaType<Plasma::Extender *>(engine, qScriptValueFromExtender, extenderFromQScriptValue);
qScriptRegisterMetaType<Plasma::VideoWidget::Controls>(engine, qScriptValueFromControls, controlsFromScriptValue, QScriptValue());
qScriptRegisterMetaType<Plasma::Service *>(engine, qScriptValueFromService, serviceFromQScriptValue);
qScriptRegisterMetaType<Plasma::DataEngine *>(engine, qScriptValueFromDataEngine, dataEngineFromQScriptValue);
qScriptRegisterMetaType<Plasma::ServiceJob *>(engine, qScriptValueFromServiceJob, serviceJobFromQScriptValue);
registerDataEngineMetaTypes(engine);
}

View File

@ -25,6 +25,7 @@
#include <QUiLoader>
#include <QGraphicsLayout>
#include <QParallelAnimationGroup>
#include <QPauseAnimation>
#include <QSequentialAnimationGroup>
#include <QWidget>