summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMartin Jones <martin.jones@nokia.com>2010-02-09 01:37:07 (GMT)
committerMartin Jones <martin.jones@nokia.com>2010-02-09 01:37:07 (GMT)
commit7e202bca9d21a70588e726e63abae6c9cb369fa8 (patch)
tree7cabad8a24fc8ed22c12a7c36e8e8a2f834dbe03
parent0d62d8e14433f1f0feebb7d151e9a397589be35a (diff)
downloadQt-7e202bca9d21a70588e726e63abae6c9cb369fa8.zip
Qt-7e202bca9d21a70588e726e63abae6c9cb369fa8.tar.gz
Qt-7e202bca9d21a70588e726e63abae6c9cb369fa8.tar.bz2
Use networkAccessManagerFactory() for worker threads too.
Task-number: QT-2850
-rw-r--r--src/declarative/qml/qmlworkerscript.cpp32
-rw-r--r--src/declarative/qml/qmlworkerscript_p.h2
2 files changed, 20 insertions, 14 deletions
diff --git a/src/declarative/qml/qmlworkerscript.cpp b/src/declarative/qml/qmlworkerscript.cpp
index f58aa8b..5e39eaf 100644
--- a/src/declarative/qml/qmlworkerscript.cpp
+++ b/src/declarative/qml/qmlworkerscript.cpp
@@ -53,6 +53,7 @@
#include <QtCore/qfile.h>
#include <QtNetwork/qnetworkaccessmanager.h>
#include <QtDeclarative/qmlinfo.h>
+#include "qmlnetworkaccessmanagerfactory.h"
QT_BEGIN_NAMESPACE
@@ -103,18 +104,24 @@ private:
class QmlWorkerScriptEnginePrivate : public QObject
{
public:
- QmlWorkerScriptEnginePrivate();
+ QmlWorkerScriptEnginePrivate(QmlEngine *eng);
struct ScriptEngine : public QmlScriptEngine
{
- ScriptEngine(QmlWorkerScriptEnginePrivate *parent) : QmlScriptEngine(0), p(parent) {}
- ~ScriptEngine() { delete manager; };
+ ScriptEngine(QmlWorkerScriptEnginePrivate *parent) : QmlScriptEngine(0), p(parent), accessManager(0) {}
+ ~ScriptEngine() { delete accessManager; }
QmlWorkerScriptEnginePrivate *p;
- QNetworkAccessManager *manager;
+ QNetworkAccessManager *accessManager;
virtual QNetworkAccessManager *networkAccessManager() {
- if (!manager) manager = new QNetworkAccessManager;
- return manager;
+ if (!accessManager) {
+ if (p->qmlengine && p->qmlengine->networkAccessManagerFactory()) {
+ accessManager = p->qmlengine->networkAccessManagerFactory()->create(this);
+ } else {
+ accessManager = new QNetworkAccessManager(this);
+ }
+ }
+ return accessManager;
}
};
ScriptEngine *workerEngine;
@@ -122,6 +129,8 @@ public:
return static_cast<ScriptEngine *>(e)->p;
}
+ QmlEngine *qmlengine;
+
QMutex m_lock;
QWaitCondition m_wait;
@@ -136,9 +145,6 @@ public:
QScriptValue callback;
};
- QNetworkAccessManager *networkAccessManager;
- QNetworkAccessManager *getNetworkAccessManager();
-
QHash<int, WorkerScript *> workers;
QScriptValue getWorker(int);
@@ -234,8 +240,8 @@ private:
};
Q_DECLARE_METATYPE(QmlWorkerListModelAgent::VariantRef);
-QmlWorkerScriptEnginePrivate::QmlWorkerScriptEnginePrivate()
-: workerEngine(0), networkAccessManager(0), m_nextId(0)
+QmlWorkerScriptEnginePrivate::QmlWorkerScriptEnginePrivate(QmlEngine *engine)
+: workerEngine(0), qmlengine(engine), m_nextId(0)
{
}
@@ -485,8 +491,8 @@ int WorkerRemoveEvent::workerId() const
return m_id;
}
-QmlWorkerScriptEngine::QmlWorkerScriptEngine(QObject *parent)
-: QThread(parent), d(new QmlWorkerScriptEnginePrivate)
+QmlWorkerScriptEngine::QmlWorkerScriptEngine(QmlEngine *parent)
+: QThread(parent), d(new QmlWorkerScriptEnginePrivate(parent))
{
d->m_lock.lock();
start(QThread::LowPriority);
diff --git a/src/declarative/qml/qmlworkerscript_p.h b/src/declarative/qml/qmlworkerscript_p.h
index f0ef7c9..3a29498 100644
--- a/src/declarative/qml/qmlworkerscript_p.h
+++ b/src/declarative/qml/qmlworkerscript_p.h
@@ -69,7 +69,7 @@ class QmlWorkerScriptEngine : public QThread
{
Q_OBJECT
public:
- QmlWorkerScriptEngine(QObject *parent = 0);
+ QmlWorkerScriptEngine(QmlEngine *parent = 0);
virtual ~QmlWorkerScriptEngine();
int registerWorkerScript(QmlWorkerScript *);