diff --git a/src/plugins/bearer/connman/connman.pro b/src/plugins/bearer/connman/connman.pro index bc4efe8b62..efa13a6ebd 100644 --- a/src/plugins/bearer/connman/connman.pro +++ b/src/plugins/bearer/connman/connman.pro @@ -8,14 +8,14 @@ QT = core network-private dbus CONFIG += link_pkgconfig HEADERS += qconnmanservice_linux_p.h \ - qofonoservice_linux_p.h \ + ../linux_common/qofonoservice_linux_p.h \ qconnmanengine.h \ ../qnetworksession_impl.h \ ../qbearerengine_impl.h SOURCES += main.cpp \ qconnmanservice_linux.cpp \ - qofonoservice_linux.cpp \ + ../linux_common/qofonoservice_linux.cpp \ qconnmanengine.cpp \ ../qnetworksession_impl.cpp diff --git a/src/plugins/bearer/connman/qconnmanengine.h b/src/plugins/bearer/connman/qconnmanengine.h index 52e8b384a0..a995d8ed25 100644 --- a/src/plugins/bearer/connman/qconnmanengine.h +++ b/src/plugins/bearer/connman/qconnmanengine.h @@ -48,7 +48,7 @@ #include "../qbearerengine_impl.h" #include "qconnmanservice_linux_p.h" -#include "qofonoservice_linux_p.h" +#include "../linux_common/qofonoservice_linux_p.h" #include #include diff --git a/src/plugins/bearer/connman/qofonoservice_linux.cpp b/src/plugins/bearer/linux_common/qofonoservice_linux.cpp similarity index 76% rename from src/plugins/bearer/connman/qofonoservice_linux.cpp rename to src/plugins/bearer/linux_common/qofonoservice_linux.cpp index 2ce2bd40e4..e994ebf2ce 100644 --- a/src/plugins/bearer/connman/qofonoservice_linux.cpp +++ b/src/plugins/bearer/linux_common/qofonoservice_linux.cpp @@ -95,14 +95,12 @@ QStringList QOfonoManagerInterface::getModems() { if (modemList.isEmpty()) { QList argumentList; - QDBusPendingReply reply = asyncCallWithArgumentList(QLatin1String("GetModems"), argumentList); + QDBusPendingReply reply = callWithArgumentList(QDBus::Block, QLatin1String("GetModems"), argumentList); reply.waitForFinished(); if (!reply.isError()) { foreach (ObjectPathProperties modem, reply.value()) { modemList << modem.path.path(); } - } else { - qDebug() << reply.error().message(); } } @@ -175,7 +173,7 @@ QVariantMap QOfonoModemInterface::getProperties() { if (propertiesMap.isEmpty()) { QList argumentList; - QDBusPendingReply reply = asyncCallWithArgumentList(QLatin1String("GetProperties"), argumentList); + QDBusPendingReply reply = callWithArgumentList(QDBus::Block, QLatin1String("GetProperties"), argumentList); if (!reply.isError()) { propertiesMap = reply.value(); } @@ -187,7 +185,8 @@ QVariant QOfonoModemInterface::getProperty(const QString &property) { QVariant var; QVariantMap map = getProperties(); - var = map.value(property); + if (map.contains(property)) + var = map.value(property); return var; } @@ -214,7 +213,8 @@ QVariant QOfonoNetworkRegistrationInterface::getProperty(const QString &property { QVariant var; QVariantMap map = getProperties(); - var = map.value(property); + if (map.contains(property)) + var = map.value(property); return var; } @@ -222,12 +222,10 @@ QVariantMap QOfonoNetworkRegistrationInterface::getProperties() { if (propertiesMap.isEmpty()) { QList argumentList; - QDBusPendingReply reply = asyncCallWithArgumentList(QLatin1String("GetProperties"), argumentList); + QDBusPendingReply reply = callWithArgumentList(QDBus::Block, QLatin1String("GetProperties"), argumentList); reply.waitForFinished(); if (!reply.isError()) { propertiesMap = reply.value(); - } else { - qDebug() << reply.error().message(); } } return propertiesMap; @@ -270,11 +268,18 @@ bool QOfonoDataConnectionManagerInterface::roamingAllowed() return qdbus_cast(var); } +QString QOfonoDataConnectionManagerInterface::bearer() +{ + QVariant var = getProperty(QStringLiteral("Bearer")); + return qdbus_cast(var); +} + QVariant QOfonoDataConnectionManagerInterface::getProperty(const QString &property) { QVariant var; QVariantMap map = getProperties(); - var = map.value(property); + if (map.contains(property)) + var = map.value(property); return var; } @@ -282,7 +287,7 @@ QVariantMap QOfonoDataConnectionManagerInterface::getProperties() { if (propertiesMap.isEmpty()) { QList argumentList; - QDBusPendingReply reply = asyncCallWithArgumentList(QLatin1String("GetProperties"), argumentList); + QDBusPendingReply reply = callWithArgumentList(QDBus::Block, QLatin1String("GetProperties"), argumentList); if (!reply.isError()) { propertiesMap = reply.value(); } @@ -297,6 +302,68 @@ void QOfonoDataConnectionManagerInterface::propertyChanged(const QString &name, Q_EMIT roamingAllowedChanged(value.variant().toBool()); } + +QOfonoConnectionContextInterface::QOfonoConnectionContextInterface(const QString &dbusPathName, QObject *parent) + : QDBusAbstractInterface(QLatin1String(OFONO_SERVICE), + dbusPathName, + OFONO_CONNECTION_CONTEXT_INTERFACE, + QDBusConnection::systemBus(), parent) +{ + QDBusConnection::systemBus().connect(QLatin1String(OFONO_SERVICE), + path(), + QLatin1String(OFONO_MODEM_INTERFACE), + QLatin1String("PropertyChanged"), + this,SLOT(propertyChanged(QString,QDBusVariant))); +} + +QOfonoConnectionContextInterface::~QOfonoConnectionContextInterface() +{ +} + +QVariantMap QOfonoConnectionContextInterface::getProperties() +{ + if (propertiesMap.isEmpty()) { + QList argumentList; + QDBusPendingReply reply = callWithArgumentList(QDBus::Block, QLatin1String("GetProperties"), argumentList); + if (!reply.isError()) { + propertiesMap = reply.value(); + } + } + return propertiesMap; +} + +void QOfonoConnectionContextInterface::propertyChanged(const QString &name, const QDBusVariant &value) +{ + propertiesMap[name] = value.variant(); +} + +QVariant QOfonoConnectionContextInterface::getProperty(const QString &property) +{ + QVariant var; + QVariantMap map = getProperties(); + if (map.contains(property)) + var = map.value(property); + return var; +} + +bool QOfonoConnectionContextInterface::active() +{ + QVariant var = getProperty(QStringLiteral("Active")); + return qdbus_cast(var); +} + +QString QOfonoConnectionContextInterface::accessPointName() +{ + QVariant var = getProperty(QStringLiteral("AccessPointName")); + return qdbus_cast(var); +} + +QString QOfonoConnectionContextInterface::name() +{ + QVariant var = getProperty(QStringLiteral("Name")); + return qdbus_cast(var); +} + QT_END_NAMESPACE #endif // QT_NO_DBUS diff --git a/src/plugins/bearer/connman/qofonoservice_linux_p.h b/src/plugins/bearer/linux_common/qofonoservice_linux_p.h similarity index 88% rename from src/plugins/bearer/connman/qofonoservice_linux_p.h rename to src/plugins/bearer/linux_common/qofonoservice_linux_p.h index 8a6a932e0d..2b3d43deb5 100644 --- a/src/plugins/bearer/connman/qofonoservice_linux_p.h +++ b/src/plugins/bearer/linux_common/qofonoservice_linux_p.h @@ -67,6 +67,7 @@ #define OFONO_MODEM_INTERFACE "org.ofono.Modem" #define OFONO_NETWORK_REGISTRATION_INTERFACE "org.ofono.NetworkRegistration" #define OFONO_DATA_CONNECTION_MANAGER_INTERFACE "org.ofono.ConnectionManager" +#define OFONO_CONNECTION_CONTEXT_INTERFACE "org.ofono.ConnectionContext" QT_BEGIN_NAMESPACE @@ -152,17 +153,39 @@ public: QStringList contexts(); bool roamingAllowed(); + QVariant getProperty(const QString &); + QString bearer(); Q_SIGNALS: void roamingAllowedChanged(bool); private: QVariantMap getProperties(); QVariantMap propertiesMap; - QVariant getProperty(const QString &); QStringList contextList; private slots: void propertyChanged(const QString &, const QDBusVariant &value); }; +class QOfonoConnectionContextInterface : public QDBusAbstractInterface +{ + Q_OBJECT + +public: + + explicit QOfonoConnectionContextInterface(const QString &dbusPathName, QObject *parent = 0); + ~QOfonoConnectionContextInterface(); + + QVariant getProperty(const QString &); + bool active(); + QString accessPointName(); + QString name(); + +Q_SIGNALS: +private: + QVariantMap getProperties(); + QVariantMap propertiesMap; +private slots: + void propertyChanged(const QString &, const QDBusVariant &value); +}; QT_END_NAMESPACE diff --git a/src/plugins/bearer/networkmanager/networkmanager.pro b/src/plugins/bearer/networkmanager/networkmanager.pro index 1ed9bfaa1b..b3a270615c 100644 --- a/src/plugins/bearer/networkmanager/networkmanager.pro +++ b/src/plugins/bearer/networkmanager/networkmanager.pro @@ -6,16 +6,16 @@ load(qt_plugin) QT = core network-private dbus -HEADERS += qnmdbushelper.h \ - qnetworkmanagerservice.h \ +HEADERS += qnetworkmanagerservice.h \ qnetworkmanagerengine.h \ + ../linux_common/qofonoservice_linux_p.h \ ../qnetworksession_impl.h \ ../qbearerengine_impl.h SOURCES += main.cpp \ - qnmdbushelper.cpp \ qnetworkmanagerservice.cpp \ qnetworkmanagerengine.cpp \ + ../linux_common/qofonoservice_linux.cpp \ ../qnetworksession_impl.cpp OTHER_FILES += networkmanager.json diff --git a/src/plugins/bearer/networkmanager/qnetworkmanagerengine.cpp b/src/plugins/bearer/networkmanager/qnetworkmanagerengine.cpp index 5f49ea0b6d..f07d7b242b 100644 --- a/src/plugins/bearer/networkmanager/qnetworkmanagerengine.cpp +++ b/src/plugins/bearer/networkmanager/qnetworkmanagerengine.cpp @@ -47,6 +47,7 @@ #include #include #include +#include "../linux_common/qofonoservice_linux_p.h" #ifndef QT_NO_BEARERMANAGEMENT #ifndef QT_NO_DBUS @@ -57,44 +58,55 @@ QNetworkManagerEngine::QNetworkManagerEngine(QObject *parent) : QBearerEngineImpl(parent), managerInterface(new QNetworkManagerInterface(this)), systemSettings(new QNetworkManagerSettings(NM_DBUS_SERVICE, this)), - userSettings(new QNetworkManagerSettings(NM_DBUS_SERVICE, this)) + ofonoManager(new QOfonoManagerInterface(this)), + ofonoNetwork(0), + ofonoContextManager(0) { + if (!managerInterface->isValid()) return; - managerInterface->setConnections(); + qDBusRegisterMetaType(); + connect(managerInterface, SIGNAL(deviceAdded(QDBusObjectPath)), this, SLOT(deviceAdded(QDBusObjectPath))); connect(managerInterface, SIGNAL(deviceRemoved(QDBusObjectPath)), this, SLOT(deviceRemoved(QDBusObjectPath))); connect(managerInterface, SIGNAL(activationFinished(QDBusPendingCallWatcher*)), this, SLOT(activationFinished(QDBusPendingCallWatcher*))); - connect(managerInterface, SIGNAL(propertiesChanged(QString,QMap)), - this, SLOT(interfacePropertiesChanged(QString,QMap))); + connect(managerInterface, SIGNAL(propertiesChanged(QMap)), + this, SLOT(interfacePropertiesChanged(QMap))); + managerInterface->setConnections(); - qDBusRegisterMetaType(); - - systemSettings->setConnections(); connect(systemSettings, SIGNAL(newConnection(QDBusObjectPath)), this, SLOT(newConnection(QDBusObjectPath))); - - userSettings->setConnections(); - connect(userSettings, SIGNAL(newConnection(QDBusObjectPath)), - this, SLOT(newConnection(QDBusObjectPath))); + systemSettings->setConnections(); } QNetworkManagerEngine::~QNetworkManagerEngine() { qDeleteAll(connections); + connections.clear(); qDeleteAll(accessPoints); + accessPoints.clear(); qDeleteAll(wirelessDevices); - qDeleteAll(activeConnections); + wirelessDevices.clear(); + qDeleteAll(activeConnectionsList); + activeConnectionsList.clear(); + qDeleteAll(interfaceDevices); + interfaceDevices.clear(); + + connectionInterfaces.clear(); } void QNetworkManagerEngine::initialize() { QMutexLocker locker(&mutex); + connect(ofonoManager,SIGNAL(modemChanged()),this,SLOT(changedModem())); + ofonoNetwork = new QOfonoNetworkRegistrationInterface(ofonoManager->currentModem(),this); + ofonoContextManager = new QOfonoDataConnectionManagerInterface(ofonoManager->currentModem(),this); + // Get current list of access points. foreach (const QDBusObjectPath &devicePath, managerInterface->getDevices()) { locker.unlock(); @@ -102,8 +114,24 @@ void QNetworkManagerEngine::initialize() locker.relock(); } - // Get connections. + // Get active connections. + foreach (const QDBusObjectPath &acPath, managerInterface->activeConnections()) { + QNetworkManagerConnectionActive *activeConnection = + new QNetworkManagerConnectionActive(acPath.path(),this); + activeConnectionsList.insert(acPath.path(), activeConnection); + connect(activeConnection, SIGNAL(propertiesChanged(QMap)), + this, SLOT(activeConnectionPropertiesChanged(QMap))); + activeConnection->setConnections(); + + QList devices = activeConnection->devices(); + if (!devices.isEmpty()) { + QNetworkManagerInterfaceDevice device(devices.at(0).path(),this); + connectionInterfaces.insert(activeConnection->connection().path(),device.networkInterface()); + } + } + + // Get connections. foreach (const QDBusObjectPath &settingsPath, systemSettings->listConnections()) { locker.unlock(); if (!hasIdentifier(settingsPath.path())) @@ -111,57 +139,19 @@ void QNetworkManagerEngine::initialize() locker.relock(); } - foreach (const QDBusObjectPath &settingsPath, userSettings->listConnections()) { - locker.unlock(); - if (!hasIdentifier(settingsPath.path())) - newConnection(settingsPath, userSettings); - locker.relock(); - } - - // Get active connections. - foreach (const QDBusObjectPath &acPath, managerInterface->activeConnections()) { - QNetworkManagerConnectionActive *activeConnection = - new QNetworkManagerConnectionActive(acPath.path(),this); - activeConnections.insert(acPath.path(), activeConnection); - - activeConnection->setConnections(); - connect(activeConnection, SIGNAL(propertiesChanged(QString,QMap)), - this, SLOT(activeConnectionPropertiesChanged(QString,QMap))); - } Q_EMIT updateCompleted(); } bool QNetworkManagerEngine::networkManagerAvailable() const { - QMutexLocker locker(&mutex); - return managerInterface->isValid(); } -QString QNetworkManagerEngine::getInterfaceFromId(const QString &id) +QString QNetworkManagerEngine::getInterfaceFromId(const QString &settingsPath) { - QMutexLocker locker(&mutex); - - foreach (const QDBusObjectPath &acPath, managerInterface->activeConnections()) { - QNetworkManagerConnectionActive activeConnection(acPath.path()); - - const QString identifier = activeConnection.connection().path(); - - if (id == identifier) { - QList devices = activeConnection.devices(); - - if (devices.isEmpty()) - continue; - - QNetworkManagerInterfaceDevice device(devices.at(0).path()); - return device.networkInterface(); - } - } - - return QString(); + return connectionInterfaces.value(settingsPath); } - bool QNetworkManagerEngine::hasIdentifier(const QString &id) { QMutexLocker locker(&mutex); @@ -177,35 +167,34 @@ void QNetworkManagerEngine::connectToId(const QString &id) if (!connection) return; - QNmSettingsMap map = connection->getSettings(); - const QString connectionType = map.value("connection").value("type").toString(); + NMDeviceType connectionType = connection->getType(); QString dbusDevicePath; - foreach (const QDBusObjectPath &devicePath, managerInterface->getDevices()) { - QNetworkManagerInterfaceDevice device(devicePath.path()); - if (device.deviceType() == DEVICE_TYPE_ETHERNET && - connectionType == QLatin1String("802-3-ethernet")) { - dbusDevicePath = devicePath.path(); + const QString settingsPath = connection->connectionInterface()->path(); + QString specificPath = configuredAccessPoints.key(settingsPath); + + QHashIterator i(interfaceDevices); + while (i.hasNext()) { + i.next(); + if (i.value()->deviceType() == DEVICE_TYPE_ETHERNET && + connectionType == DEVICE_TYPE_ETHERNET) { + dbusDevicePath = i.key(); break; - } else if (device.deviceType() == DEVICE_TYPE_WIFI && - connectionType == QLatin1String("802-11-wireless")) { - dbusDevicePath = devicePath.path(); + } else if (i.value()->deviceType() == DEVICE_TYPE_WIFI && + connectionType == DEVICE_TYPE_WIFI) { + dbusDevicePath = i.key(); break; - } else if (device.deviceType() == DEVICE_TYPE_MODEM && - connectionType == QLatin1String("gsm")) { - dbusDevicePath = devicePath.path(); + } else if (i.value()->deviceType() == DEVICE_TYPE_MODEM && + connectionType == DEVICE_TYPE_MODEM) { + dbusDevicePath = i.key(); break; } } - const QString service = connection->connectionInterface()->service(); - const QString settingsPath = connection->connectionInterface()->path(); - QString specificPath = configuredAccessPoints.key(settingsPath); - if (specificPath.isEmpty()) specificPath = "/"; - managerInterface->activateConnection(service, QDBusObjectPath(settingsPath), + managerInterface->activateConnection(QDBusObjectPath(settingsPath), QDBusObjectPath(dbusDevicePath), QDBusObjectPath(specificPath)); } @@ -221,13 +210,11 @@ void QNetworkManagerEngine::disconnectFromId(const QString &id) return; } - foreach (const QDBusObjectPath &acPath, managerInterface->activeConnections()) { - QNetworkManagerConnectionActive activeConnection(acPath.path()); - - const QString identifier = activeConnection.connection().path(); - - if (id == identifier && accessPointConfigurations.contains(id)) { - managerInterface->deactivateConnection(acPath); + QHashIterator i(activeConnectionsList); + while (i.hasNext()) { + i.next(); + if (id == i.value()->connection().path() && accessPointConfigurations.contains(id)) { + managerInterface->deactivateConnection(QDBusObjectPath(i.key())); break; } } @@ -250,12 +237,9 @@ void QNetworkManagerEngine::scanFinished() QMetaObject::invokeMethod(this, "updateCompleted", Qt::QueuedConnection); } -void QNetworkManagerEngine::interfacePropertiesChanged(const QString &path, - const QMap &properties) +void QNetworkManagerEngine::interfacePropertiesChanged(const QMap &properties) { - Q_UNUSED(path) QMutexLocker locker(&mutex); - QMapIterator i(properties); while (i.hasNext()) { i.next(); @@ -267,22 +251,20 @@ void QNetworkManagerEngine::interfacePropertiesChanged(const QString &path, qdbus_cast >(i.value().value()); QStringList identifiers = accessPointConfigurations.keys(); - foreach (const QString &id, identifiers) - QNetworkConfigurationPrivatePointer ptr = accessPointConfigurations.value(id); - - QStringList priorActiveConnections = this->activeConnections.keys(); + QStringList priorActiveConnections = activeConnectionsList.keys(); foreach (const QDBusObjectPath &acPath, activeConnections) { priorActiveConnections.removeOne(acPath.path()); QNetworkManagerConnectionActive *activeConnection = - this->activeConnections.value(acPath.path()); + activeConnectionsList.value(acPath.path()); + if (!activeConnection) { activeConnection = new QNetworkManagerConnectionActive(acPath.path(),this); - this->activeConnections.insert(acPath.path(), activeConnection); + activeConnectionsList.insert(acPath.path(), activeConnection); + connect(activeConnection, SIGNAL(propertiesChanged(QMap)), + this, SLOT(activeConnectionPropertiesChanged(QMap))); activeConnection->setConnections(); - connect(activeConnection, SIGNAL(propertiesChanged(QString,QMap)), - this, SLOT(activeConnectionPropertiesChanged(QString,QMap))); } const QString id = activeConnection->connection().path(); @@ -295,6 +277,11 @@ void QNetworkManagerEngine::interfacePropertiesChanged(const QString &path, if (activeConnection->state() == NM_ACTIVE_CONNECTION_STATE_ACTIVATED && ptr->state != QNetworkConfiguration::Active) { ptr->state = QNetworkConfiguration::Active; + + if (activeConnectionsList.value(id) && activeConnectionsList.value(id)->defaultRoute() + && managerInterface->state() < QNetworkManagerInterface::NM_STATE_CONNECTED_GLOBAL) { + ptr->purpose = QNetworkConfiguration::PrivatePurpose; + } ptr->mutex.unlock(); locker.unlock(); @@ -307,7 +294,7 @@ void QNetworkManagerEngine::interfacePropertiesChanged(const QString &path, } while (!priorActiveConnections.isEmpty()) - delete this->activeConnections.take(priorActiveConnections.takeFirst()); + delete activeConnectionsList.take(priorActiveConnections.takeFirst()); while (!identifiers.isEmpty()) { QNetworkConfigurationPrivatePointer ptr = @@ -330,14 +317,13 @@ void QNetworkManagerEngine::interfacePropertiesChanged(const QString &path, } } -void QNetworkManagerEngine::activeConnectionPropertiesChanged(const QString &path, - const QMap &properties) +void QNetworkManagerEngine::activeConnectionPropertiesChanged(const QMap &properties) { QMutexLocker locker(&mutex); Q_UNUSED(properties) - QNetworkManagerConnectionActive *activeConnection = activeConnections.value(path); + QNetworkManagerConnectionActive *activeConnection = qobject_cast(sender()); if (!activeConnection) return; @@ -347,8 +333,13 @@ void QNetworkManagerEngine::activeConnectionPropertiesChanged(const QString &pat QNetworkConfigurationPrivatePointer ptr = accessPointConfigurations.value(id); if (ptr) { ptr->mutex.lock(); - if (activeConnection->state() == NM_ACTIVE_CONNECTION_STATE_ACTIVATED && - ptr->state != QNetworkConfiguration::Active) { + if (properties.value("State").toUInt() == NM_ACTIVE_CONNECTION_STATE_ACTIVATED) { + QList devices = activeConnection->devices(); + if (!devices.isEmpty()) { + QNetworkManagerInterfaceDevice device(devices.at(0).path(),this); + connectionInterfaces.insert(id,device.networkInterface()); + } + ptr->state |= QNetworkConfiguration::Active; ptr->mutex.unlock(); @@ -356,22 +347,17 @@ void QNetworkManagerEngine::activeConnectionPropertiesChanged(const QString &pat emit configurationChanged(ptr); locker.relock(); } else { + connectionInterfaces.remove(id); ptr->mutex.unlock(); } } } -void QNetworkManagerEngine::devicePropertiesChanged(const QString &/*path*/,quint32 /*state*/) -{ -// Q_UNUSED(path); -// Q_UNUSED(state) -} - -void QNetworkManagerEngine::deviceConnectionsChanged(const QStringList &activeConnectionsList) +void QNetworkManagerEngine::deviceConnectionsChanged(const QStringList &connectionsList) { QMutexLocker locker(&mutex); for (int i = 0; i < connections.count(); ++i) { - if (activeConnectionsList.contains(connections.at(i)->connectionInterface()->path())) + if (connectionsList.contains(connections.at(i)->connectionInterface()->path())) continue; const QString settingsPath = connections.at(i)->connectionInterface()->path(); @@ -392,27 +378,23 @@ void QNetworkManagerEngine::deviceConnectionsChanged(const QStringList &activeCo void QNetworkManagerEngine::deviceAdded(const QDBusObjectPath &path) { - QMutexLocker locker(&mutex); QNetworkManagerInterfaceDevice *iDevice; iDevice = new QNetworkManagerInterfaceDevice(path.path(),this); connect(iDevice,SIGNAL(connectionsChanged(QStringList)), this,SLOT(deviceConnectionsChanged(QStringList))); - connect(iDevice,SIGNAL(stateChanged(QString,quint32)), - this,SLOT(devicePropertiesChanged(QString,quint32))); iDevice->setConnections(); interfaceDevices.insert(path.path(),iDevice); - if (iDevice->deviceType() == DEVICE_TYPE_WIFI) { QNetworkManagerInterfaceDeviceWireless *wirelessDevice = new QNetworkManagerInterfaceDeviceWireless(iDevice->connectionInterface()->path(),this); - wirelessDevice->setConnections(); connect(wirelessDevice, SIGNAL(accessPointAdded(QString)), this, SLOT(newAccessPoint(QString))); connect(wirelessDevice, SIGNAL(accessPointRemoved(QString)), this, SLOT(removeAccessPoint(QString))); connect(wirelessDevice,SIGNAL(scanDone()),this,SLOT(scanFinished())); + wirelessDevice->setConnections(); foreach (const QDBusObjectPath &apPath, wirelessDevice->getAccessPoints()) newAccessPoint(apPath.path()); @@ -444,10 +426,10 @@ void QNetworkManagerEngine::newConnection(const QDBusObjectPath &path, if (!settings) settings = qobject_cast(sender()); - if (!settings) + if (!settings) { return; + } - settings->deleteLater(); QNetworkManagerSettingsConnection *connection = new QNetworkManagerSettingsConnection(settings->connectionInterface()->service(), path.path(),this); @@ -482,12 +464,10 @@ void QNetworkManagerEngine::newConnection(const QDBusObjectPath &path, parseConnection(settingsPath, connection->getSettings()); // Check if connection is active. - foreach (const QDBusObjectPath &acPath, managerInterface->activeConnections()) { - QNetworkManagerConnectionActive activeConnection(acPath.path()); - - if (activeConnection.defaultRoute() && - activeConnection.connection().path() == settingsPath && - activeConnection.state() == NM_ACTIVE_CONNECTION_STATE_ACTIVATED) { + QHashIterator i(activeConnectionsList); + while (i.hasNext()) { + i.next(); + if (i.value()->connection().path() == settingsPath) { cpPriv->state |= QNetworkConfiguration::Active; break; } @@ -505,6 +485,7 @@ void QNetworkManagerEngine::removeConnection(const QString &path) QNetworkManagerSettingsConnection *connection = qobject_cast(sender()); + if (!connection) return; @@ -525,6 +506,7 @@ void QNetworkManagerEngine::removeConnection(const QString &path) while (i.hasNext()) { i.next(); if (i.value() == path) { + configuredAccessPoints.remove(i.key()); newAccessPoint(i.key()); } } @@ -575,10 +557,9 @@ void QNetworkManagerEngine::updateConnection() void QNetworkManagerEngine::activationFinished(QDBusPendingCallWatcher *watcher) { QMutexLocker locker(&mutex); - + QDBusPendingReply reply(*watcher); watcher->deleteLater(); - QDBusPendingReply reply(*watcher); if (!reply.isError()) { QDBusObjectPath result = reply.value(); @@ -620,15 +601,14 @@ void QNetworkManagerEngine::newAccessPoint(const QString &path) if (okToAdd) { accessPoints.append(accessPoint); accessPoint->setConnections(); - connect(accessPoint, SIGNAL(propertiesChanged(QMap)), - this, SLOT(updateAccessPoint(QMap))); } - // Check if configuration exists for connection. if (!accessPoint->ssid().isEmpty()) { + for (int i = 0; i < connections.count(); ++i) { QNetworkManagerSettingsConnection *connection = connections.at(i); const QString settingsPath = connection->connectionInterface()->path(); + if (accessPoint->ssid() == connection->getSsid()) { if (!configuredAccessPoints.contains(path)) { configuredAccessPoints.insert(path,settingsPath); @@ -655,11 +635,7 @@ void QNetworkManagerEngine::newAccessPoint(const QString &path) ptr->isValid = true; ptr->id = path; ptr->type = QNetworkConfiguration::InternetAccessPoint; - if (accessPoint->flags() == NM_802_11_AP_FLAGS_PRIVACY) { - ptr->purpose = QNetworkConfiguration::PrivatePurpose; - } else { - ptr->purpose = QNetworkConfiguration::PublicPurpose; - } + ptr->purpose = QNetworkConfiguration::PublicPurpose; ptr->state = QNetworkConfiguration::Undefined; ptr->bearerType = QNetworkConfiguration::BearerWLAN; @@ -674,13 +650,13 @@ void QNetworkManagerEngine::removeAccessPoint(const QString &path) QMutexLocker locker(&mutex); for (int i = 0; i < accessPoints.count(); ++i) { QNetworkManagerInterfaceAccessPoint *accessPoint = accessPoints.at(i); - if (accessPoint->connectionInterface()->path() == path) { accessPoints.removeOne(accessPoint); if (configuredAccessPoints.contains(accessPoint->connectionInterface()->path())) { // find connection and change state to Defined configuredAccessPoints.remove(accessPoint->connectionInterface()->path()); + for (int i = 0; i < connections.count(); ++i) { QNetworkManagerSettingsConnection *connection = connections.at(i); @@ -705,8 +681,6 @@ void QNetworkManagerEngine::removeAccessPoint(const QString &path) accessPointConfigurations.take(path); if (ptr) { - locker.unlock(); - locker.unlock(); emit configurationRemoved(ptr); locker.relock(); @@ -718,42 +692,9 @@ void QNetworkManagerEngine::removeAccessPoint(const QString &path) } } -void QNetworkManagerEngine::updateAccessPoint(const QMap &map) -{ - QMutexLocker locker(&mutex); - - Q_UNUSED(map) - - QNetworkManagerInterfaceAccessPoint *accessPoint = - qobject_cast(sender()); - if (!accessPoint) - return; - accessPoint->deleteLater(); - for (int i = 0; i < connections.count(); ++i) { - QNetworkManagerSettingsConnection *connection = connections.at(i); - - if (accessPoint->ssid() == connection->getSsid()) { - const QString settingsPath = connection->connectionInterface()->path(); - const QString connectionId = settingsPath; - - QNetworkConfigurationPrivatePointer ptr = - accessPointConfigurations.value(connectionId); - ptr->mutex.lock(); - QNetworkConfiguration::StateFlags flag = QNetworkConfiguration::Defined; - ptr->state = (flag | QNetworkConfiguration::Discovered); - ptr->mutex.unlock(); - - locker.unlock(); - emit configurationChanged(ptr); - return; - } - } -} - QNetworkConfigurationPrivate *QNetworkManagerEngine::parseConnection(const QString &settingsPath, const QNmSettingsMap &map) { - // Q_UNUSED(service); QMutexLocker locker(&mutex); QNetworkConfigurationPrivate *cpPriv = new QNetworkConfigurationPrivate; cpPriv->name = map.value("connection").value("id").toString(); @@ -765,17 +706,15 @@ QNetworkConfigurationPrivate *QNetworkManagerEngine::parseConnection(const QStri cpPriv->purpose = QNetworkConfiguration::PublicPurpose; cpPriv->state = QNetworkConfiguration::Defined; - const QString connectionType = map.value("connection").value("type").toString(); if (connectionType == QLatin1String("802-3-ethernet")) { cpPriv->bearerType = QNetworkConfiguration::BearerEthernet; - cpPriv->purpose = QNetworkConfiguration::PublicPurpose; foreach (const QDBusObjectPath &devicePath, managerInterface->getDevices()) { - QNetworkManagerInterfaceDevice device(devicePath.path()); + QNetworkManagerInterfaceDevice device(devicePath.path(),this); if (device.deviceType() == DEVICE_TYPE_ETHERNET) { - QNetworkManagerInterfaceDeviceWired wiredDevice(device.connectionInterface()->path()); + QNetworkManagerInterfaceDeviceWired wiredDevice(device.connectionInterface()->path(),this); if (wiredDevice.carrier()) { cpPriv->state |= QNetworkConfiguration::Discovered; break; @@ -786,12 +725,6 @@ QNetworkConfigurationPrivate *QNetworkManagerEngine::parseConnection(const QStri cpPriv->bearerType = QNetworkConfiguration::BearerWLAN; const QString connectionSsid = map.value("802-11-wireless").value("ssid").toString(); - const QString connectionSecurity = map.value("802-11-wireless").value("security").toString(); - if (!connectionSecurity.isEmpty()) { - cpPriv->purpose = QNetworkConfiguration::PrivatePurpose; - } else { - cpPriv->purpose = QNetworkConfiguration::PublicPurpose; - } for (int i = 0; i < accessPoints.count(); ++i) { if (connectionSsid == accessPoints.at(i)->ssid() && map.value("802-11-wireless").value("seen-bssids").toStringList().contains(accessPoints.at(i)->hwAddress())) { @@ -813,31 +746,11 @@ QNetworkConfigurationPrivate *QNetworkManagerEngine::parseConnection(const QStri } } } else if (connectionType == QLatin1String("gsm")) { - - foreach (const QDBusObjectPath &devicePath, managerInterface->getDevices()) { - QNetworkManagerInterfaceDevice device(devicePath.path()); - - if (device.deviceType() == DEVICE_TYPE_MODEM) { - QNetworkManagerInterfaceDeviceModem deviceModem(device.connectionInterface()->path(),this); - switch (deviceModem.currentCapabilities()) { - case 2: - cpPriv->bearerType = QNetworkConfiguration::Bearer2G; - break; - case 4: - cpPriv->bearerType = QNetworkConfiguration::Bearer3G; - break; - case 8: - cpPriv->bearerType = QNetworkConfiguration::Bearer4G; - break; - default: - cpPriv->bearerType = QNetworkConfiguration::BearerUnknown; - break; - }; - } + cpPriv->bearerType = currentBearerType(); + if (map.value("connection").contains("timestamp")) { + cpPriv->state |= QNetworkConfiguration::Discovered; } - - cpPriv->purpose = QNetworkConfiguration::PrivatePurpose; - cpPriv->state |= QNetworkConfiguration::Discovered; + cpPriv->name = contextName(map.value("connection").value("id").toString()); } return cpPriv; @@ -857,7 +770,6 @@ QNetworkManagerSettingsConnection *QNetworkManagerEngine::connectionFromId(const QNetworkSession::State QNetworkManagerEngine::sessionStateForId(const QString &id) { QMutexLocker locker(&mutex); - QNetworkConfigurationPrivatePointer ptr = accessPointConfigurations.value(id); if (!ptr) @@ -866,8 +778,8 @@ QNetworkSession::State QNetworkManagerEngine::sessionStateForId(const QString &i if (!ptr->isValid) return QNetworkSession::Invalid; - foreach (const QString &acPath, activeConnections.keys()) { - QNetworkManagerConnectionActive *activeConnection = activeConnections.value(acPath); + foreach (const QString &acPath, activeConnectionsList.keys()) { + QNetworkManagerConnectionActive *activeConnection = activeConnectionsList.value(acPath); const QString identifier = activeConnection->connection().path(); @@ -899,7 +811,7 @@ quint64 QNetworkManagerEngine::bytesWritten(const QString &id) QNetworkConfigurationPrivatePointer ptr = accessPointConfigurations.value(id); if (ptr && (ptr->state & QNetworkConfiguration::Active) == QNetworkConfiguration::Active) { - const QString networkInterface = getInterfaceFromId(id); + const QString networkInterface = connectionInterfaces.value(id); if (!networkInterface.isEmpty()) { const QString devFile = QLatin1String("/sys/class/net/") + networkInterface + @@ -927,7 +839,7 @@ quint64 QNetworkManagerEngine::bytesReceived(const QString &id) QNetworkConfigurationPrivatePointer ptr = accessPointConfigurations.value(id); if (ptr && (ptr->state & QNetworkConfiguration::Active) == QNetworkConfiguration::Active) { - const QString networkInterface = getInterfaceFromId(id); + const QString networkInterface = connectionInterfaces.value(id); if (!networkInterface.isEmpty()) { const QString devFile = QLatin1String("/sys/class/net/") + networkInterface + @@ -977,6 +889,54 @@ QNetworkConfigurationPrivatePointer QNetworkManagerEngine::defaultConfiguration( return QNetworkConfigurationPrivatePointer(); } +void QNetworkManagerEngine::changedModem() +{ + if (ofonoNetwork) + delete ofonoNetwork; + + ofonoNetwork = new QOfonoNetworkRegistrationInterface(ofonoManager->currentModem(),this); + + if (ofonoContextManager) + delete ofonoContextManager; + ofonoContextManager = new QOfonoDataConnectionManagerInterface(ofonoManager->currentModem(),this); +} + +QNetworkConfiguration::BearerType QNetworkManagerEngine::currentBearerType() +{ + if (ofonoContextManager) { + QString bearer = ofonoContextManager->bearer(); + if (bearer == QLatin1String("gsm")) { + return QNetworkConfiguration::Bearer2G; + } else if (bearer == QLatin1String("edge")) { + return QNetworkConfiguration::Bearer2G; + } else if (bearer == QLatin1String("umts")) { + return QNetworkConfiguration::BearerWCDMA; + } else if (bearer == QLatin1String("hspa") + || bearer == QLatin1String("hsdpa") + || bearer == QLatin1String("hsupa")) { + return QNetworkConfiguration::BearerHSPA; + } else if (bearer == QLatin1String("lte")) { + return QNetworkConfiguration::BearerLTE; + } + } + return QNetworkConfiguration::BearerUnknown; +} + +QString QNetworkManagerEngine::contextName(const QString &path) +{ + if (ofonoContextManager) { + QString contextPart = path.section('/', -1); + + Q_FOREACH (const QString &oContext, ofonoContextManager->contexts()) { + if (oContext.contains(contextPart)) { + QOfonoConnectionContextInterface contextInterface(oContext,this); + return contextInterface.name(); + } + } + } + return path; +} + QT_END_NAMESPACE #endif // QT_NO_DBUS diff --git a/src/plugins/bearer/networkmanager/qnetworkmanagerengine.h b/src/plugins/bearer/networkmanager/qnetworkmanagerengine.h index ab1cfea71e..d2ef9886a3 100644 --- a/src/plugins/bearer/networkmanager/qnetworkmanagerengine.h +++ b/src/plugins/bearer/networkmanager/qnetworkmanagerengine.h @@ -49,6 +49,8 @@ #include "qnetworkmanagerservice.h" +#include "../linux_common/qofonoservice_linux_p.h" + #include #include @@ -89,11 +91,8 @@ public: QNetworkConfigurationPrivatePointer defaultConfiguration(); private Q_SLOTS: - void interfacePropertiesChanged(const QString &path, - const QMap &properties); - void activeConnectionPropertiesChanged(const QString &path, - const QMap &properties); - void devicePropertiesChanged(const QString &path, quint32); + void interfacePropertiesChanged(const QMap &properties); + void activeConnectionPropertiesChanged(const QMap &properties); void deviceAdded(const QDBusObjectPath &path); void deviceRemoved(const QDBusObjectPath &path); @@ -106,8 +105,8 @@ private Q_SLOTS: void newAccessPoint(const QString &path); void removeAccessPoint(const QString &path); - void updateAccessPoint(const QMap &map); void scanFinished(); + void changedModem(); private: QNetworkConfigurationPrivate *parseConnection(const QString &settingsPath, @@ -116,14 +115,21 @@ private: QNetworkManagerInterface *managerInterface; QNetworkManagerSettings *systemSettings; - QNetworkManagerSettings *userSettings; QHash wirelessDevices; - QHash activeConnections; + QHash activeConnectionsList; QList connections; QList accessPoints; QHash interfaceDevices; QMap configuredAccessPoints; //ap, settings path + QHash connectionInterfaces; // ac, interface + + QOfonoManagerInterface *ofonoManager; + QOfonoNetworkRegistrationInterface *ofonoNetwork; + QOfonoDataConnectionManagerInterface *ofonoContextManager; + QNetworkConfiguration::BearerType currentBearerType(); + QString contextName(const QString &path); + }; QT_END_NAMESPACE diff --git a/src/plugins/bearer/networkmanager/qnetworkmanagerservice.cpp b/src/plugins/bearer/networkmanager/qnetworkmanagerservice.cpp index f249ac6100..2d54fa3029 100644 --- a/src/plugins/bearer/networkmanager/qnetworkmanagerservice.cpp +++ b/src/plugins/bearer/networkmanager/qnetworkmanagerservice.cpp @@ -44,7 +44,6 @@ #include #include "qnetworkmanagerservice.h" -#include "qnmdbushelper.h" #ifndef QT_NO_DBUS @@ -64,18 +63,38 @@ QNetworkManagerInterface::QNetworkManagerInterface(QObject *parent) d->connectionInterface = new QDBusInterface(QLatin1String(NM_DBUS_SERVICE), QLatin1String(NM_DBUS_PATH), QLatin1String(NM_DBUS_INTERFACE), - QDBusConnection::systemBus()); + QDBusConnection::systemBus(),parent); if (!d->connectionInterface->isValid()) { d->valid = false; return; } d->valid = true; - nmDBusHelper = new QNmDBusHelper(this); - connect(nmDBusHelper, SIGNAL(pathForPropertiesChanged(QString,QMap)), - this,SIGNAL(propertiesChanged(QString,QMap))); - connect(nmDBusHelper,SIGNAL(pathForStateChanged(QString,quint32)), - this, SIGNAL(stateChanged(QString,quint32))); + QDBusInterface managerPropertiesInterface(QLatin1String(NM_DBUS_SERVICE), + QLatin1String(NM_DBUS_PATH), + QLatin1String("org.freedesktop.DBus.Properties"), + QDBusConnection::systemBus()); + QList argumentList; + argumentList << QLatin1String(NM_DBUS_INTERFACE); + QDBusPendingReply propsReply + = managerPropertiesInterface.callWithArgumentList(QDBus::Block,QLatin1String("GetAll"), + argumentList); + if (!propsReply.isError()) { + propertyMap = propsReply.value(); + } + + QDBusPendingReply > nmReply + = d->connectionInterface->call(QLatin1String("GetDevices")); + nmReply.waitForFinished(); + if (!nmReply.isError()) { + devicesPathList = nmReply.value(); + } + + QDBusConnection::systemBus().connect(QLatin1String(NM_DBUS_SERVICE), + QLatin1String(NM_DBUS_PATH), + QLatin1String(NM_DBUS_INTERFACE), + QLatin1String("PropertiesChanged"), + this,SLOT(propertiesSwap(QMap))); } QNetworkManagerInterface::~QNetworkManagerInterface() @@ -91,27 +110,24 @@ bool QNetworkManagerInterface::isValid() bool QNetworkManagerInterface::setConnections() { - if(!isValid() ) + if (!isValid()) return false; - QDBusConnection dbusConnection = QDBusConnection::systemBus(); - - bool allOk = false; - if (dbusConnection.connect(QLatin1String(NM_DBUS_SERVICE), + QDBusConnection::systemBus().connect(QLatin1String(NM_DBUS_SERVICE), QLatin1String(NM_DBUS_PATH), QLatin1String(NM_DBUS_INTERFACE), QLatin1String("PropertiesChanged"), - nmDBusHelper,SLOT(slotPropertiesChanged(QMap)))) { - allOk = true; - } - if (dbusConnection.connect(QLatin1String(NM_DBUS_SERVICE), + this,SLOT(propertiesSwap(QMap))); + + bool allOk = false; + if (QDBusConnection::systemBus().connect(QLatin1String(NM_DBUS_SERVICE), QLatin1String(NM_DBUS_PATH), QLatin1String(NM_DBUS_INTERFACE), QLatin1String("DeviceAdded"), this,SIGNAL(deviceAdded(QDBusObjectPath)))) { allOk = true; } - if (dbusConnection.connect(QLatin1String(NM_DBUS_SERVICE), + if (QDBusConnection::systemBus().connect(QLatin1String(NM_DBUS_SERVICE), QLatin1String(NM_DBUS_PATH), QLatin1String(NM_DBUS_INTERFACE), QLatin1String("DeviceRemoved"), @@ -127,14 +143,17 @@ QDBusInterface *QNetworkManagerInterface::connectionInterface() const return d->connectionInterface; } -QList QNetworkManagerInterface::getDevices() const +QList QNetworkManagerInterface::getDevices() { - QDBusReply > reply = d->connectionInterface->call(QLatin1String("GetDevices")); - return reply.value(); + if (devicesPathList.isEmpty()) { + qWarning() << "using blocking call!"; + QDBusReply > reply = d->connectionInterface->call(QLatin1String("GetDevices")); + devicesPathList = reply.value(); + } + return devicesPathList; } -void QNetworkManagerInterface::activateConnection( const QString &, - QDBusObjectPath connectionPath, +void QNetworkManagerInterface::activateConnection(QDBusObjectPath connectionPath, QDBusObjectPath devicePath, QDBusObjectPath specificObject) { @@ -150,28 +169,80 @@ void QNetworkManagerInterface::activateConnection( const QString &, void QNetworkManagerInterface::deactivateConnection(QDBusObjectPath connectionPath) const { - d->connectionInterface->call(QLatin1String("DeactivateConnection"), QVariant::fromValue(connectionPath)); + d->connectionInterface->asyncCall(QLatin1String("DeactivateConnection"), QVariant::fromValue(connectionPath)); } bool QNetworkManagerInterface::wirelessEnabled() const { - return d->connectionInterface->property("WirelessEnabled").toBool(); + if (propertyMap.contains("WirelessEnabled")) + return propertyMap.value("WirelessEnabled").toBool(); + return false; } bool QNetworkManagerInterface::wirelessHardwareEnabled() const { - return d->connectionInterface->property("WirelessHardwareEnabled").toBool(); + if (propertyMap.contains("WirelessHardwareEnabled")) + return propertyMap.value("WirelessHardwareEnabled").toBool(); + return false; } QList QNetworkManagerInterface::activeConnections() const { - QVariant prop = d->connectionInterface->property("ActiveConnections"); - return prop.value >(); + if (propertyMap.contains("ActiveConnections")) { + + const QDBusArgument &dbusArgs = propertyMap.value("ActiveConnections").value(); + QDBusObjectPath path; + QList list; + + dbusArgs.beginArray(); + while (!dbusArgs.atEnd()) { + dbusArgs >> path; + list.append(path); + } + dbusArgs.endArray(); + + return list; + } + + QList list; + list << QDBusObjectPath(); + return list; } -quint32 QNetworkManagerInterface::state() +QNetworkManagerInterface::NMState QNetworkManagerInterface::state() { - return d->connectionInterface->property("State").toUInt(); + if (propertyMap.contains("State")) + return static_cast(propertyMap.value("State").toUInt()); + return QNetworkManagerInterface::NM_STATE_UNKNOWN; +} + +QString QNetworkManagerInterface::version() const +{ + if (propertyMap.contains("Version")) + return propertyMap.value("Version").toString(); + return QString(); +} + +void QNetworkManagerInterface::propertiesSwap(QMap map) +{ + QMapIterator i(map); + while (i.hasNext()) { + i.next(); + propertyMap.insert(i.key(),i.value()); + + if (i.key() == QStringLiteral("State")) { + quint32 state = i.value().toUInt(); + if (state == NM_DEVICE_STATE_ACTIVATED + || state == NM_DEVICE_STATE_DISCONNECTED + || state == NM_DEVICE_STATE_UNAVAILABLE + || state == NM_DEVICE_STATE_FAILED) { + Q_EMIT propertiesChanged(map); + Q_EMIT stateChanged(state); + } + } else if (i.key() == QStringLiteral("ActiveConnections")) { + Q_EMIT propertiesChanged(map); + } + } } class QNetworkManagerInterfaceAccessPointPrivate @@ -183,18 +254,38 @@ public: }; QNetworkManagerInterfaceAccessPoint::QNetworkManagerInterfaceAccessPoint(const QString &dbusPathName, QObject *parent) - : QObject(parent), nmDBusHelper(0) + : QObject(parent) { d = new QNetworkManagerInterfaceAccessPointPrivate(); d->path = dbusPathName; d->connectionInterface = new QDBusInterface(QLatin1String(NM_DBUS_SERVICE), d->path, QLatin1String(NM_DBUS_INTERFACE_ACCESS_POINT), - QDBusConnection::systemBus()); + QDBusConnection::systemBus(),parent); if (!d->connectionInterface->isValid()) { d->valid = false; return; } + QDBusInterface accessPointPropertiesInterface(QLatin1String(NM_DBUS_SERVICE), + d->path, + QLatin1String("org.freedesktop.DBus.Properties"), + QDBusConnection::systemBus()); + + QList argumentList; + argumentList << QLatin1String(NM_DBUS_INTERFACE_ACCESS_POINT); + QDBusPendingReply propsReply + = accessPointPropertiesInterface.callWithArgumentList(QDBus::Block,QLatin1String("GetAll"), + argumentList); + if (!propsReply.isError()) { + propertyMap = propsReply.value(); + } + + QDBusConnection::systemBus().connect(QLatin1String(NM_DBUS_SERVICE), + d->path, + QLatin1String(NM_DBUS_INTERFACE_ACCESS_POINT), + QLatin1String("PropertiesChanged"), + this,SLOT(propertiesSwap(QMap))); + d->valid = true; } @@ -212,24 +303,10 @@ bool QNetworkManagerInterfaceAccessPoint::isValid() bool QNetworkManagerInterfaceAccessPoint::setConnections() { - if(!isValid() ) + if (!isValid()) return false; - bool allOk = false; - delete nmDBusHelper; - nmDBusHelper = new QNmDBusHelper(this); - connect(nmDBusHelper, SIGNAL(pathForPropertiesChanged(QString,QMap)), - this,SIGNAL(propertiesChanged(QString,QMap))); - - if (QDBusConnection::systemBus().connect(QLatin1String(NM_DBUS_SERVICE), - d->path, - QLatin1String(NM_DBUS_INTERFACE_ACCESS_POINT), - QLatin1String("PropertiesChanged"), - nmDBusHelper,SLOT(slotPropertiesChanged(QMap))) ) { - allOk = true; - - } - return allOk; + return true; } QDBusInterface *QNetworkManagerInterfaceAccessPoint::connectionInterface() const @@ -239,47 +316,74 @@ QDBusInterface *QNetworkManagerInterfaceAccessPoint::connectionInterface() const quint32 QNetworkManagerInterfaceAccessPoint::flags() const { - return d->connectionInterface->property("Flags").toUInt(); + if (propertyMap.contains("Flags")) + return propertyMap.value("Flags").toUInt(); + return 0; } quint32 QNetworkManagerInterfaceAccessPoint::wpaFlags() const { - return d->connectionInterface->property("WpaFlags").toUInt(); + if (propertyMap.contains("WpaFlags")) + return propertyMap.value("WpaFlags").toUInt(); + return 0; } quint32 QNetworkManagerInterfaceAccessPoint::rsnFlags() const { - return d->connectionInterface->property("RsnFlags").toUInt(); + if (propertyMap.contains("RsnFlags")) + return propertyMap.value("RsnFlags").toUInt(); + return 0; } QString QNetworkManagerInterfaceAccessPoint::ssid() const { - return d->connectionInterface->property("Ssid").toString(); + if (propertyMap.contains("Ssid")) + return propertyMap.value("Ssid").toString(); + return QString(); } quint32 QNetworkManagerInterfaceAccessPoint::frequency() const { - return d->connectionInterface->property("Frequency").toUInt(); + if (propertyMap.contains("Frequency")) + return propertyMap.value("Frequency").toUInt(); + return 0; } QString QNetworkManagerInterfaceAccessPoint::hwAddress() const { - return d->connectionInterface->property("HwAddress").toString(); + if (propertyMap.contains("HwAddress")) + return propertyMap.value("HwAddress").toString(); + return QString(); } quint32 QNetworkManagerInterfaceAccessPoint::mode() const { - return d->connectionInterface->property("Mode").toUInt(); + if (propertyMap.contains("Mode")) + return propertyMap.value("Mode").toUInt(); + return 0; } quint32 QNetworkManagerInterfaceAccessPoint::maxBitrate() const { - return d->connectionInterface->property("MaxBitrate").toUInt(); + if (propertyMap.contains("MaxBitrate")) + return propertyMap.value("MaxBitrate").toUInt(); + return 0; } quint32 QNetworkManagerInterfaceAccessPoint::strength() const { - return d->connectionInterface->property("Strength").toUInt(); + if (propertyMap.contains("Strength")) + return propertyMap.value("Strength").toUInt(); + return 0; +} + +void QNetworkManagerInterfaceAccessPoint::propertiesSwap(QMap map) +{ + QMapIterator i(map); + while (i.hasNext()) { + i.next(); + propertyMap.insert(i.key(),i.value()); + } } class QNetworkManagerInterfaceDevicePrivate @@ -291,18 +395,39 @@ public: }; QNetworkManagerInterfaceDevice::QNetworkManagerInterfaceDevice(const QString &deviceObjectPath, QObject *parent) - : QObject(parent), nmDBusHelper(0) + : QObject(parent) { + d = new QNetworkManagerInterfaceDevicePrivate(); d->path = deviceObjectPath; d->connectionInterface = new QDBusInterface(QLatin1String(NM_DBUS_SERVICE), d->path, QLatin1String(NM_DBUS_INTERFACE_DEVICE), - QDBusConnection::systemBus()); + QDBusConnection::systemBus(),parent); if (!d->connectionInterface->isValid()) { d->valid = false; return; } + QDBusInterface devicePropertiesInterface(QLatin1String(NM_DBUS_SERVICE), + d->path, + QLatin1String("org.freedesktop.DBus.Properties"), + QDBusConnection::systemBus(),parent); + + QList argumentList; + argumentList << QLatin1String(NM_DBUS_INTERFACE_DEVICE); + QDBusPendingReply propsReply + = devicePropertiesInterface.callWithArgumentList(QDBus::Block,QLatin1String("GetAll"), + argumentList); + + if (!propsReply.isError()) { + propertyMap = propsReply.value(); + } + + QDBusConnection::systemBus().connect(QLatin1String(NM_DBUS_SERVICE), + d->path, + QLatin1String(NM_DBUS_INTERFACE_DEVICE), + QLatin1String("PropertiesChanged"), + this,SLOT(propertiesSwap(QMap))); d->valid = true; } @@ -319,35 +444,10 @@ bool QNetworkManagerInterfaceDevice::isValid() bool QNetworkManagerInterfaceDevice::setConnections() { - if(!isValid() ) + if (!isValid()) return false; - bool allOk = true; - delete nmDBusHelper; - nmDBusHelper = new QNmDBusHelper(this); - connect(nmDBusHelper,SIGNAL(pathForStateChanged(QString,quint32)), - this, SIGNAL(stateChanged(QString,quint32))); - - if (QDBusConnection::systemBus().connect(QLatin1String(NM_DBUS_SERVICE), - d->path, - QLatin1String(NM_DBUS_INTERFACE_DEVICE), - QLatin1String("StateChanged"), - nmDBusHelper,SLOT(deviceStateChanged(quint32)))) { - allOk = false; - } - - connect(nmDBusHelper, SIGNAL(pathForConnectionsChanged(QStringList)), - this,SIGNAL(connectionsChanged(QStringList))); - - if (QDBusConnection::systemBus().connect(QLatin1String(NM_DBUS_SERVICE), - d->path, - QLatin1String(NM_DBUS_INTERFACE_ACCESS_POINT), - QLatin1String("PropertiesChanged"), - nmDBusHelper,SLOT(slotPropertiesChanged(QMap))) ) { - allOk = false; - } - - return allOk; + return true; } QDBusInterface *QNetworkManagerInterfaceDevice::connectionInterface() const @@ -357,33 +457,66 @@ QDBusInterface *QNetworkManagerInterfaceDevice::connectionInterface() const QString QNetworkManagerInterfaceDevice::udi() const { - return d->connectionInterface->property("Udi").toString(); + if (propertyMap.contains("Udi")) + return propertyMap.value("Udi").toString(); + return QString(); } QString QNetworkManagerInterfaceDevice::networkInterface() const { - return d->connectionInterface->property("Interface").toString(); + if (propertyMap.contains("Interface")) + return propertyMap.value("Interface").toString(); + return QString(); } quint32 QNetworkManagerInterfaceDevice::ip4Address() const { - return d->connectionInterface->property("Ip4Address").toUInt(); + if (propertyMap.contains("Ip4Address")) + return propertyMap.value("Ip4Address").toUInt(); + return 0; } quint32 QNetworkManagerInterfaceDevice::state() const { - return d->connectionInterface->property("State").toUInt(); + if (propertyMap.contains("State")) + return propertyMap.value("State").toUInt(); + return 0; } quint32 QNetworkManagerInterfaceDevice::deviceType() const { - return d->connectionInterface->property("DeviceType").toUInt(); + if (propertyMap.contains("DeviceType")) + return propertyMap.value("DeviceType").toUInt(); + return 0; } QDBusObjectPath QNetworkManagerInterfaceDevice::ip4config() const { - QVariant prop = d->connectionInterface->property("Ip4Config"); - return prop.value(); + if (propertyMap.contains("Ip4Config")) + return propertyMap.value("Ip4Config").value(); + return QDBusObjectPath(); +} + +void QNetworkManagerInterfaceDevice::propertiesSwap(QMap map) +{ + QMapIterator i(map); + while (i.hasNext()) { + i.next(); + if (i.key() == QStringLiteral("AvailableConnections")) { //Device + const QDBusArgument &dbusArgs = i.value().value(); + QDBusObjectPath path; + QStringList paths; + dbusArgs.beginArray(); + while (!dbusArgs.atEnd()) { + dbusArgs >> path; + paths << path.path(); + } + dbusArgs.endArray(); + Q_EMIT connectionsChanged(paths); + } + propertyMap.insert(i.key(),i.value()); + } + Q_EMIT propertiesChanged(map); } class QNetworkManagerInterfaceDeviceWiredPrivate @@ -395,7 +528,7 @@ public: }; QNetworkManagerInterfaceDeviceWired::QNetworkManagerInterfaceDeviceWired(const QString &ifaceDevicePath, QObject *parent) - : QObject(parent), nmDBusHelper(0) + : QObject(parent) { d = new QNetworkManagerInterfaceDeviceWiredPrivate(); d->path = ifaceDevicePath; @@ -407,6 +540,27 @@ QNetworkManagerInterfaceDeviceWired::QNetworkManagerInterfaceDeviceWired(const Q d->valid = false; return; } + QDBusInterface deviceWiredPropertiesInterface(QLatin1String(NM_DBUS_SERVICE), + d->path, + QLatin1String("org.freedesktop.DBus.Properties"), + QDBusConnection::systemBus(),parent); + + QList argumentList; + argumentList << QLatin1String(NM_DBUS_INTERFACE_DEVICE_WIRED); + QDBusPendingReply propsReply + = deviceWiredPropertiesInterface.callWithArgumentList(QDBus::Block,QLatin1String("GetAll"), + argumentList); + + if (!propsReply.isError()) { + propertyMap = propsReply.value(); + } + + QDBusConnection::systemBus().connect(QLatin1String(NM_DBUS_SERVICE), + d->path, + QLatin1String(NM_DBUS_INTERFACE_DEVICE_WIRED), + QLatin1String("PropertiesChanged"), + this,SLOT(propertiesSwap(QMap))); + d->valid = true; } @@ -424,23 +578,9 @@ bool QNetworkManagerInterfaceDeviceWired::isValid() bool QNetworkManagerInterfaceDeviceWired::setConnections() { - if(!isValid() ) + if (!isValid()) return false; - - bool allOk = true; - - delete nmDBusHelper; - nmDBusHelper = new QNmDBusHelper(this); - connect(nmDBusHelper, SIGNAL(pathForPropertiesChanged(QString,QMap)), - this,SIGNAL(propertiesChanged(QString,QMap))); - if (!QDBusConnection::systemBus().connect(QLatin1String(NM_DBUS_SERVICE), - d->path, - QLatin1String(NM_DBUS_INTERFACE_DEVICE_WIRED), - QLatin1String("PropertiesChanged"), - nmDBusHelper,SLOT(slotPropertiesChanged(QMap))) ) { - allOk = false; - } - return allOk; + return true; } QDBusInterface *QNetworkManagerInterfaceDeviceWired::connectionInterface() const @@ -450,17 +590,33 @@ QDBusInterface *QNetworkManagerInterfaceDeviceWired::connectionInterface() const QString QNetworkManagerInterfaceDeviceWired::hwAddress() const { - return d->connectionInterface->property("HwAddress").toString(); + if (propertyMap.contains("HwAddress")) + return propertyMap.value("HwAddress").toString(); + return QString(); } quint32 QNetworkManagerInterfaceDeviceWired::speed() const { - return d->connectionInterface->property("Speed").toUInt(); + if (propertyMap.contains("Speed")) + return propertyMap.value("Speed").toUInt(); + return 0; } bool QNetworkManagerInterfaceDeviceWired::carrier() const { - return d->connectionInterface->property("Carrier").toBool(); + if (propertyMap.contains("Carrier")) + return propertyMap.value("Carrier").toBool(); + return false; +} + +void QNetworkManagerInterfaceDeviceWired::propertiesSwap(QMap map) +{ + QMapIterator i(map); + while (i.hasNext()) { + i.next(); + propertyMap.insert(i.key(),i.value()); + } + Q_EMIT propertiesChanged(map); } class QNetworkManagerInterfaceDeviceWirelessPrivate @@ -472,7 +628,7 @@ public: }; QNetworkManagerInterfaceDeviceWireless::QNetworkManagerInterfaceDeviceWireless(const QString &ifaceDevicePath, QObject *parent) - : QObject(parent), nmDBusHelper(0) + : QObject(parent) { d = new QNetworkManagerInterfaceDeviceWirelessPrivate(); d->path = ifaceDevicePath; @@ -484,6 +640,34 @@ QNetworkManagerInterfaceDeviceWireless::QNetworkManagerInterfaceDeviceWireless(c d->valid = false; return; } + + + QDBusPendingReply > nmReply + = d->connectionInterface->call(QLatin1String("GetAccessPoints")); + + if (!nmReply.isError()) { + accessPointsList = nmReply.value(); + } + + QDBusInterface deviceWirelessPropertiesInterface(QLatin1String(NM_DBUS_SERVICE), + d->path, + QLatin1String("org.freedesktop.DBus.Properties"), + QDBusConnection::systemBus(),parent); + + QList argumentList; + argumentList << QLatin1String(NM_DBUS_INTERFACE_DEVICE_WIRELESS); + QDBusPendingReply propsReply + = deviceWirelessPropertiesInterface.callWithArgumentList(QDBus::Block,QLatin1String("GetAll"), + argumentList); + if (!propsReply.isError()) { + propertyMap = propsReply.value(); + } + + QDBusConnection::systemBus().connect(QLatin1String(NM_DBUS_SERVICE), + d->path, + QLatin1String(NM_DBUS_INTERFACE_DEVICE_WIRELESS), + QLatin1String("PropertiesChanged"), + this,SLOT(propertiesSwap(QMap))); d->valid = true; } @@ -498,29 +682,31 @@ bool QNetworkManagerInterfaceDeviceWireless::isValid() return d->valid; } +void QNetworkManagerInterfaceDeviceWireless::slotAccessPointAdded(QDBusObjectPath path) +{ + if (path.path().length() > 2) + Q_EMIT accessPointAdded(path.path()); +} + +void QNetworkManagerInterfaceDeviceWireless::slotAccessPointRemoved(QDBusObjectPath path) +{ + if (path.path().length() > 2) + Q_EMIT accessPointRemoved(path.path()); +} + bool QNetworkManagerInterfaceDeviceWireless::setConnections() { - if(!isValid() ) + if (!isValid()) return false; QDBusConnection dbusConnection = QDBusConnection::systemBus(); bool allOk = true; - delete nmDBusHelper; - nmDBusHelper = new QNmDBusHelper(this); - connect(nmDBusHelper, SIGNAL(pathForPropertiesChanged(QString,QMap)), - this,SIGNAL(propertiesChanged(QString,QMap))); - - connect(nmDBusHelper, SIGNAL(pathForAccessPointAdded(QString)), - this,SIGNAL(accessPointAdded(QString))); - - connect(nmDBusHelper, SIGNAL(pathForAccessPointRemoved(QString)), - this,SIGNAL(accessPointRemoved(QString))); if (!dbusConnection.connect(QLatin1String(NM_DBUS_SERVICE), - d->path, + d->path, QLatin1String(NM_DBUS_INTERFACE_DEVICE_WIRELESS), QLatin1String("AccessPointAdded"), - nmDBusHelper, SLOT(slotAccessPointAdded(QDBusObjectPath)))) { + this, SLOT(slotAccessPointAdded(QDBusObjectPath)))) { allOk = false; } @@ -529,18 +715,10 @@ bool QNetworkManagerInterfaceDeviceWireless::setConnections() d->path, QLatin1String(NM_DBUS_INTERFACE_DEVICE_WIRELESS), QLatin1String("AccessPointRemoved"), - nmDBusHelper, SLOT(slotAccessPointRemoved(QDBusObjectPath)))) { + this, SLOT(slotAccessPointRemoved(QDBusObjectPath)))) { allOk = false; } - - if (!dbusConnection.connect(QLatin1String(NM_DBUS_SERVICE), - d->path, - QLatin1String(NM_DBUS_INTERFACE_DEVICE_WIRELESS), - QLatin1String("PropertiesChanged"), - nmDBusHelper,SLOT(slotPropertiesChanged(QMap)))) { - allOk = false; - } if (!dbusConnection.connect(QLatin1String(NM_DBUS_SERVICE), d->path, QLatin1String(NM_DBUS_INTERFACE_DEVICE_WIRELESS), @@ -558,33 +736,48 @@ QDBusInterface *QNetworkManagerInterfaceDeviceWireless::connectionInterface() co QList QNetworkManagerInterfaceDeviceWireless::getAccessPoints() { - QDBusReply > reply = d->connectionInterface->call(QLatin1String("GetAccessPoints")); - return reply.value(); + if (accessPointsList.isEmpty()) { + qWarning() << "Using blocking call!"; + QDBusReply > reply + = d->connectionInterface->call(QLatin1String("GetAccessPoints")); + accessPointsList = reply.value(); + } + return accessPointsList; } QString QNetworkManagerInterfaceDeviceWireless::hwAddress() const { - return d->connectionInterface->property("HwAddress").toString(); + if (propertyMap.contains("HwAddress")) + return propertyMap.value("HwAddress").toString(); + return QString(); } quint32 QNetworkManagerInterfaceDeviceWireless::mode() const { - return d->connectionInterface->property("Mode").toUInt(); + if (propertyMap.contains("Mode")) + return propertyMap.value("Mode").toUInt(); + return 0; } quint32 QNetworkManagerInterfaceDeviceWireless::bitrate() const { - return d->connectionInterface->property("Bitrate").toUInt(); + if (propertyMap.contains("Bitrate")) + return propertyMap.value("Bitrate").toUInt(); + return 0; } QDBusObjectPath QNetworkManagerInterfaceDeviceWireless::activeAccessPoint() const { - return d->connectionInterface->property("ActiveAccessPoint").value(); + if (propertyMap.contains("ActiveAccessPoint")) + return propertyMap.value("ActiveAccessPoint").value(); + return QDBusObjectPath(); } quint32 QNetworkManagerInterfaceDeviceWireless::wirelessCapabilities() const { - return d->connectionInterface->property("WirelelessCapabilities").toUInt(); + if (propertyMap.contains("WirelelessCapabilities")) + return propertyMap.value("WirelelessCapabilities").toUInt(); + return 0; } void QNetworkManagerInterfaceDeviceWireless::scanIsDone() @@ -597,6 +790,17 @@ void QNetworkManagerInterfaceDeviceWireless::requestScan() d->connectionInterface->asyncCall(QLatin1String("RequestScan")); } +void QNetworkManagerInterfaceDeviceWireless::propertiesSwap(QMap map) +{ + QMapIterator i(map); + while (i.hasNext()) { + i.next(); + propertyMap.insert(i.key(),i.value()); + if (i.key() == QStringLiteral("ActiveAccessPoint")) { //DeviceWireless + Q_EMIT propertiesChanged(map); + } + } +} class QNetworkManagerInterfaceDeviceModemPrivate { @@ -607,7 +811,7 @@ public: }; QNetworkManagerInterfaceDeviceModem::QNetworkManagerInterfaceDeviceModem(const QString &ifaceDevicePath, QObject *parent) - : QObject(parent), nmDBusHelper(0) + : QObject(parent) { d = new QNetworkManagerInterfaceDeviceModemPrivate(); d->path = ifaceDevicePath; @@ -619,6 +823,25 @@ QNetworkManagerInterfaceDeviceModem::QNetworkManagerInterfaceDeviceModem(const Q d->valid = false; return; } + QDBusInterface deviceModemPropertiesInterface(QLatin1String(NM_DBUS_SERVICE), + d->path, + QLatin1String("org.freedesktop.DBus.Properties"), + QDBusConnection::systemBus(),parent); + + QList argumentList; + argumentList << QLatin1String(NM_DBUS_INTERFACE_DEVICE_MODEM); + QDBusPendingReply propsReply + = deviceModemPropertiesInterface.callWithArgumentList(QDBus::Block,QLatin1String("GetAll"), + argumentList); + if (!propsReply.isError()) { + propertyMap = propsReply.value(); + } + + QDBusConnection::systemBus().connect(QLatin1String(NM_DBUS_SERVICE), + d->path, + QLatin1String(NM_DBUS_INTERFACE_DEVICE_MODEM), + QLatin1String("PropertiesChanged"), + this,SLOT(propertiesSwap(QMap))); d->valid = true; } @@ -639,20 +862,7 @@ bool QNetworkManagerInterfaceDeviceModem::setConnections() if (!isValid() ) return false; - bool allOk = true; - - delete nmDBusHelper; - nmDBusHelper = new QNmDBusHelper(this); - connect(nmDBusHelper, SIGNAL(pathForPropertiesChanged(QString,QMap)), - this,SIGNAL(propertiesChanged(QString,QMap))); - if (!QDBusConnection::systemBus().connect(QLatin1String(NM_DBUS_SERVICE), - d->path, - QLatin1String(NM_DBUS_INTERFACE_DEVICE_MODEM), - QLatin1String("PropertiesChanged"), - nmDBusHelper,SLOT(slotDevicePropertiesChanged(QMap))) ) { - allOk = false; - } - return allOk; + return true; } QDBusInterface *QNetworkManagerInterfaceDeviceModem::connectionInterface() const @@ -660,14 +870,28 @@ QDBusInterface *QNetworkManagerInterfaceDeviceModem::connectionInterface() const return d->connectionInterface; } -quint32 QNetworkManagerInterfaceDeviceModem::modemCapabilities() const +QNetworkManagerInterfaceDeviceModem::ModemCapabilities QNetworkManagerInterfaceDeviceModem::modemCapabilities() const { - return d->connectionInterface->property("ModemCapabilities").toUInt(); + if (propertyMap.contains("ModemCapabilities")) + return static_cast(propertyMap.value("ModemCapabilities").toUInt()); + return QNetworkManagerInterfaceDeviceModem::None; } -quint32 QNetworkManagerInterfaceDeviceModem::currentCapabilities() const +QNetworkManagerInterfaceDeviceModem::ModemCapabilities QNetworkManagerInterfaceDeviceModem::currentCapabilities() const { - return d->connectionInterface->property("CurrentCapabilities").toUInt(); + if (propertyMap.contains("CurrentCapabilities")) + return static_cast(propertyMap.value("CurrentCapabilities").toUInt()); + return QNetworkManagerInterfaceDeviceModem::None; +} + +void QNetworkManagerInterfaceDeviceModem::propertiesSwap(QMap map) +{ + QMapIterator i(map); + while (i.hasNext()) { + i.next(); + propertyMap.insert(i.key(),i.value()); + } + Q_EMIT propertiesChanged(map); } class QNetworkManagerSettingsPrivate @@ -691,6 +915,14 @@ QNetworkManagerSettings::QNetworkManagerSettings(const QString &settingsService, d->valid = false; return; } + + QDBusPendingReply > nmReply + = d->connectionInterface->call(QLatin1String("ListConnections")); + + if (!nmReply.isError()) { + connectionsList = nmReply.value(); + } + d->valid = true; } @@ -722,10 +954,16 @@ bool QNetworkManagerSettings::setConnections() QList QNetworkManagerSettings::listConnections() { - QDBusReply > reply = d->connectionInterface->call(QLatin1String("ListConnections")); - return reply.value(); + if (connectionsList.isEmpty()) { + qWarning() << "Using blocking call!"; + QDBusReply > reply + = d->connectionInterface->call(QLatin1String("ListConnections")); + connectionsList = reply.value(); + } + return connectionsList; } + QString QNetworkManagerSettings::getConnectionByUuid(const QString &uuid) { QList argumentList; @@ -751,7 +989,7 @@ public: }; QNetworkManagerSettingsConnection::QNetworkManagerSettingsConnection(const QString &settingsService, const QString &connectionObjectPath, QObject *parent) - : QObject(parent), nmDBusHelper(0) + : QObject(parent) { qDBusRegisterMetaType(); d = new QNetworkManagerSettingsConnectionPrivate(); @@ -766,8 +1004,12 @@ QNetworkManagerSettingsConnection::QNetworkManagerSettingsConnection(const QStri return; } d->valid = true; - QDBusReply< QNmSettingsMap > rep = d->connectionInterface->call(QLatin1String("GetSettings")); - d->settingsMap = rep.value(); + + QDBusPendingReply nmReply + = d->connectionInterface->call(QLatin1String("GetSettings")); + if (!nmReply.isError()) { + d->settingsMap = nmReply.value(); + } } QNetworkManagerSettingsConnection::~QNetworkManagerSettingsConnection() @@ -783,7 +1025,7 @@ bool QNetworkManagerSettingsConnection::isValid() bool QNetworkManagerSettingsConnection::setConnections() { - if(!isValid() ) + if (!isValid()) return false; QDBusConnection dbusConnection = QDBusConnection::systemBus(); @@ -796,21 +1038,21 @@ bool QNetworkManagerSettingsConnection::setConnections() allOk = false; } - delete nmDBusHelper; - nmDBusHelper = new QNmDBusHelper(this); - connect(nmDBusHelper, SIGNAL(pathForSettingsRemoved(QString)), - this,SIGNAL(removed(QString))); - if (!dbusConnection.connect(d->service, d->path, QLatin1String(NM_DBUS_IFACE_SETTINGS_CONNECTION), QLatin1String("Removed"), - nmDBusHelper, SIGNAL(slotSettingsRemoved()))) { + this, SIGNAL(slotSettingsRemoved()))) { allOk = false; } return allOk; } +void QNetworkManagerSettingsConnection::slotSettingsRemoved() +{ + Q_EMIT removed(d->path); +} + QDBusInterface *QNetworkManagerSettingsConnection::connectionInterface() const { return d->connectionInterface; @@ -818,8 +1060,11 @@ QDBusInterface *QNetworkManagerSettingsConnection::connectionInterface() const QNmSettingsMap QNetworkManagerSettingsConnection::getSettings() { - QDBusReply< QNmSettingsMap > rep = d->connectionInterface->call(QLatin1String("GetSettings")); - d->settingsMap = rep.value(); + if (d->settingsMap.isEmpty()) { + qWarning() << "Using blocking call!"; + QDBusReply reply = d->connectionInterface->call(QLatin1String("GetSettings")); + d->settingsMap = reply.value(); + } return d->settingsMap; } @@ -832,6 +1077,8 @@ NMDeviceType QNetworkManagerSettingsConnection::getType() return DEVICE_TYPE_ETHERNET; else if (devType == QLatin1String("802-11-wireless")) return DEVICE_TYPE_WIFI; + else if (devType == QLatin1String("gsm")) + return DEVICE_TYPE_MODEM; else return DEVICE_TYPE_UNKNOWN; } @@ -908,7 +1155,7 @@ public: }; QNetworkManagerConnectionActive::QNetworkManagerConnectionActive(const QString &activeConnectionObjectPath, QObject *parent) - : QObject(parent), nmDBusHelper(0) + : QObject(parent) { d = new QNetworkManagerConnectionActivePrivate(); d->path = activeConnectionObjectPath; @@ -920,6 +1167,29 @@ QNetworkManagerConnectionActive::QNetworkManagerConnectionActive(const QString & d->valid = false; return; } + QDBusInterface connectionActivePropertiesInterface(QLatin1String(NM_DBUS_SERVICE), + d->path, + QLatin1String("org.freedesktop.DBus.Properties"), + QDBusConnection::systemBus()); + + + QList argumentList; + argumentList << QLatin1String(NM_DBUS_INTERFACE_ACTIVE_CONNECTION); + QDBusPendingReply propsReply + = connectionActivePropertiesInterface.callWithArgumentList(QDBus::Block,QLatin1String("GetAll"), + argumentList); + + if (!propsReply.isError()) { + propertyMap = propsReply.value(); + } else { + qWarning() << propsReply.error().message(); + } + + QDBusConnection::systemBus().connect(QLatin1String(NM_DBUS_SERVICE), + d->path, + QLatin1String(NM_DBUS_INTERFACE_ACTIVE_CONNECTION), + QLatin1String("PropertiesChanged"), + this,SLOT(propertiesSwap(QMap))); d->valid = true; } @@ -936,24 +1206,10 @@ bool QNetworkManagerConnectionActive::isValid() bool QNetworkManagerConnectionActive::setConnections() { - if(!isValid() ) + if (!isValid()) return false; - bool allOk = true; - delete nmDBusHelper; - nmDBusHelper = new QNmDBusHelper(this); - connect(nmDBusHelper, SIGNAL(pathForPropertiesChanged(QString,QMap)), - this,SIGNAL(propertiesChanged(QString,QMap))); - - if (!QDBusConnection::systemBus().connect(QLatin1String(NM_DBUS_SERVICE), - d->path, - QLatin1String(NM_DBUS_INTERFACE_ACTIVE_CONNECTION), - QLatin1String("PropertiesChanged"), - nmDBusHelper,SLOT(activeConnectionPropertiesChanged(QMap))) ) { - allOk = false; - } - - return allOk; + return true; } QDBusInterface *QNetworkManagerConnectionActive::connectionInterface() const @@ -963,30 +1219,67 @@ QDBusInterface *QNetworkManagerConnectionActive::connectionInterface() const QDBusObjectPath QNetworkManagerConnectionActive::connection() const { - QVariant prop = d->connectionInterface->property("Connection"); - return prop.value(); + if (propertyMap.contains("Connection")) + return propertyMap.value("Connection").value(); + return QDBusObjectPath(); } QDBusObjectPath QNetworkManagerConnectionActive::specificObject() const { - QVariant prop = d->connectionInterface->property("SpecificObject"); - return prop.value(); + if (propertyMap.contains("SpecificObject")) + return propertyMap.value("SpecificObject").value(); + return QDBusObjectPath(); } QList QNetworkManagerConnectionActive::devices() const { - QVariant prop = d->connectionInterface->property("Devices"); - return prop.value >(); + if (propertyMap.contains("Devices")) { + const QDBusArgument &dbusArgs = propertyMap.value("Devices").value(); + QDBusObjectPath path; + QList list; + + dbusArgs.beginArray(); + while (!dbusArgs.atEnd()) { + dbusArgs >> path; + list.append(path); + } + dbusArgs.endArray(); + + return list; + } + QList list; + list << QDBusObjectPath(); + return list; } quint32 QNetworkManagerConnectionActive::state() const { - return d->connectionInterface->property("State").toUInt(); + if (propertyMap.contains("State")) + return propertyMap.value("State").toUInt(); + return 0; } bool QNetworkManagerConnectionActive::defaultRoute() const { - return d->connectionInterface->property("Default").toBool(); + if (propertyMap.contains("Default")) + return propertyMap.value("Default").toBool(); + return false; +} + +void QNetworkManagerConnectionActive::propertiesSwap(QMap map) +{ + QMapIterator i(map); + while (i.hasNext()) { + i.next(); + propertyMap.insert(i.key(),i.value()); + if (i.key() == QStringLiteral("State")) { + quint32 state = i.value().toUInt(); + if (state == NM_ACTIVE_CONNECTION_STATE_ACTIVATED + || state == NM_ACTIVE_CONNECTION_STATE_DEACTIVATED) { + Q_EMIT propertiesChanged(map); + } + } + } } class QNetworkManagerIp4ConfigPrivate diff --git a/src/plugins/bearer/networkmanager/qnetworkmanagerservice.h b/src/plugins/bearer/networkmanager/qnetworkmanagerservice.h index 11ddaf7088..df4e5d49e1 100644 --- a/src/plugins/bearer/networkmanager/qnetworkmanagerservice.h +++ b/src/plugins/bearer/networkmanager/qnetworkmanagerservice.h @@ -56,7 +56,6 @@ #include #include #include -#include "qnmdbushelper.h" #ifndef QT_NO_DBUS @@ -89,7 +88,7 @@ typedef enum NM_ACTIVE_CONNECTION_STATE_UNKNOWN = 0, NM_ACTIVE_CONNECTION_STATE_ACTIVATING, NM_ACTIVE_CONNECTION_STATE_ACTIVATED, - NM_ACTIVE_CONNECTION_STATE_DEACTIVATED + NM_ACTIVE_CONNECTION_STATE_DEACTIVATED = 4 } NMActiveConnectionState; #define NM_DBUS_SERVICE "org.freedesktop.NetworkManager" @@ -135,12 +134,23 @@ class QNetworkManagerInterface : public QObject Q_OBJECT public: + typedef enum + { + NM_STATE_UNKNOWN = 0, + NM_STATE_ASLEEP = 10, + NM_STATE_DISCONNECTED = 20, + NM_STATE_DISCONNECTING = 30, + NM_STATE_CONNECTING = 40, + NM_STATE_CONNECTED_LOCAL = 50, + NM_STATE_CONNECTED_SITE = 60, + NM_STATE_CONNECTED_GLOBAL = 70 + } NMState; QNetworkManagerInterface(QObject *parent = 0); ~QNetworkManagerInterface(); - QList getDevices() const; - void activateConnection(const QString &serviceName, QDBusObjectPath connection, QDBusObjectPath device, QDBusObjectPath specificObject); + QList getDevices(); + void activateConnection(QDBusObjectPath connection,QDBusObjectPath device, QDBusObjectPath specificObject); void deactivateConnection(QDBusObjectPath connectionPath) const; QDBusObjectPath path() const; @@ -149,21 +159,28 @@ public: bool wirelessEnabled() const; bool wirelessHardwareEnabled() const; QList activeConnections() const; - quint32 state(); + NMState state(); + QString version() const; bool setConnections(); bool isValid(); Q_SIGNALS: void deviceAdded(QDBusObjectPath); void deviceRemoved(QDBusObjectPath); - void propertiesChanged( const QString &, QMap); - void stateChanged(const QString&, quint32); + void propertiesChanged(QMap); + void stateChanged(quint32); void activationFinished(QDBusPendingCallWatcher*); + void propertiesReady(); + void devicesListReady(); private Q_SLOTS: + void propertiesSwap(QMap); + private: QNetworkManagerInterfacePrivate *d; - QNmDBusHelper *nmDBusHelper; + QVariantMap propertyMap; + QList devicesPathList; + }; class QNetworkManagerInterfaceAccessPointPrivate; @@ -228,11 +245,14 @@ public: Q_SIGNALS: void propertiesChanged(QMap ); - void propertiesChanged( const QString &, QMap); + void propertiesReady(); + +private Q_SLOTS: + void propertiesSwap(QMap); + private: QNetworkManagerInterfaceAccessPointPrivate *d; - QNmDBusHelper *nmDBusHelper; - + QVariantMap propertyMap; }; class QNetworkManagerInterfaceDevicePrivate; @@ -258,11 +278,14 @@ public: Q_SIGNALS: void stateChanged(const QString &, quint32); - void propertiesChanged(const QString &, QMap); + void propertiesChanged(QMap); void connectionsChanged(QStringList); + void propertiesReady(); +private Q_SLOTS: + void propertiesSwap(QMap); private: QNetworkManagerInterfaceDevicePrivate *d; - QNmDBusHelper *nmDBusHelper; + QVariantMap propertyMap; }; class QNetworkManagerInterfaceDeviceWiredPrivate; @@ -284,10 +307,15 @@ public: bool isValid(); Q_SIGNALS: - void propertiesChanged( const QString &, QMap); + void propertiesChanged(QMap); + void propertiesReady(); + +private Q_SLOTS: + void propertiesSwap(QMap); + private: QNetworkManagerInterfaceDeviceWiredPrivate *d; - QNmDBusHelper *nmDBusHelper; + QVariantMap propertyMap; }; class QNetworkManagerInterfaceDeviceWirelessPrivate; @@ -325,15 +353,24 @@ public: void requestScan(); Q_SIGNALS: - void propertiesChanged( const QString &, QMap); + void propertiesChanged(QMap); void accessPointAdded(const QString &); void accessPointRemoved(const QString &); void scanDone(); + void propertiesReady(); + void accessPointsReady(); + private Q_SLOTS: void scanIsDone(); + void propertiesSwap(QMap); + + void slotAccessPointAdded(QDBusObjectPath); + void slotAccessPointRemoved(QDBusObjectPath); + private: QNetworkManagerInterfaceDeviceWirelessPrivate *d; - QNmDBusHelper *nmDBusHelper; + QVariantMap propertyMap; + QList accessPointsList; }; class QNetworkManagerInterfaceDeviceModemPrivate; @@ -350,6 +387,7 @@ public: Gsm_Umts = 0x4, Lte = 0x08 }; + Q_DECLARE_FLAGS(ModemCapabilities, ModemCapability) explicit QNetworkManagerInterfaceDeviceModem(const QString &ifaceDevicePath, QObject *parent = 0); @@ -361,16 +399,22 @@ public: bool setConnections(); bool isValid(); - quint32 modemCapabilities() const; - quint32 currentCapabilities() const; + ModemCapabilities modemCapabilities() const; + ModemCapabilities currentCapabilities() const; Q_SIGNALS: - void propertiesChanged( const QString &, QMap); + void propertiesChanged(QMap); + void propertiesReady(); + +private Q_SLOTS: + void propertiesSwap(QMap); + private: QNetworkManagerInterfaceDeviceModemPrivate *d; - QNmDBusHelper *nmDBusHelper; + QVariantMap propertyMap; }; +Q_DECLARE_OPERATORS_FOR_FLAGS(QNetworkManagerInterfaceDeviceModem::ModemCapabilities) class QNetworkManagerSettingsPrivate; class QNetworkManagerSettings : public QObject @@ -390,8 +434,10 @@ public: Q_SIGNALS: void newConnection(QDBusObjectPath); + void connectionsListReady(); private: QNetworkManagerSettingsPrivate *d; + QList connectionsList; }; class QNetworkManagerSettingsConnectionPrivate; @@ -418,12 +464,14 @@ public: bool isValid(); Q_SIGNALS: - void updated(); void removed(const QString &path); + void settingsReady(); + +private Q_SLOTS: + void slotSettingsRemoved(); private: - QNmDBusHelper *nmDBusHelper; QNetworkManagerSettingsConnectionPrivate *d; }; @@ -444,7 +492,6 @@ public: ~ QNetworkManagerConnectionActive(); QDBusInterface *connectionInterface() const; - QString serviceName() const; QDBusObjectPath connection() const; QDBusObjectPath specificObject() const; QList devices() const; @@ -455,11 +502,15 @@ public: Q_SIGNALS: - void propertiesChanged(QList); - void propertiesChanged( const QString &, QMap); + void propertiesChanged(QMap); + void propertiesReady(); + +private Q_SLOTS: + void propertiesSwap(QMap); + private: QNetworkManagerConnectionActivePrivate *d; - QNmDBusHelper *nmDBusHelper; + QVariantMap propertyMap; }; class QNetworkManagerIp4ConfigPrivate; diff --git a/src/plugins/bearer/networkmanager/qnmdbushelper.cpp b/src/plugins/bearer/networkmanager/qnmdbushelper.cpp deleted file mode 100644 index 0decfd78b9..0000000000 --- a/src/plugins/bearer/networkmanager/qnmdbushelper.cpp +++ /dev/null @@ -1,140 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal -** -** This file is part of the plugins of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL21$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information -** use the contact form at http://qt.digia.com/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 or version 3 as published by the Free -** Software Foundation and appearing in the file LICENSE.LGPLv21 and -** LICENSE.LGPLv3 included in the packaging of this file. Please review the -** following information to ensure the GNU Lesser General Public License -** requirements will be met: https://www.gnu.org/licenses/lgpl.html and -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -// this class is for helping qdbus get stuff - -#include "qnmdbushelper.h" - -#include "qnetworkmanagerservice.h" - -#include -#include -#include -#include - -#include - -#ifndef QT_NO_DBUS - -QT_BEGIN_NAMESPACE - -QNmDBusHelper::QNmDBusHelper(QObject * parent) - : QObject(parent) -{ -} - -QNmDBusHelper::~QNmDBusHelper() -{ -} - -void QNmDBusHelper::deviceStateChanged(quint32 state) - { - QDBusMessage msg = this->message(); - if (state == NM_DEVICE_STATE_ACTIVATED - || state == NM_DEVICE_STATE_DISCONNECTED - || state == NM_DEVICE_STATE_UNAVAILABLE - || state == NM_DEVICE_STATE_FAILED) { - emit pathForStateChanged(msg.path(), state); - } - } - -void QNmDBusHelper::slotAccessPointAdded(QDBusObjectPath path) -{ - if (path.path().length() > 2) - emit pathForAccessPointAdded(path.path()); -} - -void QNmDBusHelper::slotAccessPointRemoved(QDBusObjectPath path) -{ - if (path.path().length() > 2) - emit pathForAccessPointRemoved(path.path()); -} - -void QNmDBusHelper::slotPropertiesChanged(QMap map) -{ - QDBusMessage msg = this->message(); - QMapIterator i(map); - while (i.hasNext()) { - i.next(); - if (i.key() == QStringLiteral("State")) { - quint32 state = i.value().toUInt(); - if (state == NM_DEVICE_STATE_ACTIVATED - || state == NM_DEVICE_STATE_DISCONNECTED - || state == NM_DEVICE_STATE_UNAVAILABLE - || state == NM_DEVICE_STATE_FAILED) { - emit pathForPropertiesChanged(msg.path(), map); - } - } else if (i.key() == QStringLiteral("ActiveAccessPoint")) { - emit pathForPropertiesChanged(msg.path(), map); - } else if (i.key() == QStringLiteral("ActiveConnections")) { - emit pathForPropertiesChanged(msg.path(), map); - } else if (i.key() == QStringLiteral("AvailableConnections")) { - const QDBusArgument &dbusArgs = i.value().value(); - QDBusObjectPath path; - QStringList paths; - dbusArgs.beginArray(); - while (!dbusArgs.atEnd()) { - dbusArgs >> path; - paths << path.path(); - } - dbusArgs.endArray(); - emit pathForConnectionsChanged(paths); - } - } -} - -void QNmDBusHelper::slotSettingsRemoved() -{ - QDBusMessage msg = this->message(); - emit pathForSettingsRemoved(msg.path()); -} - -void QNmDBusHelper::activeConnectionPropertiesChanged(QMap map) -{ - QDBusMessage msg = this->message(); - QMapIterator i(map); - while (i.hasNext()) { - i.next(); - if (i.key() == QStringLiteral("State")) { - quint32 state = i.value().toUInt(); - if (state == NM_ACTIVE_CONNECTION_STATE_ACTIVATED - || state == NM_ACTIVE_CONNECTION_STATE_DEACTIVATED) { - emit pathForPropertiesChanged(msg.path(), map); - } - } - } -} - -QT_END_NAMESPACE - -#endif // QT_NO_DBUS diff --git a/src/plugins/bearer/networkmanager/qnmdbushelper.h b/src/plugins/bearer/networkmanager/qnmdbushelper.h deleted file mode 100644 index e224af87f1..0000000000 --- a/src/plugins/bearer/networkmanager/qnmdbushelper.h +++ /dev/null @@ -1,73 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal -** -** This file is part of the plugins of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL21$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information -** use the contact form at http://qt.digia.com/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 or version 3 as published by the Free -** Software Foundation and appearing in the file LICENSE.LGPLv21 and -** LICENSE.LGPLv3 included in the packaging of this file. Please review the -** following information to ensure the GNU Lesser General Public License -** requirements will be met: https://www.gnu.org/licenses/lgpl.html and -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QNMDBUSHELPERPRIVATE_H -#define QNMDBUSHELPERPRIVATE_H - -#include -#include -#include - -#ifndef QT_NO_DBUS - -QT_BEGIN_NAMESPACE - -class QNmDBusHelper: public QObject, protected QDBusContext - { - Q_OBJECT - public: - QNmDBusHelper(QObject *parent = 0); - ~QNmDBusHelper(); - - public slots: - void deviceStateChanged(quint32); - void slotAccessPointAdded(QDBusObjectPath); - void slotAccessPointRemoved(QDBusObjectPath); - void slotPropertiesChanged(QMap); - void slotSettingsRemoved(); - void activeConnectionPropertiesChanged(QMap); - -Q_SIGNALS: - void pathForStateChanged(const QString &, quint32); - void pathForAccessPointAdded(const QString &); - void pathForAccessPointRemoved(const QString &); - void pathForPropertiesChanged(const QString &, QMap); - void pathForSettingsRemoved(const QString &); - void pathForConnectionsChanged(const QStringList &pathsList); -}; - -QT_END_NAMESPACE - -#endif // QT_NO_DBUS - -#endif// QNMDBUSHELPERPRIVATE_H