Skip to content

Commit

Permalink
[qtbase] Fixes MER#1028 Make sure networkAccessibilityChanged is emitted
Browse files Browse the repository at this point in the history
From 957ae2c3fbd50d5f78292762e0df228058964e6e Mon Sep 17 00:00:00 2001
From: Lorn Potter <lorn.potter@gmail.com>
Date: Fri, 17 Jul 2015 15:32:23 +1000
Subject: [PATCH] Make sure networkAccessibilityChanged is emitted

Task-number: QTBUG-46323
Change-Id: I8297072b62763136f457ca6ae15282d1c22244f4
  • Loading branch information
lpotter committed Aug 6, 2015
1 parent caa1986 commit 8307608
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 28 deletions.
61 changes: 35 additions & 26 deletions src/network/access/qnetworkaccessmanager.cpp
Expand Up @@ -286,7 +286,8 @@ static void ensureInitialized()
\snippet code/src_network_access_qnetworkaccessmanager.cpp 4
Network requests can be reenabled again by calling
Network requests can be re-enabled again, and this property will resume to
reflect the actual device state by calling
\snippet code/src_network_access_qnetworkaccessmanager.cpp 5
Expand Down Expand Up @@ -451,16 +452,13 @@ QNetworkAccessManager::QNetworkAccessManager(QObject *parent)
qRegisterMetaType<QSharedPointer<char> >();

#ifndef QT_NO_BEARERMANAGEMENT
if (!d->networkSessionRequired) {
// if a session is required, we track online state through
// the QNetworkSession's signals
connect(&d->networkConfigurationManager, SIGNAL(onlineStateChanged(bool)),
SLOT(_q_onlineStateChanged(bool)));
// 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);
// if a session is required, we track online state through
// the QNetworkSession's signals but only if a request is already made.
// we need to track current accessibility state by default
//
connect(&d->networkConfigurationManager, SIGNAL(onlineStateChanged(bool)),
SLOT(_q_onlineStateChanged(bool)));

#endif
}

Expand Down Expand Up @@ -930,7 +928,9 @@ QNetworkConfiguration QNetworkAccessManager::activeConfiguration() const
void QNetworkAccessManager::setNetworkAccessible(QNetworkAccessManager::NetworkAccessibility accessible)
{
Q_D(QNetworkAccessManager);
d->defaultAccessControl = false;

d->defaultAccessControl = accessible == NotAccessible ? false : true;

if (d->networkAccessible != accessible) {
NetworkAccessibility previous = networkAccessible();
d->networkAccessible = accessible;
Expand Down Expand Up @@ -959,7 +959,6 @@ QNetworkAccessManager::NetworkAccessibility QNetworkAccessManager::networkAccess
return NotAccessible;
} else {
// Network accessibility is either disabled or unknown.
// return (d->networkAccessible == NotAccessible) ? NotAccessible : UnknownAccessibility;
if (d->defaultAccessControl) {
if (d->online)
return d->networkAccessible;
Expand Down Expand Up @@ -1574,15 +1573,19 @@ void QNetworkAccessManagerPrivate::_q_networkSessionStateChanged(QNetworkSession
if (online) {
if (state != QNetworkSession::Connected && state != QNetworkSession::Roaming) {
online = false;
networkAccessible = QNetworkAccessManager::NotAccessible;
emit q->networkAccessibleChanged(QNetworkAccessManager::NotAccessible);
if (networkAccessible != QNetworkAccessManager::NotAccessible) {
networkAccessible = QNetworkAccessManager::NotAccessible;
emit q->networkAccessibleChanged(networkAccessible);
}
}
} else {
if (state == QNetworkSession::Connected || state == QNetworkSession::Roaming) {
online = true;
if (defaultAccessControl)
networkAccessible = QNetworkAccessManager::NotAccessible;
emit q->networkAccessibleChanged(networkAccessible);
if (defaultAccessControl)
if (networkAccessible != QNetworkAccessManager::Accessible) {
networkAccessible = QNetworkAccessManager::Accessible;
emit q->networkAccessibleChanged(networkAccessible);
}
}
}
}
Expand All @@ -1597,21 +1600,27 @@ void QNetworkAccessManagerPrivate::_q_onlineStateChanged(bool isOnline)
online = (networkConfiguration.state() & QNetworkConfiguration::Active);
} else {
if (online != isOnline) {
if (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);
if (networkAccessible != QNetworkAccessManager::Accessible) {
networkAccessible = QNetworkAccessManager::Accessible;
emit q->networkAccessibleChanged(networkAccessible);
}
}
} else {
networkAccessible = QNetworkAccessManager::NotAccessible;
emit q->networkAccessibleChanged(networkAccessible);
if (networkAccessible != QNetworkAccessManager::NotAccessible) {
networkAccessible = QNetworkAccessManager::NotAccessible;
emit q->networkAccessibleChanged(networkAccessible);
}
}
}

Expand Down
14 changes: 12 additions & 2 deletions src/network/access/qnetworkaccessmanager_p.h
Expand Up @@ -86,15 +86,25 @@ class QNetworkAccessManagerPrivate: public QObjectPrivate
customNetworkConfiguration(false),
networkSessionRequired(networkConfigurationManager.capabilities()
& QNetworkConfigurationManager::NetworkSessionRequired),
networkAccessible(QNetworkAccessManager::Accessible),
activeReplyCount(0),
online(false),
initializeSession(true),
#endif
cookieJarCreated(false),
defaultAccessControl(true),
authenticationManager(new QNetworkAccessAuthenticationManager)
{ }
{
#ifndef QT_NO_BEARERMANAGEMENT
// 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
online = (networkConfiguration.state().testFlag(QNetworkConfiguration::Active));
if (online)
networkAccessible = QNetworkAccessManager::Accessible;
else
networkAccessible = QNetworkAccessManager::NotAccessible;
#endif
}
~QNetworkAccessManagerPrivate();

void _q_replyFinished();
Expand Down

0 comments on commit 8307608

Please sign in to comment.