Make sure to report correct NetworkAccessibility
Task-number: QTBUG-46323 Change-Id: Ibdeb3280091a97d785d4314340678a63e88fb219 Reviewed-by: Markus Goetz (Woboq GmbH) <markus@woboq.com> Reviewed-by: Alex Blasche <alexander.blasche@theqtcompany.com>
This commit is contained in:
parent
a889faf0b8
commit
c056e63cea
@ -472,11 +472,11 @@ QNetworkAccessManager::QNetworkAccessManager(QObject *parent)
|
|||||||
// the QNetworkSession's signals
|
// the QNetworkSession's signals
|
||||||
connect(&d->networkConfigurationManager, SIGNAL(onlineStateChanged(bool)),
|
connect(&d->networkConfigurationManager, SIGNAL(onlineStateChanged(bool)),
|
||||||
SLOT(_q_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);
|
|
||||||
}
|
}
|
||||||
|
// 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);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -946,6 +946,7 @@ QNetworkConfiguration QNetworkAccessManager::activeConfiguration() const
|
|||||||
void QNetworkAccessManager::setNetworkAccessible(QNetworkAccessManager::NetworkAccessibility accessible)
|
void QNetworkAccessManager::setNetworkAccessible(QNetworkAccessManager::NetworkAccessibility accessible)
|
||||||
{
|
{
|
||||||
Q_D(QNetworkAccessManager);
|
Q_D(QNetworkAccessManager);
|
||||||
|
d->defaultAccessControl = false;
|
||||||
|
|
||||||
if (d->networkAccessible != accessible) {
|
if (d->networkAccessible != accessible) {
|
||||||
NetworkAccessibility previous = networkAccessible();
|
NetworkAccessibility previous = networkAccessible();
|
||||||
@ -964,7 +965,6 @@ void QNetworkAccessManager::setNetworkAccessible(QNetworkAccessManager::NetworkA
|
|||||||
QNetworkAccessManager::NetworkAccessibility QNetworkAccessManager::networkAccessible() const
|
QNetworkAccessManager::NetworkAccessibility QNetworkAccessManager::networkAccessible() const
|
||||||
{
|
{
|
||||||
Q_D(const QNetworkAccessManager);
|
Q_D(const QNetworkAccessManager);
|
||||||
|
|
||||||
if (d->networkSessionRequired) {
|
if (d->networkSessionRequired) {
|
||||||
QSharedPointer<QNetworkSession> networkSession(d->getNetworkSession());
|
QSharedPointer<QNetworkSession> networkSession(d->getNetworkSession());
|
||||||
if (networkSession) {
|
if (networkSession) {
|
||||||
@ -975,7 +975,13 @@ QNetworkAccessManager::NetworkAccessibility QNetworkAccessManager::networkAccess
|
|||||||
return NotAccessible;
|
return NotAccessible;
|
||||||
} else {
|
} else {
|
||||||
// Network accessibility is either disabled or unknown.
|
// Network accessibility is either disabled or unknown.
|
||||||
return (d->networkAccessible == NotAccessible) ? NotAccessible : UnknownAccessibility;
|
if (d->defaultAccessControl) {
|
||||||
|
if (d->online)
|
||||||
|
return d->networkAccessible;
|
||||||
|
else
|
||||||
|
return NotAccessible;
|
||||||
|
}
|
||||||
|
return (d->networkAccessible);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (d->online)
|
if (d->online)
|
||||||
@ -1568,7 +1574,7 @@ void QNetworkAccessManagerPrivate::createSession(const QNetworkConfiguration &co
|
|||||||
if (!networkSessionStrongRef) {
|
if (!networkSessionStrongRef) {
|
||||||
online = false;
|
online = false;
|
||||||
|
|
||||||
if (networkAccessible == QNetworkAccessManager::NotAccessible)
|
if (networkAccessible == QNetworkAccessManager::NotAccessible || !online)
|
||||||
emit q->networkAccessibleChanged(QNetworkAccessManager::NotAccessible);
|
emit q->networkAccessibleChanged(QNetworkAccessManager::NotAccessible);
|
||||||
else
|
else
|
||||||
emit q->networkAccessibleChanged(QNetworkAccessManager::UnknownAccessibility);
|
emit q->networkAccessibleChanged(QNetworkAccessManager::UnknownAccessibility);
|
||||||
@ -1616,11 +1622,14 @@ void QNetworkAccessManagerPrivate::_q_networkSessionStateChanged(QNetworkSession
|
|||||||
if (online) {
|
if (online) {
|
||||||
if (state != QNetworkSession::Connected && state != QNetworkSession::Roaming) {
|
if (state != QNetworkSession::Connected && state != QNetworkSession::Roaming) {
|
||||||
online = false;
|
online = false;
|
||||||
emit q->networkAccessibleChanged(QNetworkAccessManager::NotAccessible);
|
networkAccessible = QNetworkAccessManager::NotAccessible;
|
||||||
|
emit q->networkAccessibleChanged(networkAccessible);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (state == QNetworkSession::Connected || state == QNetworkSession::Roaming) {
|
if (state == QNetworkSession::Connected || state == QNetworkSession::Roaming) {
|
||||||
online = true;
|
online = true;
|
||||||
|
if (defaultAccessControl)
|
||||||
|
networkAccessible = QNetworkAccessManager::Accessible;
|
||||||
emit q->networkAccessibleChanged(networkAccessible);
|
emit q->networkAccessibleChanged(networkAccessible);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -84,6 +84,7 @@ public:
|
|||||||
initializeSession(true),
|
initializeSession(true),
|
||||||
#endif
|
#endif
|
||||||
cookieJarCreated(false),
|
cookieJarCreated(false),
|
||||||
|
defaultAccessControl(true),
|
||||||
authenticationManager(QSharedPointer<QNetworkAccessAuthenticationManager>::create())
|
authenticationManager(QSharedPointer<QNetworkAccessAuthenticationManager>::create())
|
||||||
{ }
|
{ }
|
||||||
~QNetworkAccessManagerPrivate();
|
~QNetworkAccessManagerPrivate();
|
||||||
@ -164,6 +165,7 @@ public:
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
bool cookieJarCreated;
|
bool cookieJarCreated;
|
||||||
|
bool defaultAccessControl;
|
||||||
|
|
||||||
// The cache with authorization data:
|
// The cache with authorization data:
|
||||||
QSharedPointer<QNetworkAccessAuthenticationManager> authenticationManager;
|
QSharedPointer<QNetworkAccessAuthenticationManager> authenticationManager;
|
||||||
|
Loading…
Reference in New Issue
Block a user