add more spacing
[personal-kdebase.git] / workspace / plasma / scriptengines / javascript / bind_dataengine.h
blobf1707c8674383d4d8e84b3d225433e18210d0c15
1 /*
2 * Copyright 2007 Richard J. Moore <rich@kde.org>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU Library General Public License version 2 as
6 * published by the Free Software Foundation
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details
13 * You should have received a copy of the GNU Library General Public
14 * License along with this program; if not, write to the
15 * Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 #ifndef BIND_DATAENGINE_H
20 #define BIND_DATAENGINE_H
22 #include <QtScript/QtScript>
23 #include <KDebug>
25 #include <Plasma/DataEngine>
26 #include <Plasma/Service>
27 #include <Plasma/ServiceJob>
29 using namespace Plasma;
31 Q_DECLARE_METATYPE(DataEngine*)
32 Q_DECLARE_METATYPE(Service*)
33 Q_DECLARE_METATYPE(ServiceJob*)
34 Q_DECLARE_METATYPE(QVariant)
35 Q_DECLARE_METATYPE(DataEngine::Dict)
36 Q_DECLARE_METATYPE(DataEngine::Data)
39 template <class M>
40 QScriptValue qScriptValueFromMap(QScriptEngine *eng, const M &map)
42 kDebug() << "qScriptValueFromMap called";
44 QScriptValue obj = eng->newObject();
45 typename M::const_iterator begin = map.constBegin();
46 typename M::const_iterator end = map.constEnd();
47 typename M::const_iterator it;
48 for (it = begin; it != end; ++it)
49 obj.setProperty(it.key(), qScriptValueFromValue(eng, it.value()));
50 return obj;
53 template <class M>
54 void qScriptValueToMap(const QScriptValue &value, M &map)
56 QScriptValueIterator it(value);
57 while (it.hasNext()) {
58 it.next();
59 map[it.name()] = qscriptvalue_cast<typename M::mapped_type>(it.value());
63 template<typename T>
64 int qScriptRegisterMapMetaType(
65 QScriptEngine *engine,
66 const QScriptValue &prototype = QScriptValue()
67 #ifndef qdoc
68 , T * /* dummy */ = 0
69 #endif
72 return qScriptRegisterMetaType<T>(engine, qScriptValueFromMap,
73 qScriptValueToMap, prototype);
76 #endif // BIND_DATAENGINE_H