bindings for dataengine in DeclarativeWidget
This commit is contained in:
parent
38fd4f487f
commit
a6fa660809
@ -107,6 +107,7 @@ set(plasma_LIB_SRCS
|
||||
private/applethandle.cpp
|
||||
private/associatedapplicationmanager.cpp
|
||||
private/datacontainer_p.cpp
|
||||
private/dataenginebindings.cpp
|
||||
private/dataengineconsumer.cpp
|
||||
private/dataengineservice.cpp
|
||||
private/denyallauthorization.cpp
|
||||
|
66
private/dataenginebindings.cpp
Normal file
66
private/dataenginebindings.cpp
Normal 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 "dataenginebindings_p.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<Plasma::DataEngine::Data>("Plasma::DataEngine::Data");
|
||||
qRegisterMetaType<Plasma::DataEngine::Data>("DataEngine::Data");
|
||||
qScriptRegisterMapMetaType<Plasma::DataEngine::Data>(engine);
|
||||
qScriptRegisterMetaType<Plasma::Service *>(engine, qScriptValueFromService, serviceFromQScriptValue);
|
||||
qScriptRegisterMetaType<Plasma::DataEngine *>(engine, qScriptValueFromDataEngine, dataEngineFromQScriptValue);
|
||||
qScriptRegisterMetaType<Plasma::ServiceJob *>(engine, qScriptValueFromServiceJob, serviceJobFromQScriptValue);
|
||||
}
|
||||
|
85
private/dataenginebindings_p.h
Normal file
85
private/dataenginebindings_p.h
Normal file
@ -0,0 +1,85 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifndef DATAENGINE_H
|
||||
#define DATAENGINE_H
|
||||
|
||||
#include <QScriptEngine>
|
||||
#include <QScriptValue>
|
||||
#include <QScriptValueIterator>
|
||||
#include <kdebug.h>
|
||||
|
||||
#include <dataengine.h>
|
||||
#include <service.h>
|
||||
#include <servicejob.h>
|
||||
|
||||
using namespace Plasma;
|
||||
|
||||
Q_DECLARE_METATYPE(Service*)
|
||||
Q_DECLARE_METATYPE(ServiceJob*)
|
||||
Q_DECLARE_METATYPE(DataEngine::Dict)
|
||||
Q_DECLARE_METATYPE(DataEngine::Data)
|
||||
|
||||
template <class M>
|
||||
QScriptValue qScriptValueFromMap(QScriptEngine *eng, const M &map)
|
||||
{
|
||||
//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) {
|
||||
if (it.value().type() == QVariant::Hash) {
|
||||
obj.setProperty(it.key(), qScriptValueFromMap(eng, it.value().toHash()));
|
||||
} else if (it.value().type() == QVariant::Map) {
|
||||
obj.setProperty(it.key(), qScriptValueFromMap(eng, it.value().toMap()));
|
||||
} else {
|
||||
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();
|
||||
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
|
||||
)
|
||||
{
|
||||
return qScriptRegisterMetaType<T>(engine, qScriptValueFromMap, qScriptValueToMap, prototype);
|
||||
}
|
||||
|
||||
void registerDataEngineMetaTypes(QScriptEngine *engine);
|
||||
|
||||
#endif // DATAENGINE_H
|
||||
|
@ -35,6 +35,7 @@
|
||||
#include <kstandarddirs.h>
|
||||
|
||||
#include "private/declarative/declarativenetworkaccessmanagerfactory_p.h"
|
||||
#include "private/dataenginebindings_p.h"
|
||||
|
||||
namespace Plasma
|
||||
{
|
||||
@ -99,6 +100,7 @@ void DeclarativeWidgetPrivate::execute(const QString &fileName)
|
||||
//binds things like kconfig and icons
|
||||
kdeclarative.setupBindings();
|
||||
scriptEngine = kdeclarative.scriptEngine();
|
||||
registerDataEngineMetaTypes(scriptEngine);
|
||||
|
||||
if (delay) {
|
||||
QTimer::singleShot(0, q, SLOT(scheduleExecutionEnd()));
|
||||
|
Loading…
x
Reference in New Issue
Block a user