2009-05-13 02:55:25 +02:00
|
|
|
/*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
2009-12-16 23:05:46 +01:00
|
|
|
#ifndef DATAENGINE_H
|
|
|
|
#define DATAENGINE_H
|
2009-05-13 02:55:25 +02:00
|
|
|
|
2010-02-13 01:53:46 +01:00
|
|
|
#include <QScriptEngine>
|
|
|
|
#include <QScriptValue>
|
|
|
|
#include <QScriptValueIterator>
|
2009-05-13 02:55:25 +02:00
|
|
|
#include <KDebug>
|
|
|
|
|
|
|
|
#include <Plasma/DataEngine>
|
|
|
|
#include <Plasma/Service>
|
|
|
|
#include <Plasma/ServiceJob>
|
|
|
|
|
2009-12-16 23:05:46 +01:00
|
|
|
#include "variant.h"
|
|
|
|
|
2009-05-13 02:55:25 +02:00
|
|
|
using namespace Plasma;
|
|
|
|
|
|
|
|
Q_DECLARE_METATYPE(DataEngine*)
|
|
|
|
Q_DECLARE_METATYPE(Service*)
|
|
|
|
Q_DECLARE_METATYPE(ServiceJob*)
|
|
|
|
Q_DECLARE_METATYPE(QVariant)
|
|
|
|
Q_DECLARE_METATYPE(DataEngine::Dict)
|
|
|
|
Q_DECLARE_METATYPE(DataEngine::Data)
|
|
|
|
|
|
|
|
template <class M>
|
|
|
|
QScriptValue qScriptValueFromMap(QScriptEngine *eng, const M &map)
|
|
|
|
{
|
2010-01-21 00:13:40 +01:00
|
|
|
//kDebug() << "qScriptValueFromMap called";
|
2009-05-13 02:55:25 +02:00
|
|
|
QScriptValue obj = eng->newObject();
|
|
|
|
typename M::const_iterator begin = map.constBegin();
|
|
|
|
typename M::const_iterator end = map.constEnd();
|
|
|
|
typename M::const_iterator it;
|
2010-01-21 00:13:40 +01:00
|
|
|
for (it = begin; it != end; ++it) {
|
2009-05-13 02:55:25 +02:00
|
|
|
obj.setProperty(it.key(), qScriptValueFromValue(eng, it.value()));
|
2010-01-21 00:13:40 +01:00
|
|
|
}
|
|
|
|
|
2009-05-13 02:55:25 +02:00
|
|
|
return obj;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class M>
|
|
|
|
void qScriptValueToMap(const QScriptValue &value, M &map)
|
|
|
|
{
|
2010-01-21 00:13:40 +01:00
|
|
|
//kDebug() << "qScriptValueToMap called";
|
2009-05-13 02:55:25 +02:00
|
|
|
QScriptValueIterator it(value);
|
|
|
|
while (it.hasNext()) {
|
|
|
|
it.next();
|
|
|
|
map[it.name()] = qscriptvalue_cast<typename M::mapped_type>(it.value());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
template<typename T>
|
|
|
|
int qScriptRegisterMapMetaType(
|
|
|
|
QScriptEngine *engine,
|
|
|
|
const QScriptValue &prototype = QScriptValue()
|
|
|
|
#ifndef qdoc
|
|
|
|
, T * /* dummy */ = 0
|
|
|
|
#endif
|
|
|
|
)
|
|
|
|
{
|
2010-01-21 00:13:40 +01:00
|
|
|
return qScriptRegisterMetaType<T>(engine, qScriptValueFromMap, qScriptValueToMap, prototype);
|
2009-05-13 02:55:25 +02:00
|
|
|
}
|
|
|
|
|
2010-02-13 01:53:46 +01:00
|
|
|
void registerDataEngineMetaTypes(QScriptEngine *engine);
|
2010-01-21 00:25:24 +01:00
|
|
|
|
2009-12-16 23:05:46 +01:00
|
|
|
#endif // DATAENGINE_H
|
2009-05-13 02:55:25 +02:00
|
|
|
|