summaryrefslogtreecommitdiffstats
path: root/src/network
diff options
context:
space:
mode:
Diffstat (limited to 'src/network')
-rw-r--r--src/network/bearer/qnetworkconfigmanager.cpp2
-rw-r--r--src/network/bearer/qnetworkconfigmanager_p.cpp47
-rw-r--r--src/network/bearer/qnetworkconfigmanager_p.h5
-rw-r--r--src/network/bearer/qnetworksession_p.cpp30
-rw-r--r--src/network/bearer/qnetworksessionengine_p.h3
5 files changed, 43 insertions, 44 deletions
diff --git a/src/network/bearer/qnetworkconfigmanager.cpp b/src/network/bearer/qnetworkconfigmanager.cpp
index 6c0b17d..6b73e3c 100644
--- a/src/network/bearer/qnetworkconfigmanager.cpp
+++ b/src/network/bearer/qnetworkconfigmanager.cpp
@@ -48,6 +48,8 @@
#include "qnetworksessionengine_p.h"
#endif
+#include <QtCore/qstringlist.h>
+
QT_BEGIN_NAMESPACE
Q_GLOBAL_STATIC(QNetworkConfigurationManagerPrivate, connManager);
diff --git a/src/network/bearer/qnetworkconfigmanager_p.cpp b/src/network/bearer/qnetworkconfigmanager_p.cpp
index 09714e5..6f833f3 100644
--- a/src/network/bearer/qnetworkconfigmanager_p.cpp
+++ b/src/network/bearer/qnetworkconfigmanager_p.cpp
@@ -73,15 +73,15 @@ void QNetworkConfigurationManagerPrivate::configurationAdded(QNetworkConfigurati
}
if (ptr->state == QNetworkConfiguration::Active) {
- ++onlineConfigurations;
- if (!firstUpdate && onlineConfigurations == 1)
+ onlineConfigurations.insert(ptr);
+ if (!firstUpdate && onlineConfigurations.count() == 1)
emit onlineStateChanged(true);
}
}
void QNetworkConfigurationManagerPrivate::configurationRemoved(QNetworkConfigurationPrivatePointer ptr)
{
- ptr.data()->isValid = false;
+ ptr->isValid = false;
if (!firstUpdate) {
QNetworkConfiguration item;
@@ -89,11 +89,9 @@ void QNetworkConfigurationManagerPrivate::configurationRemoved(QNetworkConfigura
emit configurationRemoved(item);
}
- if (ptr.data()->state == QNetworkConfiguration::Active) {
- --onlineConfigurations;
- if (!firstUpdate && onlineConfigurations == 0)
- emit onlineStateChanged(false);
- }
+ onlineConfigurations.remove(ptr);
+ if (!firstUpdate && onlineConfigurations.isEmpty())
+ emit onlineStateChanged(false);
}
void QNetworkConfigurationManagerPrivate::configurationChanged(QNetworkConfigurationPrivatePointer ptr)
@@ -104,20 +102,17 @@ void QNetworkConfigurationManagerPrivate::configurationChanged(QNetworkConfigura
emit configurationChanged(item);
}
- qDebug() << "Need to recalculate online state.";
- QNetworkConfiguration::StateFlags oldState = ptr->state;
+ bool previous = !onlineConfigurations.isEmpty();
- if (ptr->state == QNetworkConfiguration::Active && oldState != ptr->state) {
- // configuration went online
- ++onlineConfigurations;
- if (!firstUpdate && onlineConfigurations == 1)
- emit onlineStateChanged(true);
- } else if (ptr->state != QNetworkConfiguration::Active && oldState == QNetworkConfiguration::Active) {
- // configuration went offline
- --onlineConfigurations;
- if (!firstUpdate && onlineConfigurations == 0)
- emit onlineStateChanged(false);
- }
+ if (ptr->state == QNetworkConfiguration::Active)
+ onlineConfigurations.insert(ptr);
+ else
+ onlineConfigurations.remove(ptr);
+
+ bool online = !onlineConfigurations.isEmpty();
+
+ if (!firstUpdate && online != previous)
+ emit onlineStateChanged(online);
}
void QNetworkConfigurationManagerPrivate::updateInternetServiceConfiguration()
@@ -179,7 +174,7 @@ void QNetworkConfigurationManagerPrivate::updateInternetServiceConfiguration()
void QNetworkConfigurationManagerPrivate::updateConfigurations()
{
if (firstUpdate) {
- onlineConfigurations = 0;
+ updating = false;
QFactoryLoader *l = loader();
QStringList keys = l->keys();
@@ -202,6 +197,14 @@ void QNetworkConfigurationManagerPrivate::updateConfigurations()
QNetworkSessionEngine *nmWifi = nmPlugin->create(QLatin1String("networkmanager"));
if (nmWifi) {
sessionEngines.append(nmWifi);
+ connect(nmWifi, SIGNAL(updateCompleted()),
+ this, SIGNAL(configurationUpdateComplete()));
+ connect(nmWifi, SIGNAL(configurationAdded(QNetworkConfigurationPrivatePointer)),
+ this, SLOT(configurationAdded(QNetworkConfigurationPrivatePointer)));
+ connect(nmWifi, SIGNAL(configurationRemoved(QNetworkConfigurationPrivatePointer)),
+ this, SLOT(configurationRemoved(QNetworkConfigurationPrivatePointer)));
+ connect(nmWifi, SIGNAL(configurationChanged(QNetworkConfigurationPrivatePointer)),
+ this, SLOT(configurationChanged(QNetworkConfigurationPrivatePointer)));
}
}
}
diff --git a/src/network/bearer/qnetworkconfigmanager_p.h b/src/network/bearer/qnetworkconfigmanager_p.h
index 27a0252..37e88d3 100644
--- a/src/network/bearer/qnetworkconfigmanager_p.h
+++ b/src/network/bearer/qnetworkconfigmanager_p.h
@@ -80,9 +80,6 @@ public:
void performAsyncConfigurationUpdate();
-#ifdef BEARER_ENGINE
- QHash<QString, QNetworkSessionEngine *> configurationEngine;
-#endif
bool firstUpdate;
public slots:
@@ -107,7 +104,7 @@ public:
QList<QNetworkSessionEngine *> sessionEngines;
private:
- uint onlineConfigurations;
+ QSet<QNetworkConfigurationPrivatePointer> onlineConfigurations;
bool updating;
QSet<int> updatingEngines;
diff --git a/src/network/bearer/qnetworksession_p.cpp b/src/network/bearer/qnetworksession_p.cpp
index df0ad3e..8421fbc 100644
--- a/src/network/bearer/qnetworksession_p.cpp
+++ b/src/network/bearer/qnetworksession_p.cpp
@@ -56,9 +56,10 @@ static QNetworkSessionEngine *getEngineFromId(const QString &id)
{
QNetworkConfigurationManagerPrivate *priv = qNetworkConfigurationManagerPrivate();
- QNetworkSessionEngine *engine = priv->configurationEngine.value(id);
- if (engine && engine->hasIdentifier(id))
- return engine;
+ foreach (QNetworkSessionEngine *engine, priv->sessionEngines) {
+ if (engine->hasIdentifier(id))
+ return engine;
+ }
return 0;
}
@@ -104,6 +105,7 @@ void QNetworkSessionPrivate::syncStateWithInterface()
this, SLOT(forcedSessionClose(QNetworkConfiguration)));
opened = false;
+ isActive = false;
state = QNetworkSession::Invalid;
lastError = QNetworkSession::UnknownSessionError;
@@ -341,6 +343,7 @@ void QNetworkSessionPrivate::updateStateFromServiceNetwork()
}
state = QNetworkSession::Connected;
+ qDebug() << oldState << "->" << state;
if (state != oldState)
emit q->stateChanged(state);
@@ -352,31 +355,22 @@ void QNetworkSessionPrivate::updateStateFromServiceNetwork()
else
state = QNetworkSession::Disconnected;
+ qDebug() << oldState << "->" << state;
if (state != oldState)
emit q->stateChanged(state);
}
void QNetworkSessionPrivate::updateStateFromActiveConfig()
{
- QNetworkSession::State oldState = state;
+ if (!engine)
+ return;
- bool newActive = false;
+ QNetworkSession::State oldState = state;
- if (!activeConfig.isValid()) {
- state = QNetworkSession::Invalid;
- } else if ((activeConfig.state() & QNetworkConfiguration::Active) == QNetworkConfiguration::Active) {
- state = QNetworkSession::Connected;
- newActive = opened;
- } else if ((activeConfig.state() & QNetworkConfiguration::Discovered) == QNetworkConfiguration::Discovered) {
- state = QNetworkSession::Disconnected;
- } else if ((activeConfig.state() & QNetworkConfiguration::Defined) == QNetworkConfiguration::Defined) {
- state = QNetworkSession::NotAvailable;
- } else if ((activeConfig.state() & QNetworkConfiguration::Undefined) == QNetworkConfiguration::Undefined) {
- state = QNetworkSession::NotAvailable;
- }
+ state = engine->sessionStateForId(activeConfig.identifier());
bool oldActive = isActive;
- isActive = newActive;
+ isActive = (state == QNetworkSession::Connected) ? opened : false;
if (!oldActive && isActive)
emit quitPendingWaitsForOpened();
diff --git a/src/network/bearer/qnetworksessionengine_p.h b/src/network/bearer/qnetworksessionengine_p.h
index 0145976..a698c40 100644
--- a/src/network/bearer/qnetworksessionengine_p.h
+++ b/src/network/bearer/qnetworksessionengine_p.h
@@ -54,6 +54,7 @@
//
#include "qnetworkconfiguration_p.h"
+#include "qnetworksession.h"
#include <QtCore/qobject.h>
#include <QtCore/qglobal.h>
@@ -91,6 +92,8 @@ public:
virtual void requestUpdate() = 0;
+ virtual QNetworkSession::State sessionStateForId(const QString &id) = 0;
+
public:
//this table contains an up to date list of all configs at any time.
//it must be updated if configurations change, are added/removed or