diff options
Diffstat (limited to 'src/networksettings/connman')
11 files changed, 154 insertions, 93 deletions
diff --git a/src/networksettings/connman/connman_manager.xml b/src/networksettings/connman/connman_manager.xml index 95bc0cb..ba95e8b 100644 --- a/src/networksettings/connman/connman_manager.xml +++ b/src/networksettings/connman/connman_manager.xml @@ -80,7 +80,7 @@ <signal name="TechnologyAdded" tp:name-for-bindings="Technology_Added"> <arg name="technology" type="o"/> <arg name="properties" type="a{sv}"/> - <annotation name="org.qtproject.QtDBus.QtTypeName.In1" value="QVariantMap"/> + <annotation name="org.qtproject.QtDBus.QtTypeName.Out1" value="QVariantMap"/> </signal> <signal name="TechnologyRemoved" tp:name-for-bindings="Technology_Removed"> diff --git a/src/networksettings/connman/connmancommon.cpp b/src/networksettings/connman/connmancommon.cpp index 887af48..a77bb1d 100644 --- a/src/networksettings/connman/connmancommon.cpp +++ b/src/networksettings/connman/connmancommon.cpp @@ -28,6 +28,8 @@ ****************************************************************************/ #include "connmancommon.h" +#include <QtNetworkSettings/qnetworksettings.h> + QT_BEGIN_NAMESPACE //Conversion operations for datatypes diff --git a/src/networksettings/connman/connmancommon.h b/src/networksettings/connman/connmancommon.h index 4b792ce..3b3cb79 100644 --- a/src/networksettings/connman/connmancommon.h +++ b/src/networksettings/connman/connmancommon.h @@ -30,8 +30,7 @@ #define CONNMANCOMMON_H #include <QtCore/QMetaType> -#include <QtDBus> -#include <QtNetworkSettings/qnetworksettings.h> +#include <QtDBus/QtDBus> #define PropertyAgentPath QStringLiteral("/ConnmanAgent") #define PropertyState QStringLiteral("State") @@ -54,6 +53,9 @@ QT_BEGIN_NAMESPACE +class QNetworkSettingsType; +class QNetworkSettingsState; + struct ConnmanMapStruct { QDBusObjectPath objectPath; QVariantMap propertyMap; diff --git a/src/networksettings/connman/qnetworksettingsinterface_p.cpp b/src/networksettings/connman/qnetworksettingsinterface_p.cpp index 5f008ff..eeb2abc 100644 --- a/src/networksettings/connman/qnetworksettingsinterface_p.cpp +++ b/src/networksettings/connman/qnetworksettingsinterface_p.cpp @@ -27,7 +27,6 @@ ** ****************************************************************************/ #include "qnetworksettingsinterface_p.h" -#include "qnetworksettingsinterface.h" #include "connman_technology_interface.h" #include "connmancommon.h" @@ -35,10 +34,9 @@ QT_BEGIN_NAMESPACE QNetworkSettingsInterfacePrivate::QNetworkSettingsInterfacePrivate(QNetworkSettingsInterface* parent) : QObject(parent) - , m_technology(Q_NULLPTR) + , m_technology(nullptr) ,q_ptr(parent) { - } void QNetworkSettingsInterfacePrivate::initialize(const QString& path, const QVariantMap& properties) @@ -83,7 +81,7 @@ void QNetworkSettingsInterfacePrivate::updateProperty(const QString &name, const } } -void QNetworkSettingsInterfacePrivate::setState(QNetworkSettingsState::States aState) +void QNetworkSettingsInterfacePrivate::setState(QNetworkSettingsState::State aState) { Q_Q(QNetworkSettingsInterface); m_state.setState(aState); diff --git a/src/networksettings/connman/qnetworksettingsinterface_p.h b/src/networksettings/connman/qnetworksettingsinterface_p.h index d85712a..25fbd2d 100644 --- a/src/networksettings/connman/qnetworksettingsinterface_p.h +++ b/src/networksettings/connman/qnetworksettingsinterface_p.h @@ -41,10 +41,11 @@ // #include <QObject> -#include <QtDBus> +#include <QtDBus/QDBusVariant> #include "qnetworksettings.h" #include "qnetworksettingsinterface.h" +// Automatically generated class in global namespace class NetConnmanTechnologyInterface; QT_BEGIN_NAMESPACE @@ -57,11 +58,11 @@ public: explicit QNetworkSettingsInterfacePrivate(QNetworkSettingsInterface* parent); void initialize(const QString& path, const QVariantMap& properties); void setPowered(const bool power); - void setState(QNetworkSettingsState::States aState); + void setState(QNetworkSettingsState::State aState); void scan(); QString name() const {return m_name;} - QNetworkSettingsType::Types type() const {return m_type.type();} - QNetworkSettingsState::States state() const {return m_state.state();} + QNetworkSettingsType::Type type() const {return m_type.type();} + QNetworkSettingsState::State state() const {return m_state.state();} bool powered() const {return m_powered;} QString path() const; @@ -84,21 +85,19 @@ class ConnmanSettingsInterface : public QNetworkSettingsInterface { Q_OBJECT public: - ConnmanSettingsInterface(const QString& path, const QVariantMap& properties, QObject *parent = Q_NULLPTR) + ConnmanSettingsInterface(const QString& path, const QVariantMap& properties, QObject *parent = nullptr) :QNetworkSettingsInterface(parent) { if (d_ptr) d_ptr->initialize(path, properties); } - void setState(QNetworkSettingsState::States aState) { + void setState(QNetworkSettingsState::State aState) { Q_D(QNetworkSettingsInterface); d->setState(aState); } - virtual ~ConnmanSettingsInterface() { - - } + virtual ~ConnmanSettingsInterface() {} QString path() const { if (d_ptr) 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()); diff --git a/src/networksettings/connman/qnetworksettingsmanager_p.h b/src/networksettings/connman/qnetworksettingsmanager_p.h index c696cdd..0b0c39b 100644 --- a/src/networksettings/connman/qnetworksettingsmanager_p.h +++ b/src/networksettings/connman/qnetworksettingsmanager_p.h @@ -41,19 +41,22 @@ // #include <QObject> -#include <QtDBus> #include <QMap> +#include <QPointer> +#include <QtDBus/QDBusServiceWatcher> #include "connmancommon.h" #include "qnetworksettingsmanager.h" #include "qnetworksettingsinterfacemodel.h" #include "connman_manager_interface.h" -QT_FORWARD_DECLARE_CLASS(QNetworkSettingsServiceModel) -QT_FORWARD_DECLARE_CLASS(QNetworkSettingsServiceFilter) -QT_FORWARD_DECLARE_CLASS(QNetworkSettingsService) - QT_BEGIN_NAMESPACE +class QDBusObjectPath; +class QDBusPendingCallWatcher; +class QNetworkSettingsService; +class QNetworkSettingsServiceModel; +class QNetworkSettingsServiceFilter; + class QNetworkSettingsManagerPrivate : public QObject { Q_OBJECT @@ -69,10 +72,10 @@ public: void connectBySsid(const QString &name); void clearConnectionState(); void tryNextConnection(); - void setCurrentWifiConnection(QNetworkSettingsService *connection) {m_currentWifiConnection = connection;} - QNetworkSettingsService* currentWifiConnection() const {return m_currentWifiConnection;} - void setCurrentWiredConnection(QNetworkSettingsService *connection) {m_currentWiredConnection = connection;} - QNetworkSettingsService* currentWiredConnection() const {return m_currentWiredConnection;} + void setCurrentWifiConnection(QNetworkSettingsService *connection); + QNetworkSettingsService* currentWifiConnection() const; + void setCurrentWiredConnection(QNetworkSettingsService *connection); + QNetworkSettingsService* currentWiredConnection() const; public slots: void getServicesFinished(QDBusPendingCallWatcher *watcher); @@ -91,6 +94,7 @@ private: protected: QNetworkSettingsInterfaceModel m_interfaceModel; QNetworkSettingsServiceModel *m_serviceModel; + QMap<QString, QNetworkSettingsService*> m_unknownServices; QMap<QString, QNetworkSettingsService*> m_unnamedServices; QMap<QString, QNetworkSettingsService*> m_unnamedServicesForSsidConnection; QNetworkSettingsServiceFilter *m_serviceFilter; @@ -99,8 +103,8 @@ private: QNetworkSettingsUserAgent *m_agent; QDBusServiceWatcher *m_serviceWatcher; QString m_currentSsid; - QNetworkSettingsService *m_currentWifiConnection; - QNetworkSettingsService *m_currentWiredConnection; + QPointer<QNetworkSettingsService> m_currentWifiConnection; + QPointer<QNetworkSettingsService> m_currentWiredConnection; bool m_initialized; }; diff --git a/src/networksettings/connman/qnetworksettingsservice_p.cpp b/src/networksettings/connman/qnetworksettingsservice_p.cpp index 2523e81..082b458 100644 --- a/src/networksettings/connman/qnetworksettingsservice_p.cpp +++ b/src/networksettings/connman/qnetworksettingsservice_p.cpp @@ -438,20 +438,22 @@ void QNetworkSettingsServicePrivate::updateProperty(const QString& key, const QV } else if (key == PropertySecurity) { QStringList value = qdbus_cast<QStringList>(val); - foreach (const QString str, value) { + QNetworkSettingsWireless::Securities securities; + for (const QString &str : value) { if (str == AttributeNone || str == AttributeWps) { - m_wifiConfig.setSecurity(QNetworkSettingsWireless::None); + securities |= QNetworkSettingsWireless::Security::None; } else if (str == AttributeWep) { - m_wifiConfig.setSecurity(QNetworkSettingsWireless::WEP); + securities |= QNetworkSettingsWireless::Security::WEP; } else if (str == AttributePsk) { - m_wifiConfig.setSecurity(QNetworkSettingsWireless::WPA); + securities |=QNetworkSettingsWireless::Security::WPA; } else if (str == AttributeIeee) { - m_wifiConfig.setSecurity(QNetworkSettingsWireless::WPA2); + securities |=QNetworkSettingsWireless::Security::WPA2; } } + m_wifiConfig.setSecurity(securities); } else if (key == PropertyAutoConnect) { m_autoConnect = qdbus_cast<bool>(val); diff --git a/src/networksettings/connman/qnetworksettingsservice_p.h b/src/networksettings/connman/qnetworksettingsservice_p.h index 9190e2d..8c798c3 100644 --- a/src/networksettings/connman/qnetworksettingsservice_p.h +++ b/src/networksettings/connman/qnetworksettingsservice_p.h @@ -43,20 +43,19 @@ #include "qnetworksettingsservice.h" #include "qnetworksettings.h" -QT_FORWARD_DECLARE_CLASS(QDBusPendingCallWatcher) -QT_FORWARD_DECLARE_CLASS(QDBusVariant) - // Automatically generated class in global namespace class NetConnmanServiceInterface; QT_BEGIN_NAMESPACE +class QDBusVariant; +class QDBusPendingCallWatcher; class QNetworkSettingsServicePrivate : public QObject { Q_OBJECT Q_DECLARE_PUBLIC(QNetworkSettingsService) public: - QNetworkSettingsServicePrivate(const QString& aPath, QNetworkSettingsService *parent = Q_NULLPTR); + QNetworkSettingsServicePrivate(const QString& aPath, QNetworkSettingsService *parent = nullptr); QNetworkSettingsService *q_ptr; private slots: diff --git a/src/networksettings/connman/qnetworksettingsuseragent_p.cpp b/src/networksettings/connman/qnetworksettingsuseragent_p.cpp index 2c1e399..6ba8be7 100644 --- a/src/networksettings/connman/qnetworksettingsuseragent_p.cpp +++ b/src/networksettings/connman/qnetworksettingsuseragent_p.cpp @@ -26,6 +26,9 @@ ** $QT_END_LICENSE$ ** ****************************************************************************/ +#include <QtDBus/QDBusConnection> + +#include "qnetworksettingsuseragent.h" #include "qnetworksettingsuseragent_p.h" #include "connmancommon.h" diff --git a/src/networksettings/connman/qnetworksettingsuseragent_p.h b/src/networksettings/connman/qnetworksettingsuseragent_p.h index b85ddd2..8f356d9 100644 --- a/src/networksettings/connman/qnetworksettingsuseragent_p.h +++ b/src/networksettings/connman/qnetworksettingsuseragent_p.h @@ -41,25 +41,20 @@ // #include <QtCore/QObject> -#include <QtDBus/QtDBus> -#include "qnetworksettingsuseragent.h" +#include <QtDBus/QDBusMessage> +#include <QtDBus/QDBusObjectPath> +#include <QtDBus/QDBusAbstractAdaptor> QT_BEGIN_NAMESPACE -class QByteArray; -template<class T> class QList; -template<class Key, class Value> class QMap; -class QString; -class QVariant; - -const QString AgentPath(QStringLiteral("/ConnmanAgent")); +class QNetworkSettingsUserAgent; class QNetworkSettingsUserAgentPrivate : public QDBusAbstractAdaptor { Q_OBJECT Q_CLASSINFO("D-Bus Interface", "net.connman.Agent") Q_DECLARE_PUBLIC(QNetworkSettingsUserAgent) public: - QNetworkSettingsUserAgentPrivate(QNetworkSettingsUserAgent *parent = Q_NULLPTR); + QNetworkSettingsUserAgentPrivate(QNetworkSettingsUserAgent *parent = nullptr); void setPassphrase(const QString &passphrase); QString passphrase() const {return m_passphrase;} void cancel(); @@ -82,3 +77,4 @@ private: QT_END_NAMESPACE #endif // QNETWORKSETTINGSUSERAGENTPRIVATE_H + |