summaryrefslogtreecommitdiffstats
path: root/tools/qml/qmlruntime.cpp
diff options
context:
space:
mode:
authorMartin Jones <martin.jones@nokia.com>2010-07-02 03:39:23 (GMT)
committerMartin Jones <martin.jones@nokia.com>2010-07-02 03:39:23 (GMT)
commit953142469cd49fd2f5180a60dcaa7d2029457401 (patch)
tree69f58e1e533805ffed06872afbce79501f36b345 /tools/qml/qmlruntime.cpp
parent7cc5171a7d66390688444d57bb3f4550dbbd26ee (diff)
downloadQt-953142469cd49fd2f5180a60dcaa7d2029457401.zip
Qt-953142469cd49fd2f5180a60dcaa7d2029457401.tar.gz
Qt-953142469cd49fd2f5180a60dcaa7d2029457401.tar.bz2
qmlviewer: Update the proxy factory when the user changes the proxy.
Task-number: QTBUG-11856
Diffstat (limited to 'tools/qml/qmlruntime.cpp')
-rw-r--r--tools/qml/qmlruntime.cpp104
1 files changed, 62 insertions, 42 deletions
diff --git a/tools/qml/qmlruntime.cpp b/tools/qml/qmlruntime.cpp
index 94fcc82..3d7d298 100644
--- a/tools/qml/qmlruntime.cpp
+++ b/tools/qml/qmlruntime.cpp
@@ -431,65 +431,82 @@ private:
mutable QMutex mutex;
};
-class NetworkAccessManagerFactory : public QDeclarativeNetworkAccessManagerFactory
+class SystemProxyFactory : public QNetworkProxyFactory
{
public:
- NetworkAccessManagerFactory() : cacheSize(0) {}
- ~NetworkAccessManagerFactory() {}
-
- QNetworkAccessManager *create(QObject *parent);
+ SystemProxyFactory() : proxyDirty(true), httpProxyInUse(false) {
+ }
- void setupProxy(QNetworkAccessManager *nam)
+ virtual QList<QNetworkProxy> queryProxy(const QNetworkProxyQuery &query)
{
- class SystemProxyFactory : public QNetworkProxyFactory
- {
- public:
- virtual QList<QNetworkProxy> queryProxy(const QNetworkProxyQuery &query)
- {
- QString protocolTag = query.protocolTag();
- if (httpProxyInUse && (protocolTag == "http" || protocolTag == "https")) {
- QList<QNetworkProxy> ret;
- ret << httpProxy;
- return ret;
- }
+ if (proxyDirty)
+ setupProxy();
+ QString protocolTag = query.protocolTag();
+ if (httpProxyInUse && (protocolTag == "http" || protocolTag == "https")) {
+ QList<QNetworkProxy> ret;
+ ret << httpProxy;
+ return ret;
+ }
#ifdef Q_OS_WIN
- // systemProxyForQuery can take insanely long on Windows (QTBUG-10106)
- return QNetworkProxyFactory::proxyForQuery(query);
+ // systemProxyForQuery can take insanely long on Windows (QTBUG-10106)
+ return QNetworkProxyFactory::proxyForQuery(query);
#else
- return QNetworkProxyFactory::systemProxyForQuery(query);
+ return QNetworkProxyFactory::systemProxyForQuery(query);
#endif
- }
- void setHttpProxy (QNetworkProxy proxy)
- {
- httpProxy = proxy;
- httpProxyInUse = true;
- }
- void unsetHttpProxy ()
- {
- httpProxyInUse = false;
- }
- private:
- bool httpProxyInUse;
- QNetworkProxy httpProxy;
- };
-
- SystemProxyFactory *proxyFactory = new SystemProxyFactory;
- if (ProxySettings::httpProxyInUse())
- proxyFactory->setHttpProxy(ProxySettings::httpProxy());
- else
- proxyFactory->unsetHttpProxy();
- nam->setProxyFactory(proxyFactory);
}
+ void setupProxy() {
+ // Don't bother locking because we know that the proxy only
+ // changes in response to the settings dialog and that
+ // the view will be reloaded.
+ proxyDirty = false;
+ httpProxyInUse = ProxySettings::httpProxyInUse();
+ if (httpProxyInUse)
+ httpProxy = ProxySettings::httpProxy();
+ }
+
+ void proxyChanged() {
+ proxyDirty = true;
+ }
+
+private:
+ volatile bool proxyDirty;
+ bool httpProxyInUse;
+ QNetworkProxy httpProxy;
+};
+
+class NetworkAccessManagerFactory : public QObject, public QDeclarativeNetworkAccessManagerFactory
+{
+ Q_OBJECT
+public:
+ NetworkAccessManagerFactory() : cacheSize(0) {}
+ ~NetworkAccessManagerFactory() {}
+
+ QNetworkAccessManager *create(QObject *parent);
+
void setCacheSize(int size) {
if (size != cacheSize) {
cacheSize = size;
}
}
+ void proxyChanged() {
+ foreach (QNetworkAccessManager *nam, namList) {
+ static_cast<SystemProxyFactory*>(nam->proxyFactory())->proxyChanged();
+ }
+ }
+
static PersistentCookieJar *cookieJar;
+
+private slots:
+ void managerDestroyed(QObject *obj) {
+ namList.removeOne(static_cast<QNetworkAccessManager*>(obj));
+ }
+
+private:
QMutex mutex;
int cacheSize;
+ QList<QNetworkAccessManager*> namList;
};
PersistentCookieJar *NetworkAccessManagerFactory::cookieJar = 0;
@@ -510,7 +527,7 @@ QNetworkAccessManager *NetworkAccessManagerFactory::create(QObject *parent)
}
manager->setCookieJar(cookieJar);
cookieJar->setParent(0);
- setupProxy(manager);
+ manager->setProxyFactory(new SystemProxyFactory);
if (cacheSize > 0) {
QNetworkDiskCache *cache = new QNetworkDiskCache;
cache->setCacheDirectory(QDir::tempPath()+QLatin1String("/qml-viewer-network-cache"));
@@ -519,6 +536,8 @@ QNetworkAccessManager *NetworkAccessManagerFactory::create(QObject *parent)
} else {
manager->setCache(0);
}
+ connect(manager, SIGNAL(destroyed(QObject*)), this, SLOT(managerDestroyed(QObject*)));
+ namList.append(manager);
qDebug() << "created new network access manager for" << parent;
return manager;
}
@@ -777,6 +796,7 @@ void QDeclarativeViewer::showProxySettings()
void QDeclarativeViewer::proxySettingsChanged()
{
+ namFactory->proxyChanged();
reload ();
}