From aa4ab19776a67f882b901b488de8664811df8ae5 Mon Sep 17 00:00:00 2001 From: Aaron McCarthy Date: Fri, 12 Mar 2010 10:53:32 +1000 Subject: Only enable BM by default in QNAM for appropriate platforms. Bearer Management is of little use on desktop platforms. Change QNetworkAccessManager to only create a QNetworkSession for the default configuration on platorms where it is useful (Symbian & Maemo). On other platforms Bearer Management is still available, but needs to be explicitly enabled by the application developer by calling QNetworkAccessManager::setConfiguration(). Use of Bearer Management by default from QNetworkAccessManager is controlled by the QT_QNAM_BEARERMANAGEMENT_ENABLED define. --- mkspecs/common/symbian/symbian.conf | 4 ++++ mkspecs/linux-g++-maemo/qmake.conf | 3 +++ src/network/access/qnetworkaccessmanager.cpp | 26 ++++++++++++++++++-------- src/network/access/qnetworkaccessmanager_p.h | 4 ++++ 4 files changed, 29 insertions(+), 8 deletions(-) diff --git a/mkspecs/common/symbian/symbian.conf b/mkspecs/common/symbian/symbian.conf index 9c5bcf4..df381d2 100644 --- a/mkspecs/common/symbian/symbian.conf +++ b/mkspecs/common/symbian/symbian.conf @@ -8,6 +8,10 @@ QT += core gui QMAKE_INCREMENTAL_STYLE = sublib DEFINES += UNICODE QT_KEYPAD_NAVIGATION QT_SOFTKEYS_ENABLED QT_USE_MATH_H_FLOATS + +# QNetworkAccessManager to create a network session by default +DEFINES += QT_QNAM_DEFAULT_NETWORK_SESSION + QMAKE_COMPILER_DEFINES += SYMBIAN QMAKE_EXT_OBJ = .o diff --git a/mkspecs/linux-g++-maemo/qmake.conf b/mkspecs/linux-g++-maemo/qmake.conf index ca201bc..e272e72 100644 --- a/mkspecs/linux-g++-maemo/qmake.conf +++ b/mkspecs/linux-g++-maemo/qmake.conf @@ -33,4 +33,7 @@ DEFINES += QT_GL_NO_SCISSOR_TEST # Work round SGX 1.4 driver bug (text corrupted), modify glyph cache width: DEFINES += QT_DEFAULT_TEXTURE_GLYPH_CACHE_WIDTH=1024 +# QNetworkAccessManager to create a network session by default +DEFINES += QT_QNAM_DEFAULT_NETWORK_SESSION + load(qt_config) diff --git a/src/network/access/qnetworkaccessmanager.cpp b/src/network/access/qnetworkaccessmanager.cpp index 789d57b..1940dd1 100644 --- a/src/network/access/qnetworkaccessmanager.cpp +++ b/src/network/access/qnetworkaccessmanager.cpp @@ -880,15 +880,18 @@ QNetworkReply *QNetworkAccessManager::createRequest(QNetworkAccessManager::Opera return new QDisabledNetworkReply(this, req, op); } +#ifdef QT_QNAM_DEFAULT_NETWORK_SESSION if (!d->networkSession && (d->initializeSession || !d->networkConfiguration.isEmpty())) { QNetworkConfigurationManager manager; if (d->networkConfiguration.isEmpty()) d->createSession(manager.defaultConfiguration()); else d->createSession(manager.configurationFromIdentifier(d->networkConfiguration)); - } else if (d->networkSession) { - d->networkSession->setSessionProperty(QLatin1String("AutoCloseSessionTimeout"), -1); } +#endif + + if (d->networkSession) + d->networkSession->setSessionProperty(QLatin1String("AutoCloseSessionTimeout"), -1); QNetworkRequest request = req; if (!request.header(QNetworkRequest::ContentLengthHeader).isValid() && @@ -1205,7 +1208,9 @@ void QNetworkAccessManagerPrivate::createSession(const QNetworkConfiguration &co { Q_Q(QNetworkAccessManager); +#ifdef QT_QNAM_DEFAULT_NETWORK_SESSION initializeSession = false; +#endif if (networkSession) delete networkSession; @@ -1229,24 +1234,29 @@ void QNetworkAccessManagerPrivate::createSession(const QNetworkConfiguration &co void QNetworkAccessManagerPrivate::_q_networkSessionClosed() { - networkConfiguration = networkSession->configuration().identifier(); + if (networkSession) { + networkConfiguration = networkSession->configuration().identifier(); - delete networkSession; - networkSession = 0; + networkSession->deleteLater(); + networkSession = 0; + } } void QNetworkAccessManagerPrivate::_q_networkSessionNewConfigurationActivated() { Q_Q(QNetworkAccessManager); - networkSession->accept(); + if (networkSession) { + networkSession->accept(); - emit q->networkSessionOnline(); + emit q->networkSessionOnline(); + } } void QNetworkAccessManagerPrivate::_q_networkSessionPreferredConfigurationChanged(const QNetworkConfiguration &, bool) { - networkSession->migrate(); + if (networkSession) + networkSession->migrate(); } QT_END_NAMESPACE diff --git a/src/network/access/qnetworkaccessmanager_p.h b/src/network/access/qnetworkaccessmanager_p.h index 0140268..4a2a840 100644 --- a/src/network/access/qnetworkaccessmanager_p.h +++ b/src/network/access/qnetworkaccessmanager_p.h @@ -77,7 +77,9 @@ public: #endif networkSession(0), networkAccessEnabled(true), +#ifdef QT_QNAM_DEFAULT_NETWORK_SESSION initializeSession(true), +#endif cookieJarCreated(false) { } ~QNetworkAccessManagerPrivate(); @@ -124,7 +126,9 @@ public: QNetworkSession *networkSession; QString networkConfiguration; bool networkAccessEnabled; +#ifdef QT_QNAM_DEFAULT_NETWORK_SESSION bool initializeSession; +#endif bool cookieJarCreated; -- cgit v0.12