summaryrefslogtreecommitdiffstats
path: root/src/declarative/qml
diff options
context:
space:
mode:
authorMartin Jones <martin.jones@nokia.com>2010-02-03 08:46:42 (GMT)
committerMartin Jones <martin.jones@nokia.com>2010-02-03 08:46:42 (GMT)
commit3838762e4b572017efc42e9f7dbfc43d262807cf (patch)
treeebd9533ac4474c254be3acd8ebdc92ba9b0a390d /src/declarative/qml
parent348675876dfacb6cdd2373a1a4ae9d814e057df2 (diff)
parent8003041739f2ec101bf8198f6a53375ce0112eb1 (diff)
downloadQt-3838762e4b572017efc42e9f7dbfc43d262807cf.zip
Qt-3838762e4b572017efc42e9f7dbfc43d262807cf.tar.gz
Qt-3838762e4b572017efc42e9f7dbfc43d262807cf.tar.bz2
Merge branch 'kinetic-declarativeui' of git@scm.dev.nokia.troll.no:qt/kinetic into kinetic-declarativeui
Conflicts: src/declarative/qml/qmlengine.cpp
Diffstat (limited to 'src/declarative/qml')
-rw-r--r--src/declarative/qml/qmlengine.cpp28
-rw-r--r--src/declarative/qml/qmlengine_p.h7
-rw-r--r--src/declarative/qml/qmlworkerscript.cpp13
-rw-r--r--src/declarative/qml/qmlxmlhttprequest.cpp18
4 files changed, 42 insertions, 24 deletions
diff --git a/src/declarative/qml/qmlengine.cpp b/src/declarative/qml/qmlengine.cpp
index 8b52684..ea0c054 100644
--- a/src/declarative/qml/qmlengine.cpp
+++ b/src/declarative/qml/qmlengine.cpp
@@ -221,6 +221,11 @@ QScriptValue QmlScriptEngine::resolvedUrl(QScriptContext *ctxt, QScriptEngine *e
return QScriptValue(r.toString());
}
+QNetworkAccessManager *QmlScriptEngine::networkAccessManager()
+{
+ return p->getNetworkAccessManager();
+}
+
QmlEnginePrivate::~QmlEnginePrivate()
{
while (cleanup) {
@@ -412,6 +417,20 @@ QmlNetworkAccessManagerFactory *QmlEngine::networkAccessManagerFactory() const
return d->networkAccessManagerFactory;
}
+QNetworkAccessManager *QmlEnginePrivate::getNetworkAccessManager() const
+{
+ Q_Q(const QmlEngine);
+
+ if (!networkAccessManager) {
+ if (networkAccessManagerFactory) {
+ networkAccessManager = networkAccessManagerFactory->create(const_cast<QmlEngine*>(q));
+ } else {
+ networkAccessManager = new QNetworkAccessManager(const_cast<QmlEngine*>(q));
+ }
+ }
+ return networkAccessManager;
+}
+
/*!
Returns a common QNetworkAccessManager which can be used by any QML element
instantiated by this engine.
@@ -426,14 +445,7 @@ QmlNetworkAccessManagerFactory *QmlEngine::networkAccessManagerFactory() const
QNetworkAccessManager *QmlEngine::networkAccessManager() const
{
Q_D(const QmlEngine);
- if (!d->networkAccessManager) {
- if (d->networkAccessManagerFactory) {
- d->networkAccessManager = d->networkAccessManagerFactory->create(const_cast<QmlEngine*>(this));
- } else {
- d->networkAccessManager = new QNetworkAccessManager(const_cast<QmlEngine*>(this));
- }
- }
- return d->networkAccessManager;
+ return d->getNetworkAccessManager();
}
/*!
diff --git a/src/declarative/qml/qmlengine_p.h b/src/declarative/qml/qmlengine_p.h
index ddb25a0..6aa5d69 100644
--- a/src/declarative/qml/qmlengine_p.h
+++ b/src/declarative/qml/qmlengine_p.h
@@ -108,8 +108,7 @@ class QmlScriptEngine : public QScriptEngine
{
public:
QmlScriptEngine(QmlEnginePrivate *priv);
-
- ~QmlScriptEngine();
+ virtual ~QmlScriptEngine();
QUrl resolvedUrl(QScriptContext *context, const QUrl& url); // resolved against p's context, or baseUrl if no p
static QScriptValue resolvedUrl(QScriptContext *ctxt, QScriptEngine *engine);
@@ -127,6 +126,8 @@ public:
QScriptClass *nodeListClass;
QUrl baseUrl;
+
+ virtual QNetworkAccessManager *networkAccessManager();
};
class Q_AUTOTEST_EXPORT QmlEnginePrivate : public QObjectPrivate
@@ -209,6 +210,8 @@ public:
QmlComponentAttached *componentAttacheds;
bool inBeginCreate;
+
+ QNetworkAccessManager *getNetworkAccessManager() const;
mutable QNetworkAccessManager *networkAccessManager;
mutable QmlNetworkAccessManagerFactory *networkAccessManagerFactory;
diff --git a/src/declarative/qml/qmlworkerscript.cpp b/src/declarative/qml/qmlworkerscript.cpp
index 75c5179..f58aa8b 100644
--- a/src/declarative/qml/qmlworkerscript.cpp
+++ b/src/declarative/qml/qmlworkerscript.cpp
@@ -51,6 +51,7 @@
#include <QtCore/qwaitcondition.h>
#include <QtScript/qscriptvalueiterator.h>
#include <QtCore/qfile.h>
+#include <QtNetwork/qnetworkaccessmanager.h>
#include <QtDeclarative/qmlinfo.h>
QT_BEGIN_NAMESPACE
@@ -107,7 +108,14 @@ public:
struct ScriptEngine : public QmlScriptEngine
{
ScriptEngine(QmlWorkerScriptEnginePrivate *parent) : QmlScriptEngine(0), p(parent) {}
+ ~ScriptEngine() { delete manager; };
QmlWorkerScriptEnginePrivate *p;
+ QNetworkAccessManager *manager;
+
+ virtual QNetworkAccessManager *networkAccessManager() {
+ if (!manager) manager = new QNetworkAccessManager;
+ return manager;
+ }
};
ScriptEngine *workerEngine;
static QmlWorkerScriptEnginePrivate *get(QScriptEngine *e) {
@@ -128,6 +136,9 @@ public:
QScriptValue callback;
};
+ QNetworkAccessManager *networkAccessManager;
+ QNetworkAccessManager *getNetworkAccessManager();
+
QHash<int, WorkerScript *> workers;
QScriptValue getWorker(int);
@@ -224,7 +235,7 @@ private:
Q_DECLARE_METATYPE(QmlWorkerListModelAgent::VariantRef);
QmlWorkerScriptEnginePrivate::QmlWorkerScriptEnginePrivate()
-: workerEngine(0), m_nextId(0)
+: workerEngine(0), networkAccessManager(0), m_nextId(0)
{
}
diff --git a/src/declarative/qml/qmlxmlhttprequest.cpp b/src/declarative/qml/qmlxmlhttprequest.cpp
index 2c35ebf..86bec20 100644
--- a/src/declarative/qml/qmlxmlhttprequest.cpp
+++ b/src/declarative/qml/qmlxmlhttprequest.cpp
@@ -940,7 +940,7 @@ public:
Opened = 1, HeadersReceived = 2,
Loading = 3, Done = 4 };
- QmlXMLHttpRequest();
+ QmlXMLHttpRequest(QNetworkAccessManager *manager);
virtual ~QmlXMLHttpRequest();
QScriptValue callback() const;
@@ -993,26 +993,18 @@ private:
void destroyNetwork();
QNetworkAccessManager *m_nam;
- QNetworkAccessManager *networkAccessManager()
- {
- if (!m_nam) {
- m_nam = new QNetworkAccessManager;
- // XXX proxy, etc...
- }
- return m_nam;
- }
+ QNetworkAccessManager *networkAccessManager() { return m_nam; }
};
-QmlXMLHttpRequest::QmlXMLHttpRequest()
+QmlXMLHttpRequest::QmlXMLHttpRequest(QNetworkAccessManager *manager)
: m_state(Unsent), m_errorFlag(false), m_sendFlag(false),
- m_redirectCount(0), m_network(0), m_nam(0)
+ m_redirectCount(0), m_network(0), m_nam(manager)
{
}
QmlXMLHttpRequest::~QmlXMLHttpRequest()
{
destroyNetwork();
- delete m_nam;
}
QScriptValue QmlXMLHttpRequest::callback() const
@@ -1568,7 +1560,7 @@ static QScriptValue qmlxmlhttprequest_onreadystatechange(QScriptContext *context
static QScriptValue qmlxmlhttprequest_new(QScriptContext *context, QScriptEngine *engine)
{
if (context->isCalledAsConstructor()) {
- context->thisObject().setData(engine->newQObject(new QmlXMLHttpRequest(), QScriptEngine::ScriptOwnership));
+ context->thisObject().setData(engine->newQObject(new QmlXMLHttpRequest(QmlScriptEngine::get(engine)->networkAccessManager()), QScriptEngine::ScriptOwnership));
}
return engine->undefinedValue();
}