Skip to content

Commit

Permalink
[qtbase] Fixes MER#1028 report correct NetworkAccessibility
Browse files Browse the repository at this point in the history
manual merge of

From f4e32ceea6655fdab6b7ddfec98cfac61527b89f Mon Sep 17 00:00:00 2001
From: Lorn Potter <lorn.potter@gmail.com>
Date: Tue, 2 Jun 2015 13:22:23 +1000
Subject: [PATCH] Make sure to report correct NetworkAccessibility

Task-number: QTBUG-46323
Change-Id: Ibdeb3280091a97d785d4314340678a63e88fb219
  • Loading branch information
Lorn Potter authored and lpotter committed Jul 19, 2015
1 parent 3f0086c commit caa1986
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 10 deletions.
41 changes: 32 additions & 9 deletions src/network/access/qnetworkaccessmanager.cpp
Expand Up @@ -459,8 +459,8 @@ QNetworkAccessManager::QNetworkAccessManager(QObject *parent)
// we would need all active configurations to check for
// d->networkConfigurationManager.isOnline(), which is asynchronous
// and potentially expensive. We can just check the configuration here
d->online = (d->networkConfiguration.state() & QNetworkConfiguration::Active);
}
d->online = (d->networkConfiguration.state() & QNetworkConfiguration::Active);
#endif
}

Expand Down Expand Up @@ -930,7 +930,7 @@ QNetworkConfiguration QNetworkAccessManager::activeConfiguration() const
void QNetworkAccessManager::setNetworkAccessible(QNetworkAccessManager::NetworkAccessibility accessible)
{
Q_D(QNetworkAccessManager);

d->defaultAccessControl = false;
if (d->networkAccessible != accessible) {
NetworkAccessibility previous = networkAccessible();
d->networkAccessible = accessible;
Expand Down Expand Up @@ -959,7 +959,14 @@ QNetworkAccessManager::NetworkAccessibility QNetworkAccessManager::networkAccess
return NotAccessible;
} else {
// Network accessibility is either disabled or unknown.
return (d->networkAccessible == NotAccessible) ? NotAccessible : UnknownAccessibility;
// return (d->networkAccessible == NotAccessible) ? NotAccessible : UnknownAccessibility;
if (d->defaultAccessControl) {
if (d->online)
return d->networkAccessible;
else
return NotAccessible;
}
return (d->networkAccessible);
}
} else {
if (d->online)
Expand Down Expand Up @@ -1519,7 +1526,7 @@ void QNetworkAccessManagerPrivate::createSession(const QNetworkConfiguration &co
if (!networkSessionStrongRef) {
online = false;

if (networkAccessible == QNetworkAccessManager::NotAccessible)
if (networkAccessible == QNetworkAccessManager::NotAccessible || !online)
emit q->networkAccessibleChanged(QNetworkAccessManager::NotAccessible);
else
emit q->networkAccessibleChanged(QNetworkAccessManager::UnknownAccessibility);
Expand Down Expand Up @@ -1567,32 +1574,48 @@ void QNetworkAccessManagerPrivate::_q_networkSessionStateChanged(QNetworkSession
if (online) {
if (state != QNetworkSession::Connected && state != QNetworkSession::Roaming) {
online = false;
networkAccessible = QNetworkAccessManager::NotAccessible;
emit q->networkAccessibleChanged(QNetworkAccessManager::NotAccessible);
}
} else {
if (state == QNetworkSession::Connected || state == QNetworkSession::Roaming) {
online = true;
if (defaultAccessControl)
networkAccessible = QNetworkAccessManager::NotAccessible;
emit q->networkAccessibleChanged(networkAccessible);
}
}
}

void QNetworkAccessManagerPrivate::_q_onlineStateChanged(bool isOnline)
{
Q_Q(QNetworkAccessManager);
// if the user set a config, we only care whether this one is active.
// Otherwise, this QNAM is online if there is an online config.

if (customNetworkConfiguration) {
online = (networkConfiguration.state() & QNetworkConfiguration::Active);
} else {
if (isOnline && online != isOnline) {
networkSessionStrongRef.clear();
networkSessionWeakRef.clear();
if (online != isOnline) {
if (isOnline) {
networkSessionStrongRef.clear();
networkSessionWeakRef.clear();
}
online = isOnline;
}

online = isOnline;
}
if (online) {
if (defaultAccessControl) {
networkAccessible = QNetworkAccessManager::Accessible;
emit q->networkAccessibleChanged(networkAccessible);
}
} else {
networkAccessible = QNetworkAccessManager::NotAccessible;
emit q->networkAccessibleChanged(networkAccessible);
}
}


#endif // QT_NO_BEARERMANAGEMENT

QNetworkRequest QNetworkAccessManagerPrivate::prepareMultipart(const QNetworkRequest &request, QHttpMultiPart *multiPart)
Expand Down
4 changes: 3 additions & 1 deletion src/network/access/qnetworkaccessmanager_p.h
Expand Up @@ -92,7 +92,8 @@ class QNetworkAccessManagerPrivate: public QObjectPrivate
initializeSession(true),
#endif
cookieJarCreated(false),
authenticationManager(new QNetworkAccessAuthenticationManager)
defaultAccessControl(true),
authenticationManager(new QNetworkAccessAuthenticationManager)
{ }
~QNetworkAccessManagerPrivate();

Expand Down Expand Up @@ -170,6 +171,7 @@ class QNetworkAccessManagerPrivate: public QObjectPrivate
#endif

bool cookieJarCreated;
bool defaultAccessControl;

// The cache with authorization data:
QSharedPointer<QNetworkAccessAuthenticationManager> authenticationManager;
Expand Down

0 comments on commit caa1986

Please sign in to comment.