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>
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
)
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()));
54 void qScriptValueToMap(const QScriptValue
&value
, M
&map
)
56 QScriptValueIterator
it(value
);
57 while (it
.hasNext()) {
59 map
[it
.name()] = qscriptvalue_cast
<typename
M::mapped_type
>(it
.value());
64 int qScriptRegisterMapMetaType(
65 QScriptEngine
*engine
,
66 const QScriptValue
&prototype
= QScriptValue()
72 return qScriptRegisterMetaType
<T
>(engine
, qScriptValueFromMap
,
73 qScriptValueToMap
, prototype
);
76 #endif // BIND_DATAENGINE_H