summaryrefslogtreecommitdiffstats
path: root/src/networksettings/connman/qnetworksettingsmanager_p.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/networksettings/connman/qnetworksettingsmanager_p.cpp')
-rw-r--r--src/networksettings/connman/qnetworksettingsmanager_p.cpp150
1 files changed, 103 insertions, 47 deletions
diff --git a/src/networksettings/connman/qnetworksettingsmanager_p.cpp b/src/networksettings/connman/qnetworksettingsmanager_p.cpp
index 3f594bd..94eec14 100644
--- a/src/networksettings/connman/qnetworksettingsmanager_p.cpp
+++ b/src/networksettings/connman/qnetworksettingsmanager_p.cpp
@@ -26,10 +26,8 @@
** $QT_END_LICENSE$
**
****************************************************************************/
-#include <QFile>
-#include <QNetworkInterface>
+#include "qnetworksettingsservice.h"
#include "qnetworksettingsmanager_p.h"
-#include "qnetworksettingsinterface.h"
#include "qnetworksettingsinterface_p.h"
#include "qnetworksettingsservicemodel.h"
#include "qnetworksettingsuseragent.h"
@@ -42,14 +40,14 @@ const QString ConnManServiceName(QStringLiteral("net.connman"));
QNetworkSettingsManagerPrivate::QNetworkSettingsManagerPrivate(QNetworkSettingsManager *parent)
:QObject(parent)
,q_ptr(parent)
- , m_interfaceModel(Q_NULLPTR)
- , m_serviceModel(Q_NULLPTR)
- , m_serviceFilter(Q_NULLPTR)
- , m_manager(Q_NULLPTR)
- , m_agent(Q_NULLPTR)
- , m_serviceWatcher(Q_NULLPTR)
- , m_currentWifiConnection(Q_NULLPTR)
- , m_currentWiredConnection(Q_NULLPTR)
+ , m_interfaceModel(nullptr)
+ , m_serviceModel(nullptr)
+ , m_serviceFilter(nullptr)
+ , m_manager(nullptr)
+ , m_agent(nullptr)
+ , m_serviceWatcher(nullptr)
+ , m_currentWifiConnection(nullptr)
+ , m_currentWiredConnection(nullptr)
, m_initialized(false)
{
qRegisterMetaType<ConnmanMapStruct>("ConnmanMapStruct");
@@ -140,8 +138,7 @@ void QNetworkSettingsManagerPrivate::tryNextConnection()
}
if (!service) {
if (!m_unnamedServicesForSsidConnection.isEmpty()) {
- service = *m_unnamedServicesForSsidConnection.begin();
- m_unnamedServicesForSsidConnection.erase(m_unnamedServicesForSsidConnection.begin());
+ service = m_unnamedServicesForSsidConnection.take(m_unnamedServicesForSsidConnection.firstKey());
} else {
q->clearConnectionState();
}
@@ -151,6 +148,26 @@ void QNetworkSettingsManagerPrivate::tryNextConnection()
}
}
+void QNetworkSettingsManagerPrivate::setCurrentWifiConnection(QNetworkSettingsService *connection)
+{
+ m_currentWifiConnection = connection;
+}
+
+QNetworkSettingsService *QNetworkSettingsManagerPrivate::currentWifiConnection() const
+{
+ return m_currentWifiConnection.data();
+}
+
+void QNetworkSettingsManagerPrivate::setCurrentWiredConnection(QNetworkSettingsService *connection)
+{
+ m_currentWiredConnection = connection;
+}
+
+QNetworkSettingsService *QNetworkSettingsManagerPrivate::currentWiredConnection() const
+{
+ return m_currentWiredConnection.data();
+}
+
void QNetworkSettingsManagerPrivate::onConnmanServiceRegistered(const QString &serviceName)
{
if (serviceName == ConnManServiceName) {
@@ -163,31 +180,34 @@ void QNetworkSettingsManagerPrivate::onTechnologyAdded(const QDBusObjectPath &te
{
Q_Q(QNetworkSettingsManager);
- foreach (QNetworkSettingsInterface* item, m_interfaceModel.getModel()) {
- ConnmanSettingsInterface* tech = qobject_cast<ConnmanSettingsInterface*>(item);
- if (tech->path() != technology.path()) {
- ConnmanSettingsInterface *interface = new ConnmanSettingsInterface(technology.path(), properties, this);
- interface->scanServices();
-
- if (interface->type() == QNetworkSettingsType::Wired) {
- m_interfaceModel.insert(0, interface);
- }
- else if (interface->type() == QNetworkSettingsType::Wifi) {
- m_interfaceModel.append(interface);
- }
- emit q->interfacesChanged();
+ for (QNetworkSettingsInterface* item : m_interfaceModel.getModel()) {
+ ConnmanSettingsInterface* interface = qobject_cast<ConnmanSettingsInterface*>(item);
+ if (interface->path() == technology.path()) {
+ return; // we already know the interface/technology
}
}
+
+ ConnmanSettingsInterface *interface = new ConnmanSettingsInterface(technology.path(), properties, this);
+ interface->scanServices();
+
+ if (interface->type() == QNetworkSettingsType::Wired) {
+ m_interfaceModel.insert(0, interface);
+ }
+ else if (interface->type() == QNetworkSettingsType::Wifi) {
+ m_interfaceModel.append(interface);
+ }
+
+ emit q->interfacesChanged();
}
void QNetworkSettingsManagerPrivate::onTechnologyRemoved(const QDBusObjectPath &technology)
{
Q_Q(QNetworkSettingsManager);
- foreach (QNetworkSettingsInterface* item, m_interfaceModel.getModel()) {
+ for (QNetworkSettingsInterface* item : m_interfaceModel.getModel()) {
ConnmanSettingsInterface* tech = qobject_cast<ConnmanSettingsInterface*>(item);
if (tech->path() == technology.path()) {
- m_interfaceModel.removeInterface(technology.path());
+ m_interfaceModel.removeInterface(tech->name());
emit q->interfacesChanged();
}
}
@@ -201,7 +221,7 @@ void QNetworkSettingsManagerPrivate::getServicesFinished(QDBusPendingCallWatcher
if (reply.isError())
return;
- foreach (const ConnmanMapStruct &object, reply.value()) {
+ for (const ConnmanMapStruct &object : reply.value()) {
const QString servicePath = object.objectPath.path();
handleNewService(servicePath);
}
@@ -216,7 +236,7 @@ void QNetworkSettingsManagerPrivate::getTechnologiesFinished(QDBusPendingCallWat
if (reply.isError())
return;
- foreach (const ConnmanMapStruct &object, reply.value()) {
+ for (const ConnmanMapStruct &object : reply.value()) {
ConnmanSettingsInterface *item = new ConnmanSettingsInterface(object.objectPath.path(), object.propertyMap, this);
item->scanServices();
@@ -232,21 +252,43 @@ void QNetworkSettingsManagerPrivate::getTechnologiesFinished(QDBusPendingCallWat
void QNetworkSettingsManagerPrivate::onServicesChanged(ConnmanMapStructList changed, const QList<QDBusObjectPath> &removed)
{
- foreach (QDBusObjectPath path, removed) {
- m_serviceModel->removeService(path.path());
- auto serviceIter = m_unnamedServices.find(path.path());
- if (serviceIter != m_unnamedServices.end()) {
- serviceIter.value()->deleteLater();
- m_unnamedServices.erase(serviceIter);
- }
+ Q_Q(QNetworkSettingsManager);
+ for (const QDBusObjectPath &dpath : removed) {
+ QString path = dpath.path();
+
+ if (m_serviceModel->removeService(path))
+ emit q->servicesChanged();
+
+ if (auto service = m_unnamedServices.take(path))
+ if (!service->placeholderState()) {
+ disconnect(service, &QNetworkSettingsService::nameChanged,
+ this, &QNetworkSettingsManagerPrivate::serviceReady);
+ disconnect(service, &QNetworkSettingsService::typeChanged,
+ this, &QNetworkSettingsManagerPrivate::serviceReady);
+ service->deleteLater();
+ }
+ if (auto service = m_unknownServices.take(path))
+ if (!service->placeholderState()) {
+ disconnect(service, &QNetworkSettingsService::nameChanged,
+ this, &QNetworkSettingsManagerPrivate::serviceReady);
+ disconnect(service, &QNetworkSettingsService::typeChanged,
+ this, &QNetworkSettingsManagerPrivate::serviceReady);
+ service->deleteLater();
+ }
+ m_unnamedServicesForSsidConnection.remove(path); // do not delete here
}
QStringList newServices;
- foreach (ConnmanMapStruct map, changed) {
+ for (const ConnmanMapStruct &map : changed) {
+ QString path = map.objectPath.path();
+
+ if (m_unknownServices.contains(path) || m_unnamedServices.contains(path))
+ continue;
+
bool found = false;
- foreach (QNetworkSettingsService* service, m_serviceModel->getModel()) {
- if (service->id() == map.objectPath.path() && service->placeholderState() == false) {
- found =true;
+ for (QNetworkSettingsService* service : m_serviceModel->getModel()) {
+ if (service->id() == path && service->placeholderState() == false) {
+ found = true;
break;
}
}
@@ -254,7 +296,7 @@ void QNetworkSettingsManagerPrivate::onServicesChanged(ConnmanMapStructList chan
newServices.append(map.objectPath.path());
}
- foreach (QString newService, newServices) {
+ for (QString newService : newServices) {
handleNewService(newService);
}
@@ -282,9 +324,20 @@ void QNetworkSettingsManagerPrivate::handleNewService(const QString &servicePath
}
}
else {
+ bool isUnnamedWifi = false;
+
//Service name or type not set, wait for update
- connect(service, &QNetworkSettingsService::nameChanged, this, &QNetworkSettingsManagerPrivate::serviceReady);
- connect(service, &QNetworkSettingsService::typeChanged, this, &QNetworkSettingsManagerPrivate::serviceReady);
+ if (service->name().isEmpty()) {
+ connect(service, &QNetworkSettingsService::nameChanged, this, &QNetworkSettingsManagerPrivate::serviceReady);
+ isUnnamedWifi = (service->type() == QNetworkSettingsType::Wifi);
+ }
+ if (service->type() == QNetworkSettingsType::Unknown)
+ connect(service, &QNetworkSettingsService::typeChanged, this, &QNetworkSettingsManagerPrivate::serviceReady);
+
+ if (isUnnamedWifi)
+ m_unnamedServices.insert(service->id(), service);
+ else
+ m_unknownServices.insert(service->id(), service);
}
}
@@ -299,11 +352,14 @@ void QNetworkSettingsManagerPrivate::serviceReady()
QNetworkSettingsService* service = qobject_cast<QNetworkSettingsService*>(sender());
- if (service->type() != QNetworkSettingsType::Unknown
- && service->type() == QNetworkSettingsType::Wifi) {
+ // the type changed from Unknown to Wifi
+ if ((service->type() == QNetworkSettingsType::Wifi)
+ && m_unknownServices.contains(service->id())) {
+ m_unknownServices.remove(service->id());
m_unnamedServices.insert(service->id(), service);
}
+ // we have a name and a length now
if (service->name().length() > 0 && service->type() != QNetworkSettingsType::Unknown) {
service->disconnect(this);
m_unnamedServices.remove(service->id());
@@ -314,7 +370,7 @@ void QNetworkSettingsManagerPrivate::serviceReady()
}
//Update the interface state accordingly
- foreach (QNetworkSettingsInterface* item, m_interfaceModel.getModel()) {
+ for (QNetworkSettingsInterface* item : m_interfaceModel.getModel()) {
ConnmanSettingsInterface* technology = qobject_cast<ConnmanSettingsInterface*>(item);
if (technology->name() == service->name() && technology->type() == service->type()) {
technology->setState(technology->state());