* much simpler way of registering DataEngine::Data

* register the metatype by name with Qt so it can find it; this allows DataEngine::query() to work properly

svn path=/trunk/KDE/kdebase/runtime/; revision=1077821
This commit is contained in:
Aaron J. Seigo 2010-01-20 23:13:40 +00:00
parent 59ca56a770
commit c1f3d903d8
5 changed files with 14 additions and 50 deletions

View File

@ -10,7 +10,6 @@ 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
@ -70,7 +69,6 @@ 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,7 +49,9 @@ bool JavaScriptDataEngine::init()
global.setProperty("removeData", m_qscriptEngine->newFunction(JavaScriptDataEngine::jsRemoveData));
global.setProperty("removeAllSources", m_qscriptEngine->newFunction(JavaScriptDataEngine::jsRemoveAllSources));
qScriptRegisterMetaType<DataEngine::Data>(m_qscriptEngine, qScriptValueFromData, 0, QScriptValue());
qRegisterMetaType<DataEngine::Data>("Plasma::DataEngine::Data");
qRegisterMetaType<DataEngine::Data>("DataEngine::Data");
qScriptRegisterMapMetaType<Plasma::DataEngine::Data>(m_qscriptEngine);
/**
TODO: Service bindings
m_qscriptEngine->setDefaultPrototype(qMetaTypeId<Service*>(), m_qscriptEngine->newQObject(new DummyService()));

View File

@ -1,38 +0,0 @@
/*
* 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"
QScriptValue qScriptValueFromData(QScriptEngine *engine, const DataEngine::Data &data)
{
DataEngine::Data::const_iterator begin = data.begin();
DataEngine::Data::const_iterator end = data.end();
DataEngine::Data::const_iterator it;
QScriptValue obj = engine->newObject();
for (it = begin; it != end; ++it) {
//kDebug() << "setting" << it.key() << "to" << it.value();
QString prop = it.key();
prop.replace(' ', '_');
obj.setProperty(prop, variantToScriptValue(engine, it.value()));
}
return obj;
}

View File

@ -40,20 +40,22 @@ Q_DECLARE_METATYPE(DataEngine::Data)
template <class M>
QScriptValue qScriptValueFromMap(QScriptEngine *eng, const M &map)
{
kDebug() << "qScriptValueFromMap called";
//kDebug() << "qScriptValueFromMap called";
QScriptValue obj = eng->newObject();
typename M::const_iterator begin = map.constBegin();
typename M::const_iterator end = map.constEnd();
typename M::const_iterator it;
for (it = begin; it != end; ++it)
for (it = begin; it != end; ++it) {
obj.setProperty(it.key(), qScriptValueFromValue(eng, it.value()));
}
return obj;
}
template <class M>
void qScriptValueToMap(const QScriptValue &value, M &map)
{
//kDebug() << "qScriptValueToMap called";
QScriptValueIterator it(value);
while (it.hasNext()) {
it.next();
@ -70,11 +72,8 @@ int qScriptRegisterMapMetaType(
#endif
)
{
return qScriptRegisterMetaType<T>(engine, qScriptValueFromMap,
qScriptValueToMap, prototype);
return qScriptRegisterMetaType<T>(engine, qScriptValueFromMap, qScriptValueToMap, prototype);
}
QScriptValue qScriptValueFromData(QScriptEngine *engine, const DataEngine::Data &data);
#endif // DATAENGINE_H

View File

@ -184,6 +184,7 @@ void extenderFromQScriptValue(const QScriptValue &scriptValue, ExtenderPtr &exte
QObject *obj = scriptValue.toQObject();
extender = static_cast<Plasma::Extender *>(obj);
}
using namespace Plasma;
void registerSimpleAppletMetaTypes(QScriptEngine *engine)
{
@ -194,7 +195,9 @@ void registerSimpleAppletMetaTypes(QScriptEngine *engine)
qScriptRegisterMetaType<KIO::Job *>(engine, qScriptValueFromKIOJob, qKIOJobFromQScriptValue);
qScriptRegisterMetaType<Plasma::Animation *>(engine, qScriptValueFromAnimation, abstractAnimationFromQScriptValue);
qScriptRegisterMetaType<Plasma::DataEngine::Data>(engine, qScriptValueFromData, 0, QScriptValue());
qScriptRegisterMetaType<Plasma::Extender *>(engine, qScriptValueFromExtender , extenderFromQScriptValue);
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());
}