summaryrefslogtreecommitdiffstats
path: root/src/declarative/qml/qdeclarativeinclude.cpp
diff options
context:
space:
mode:
authorAaron Kennedy <aaron.kennedy@nokia.com>2010-05-14 07:15:08 (GMT)
committerAaron Kennedy <aaron.kennedy@nokia.com>2010-05-14 07:15:08 (GMT)
commitd9ab23c190de774ea093652060981e14ac5aeaf8 (patch)
tree80a4926c2ecfd4b9284fe64e23e6d0a6ab646678 /src/declarative/qml/qdeclarativeinclude.cpp
parent2f6eb60bf4012f9a185d7cd5d4c50762c3abc7f7 (diff)
downloadQt-d9ab23c190de774ea093652060981e14ac5aeaf8.zip
Qt-d9ab23c190de774ea093652060981e14ac5aeaf8.tar.gz
Qt-d9ab23c190de774ea093652060981e14ac5aeaf8.tar.bz2
Qt.include() support in worker scripts
Diffstat (limited to 'src/declarative/qml/qdeclarativeinclude.cpp')
-rw-r--r--src/declarative/qml/qdeclarativeinclude.cpp59
1 files changed, 59 insertions, 0 deletions
diff --git a/src/declarative/qml/qdeclarativeinclude.cpp b/src/declarative/qml/qdeclarativeinclude.cpp
index b886935..97220f1 100644
--- a/src/declarative/qml/qdeclarativeinclude.cpp
+++ b/src/declarative/qml/qdeclarativeinclude.cpp
@@ -252,6 +252,65 @@ QScriptValue QDeclarativeInclude::include(QScriptContext *ctxt, QScriptEngine *e
return result;
}
+QScriptValue QDeclarativeInclude::worker_include(QScriptContext *ctxt, QScriptEngine *engine)
+{
+ if (ctxt->argumentCount() == 0)
+ return engine->undefinedValue();
+
+ QDeclarativeEnginePrivate *ep = QDeclarativeEnginePrivate::get(engine);
+
+ QString urlString = ctxt->argument(0).toString();
+ QUrl url(ctxt->argument(0).toString());
+ if (url.isRelative()) {
+ QString contextUrl = QScriptDeclarativeClass::scopeChainValue(ctxt, -3).data().toString();
+ Q_ASSERT(!contextUrl.isEmpty());
+
+ url = QUrl(contextUrl).resolved(url);
+ urlString = url.toString();
+ }
+
+ QString localFile = toLocalFileOrQrc(url);
+
+ QScriptValue func = ctxt->argument(1);
+ if (!func.isFunction())
+ func = QScriptValue();
+
+ QScriptValue result;
+ if (!localFile.isEmpty()) {
+
+ QFile f(localFile);
+ if (f.open(QIODevice::ReadOnly)) {
+ QByteArray data = f.readAll();
+ QString code = QString::fromUtf8(data);
+ QScriptContext *scriptContext = QScriptDeclarativeClass::pushCleanContext(engine);
+ QScriptValue urlContext = engine->newObject();
+ urlContext.setData(QScriptValue(engine, urlString));
+ scriptContext->pushScope(urlContext);
+
+ QScriptValue scope = QScriptDeclarativeClass::scopeChainValue(ctxt, -4);
+ scriptContext->pushScope(scope);
+ scriptContext->setActivationObject(scope);
+
+ engine->evaluate(code, urlString, 1);
+
+ engine->popContext();
+
+ if (engine->hasUncaughtException()) {
+ result = resultValue(engine, Exception);
+ result.setProperty(QLatin1String("exception"), engine->uncaughtException());
+ engine->clearExceptions();
+ } else {
+ result = resultValue(engine, Ok);
+ }
+ callback(engine, func, result);
+ } else {
+ result = resultValue(engine, NetworkError);
+ callback(engine, func, result);
+ }
+ }
+
+ return result;
+}
QT_END_NAMESPACE