diff options
author | Aaron McCarthy <aaron.mccarthy@nokia.com> | 2009-12-09 05:44:52 (GMT) |
---|---|---|
committer | Aaron McCarthy <aaron.mccarthy@nokia.com> | 2010-01-04 01:07:51 (GMT) |
commit | 7858758772ad01e6a772cb048e4f1eda7f4ec9c3 (patch) | |
tree | d8a81f486ee01f494991c89529d06f4e2fa16167 /src/plugins/bearer | |
parent | ee8b1156400791a077280138863336ea93a774a7 (diff) | |
download | Qt-7858758772ad01e6a772cb048e4f1eda7f4ec9c3.zip Qt-7858758772ad01e6a772cb048e4f1eda7f4ec9c3.tar.gz Qt-7858758772ad01e6a772cb048e4f1eda7f4ec9c3.tar.bz2 |
Rework NetworkManager backend.
Diffstat (limited to 'src/plugins/bearer')
-rw-r--r-- | src/plugins/bearer/generic/qgenericengine.cpp | 26 | ||||
-rw-r--r-- | src/plugins/bearer/generic/qgenericengine.h | 2 | ||||
-rw-r--r-- | src/plugins/bearer/networkmanager/main.cpp | 4 | ||||
-rw-r--r-- | src/plugins/bearer/networkmanager/networkmanager.pro | 4 | ||||
-rw-r--r-- | src/plugins/bearer/networkmanager/qnetworkmanagerengine.cpp | 654 | ||||
-rw-r--r-- | src/plugins/bearer/networkmanager/qnetworkmanagerengine.h | 125 | ||||
-rw-r--r-- | src/plugins/bearer/networkmanager/qnetworkmanagerservice.cpp | 6 | ||||
-rw-r--r-- | src/plugins/bearer/networkmanager/qnetworkmanagerservice.h | 4 | ||||
-rw-r--r-- | src/plugins/bearer/networkmanager/qnmdbushelper.cpp | 3 | ||||
-rw-r--r-- | src/plugins/bearer/networkmanager/qnmdbushelper.h | 14 | ||||
-rw-r--r-- | src/plugins/bearer/networkmanager/qnmwifiengine.cpp | 1128 | ||||
-rw-r--r-- | src/plugins/bearer/networkmanager/qnmwifiengine.h | 165 |
12 files changed, 820 insertions, 1315 deletions
diff --git a/src/plugins/bearer/generic/qgenericengine.cpp b/src/plugins/bearer/generic/qgenericengine.cpp index e70d23d..339ef9c 100644 --- a/src/plugins/bearer/generic/qgenericengine.cpp +++ b/src/plugins/bearer/generic/qgenericengine.cpp @@ -249,7 +249,7 @@ void QGenericEngine::doRequestUpdate() if (changed) emit configurationChanged(ptr); } else { - QExplicitlySharedDataPointer<QNetworkConfigurationPrivate> ptr(new QNetworkConfigurationPrivate); + QNetworkConfigurationPrivatePointer ptr(new QNetworkConfigurationPrivate); ptr->name = name; ptr->isValid = true; @@ -277,5 +277,29 @@ void QGenericEngine::doRequestUpdate() emit updateCompleted(); } +QNetworkSession::State QGenericEngine::sessionStateForId(const QString &id) +{ + QNetworkConfigurationPrivatePointer ptr = accessPointConfigurations.value(id); + + if (!ptr) + return QNetworkSession::Invalid; + + if (!ptr->isValid) { + return QNetworkSession::Invalid; + } else if ((ptr->state & QNetworkConfiguration::Active) == QNetworkConfiguration::Active) { + return QNetworkSession::Connected; + } else if ((ptr->state & QNetworkConfiguration::Discovered) == + QNetworkConfiguration::Discovered) { + return QNetworkSession::Disconnected; + } else if ((ptr->state & QNetworkConfiguration::Defined) == QNetworkConfiguration::Defined) { + return QNetworkSession::NotAvailable; + } else if ((ptr->state & QNetworkConfiguration::Undefined) == + QNetworkConfiguration::Undefined) { + return QNetworkSession::NotAvailable; + } + + return QNetworkSession::Invalid; +} + QT_END_NAMESPACE diff --git a/src/plugins/bearer/generic/qgenericengine.h b/src/plugins/bearer/generic/qgenericengine.h index 32d762d..9359d7f 100644 --- a/src/plugins/bearer/generic/qgenericengine.h +++ b/src/plugins/bearer/generic/qgenericengine.h @@ -69,6 +69,8 @@ public: void requestUpdate(); + QNetworkSession::State sessionStateForId(const QString &id); + static QGenericEngine *instance(); private Q_SLOTS: diff --git a/src/plugins/bearer/networkmanager/main.cpp b/src/plugins/bearer/networkmanager/main.cpp index d4b74a1..b561415 100644 --- a/src/plugins/bearer/networkmanager/main.cpp +++ b/src/plugins/bearer/networkmanager/main.cpp @@ -39,7 +39,7 @@ ** ****************************************************************************/ -#include "qnmwifiengine.h" +#include "qnetworkmanagerengine.h" #include <QtNetwork/qbearerplugin.h> @@ -73,7 +73,7 @@ QStringList QNetworkManagerEnginePlugin::keys() const QBearerEngine *QNetworkManagerEnginePlugin::create(const QString &key) const { if (key == QLatin1String("networkmanager")) - return new QNmWifiEngine; + return new QNetworkManagerEngine; else return 0; } diff --git a/src/plugins/bearer/networkmanager/networkmanager.pro b/src/plugins/bearer/networkmanager/networkmanager.pro index 36d150a..79c68ea 100644 --- a/src/plugins/bearer/networkmanager/networkmanager.pro +++ b/src/plugins/bearer/networkmanager/networkmanager.pro @@ -7,12 +7,12 @@ DEFINES += BEARER_ENGINE BACKEND_NM HEADERS += qnmdbushelper.h \ qnetworkmanagerservice.h \ - qnmwifiengine.h + qnetworkmanagerengine.h SOURCES += main.cpp \ qnmdbushelper.cpp \ qnetworkmanagerservice.cpp \ - qnmwifiengine.cpp + qnetworkmanagerengine.cpp QTDIR_build:DESTDIR = $$QT_BUILD_TREE/plugins/bearer target.path += $$[QT_INSTALL_PLUGINS]/bearer diff --git a/src/plugins/bearer/networkmanager/qnetworkmanagerengine.cpp b/src/plugins/bearer/networkmanager/qnetworkmanagerengine.cpp new file mode 100644 index 0000000..3de20a3 --- /dev/null +++ b/src/plugins/bearer/networkmanager/qnetworkmanagerengine.cpp @@ -0,0 +1,654 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the plugins of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** 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 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qnetworkmanagerengine.h" +#include "qnetworkmanagerservice.h" + +#include <QtNetwork/private/qnetworkconfiguration_p.h> + +#include <QtNetwork/qnetworksession.h> + +#include <QtCore/qdebug.h> + +#include <NetworkManager/NetworkManager.h> +#include <QtDBus> +#include <QDBusConnection> +#include <QDBusError> +#include <QDBusInterface> +#include <QDBusMessage> +#include <QDBusReply> + +QT_BEGIN_NAMESPACE + +QNetworkManagerEngine::QNetworkManagerEngine(QObject *parent) +: QNetworkSessionEngine(parent), + interface(new QNetworkManagerInterface(this)), + systemSettings(new QNetworkManagerSettings(NM_DBUS_SERVICE_SYSTEM_SETTINGS, this)), + userSettings(new QNetworkManagerSettings(NM_DBUS_SERVICE_USER_SETTINGS, this)) +{ + interface->setConnections(); + connect(interface, SIGNAL(deviceAdded(QDBusObjectPath)), + this, SLOT(deviceAdded(QDBusObjectPath))); + connect(interface, SIGNAL(deviceRemoved(QDBusObjectPath)), + this, SLOT(deviceRemoved(QDBusObjectPath))); +#if 0 + connect(interface, SIGNAL(stateChanged(const QString,quint32)), + this, SIGNAL(configurationsChanged())); +#endif + connect(interface, SIGNAL(activationFinished(QDBusPendingCallWatcher*)), + this, SLOT(activationFinished(QDBusPendingCallWatcher*))); + connect(interface, SIGNAL(propertiesChanged(QString,QMap<QString,QVariant>)), + this, SLOT(interfacePropertiesChanged(QString,QMap<QString,QVariant>))); + + qDBusRegisterMetaType<QNmSettingsMap>(); + + systemSettings->setConnections(); + connect(systemSettings, SIGNAL(newConnection(QDBusObjectPath)), + this, SLOT(newConnection(QDBusObjectPath))); + + userSettings->setConnections(); + connect(userSettings, SIGNAL(newConnection(QDBusObjectPath)), + this, SLOT(newConnection(QDBusObjectPath))); + + // Get current list of access points. + foreach (const QDBusObjectPath &devicePath, interface->getDevices()) + deviceAdded(devicePath); + + // Get connections. + foreach (const QDBusObjectPath &settingsPath, systemSettings->listConnections()) + newConnection(settingsPath, systemSettings); + foreach (const QDBusObjectPath &settingsPath, userSettings->listConnections()) + newConnection(settingsPath, userSettings); + + // Get active connections. + foreach (const QDBusObjectPath &acPath, interface->activeConnections()) { + QNetworkManagerConnectionActive *activeConnection = + new QNetworkManagerConnectionActive(acPath.path()); + activeConnections.insert(acPath.path(), activeConnection); + + activeConnection->setConnections(); + connect(activeConnection, SIGNAL(propertiesChanged(QString,QMap<QString,QVariant>)), + this, SLOT(activeConnectionPropertiesChanged(QString,QMap<QString,QVariant>))); + } +} + +QNetworkManagerEngine::~QNetworkManagerEngine() +{ +} + +void QNetworkManagerEngine::doRequestUpdate() +{ +} + +QString QNetworkManagerEngine::getInterfaceFromId(const QString &id) +{ + foreach (const QDBusObjectPath &acPath, interface->activeConnections()) { + QNetworkManagerConnectionActive activeConnection(acPath.path()); + + const QString identifier = QString::number(qHash(activeConnection.serviceName() + ' ' + + activeConnection.connection().path())); + + if (id == identifier) { + QList<QDBusObjectPath> devices = activeConnection.devices(); + + if (devices.isEmpty()) + continue; + + if (devices.count() > 1) + qDebug() << "multiple network interfaces for" << id; + + QNetworkManagerInterfaceDevice device(devices.at(0).path()); + return device.interface().name(); + } + } + + return QString(); +} + +bool QNetworkManagerEngine::hasIdentifier(const QString &id) +{ + if (connectionFromId(id)) + return true; + + for (int i = 0; i < accessPoints.count(); ++i) { + QNetworkManagerInterfaceAccessPoint *accessPoint = accessPoints.at(i); + + const QString identifier = + QString::number(qHash(accessPoint->connectionInterface()->path())); + + if (id == identifier) + return true; + } + + return false; +} + +QString QNetworkManagerEngine::bearerName(const QString &id) +{ + QNetworkManagerSettingsConnection *connection = connectionFromId(id); + + if (!connection) + return QString(); + + QNmSettingsMap map = connection->getSettings(); + const QString connectionType = map.value("connection").value("type").toString(); + + if (connectionType == "802-3-ethernet") + return QLatin1String("Ethernet"); + else if (connectionType == "802-11-wireless") + return QLatin1String("WLAN"); + else if (connectionType == "gsm") + return QLatin1String("2G"); + else if (connectionType == "cdma") + return QLatin1String("CDMA2000"); + else + return QString(); +} + +void QNetworkManagerEngine::connectToId(const QString &id) +{ + QNetworkManagerSettingsConnection *connection = connectionFromId(id); + + if (!connection) + return; + + QNmSettingsMap map = connection->getSettings(); + const QString connectionType = map.value("connection").value("type").toString(); + + QString dbusDevicePath; + foreach (const QDBusObjectPath &devicePath, interface->getDevices()) { + QNetworkManagerInterfaceDevice device(devicePath.path()); + if (device.deviceType() == DEVICE_TYPE_802_3_ETHERNET && + connectionType == QLatin1String("802-3-ethernet")) { + dbusDevicePath = devicePath.path(); + break; + } else if (device.deviceType() == DEVICE_TYPE_802_11_WIRELESS && + connectionType == QLatin1String("802-11-wireless")) { + dbusDevicePath = devicePath.path(); + break; + } + } + + const QString service = connection->connectionInterface()->service(); + const QString settingsPath = connection->connectionInterface()->path(); + + interface->activateConnection(service, QDBusObjectPath(settingsPath), + QDBusObjectPath(dbusDevicePath), QDBusObjectPath("/")); +} + +void QNetworkManagerEngine::disconnectFromId(const QString &id) +{ + foreach (const QDBusObjectPath &acPath, interface->activeConnections()) { + QNetworkManagerConnectionActive activeConnection(acPath.path()); + + const QString identifier = QString::number(qHash(activeConnection.serviceName() + ' ' + + activeConnection.connection().path())); + + if (id == identifier && accessPointConfigurations.contains(id)) { + interface->deactivateConnection(acPath); + break; + } + } +} + +void QNetworkManagerEngine::requestUpdate() +{ + QTimer::singleShot(0, this, SLOT(doRequestUpdate())); +} + +void QNetworkManagerEngine::interfacePropertiesChanged(const QString &path, + const QMap<QString, QVariant> &properties) +{ + QMapIterator<QString, QVariant> i(properties); + while (i.hasNext()) { + i.next(); + + if (i.key() == QLatin1String("ActiveConnections")) { + // Active connections changed, update configurations. + + QList<QDBusObjectPath> activeConnections = + qdbus_cast<QList<QDBusObjectPath> >(i.value().value<QDBusArgument>()); + + QStringList identifiers = accessPointConfigurations.keys(); + foreach (const QString &id, identifiers) + QNetworkConfigurationPrivatePointer ptr = accessPointConfigurations.value(id); + + QStringList priorActiveConnections = this->activeConnections.keys(); + + foreach (const QDBusObjectPath &acPath, activeConnections) { + priorActiveConnections.removeOne(acPath.path()); + QNetworkManagerConnectionActive *activeConnection = + this->activeConnections.value(acPath.path()); + if (!activeConnection) { + activeConnection = new QNetworkManagerConnectionActive(acPath.path()); + this->activeConnections.insert(acPath.path(), activeConnection); + + activeConnection->setConnections(); + connect(activeConnection, SIGNAL(propertiesChanged(QString,QMap<QString,QVariant>)), + this, SLOT(activeConnectionPropertiesChanged(QString,QMap<QString,QVariant>))); + } + + const QString id = QString::number(qHash(activeConnection->serviceName() + ' ' + + activeConnection->connection().path())); + + identifiers.removeOne(id); + + QNetworkConfigurationPrivatePointer ptr = accessPointConfigurations.value(id); + if (ptr) { + if (activeConnection->state() == 2 && + ptr->state != QNetworkConfiguration::Active) { + ptr->state = QNetworkConfiguration::Active; + emit configurationChanged(ptr); + } + } + } + + while (!priorActiveConnections.isEmpty()) + delete this->activeConnections.take(priorActiveConnections.takeFirst()); + + while (!identifiers.isEmpty()) { + // These configurations are not active + QNetworkConfigurationPrivatePointer ptr = + accessPointConfigurations.value(identifiers.takeFirst()); + + if ((ptr->state & QNetworkConfiguration::Active) == QNetworkConfiguration::Active) { + ptr->state = QNetworkConfiguration::Discovered; + emit configurationChanged(ptr); + } + } + } + } +} + +void QNetworkManagerEngine::activeConnectionPropertiesChanged(const QString &path, + const QMap<QString, QVariant> &properties) +{ + QNetworkManagerConnectionActive *activeConnection = activeConnections.value(path); + + if (!activeConnection) + return; + + const QString id = QString::number(qHash(activeConnection->serviceName() + ' ' + + activeConnection->connection().path())); + + QNetworkConfigurationPrivatePointer ptr = accessPointConfigurations.value(id); + if (ptr) { + if (activeConnection->state() == 2 && + ptr->state != QNetworkConfiguration::Active) { + ptr->state = QNetworkConfiguration::Active; + emit configurationChanged(ptr); + } + } +} + +void QNetworkManagerEngine::deviceAdded(const QDBusObjectPath &path) +{ + QNetworkManagerInterfaceDevice device(path.path()); + if (device.deviceType() == DEVICE_TYPE_802_11_WIRELESS) { + QNetworkManagerInterfaceDeviceWireless *wirelessDevice = + new QNetworkManagerInterfaceDeviceWireless(device.connectionInterface()->path()); + wirelessDevices.insert(path.path(), wirelessDevice); + + wirelessDevice->setConnections(); + connect(wirelessDevice, SIGNAL(accessPointAdded(QString,QDBusObjectPath)), + this, SLOT(newAccessPoint(QString,QDBusObjectPath))); + connect(wirelessDevice, SIGNAL(accessPointRemoved(QString,QDBusObjectPath)), + this, SLOT(removeAccessPoint(QString,QDBusObjectPath))); + connect(wirelessDevice, SIGNAL(propertiesChanged(QString,QMap<QString,QVariant>)), + this, SLOT(devicePropertiesChanged(QString,QMap<QString,QVariant>))); + + foreach (const QDBusObjectPath &apPath, wirelessDevice->getAccessPoints()) + newAccessPoint(QString(), apPath); + } +} + +void QNetworkManagerEngine::deviceRemoved(const QDBusObjectPath &path) +{ + delete wirelessDevices.value(path.path()); +} + +void QNetworkManagerEngine::newConnection(const QDBusObjectPath &path, + QNetworkManagerSettings *settings) +{ + if (!settings) + settings = qobject_cast<QNetworkManagerSettings *>(sender()); + + if (!settings) + return; + + QNetworkManagerSettingsConnection *connection = + new QNetworkManagerSettingsConnection(settings->connectionInterface()->service(), + path.path()); + connections.append(connection); + + connect(connection, SIGNAL(removed(QString)), this, SLOT(removeConnection(QString))); + connect(connection, SIGNAL(updated(const QNmSettingsMap&)), + this, SLOT(updateConnection(const QNmSettingsMap&))); + + const QString service = connection->connectionInterface()->service(); + const QString settingsPath = connection->connectionInterface()->path(); + + QNetworkConfigurationPrivate *cpPriv = + parseConnection(service, settingsPath, connection->getSettings()); + + // Check if connection is active. + foreach (const QDBusObjectPath &acPath, interface->activeConnections()) { + QNetworkManagerConnectionActive activeConnection(acPath.path()); + + if (activeConnection.serviceName() == service && + activeConnection.connection().path() == settingsPath && + activeConnection.state() == 2) { + cpPriv->state |= QNetworkConfiguration::Active; + break; + } + } + + QNetworkConfigurationPrivatePointer ptr(cpPriv); + accessPointConfigurations.insert(ptr->id, ptr); + emit configurationAdded(ptr); +} + +void QNetworkManagerEngine::removeConnection(const QString &path) +{ + QNetworkManagerSettingsConnection *connection = + qobject_cast<QNetworkManagerSettingsConnection *>(sender()); + if (!connection) + return; + + connections.removeAll(connection); + + const QString id = QString::number(qHash(connection->connectionInterface()->service() + ' ' + + connection->connectionInterface()->path())); + + QNetworkConfigurationPrivatePointer ptr = accessPointConfigurations.take(id); + ptr->isValid = false; + emit configurationRemoved(ptr); +} + +void QNetworkManagerEngine::updateConnection(const QNmSettingsMap &settings) +{ + QNetworkManagerSettingsConnection *connection = + qobject_cast<QNetworkManagerSettingsConnection *>(sender()); + if (!connection) + return; + + const QString service = connection->connectionInterface()->service(); + const QString settingsPath = connection->connectionInterface()->path(); + + qDebug() << "Should parse connection directly into existing configuration"; + QNetworkConfigurationPrivate *cpPriv = parseConnection(service, settingsPath, settings); + + // Check if connection is active. + foreach (const QDBusObjectPath &acPath, interface->activeConnections()) { + QNetworkManagerConnectionActive activeConnection(acPath.path()); + + if (activeConnection.serviceName() == service && + activeConnection.connection().path() == settingsPath && + activeConnection.state() == NM_ACTIVE_CONNECTION_STATE_ACTIVATED) { + cpPriv->state |= QNetworkConfiguration::Active; + break; + } + } + + QNetworkConfigurationPrivatePointer ptr = accessPointConfigurations.value(cpPriv->id); + + ptr->isValid = cpPriv->isValid; + ptr->name = cpPriv->name; + ptr->id = cpPriv->id; + ptr->state = cpPriv->state; + + emit configurationChanged(ptr); + delete cpPriv; +} + +void QNetworkManagerEngine::activationFinished(QDBusPendingCallWatcher *watcher) +{ + QDBusPendingReply<QDBusObjectPath> reply = *watcher; + if (reply.isError()) { + qDebug() << "error connecting NM connection"; + } else { + QDBusObjectPath result = reply.value(); + + QNetworkManagerConnectionActive activeConnection(result.path()); + + const QString id = QString::number(qHash(activeConnection.serviceName() + ' ' + + activeConnection.connection().path())); + + QNetworkConfigurationPrivatePointer ptr = accessPointConfigurations.value(id); + if (ptr) { + if (activeConnection.state() == 2 && + ptr->state != QNetworkConfiguration::Active) { + ptr->state = QNetworkConfiguration::Active; + emit configurationChanged(ptr); + } + } + } +} + +void QNetworkManagerEngine::newAccessPoint(const QString &path, const QDBusObjectPath &objectPath) +{ + QNetworkManagerInterfaceAccessPoint *accessPoint = + new QNetworkManagerInterfaceAccessPoint(objectPath.path()); + accessPoints.append(accessPoint); + + accessPoint->setConnections(); + connect(accessPoint, SIGNAL(propertiesChanged(QMap<QString,QVariant>)), + this, SLOT(updateAccessPoint(QMap<QString,QVariant>))); + + // Check if configuration for this SSID already exists. + for (int i = 0; i < accessPoints.count(); ++i) { + if (accessPoint != accessPoints.at(i) && + accessPoint->ssid() == accessPoints.at(i)->ssid()) { + return; + } + } + + // Check if configuration exists for connection. + for (int i = 0; i < connections.count(); ++i) { + QNetworkManagerSettingsConnection *connection = connections.at(i); + + if (accessPoint->ssid() == connection->getSsid()) { + const QString service = connection->connectionInterface()->service(); + const QString settingsPath = connection->connectionInterface()->path(); + const QString connectionId = QString::number(qHash(service + ' ' + settingsPath)); + + QNetworkConfigurationPrivatePointer ptr = + accessPointConfigurations.value(connectionId); + ptr->state = QNetworkConfiguration::Discovered; + emit configurationChanged(ptr); + return; + } + } + + // New access point. + QNetworkConfigurationPrivatePointer ptr(new QNetworkConfigurationPrivate); + + ptr->name = accessPoint->ssid(); + ptr->isValid = true; + ptr->id = QString::number(qHash(objectPath.path())); + ptr->type = QNetworkConfiguration::InternetAccessPoint; + ptr->purpose = QNetworkConfiguration::PublicPurpose; + ptr->state = QNetworkConfiguration::Undefined; + + accessPointConfigurations.insert(ptr->id, ptr); + emit configurationAdded(ptr); +} + +void QNetworkManagerEngine::removeAccessPoint(const QString &path, + const QDBusObjectPath &objectPath) +{ + for (int i = 0; i < accessPoints.count(); ++i) { + QNetworkManagerInterfaceAccessPoint *accessPoint = accessPoints.at(i); + + if (accessPoint->connectionInterface()->path() == objectPath.path()) { + accessPoints.removeOne(accessPoint); + + if (configuredAccessPoints.contains(accessPoint)) { + // find connection and change state to Defined + configuredAccessPoints.removeOne(accessPoint); + qDebug() << "At least one connection is no longer discovered."; + } else { + // emit configurationRemoved(cpPriv); + qDebug() << "An unconfigured wifi access point was removed."; + } + + break; + } + } +} + +void QNetworkManagerEngine::updateAccessPoint(const QMap<QString, QVariant> &map) +{ + QNetworkManagerInterfaceAccessPoint *accessPoint = + qobject_cast<QNetworkManagerInterfaceAccessPoint *>(sender()); + if (!accessPoint) + return; + + qDebug() << "update access point" << accessPoint; +} + +QNetworkConfigurationPrivate *QNetworkManagerEngine::parseConnection(const QString &service, + const QString &settingsPath, + const QNmSettingsMap &map) +{ + QNetworkConfigurationPrivate *cpPriv = new QNetworkConfigurationPrivate; + cpPriv->name = map.value("connection").value("id").toString(); + cpPriv->isValid = true; + cpPriv->id = QString::number(qHash(service + ' ' + settingsPath)); + cpPriv->type = QNetworkConfiguration::InternetAccessPoint; + + cpPriv->purpose = QNetworkConfiguration::PublicPurpose; + + cpPriv->state = QNetworkConfiguration::Defined; + + const QString connectionType = map.value("connection").value("type").toString(); + + if (connectionType == QLatin1String("802-3-ethernet")) { + foreach (const QDBusObjectPath &devicePath, interface->getDevices()) { + QNetworkManagerInterfaceDevice device(devicePath.path()); + if (device.deviceType() == DEVICE_TYPE_802_3_ETHERNET) { + QNetworkManagerInterfaceDeviceWired wiredDevice(device.connectionInterface()->path()); + if (wiredDevice.carrier()) { + cpPriv->state |= QNetworkConfiguration::Discovered; + break; + } + + } + } + } else if (connectionType == QLatin1String("802-11-wireless")) { + const QString connectionSsid = map.value("802-11-wireless").value("ssid").toString(); + + for (int i = 0; i < accessPoints.count(); ++i) { + if (connectionSsid == accessPoints.at(i)->ssid()) { + cpPriv->state |= QNetworkConfiguration::Discovered; + if (!configuredAccessPoints.contains(accessPoints.at(i))) { + configuredAccessPoints.append(accessPoints.at(i)); + + const QString accessPointId = + QString::number(qHash(accessPoints.at(i)->connectionInterface()->path())); + QNetworkConfigurationPrivatePointer ptr = + accessPointConfigurations.take(accessPointId); + emit configurationRemoved(ptr); + } + break; + } + } + } + + return cpPriv; +} + +QNetworkManagerSettingsConnection *QNetworkManagerEngine::connectionFromId(const QString &id) const +{ + for (int i = 0; i < connections.count(); ++i) { + QNetworkManagerSettingsConnection *connection = connections.at(i); + const QString service = connection->connectionInterface()->service(); + const QString settingsPath = connection->connectionInterface()->path(); + + const QString identifier = QString::number(qHash(service + ' ' + settingsPath)); + + if (id == identifier) + return connection; + } + + return 0; +} + +QNetworkSession::State QNetworkManagerEngine::sessionStateForId(const QString &id) +{ + QNetworkConfigurationPrivatePointer ptr = accessPointConfigurations.value(id); + + if (!ptr) + return QNetworkSession::Invalid; + + if (!ptr->isValid) + return QNetworkSession::Invalid; + + foreach (const QString &acPath, activeConnections.keys()) { + QNetworkManagerConnectionActive *activeConnection = activeConnections.value(acPath); + + const QString identifier = QString::number(qHash(activeConnection->serviceName() + ' ' + + activeConnection->connection().path())); + + if (id == identifier) { + switch (activeConnection->state()) { + case 0: + return QNetworkSession::Disconnected; + case 1: + return QNetworkSession::Connecting; + case 2: + return QNetworkSession::Connected; + } + } + } + + if ((ptr->state & QNetworkConfiguration::Discovered) == QNetworkConfiguration::Discovered) + return QNetworkSession::Disconnected; + else if ((ptr->state & QNetworkConfiguration::Defined) == QNetworkConfiguration::Defined) + return QNetworkSession::NotAvailable; + else if ((ptr->state & QNetworkConfiguration::Undefined) == QNetworkConfiguration::Undefined) + return QNetworkSession::NotAvailable; + + return QNetworkSession::Invalid; +} + +QT_END_NAMESPACE + diff --git a/src/plugins/bearer/networkmanager/qnetworkmanagerengine.h b/src/plugins/bearer/networkmanager/qnetworkmanagerengine.h new file mode 100644 index 0000000..9e8af3b --- /dev/null +++ b/src/plugins/bearer/networkmanager/qnetworkmanagerengine.h @@ -0,0 +1,125 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the plugins of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** 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 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QNETWORKMANAGERENGINE_P_H +#define QNETWORKMANAGERENGINE_P_H + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists for the convenience +// of the QLibrary class. This header file may change from +// version to version without notice, or even be removed. +// +// We mean it. +// + +#include <QtNetwork/private/qnetworksessionengine_p.h> + +#include "qnetworkmanagerservice.h" + +#include <QMap> +#include <QVariant> + +QT_BEGIN_NAMESPACE + +class QNetworkManagerEngine : public QNetworkSessionEngine +{ + Q_OBJECT + +public: + QNetworkManagerEngine(QObject *parent = 0); + ~QNetworkManagerEngine(); + + QString getInterfaceFromId(const QString &id); + bool hasIdentifier(const QString &id); + + QString bearerName(const QString &id); + + void connectToId(const QString &id); + void disconnectFromId(const QString &id); + + void requestUpdate(); + + QNetworkSession::State sessionStateForId(const QString &id); + +private Q_SLOTS: + void interfacePropertiesChanged(const QString &path, + const QMap<QString, QVariant> &properties); + void activeConnectionPropertiesChanged(const QString &path, + const QMap<QString, QVariant> &properties); + + void deviceAdded(const QDBusObjectPath &path); + void deviceRemoved(const QDBusObjectPath &path); + + void newConnection(const QDBusObjectPath &path, QNetworkManagerSettings *settings = 0); + void removeConnection(const QString &path); + void updateConnection(const QNmSettingsMap &settings); + void activationFinished(QDBusPendingCallWatcher *watcher); + + void newAccessPoint(const QString &path, const QDBusObjectPath &objectPath); + void removeAccessPoint(const QString &path, const QDBusObjectPath &objectPath); + void updateAccessPoint(const QMap<QString, QVariant> &map); + + void doRequestUpdate(); + +private: + QNetworkConfigurationPrivate *parseConnection(const QString &service, + const QString &settingsPath, + const QNmSettingsMap &map); + QNetworkManagerSettingsConnection *connectionFromId(const QString &id) const; + +private: + QNetworkManagerInterface *interface; + QNetworkManagerSettings *systemSettings; + QNetworkManagerSettings *userSettings; + QHash<QString, QNetworkManagerInterfaceDeviceWireless *> wirelessDevices; + QHash<QString, QNetworkManagerConnectionActive *> activeConnections; + QList<QNetworkManagerSettingsConnection *> connections; + QList<QNetworkManagerInterfaceAccessPoint *> accessPoints; + QList<QNetworkManagerInterfaceAccessPoint *> configuredAccessPoints; +}; + +QT_END_NAMESPACE + +#endif + diff --git a/src/plugins/bearer/networkmanager/qnetworkmanagerservice.cpp b/src/plugins/bearer/networkmanager/qnetworkmanagerservice.cpp index e95c2e6..9376324 100644 --- a/src/plugins/bearer/networkmanager/qnetworkmanagerservice.cpp +++ b/src/plugins/bearer/networkmanager/qnetworkmanagerservice.cpp @@ -95,6 +95,7 @@ QNetworkManagerInterface::~QNetworkManagerInterface() { delete d->connectionInterface; delete d; + delete nmDBusHelper; } bool QNetworkManagerInterface::isValid() @@ -692,9 +693,12 @@ bool QNetworkManagerSettingsConnection::setConnections() bool allOk = false; if(!dbusConnection.connect(d->service, d->path, - NM_DBUS_IFACE_SETTINGS_CONNECTION, "NewConnection", + NM_DBUS_IFACE_SETTINGS_CONNECTION, "Updated", this, SIGNAL(updated(QNmSettingsMap)))) { allOk = true; + } else { + QDBusError error = dbusConnection.lastError(); + qDebug() << error.name() << error.message() << error.type(); } nmDBusHelper = new QNmDBusHelper; diff --git a/src/plugins/bearer/networkmanager/qnetworkmanagerservice.h b/src/plugins/bearer/networkmanager/qnetworkmanagerservice.h index 8bed45b..dbed01e 100644 --- a/src/plugins/bearer/networkmanager/qnetworkmanagerservice.h +++ b/src/plugins/bearer/networkmanager/qnetworkmanagerservice.h @@ -329,8 +329,8 @@ public: Q_SIGNALS: - void updated(QMap< QString, QMap<QString,QVariant> > s); - void removed(const QString &); + void updated(const QNmSettingsMap &settings); + void removed(const QString &path); private: QNmDBusHelper *nmDBusHelper; diff --git a/src/plugins/bearer/networkmanager/qnmdbushelper.cpp b/src/plugins/bearer/networkmanager/qnmdbushelper.cpp index 1d16e55..f93a63d 100644 --- a/src/plugins/bearer/networkmanager/qnmdbushelper.cpp +++ b/src/plugins/bearer/networkmanager/qnmdbushelper.cpp @@ -96,11 +96,14 @@ void QNmDBusHelper::slotPropertiesChanged(QMap<QString,QVariant> map) emit pathForPropertiesChanged( msg.path(), map); } } else if( i.key() == "ActiveAccessPoint") { + emit pathForPropertiesChanged(msg.path(), map); // qWarning() << __PRETTY_FUNCTION__ << i.key() << ": " << i.value().value<QDBusObjectPath>().path(); // } else if( i.key() == "Strength") // qWarning() << __PRETTY_FUNCTION__ << i.key() << ": " << i.value().toUInt(); // else // qWarning() << __PRETTY_FUNCTION__ << i.key() << ": " << i.value(); + } else if (i.key() == "ActiveConnections") { + emit pathForPropertiesChanged(msg.path(), map); } } } diff --git a/src/plugins/bearer/networkmanager/qnmdbushelper.h b/src/plugins/bearer/networkmanager/qnmdbushelper.h index 9794f98..410b69f 100644 --- a/src/plugins/bearer/networkmanager/qnmdbushelper.h +++ b/src/plugins/bearer/networkmanager/qnmdbushelper.h @@ -42,25 +42,12 @@ #ifndef QNMDBUSHELPERPRIVATE_H #define QNMDBUSHELPERPRIVATE_H -// -// W A R N I N G -// ------------- -// -// This file is not part of the Qt API. It exists purely as an -// implementation detail. This header file may change from version to -// version without notice, or even be removed. -// -// We mean it. -// - #include <QDBusObjectPath> #include <QDBusContext> #include <QMap> QT_BEGIN_NAMESPACE -#if !defined(QT_NO_DBUS) && !defined(Q_OS_MAC) - class QNmDBusHelper: public QObject, protected QDBusContext { Q_OBJECT @@ -80,7 +67,6 @@ Q_SIGNALS: void pathForPropertiesChanged(const QString &, QMap<QString,QVariant>); void pathForSettingsRemoved(const QString &); }; -#endif QT_END_NAMESPACE diff --git a/src/plugins/bearer/networkmanager/qnmwifiengine.cpp b/src/plugins/bearer/networkmanager/qnmwifiengine.cpp deleted file mode 100644 index b215023..0000000 --- a/src/plugins/bearer/networkmanager/qnmwifiengine.cpp +++ /dev/null @@ -1,1128 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the plugins of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** 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 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qnmwifiengine.h" - -#include <QtNetwork/private/qnetworkconfiguration_p.h> -#include <qnetworkconfiguration.h> - -#include <QtCore/qstringlist.h> - -#include <QtNetwork/qnetworkinterface.h> -#include <NetworkManager/NetworkManager.h> -#include "qnetworkmanagerservice.h" - -#include <QNetworkInterface> - -QT_BEGIN_NAMESPACE - -Q_GLOBAL_STATIC(QNmWifiEngine, nmWifiEngine) -typedef QList<QList<uint> > QNmSettingsAddressMap; - -Q_DECLARE_METATYPE(QNmSettingsAddressMap) - -QNmWifiEngine::QNmWifiEngine(QObject *parent) -: QNetworkSessionEngine(parent) -{ - iface = new QNetworkManagerInterface(); - if(!iface->isValid()) { - return; - } - iface->setConnections(); - connect(iface,SIGNAL(deviceAdded(QDBusObjectPath)), - this,SLOT(addDevice(QDBusObjectPath))); - connect(iface,SIGNAL(deviceRemoved(QDBusObjectPath)), - this,SLOT(removeDevice(QDBusObjectPath))); - - QList<QDBusObjectPath> list = iface->getDevices(); - - foreach(QDBusObjectPath path, list) { - addDevice(path); - } - - QStringList connectionServices; - connectionServices << NM_DBUS_SERVICE_SYSTEM_SETTINGS; - connectionServices << NM_DBUS_SERVICE_USER_SETTINGS; - foreach (QString service, connectionServices) { - QNetworkManagerSettings *settingsiface; - settingsiface = new QNetworkManagerSettings(service); - settingsiface->setConnections(); - connect(settingsiface,SIGNAL(newConnection(QDBusObjectPath)), - this,(SLOT(newConnection(QDBusObjectPath)))); - } - - updated = false; -} - -QNmWifiEngine::~QNmWifiEngine() -{ -} - -QString QNmWifiEngine::getNameForConfiguration(QNetworkManagerInterfaceDevice *devIface) -{ - QString newname; - if (devIface->state() == NM_DEVICE_STATE_ACTIVATED) { - QString path = devIface->ip4config().path(); - QNetworkManagerIp4Config * ipIface; - ipIface = new QNetworkManagerIp4Config(path); - newname = ipIface->domains().join(" "); - } - //fallback to interface name - if(newname.isEmpty()) - newname = devIface->interface().name(); - return newname; -} - - -QList<QNetworkConfigurationPrivatePointer> QNmWifiEngine::getConfigurations(bool *ok) -{ -// qWarning() << Q_FUNC_INFO << updated; - if (ok) - *ok = false; - - if(!updated) { - foundConfigurations.clear(); - if(knownSsids.isEmpty()) - getKnownSsids(); // list of ssids that have user configurations. - - scanForAccessPoints(); - getActiveConnectionsPaths(); - knownConnections(); - - accessPointConnections(); - -// findConnections(); - //add access points - updated = true; - } - return QList<QNetworkConfigurationPrivatePointer>(); //foundConfigurations; -} - -void QNmWifiEngine::findConnections() -{ - QList<QDBusObjectPath> list = iface->getDevices(); - - foreach(QDBusObjectPath path, list) { - QNetworkManagerInterfaceDevice *devIface = new QNetworkManagerInterfaceDevice(path.path()); - - //// eth - switch (devIface->deviceType()) { -// qWarning() << devIface->connectionInterface()->path(); - - case DEVICE_TYPE_802_3_ETHERNET: - { - QString ident; - QNetworkManagerInterfaceDeviceWired *devWiredIface; - devWiredIface = new QNetworkManagerInterfaceDeviceWired(devIface->connectionInterface()->path()); - - ident = devWiredIface->hwAddress(); - - QNetworkConfigurationPrivate* cpPriv = new QNetworkConfigurationPrivate(); - cpPriv->name = getNameForConfiguration(devIface); - cpPriv->isValid = true; - cpPriv->id = ident; - cpPriv->internet = devWiredIface->carrier(); - - cpPriv->serviceInterface = devIface->interface(); - cpPriv->type = QNetworkConfiguration::InternetAccessPoint; - switch (devIface->state()) { - case NM_DEVICE_STATE_UNKNOWN: - case NM_DEVICE_STATE_UNMANAGED: - case NM_DEVICE_STATE_FAILED: - cpPriv->state = (cpPriv->state | QNetworkConfiguration::Undefined); - break; - case NM_DEVICE_STATE_UNAVAILABLE: - cpPriv->state = (cpPriv->state | QNetworkConfiguration::Defined); - break; - case NM_DEVICE_STATE_PREPARE: - case NM_DEVICE_STATE_CONFIG: - case NM_DEVICE_STATE_NEED_AUTH: - case NM_DEVICE_STATE_IP_CONFIG: - case NM_DEVICE_STATE_DISCONNECTED: - { - cpPriv->state = ( cpPriv->state | QNetworkConfiguration::Discovered - | QNetworkConfiguration::Defined); - } - break; - case NM_DEVICE_STATE_ACTIVATED: - cpPriv->state = (cpPriv->state | QNetworkConfiguration::Active ); - break; - default: - cpPriv->state = (cpPriv->state | QNetworkConfiguration::Undefined); - break; - }; - cpPriv->purpose = QNetworkConfiguration::PublicPurpose; - foundConfigurations.append(cpPriv); - configurationInterface[cpPriv->id] = cpPriv->serviceInterface.name(); - } - break; - case DEVICE_TYPE_802_11_WIRELESS: - { -// QNetworkManagerInterfaceDeviceWireless *devWirelessIface; -// devWirelessIface = new QNetworkManagerInterfaceDeviceWireless(devIface->connectionInterface()->path()); -// -// //// connections -// QStringList connectionServices; -// connectionServices << NM_DBUS_SERVICE_SYSTEM_SETTINGS; -// connectionServices << NM_DBUS_SERVICE_USER_SETTINGS; -// -// QString connPath; -// -// foreach (QString service, connectionServices) { -// QString ident; -// QNetworkManagerSettings *settingsiface; -// settingsiface = new QNetworkManagerSettings(service); -// QList<QDBusObjectPath> list = settingsiface->listConnections(); -// -// foreach(QDBusObjectPath path, list) { //for each connection path -//qWarning() << path.path(); -// ident = path.path(); -// bool addIt = false; -// QNetworkConfigurationPrivate* cpPriv = new QNetworkConfigurationPrivate(); -// cpPriv->isValid = true; -// cpPriv->id = ident; -// cpPriv->internet = true; -// -// cpPriv->type = QNetworkConfiguration::InternetAccessPoint; -// cpPriv->state = ( cpPriv->state | QNetworkConfiguration::Discovered -// | QNetworkConfiguration::Defined); -// cpPriv->purpose = QNetworkConfiguration::PrivatePurpose; -// -// QNetworkManagerSettingsConnection *sysIface; -// sysIface = new QNetworkManagerSettingsConnection(service, path.path()); -// cpPriv->name = sysIface->getId();//ii.value().toString(); -//qWarning() << cpPriv->name; -// if(sysIface->getType() == DEVICE_TYPE_802_3_ETHERNET/*type == "802-3-ethernet"*/ -// && devIface->deviceType() == DEVICE_TYPE_802_3_ETHERNET) { -// cpPriv->serviceInterface = devIface->interface(); -// addIt = true; -// } else if(sysIface->getType() == DEVICE_TYPE_802_11_WIRELESS/*type == "802-11-wireless"*/ -// && devIface->deviceType() == DEVICE_TYPE_802_11_WIRELESS) { -// cpPriv->serviceInterface = devIface->interface(); -// addIt = true; -// // get the wifi interface state first.. do we need this? -// // QString activeAPPath = devWirelessIface->activeAccessPoint().path(); -// } -// -// //#if 0 -// foreach(QString conpath, activeConnectionPaths) { -// QNetworkManagerConnectionActive *aConn; -// aConn = new QNetworkManagerConnectionActive(conpath); -// // in case of accesspoint, specificObject will hold the accessPOintObjectPath -// // qWarning() << aConn->connection().path() << aConn->specificObject().path() << aConn->devices().count(); -// if( aConn->connection().path() == ident) { -// -// QList <QDBusObjectPath> devs = aConn->devices(); -// foreach(QDBusObjectPath device, devs) { -// QNetworkManagerInterfaceDevice *ifaceDevice; -// ifaceDevice = new QNetworkManagerInterfaceDevice(device.path()); -// cpPriv->serviceInterface = ifaceDevice->interface(); -// cpPriv->state = getStateFlag(ifaceDevice->state()); -// //cpPriv->accessPoint = aConn->specificObject().path(); -// -// break; -// } -// } -// } -// //#endif -// // } //end while connection -// if(addIt) { -// foundConfigurations.append(cpPriv); -// configurationInterface[cpPriv->id] = cpPriv->serviceInterface.name(); -// } -// } -// } //end each connection service -// -// // ////////////// AccessPoints -//// QList<QDBusObjectPath> apList = devWirelessIface->getAccessPoints(); -////// qWarning() << apList.count(); -//// foreach(QDBusObjectPath path, apList) { -//// QNetworkConfigurationPrivate* cpPriv = new QNetworkConfigurationPrivate(); -//// cpPriv = addAccessPoint( devIface->connectionInterface()->path(), path); -//// if(cpPriv->isValid) { -//// foundConfigurations.append(cpPriv); -//// } -//// } - } // end DEVICE_TYPE_802_11_WIRELESS - break; - }; - } //end foreach device -} - -void QNmWifiEngine::knownConnections() -{ -// qWarning() << Q_FUNC_INFO; - //// connections - QStringList connectionServices; - connectionServices << NM_DBUS_SERVICE_SYSTEM_SETTINGS; - connectionServices << NM_DBUS_SERVICE_USER_SETTINGS; - - QString connPath; - - foreach (QString service, connectionServices) { - QString ident; - QNetworkManagerSettings *settingsiface; - settingsiface = new QNetworkManagerSettings(service); - QList<QDBusObjectPath> list = settingsiface->listConnections(); - -// qWarning() <<Q_FUNC_INFO << service << list.count(); - - foreach(QDBusObjectPath path, list) { //for each connection path - //qWarning() << "COnnection path:" << path.path(); - ident = path.path(); - bool addIt = false; - QNetworkConfigurationPrivate* cpPriv = new QNetworkConfigurationPrivate(); - QNetworkManagerSettingsConnection *sysIface; - sysIface = new QNetworkManagerSettingsConnection(service, path.path()); - sysIface->setConnections(); - connect(sysIface, SIGNAL(removed(QString)), - this,SLOT(settingsConnectionRemoved(QString))); - - cpPriv->name = sysIface->getId(); - cpPriv->isValid = true; - cpPriv->id = sysIface->getUuid(); -// cpPriv->id = ident; - cpPriv->internet = true; - cpPriv->type = QNetworkConfiguration::InternetAccessPoint; -//qWarning() << cpPriv->name; - cpPriv->state = getStateForId(cpPriv->id); - - cpPriv->purpose = QNetworkConfiguration::PrivatePurpose; - - if(sysIface->getType() == DEVICE_TYPE_802_3_ETHERNET) { - QString mac = sysIface->getMacAddress(); - if(!mac.length() > 2) { - qWarning() <<"XXXXXXXXXXXXXXXXXXXXXXXXX" << mac << "type ethernet"; - QString devPath; - devPath = deviceConnectionPath(mac); - - // qWarning() << Q_FUNC_INFO << devPath; - QNetworkManagerInterfaceDevice *devIface; - devIface = new QNetworkManagerInterfaceDevice(devPath); - cpPriv->serviceInterface = devIface->interface(); - QNetworkManagerInterfaceDeviceWired *devWiredIface; - devWiredIface = new QNetworkManagerInterfaceDeviceWired(devIface->connectionInterface()->path()); - cpPriv->internet = devWiredIface->carrier(); - - // use this mac addy - } else { - cpPriv->serviceInterface = getBestInterface( DEVICE_TYPE_802_3_ETHERNET, cpPriv->id); - } - - cpPriv->internet = true;//sysIface->isAutoConnect(); - - addIt = true; - } else if(sysIface->getType() == DEVICE_TYPE_802_11_WIRELESS) { - QString mac = sysIface->getMacAddress();; - if(!mac.length() > 2) { - qWarning() <<"XXXXXXXXXXXXXXXXXXXXXXXXX" << mac << "type wireless"; - QString devPath; - devPath = deviceConnectionPath(mac); -// qWarning() << Q_FUNC_INFO << devPath; - - QNetworkManagerInterfaceDevice *devIface; - devIface = new QNetworkManagerInterfaceDevice(devPath); - cpPriv->serviceInterface = devIface->interface(); - // use this mac addy - } else { - cpPriv->serviceInterface = getBestInterface( DEVICE_TYPE_802_11_WIRELESS, cpPriv->id); - } - // cpPriv->serviceInterface = devIface->interface(); - addIt = true; - // get the wifi interface state first.. do we need this? - // QString activeAPPath = devWirelessIface->activeAccessPoint().path(); - } - if(addIt) { - foundConfigurations.append(cpPriv); - configurationInterface[cpPriv->id] = cpPriv->serviceInterface.name(); - } - } //end each connection service - } -} - -void QNmWifiEngine::accessPointConnections() -{ - //qWarning() << Q_FUNC_INFO; - QList<QDBusObjectPath> list = iface->getDevices(); - foreach(QDBusObjectPath path, list) { - QNetworkManagerInterfaceDevice *devIface; - devIface = new QNetworkManagerInterfaceDevice(path.path()); - if(devIface->deviceType() == DEVICE_TYPE_802_11_WIRELESS) { - QList<QString> apList = availableAccessPoints.uniqueKeys(); - - QList<QString>::const_iterator i; - for (i = apList.constBegin(); i != apList.constEnd(); ++i) { - QNetworkConfigurationPrivate* cpPriv = new QNetworkConfigurationPrivate(); - cpPriv = addAccessPoint( devIface->connectionInterface()->path(), availableAccessPoints[*i]); - if(cpPriv->isValid) { - foundConfigurations.append(cpPriv); - // qWarning() << "adding" << cpPriv->name << "to things"; - configurationInterface[cpPriv->id] = cpPriv->serviceInterface.name(); - } - } - } - } -} - -QString QNmWifiEngine::getInterfaceFromId(const QString &id) -{ - return configurationInterface.value(id); -} - -bool QNmWifiEngine::hasIdentifier(const QString &id) -{ - if (configurationInterface.contains(id)) - return true; - foreach (QNetworkConfigurationPrivatePointer cpPriv, getConfigurations()) { - if (cpPriv->id == id) - return true; - } - return false; -} - -QString QNmWifiEngine::bearerName(const QString &id) -{ - QString interface = getInterfaceFromId(id); - - QList<QDBusObjectPath> list = iface->getDevices(); - foreach(QDBusObjectPath path, list) { - QNetworkManagerInterfaceDevice *devIface; - devIface = new QNetworkManagerInterfaceDevice(path.path()); - if(interface == devIface->interface().name()) { - switch(devIface->deviceType()) { - case DEVICE_TYPE_802_3_ETHERNET/*NM_DEVICE_TYPE_ETHERNET*/: - return QLatin1String("Ethernet"); - break; - case DEVICE_TYPE_802_11_WIRELESS/*NM_DEVICE_TYPE_WIFI*/: - return QLatin1String("WLAN"); - break; - case DEVICE_TYPE_GSM/*NM_DEVICE_TYPE_GSM*/: - return QLatin1String("2G"); - break; - case DEVICE_TYPE_CDMA/*NM_DEVICE_TYPE_CDMA*/: - return QLatin1String("CDMA2000"); - break; - default: - break; - }; - } - } - return QString(); -} - -void QNmWifiEngine::connectToId(const QString &id) -{ -// qWarning() <<"XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" << __FUNCTION__ << id; - activatingConnectionPath = id; - QStringList connectionSettings = getConnectionPathForId(id); - if(connectionSettings.isEmpty()) { - emit connectionError(id, OperationNotSupported); - return; - } - - QDBusObjectPath connectionPath(connectionSettings.at(1)); - QString interface = getInterfaceFromId(id); - - interface = QNetworkInterface::interfaceFromName(interface).hardwareAddress().toLower(); - QString devPath; - devPath = deviceConnectionPath(interface); - QDBusObjectPath devicePath(devPath); - - iface = new QNetworkManagerInterface(); - iface->activateConnection( - connectionSettings.at(0), - connectionPath, - devicePath, - connectionPath); - - connect(iface, SIGNAL(activationFinished(QDBusPendingCallWatcher*)), - this, SLOT(slotActivationFinished(QDBusPendingCallWatcher*))); -} - -void QNmWifiEngine::disconnectFromId(const QString &id) -{ - QString activeConnectionPath = getActiveConnectionPath(id); - //qWarning() <<"XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" << __FUNCTION__ << id << activeConnectionPath ; - - if (!activeConnectionPath.isEmpty()) { - QNetworkManagerConnectionActive *activeCon; - activeCon = new QNetworkManagerConnectionActive(activeConnectionPath); - QNetworkManagerSettingsConnection *settingsCon; - settingsCon = new QNetworkManagerSettingsConnection(activeCon->serviceName(), activeCon->connection().path()); - - if(settingsCon->isAutoConnect()) { -// qWarning() << id << "is autoconnect"; - emit connectionError(id, OperationNotSupported); - //unsupported - } else { -// qWarning() <<id << "is NOT autoconnect"; - QDBusObjectPath dbpath(activeConnectionPath); - iface->deactivateConnection(dbpath); - activatingConnectionPath = ""; - } - } -} - -void QNmWifiEngine::requestUpdate() -{ - updated = false; - knownSsids.clear(); - availableAccessPoints.clear(); - //emitConfigurationsChanged(); -} - -QNmWifiEngine *QNmWifiEngine::instance() -{ - QDBusConnection dbusConnection = QDBusConnection::systemBus(); - if (dbusConnection.isConnected()) { - QDBusConnectionInterface *dbiface = dbusConnection.interface(); - QDBusReply<bool> reply = dbiface->isServiceRegistered("org.freedesktop.NetworkManager"); - if (reply.isValid() && reply.value()) - return nmWifiEngine(); - } - - return 0; -} - -void QNmWifiEngine::getKnownSsids() -{ - QStringList connectionServices; - connectionServices << NM_DBUS_SERVICE_SYSTEM_SETTINGS; - connectionServices << NM_DBUS_SERVICE_USER_SETTINGS; -//qWarning() << Q_FUNC_INFO; - foreach (QString service, connectionServices) { - QNetworkManagerSettings *settingsiface; - settingsiface = new QNetworkManagerSettings(service); - QList<QDBusObjectPath> list = settingsiface->listConnections(); - foreach(QDBusObjectPath path, list) { - QNetworkManagerSettingsConnection *sysIface; - sysIface = new QNetworkManagerSettingsConnection(service, path.path()); -// qWarning() << sysIface->getSsid(); - knownSsids << sysIface->getSsid(); - } - } -} - -void QNmWifiEngine::getActiveConnectionsPaths() -{ -// qWarning() << Q_FUNC_INFO; - QNetworkManagerInterface *dbIface; - activeConnectionPaths.clear(); - dbIface = new QNetworkManagerInterface; - QList <QDBusObjectPath> connections = dbIface->activeConnections(); - - foreach(QDBusObjectPath conpath, connections) { - activeConnectionPaths << conpath.path(); -// qWarning() << __FUNCTION__ << conpath.path() << activeConnectionPaths.count(); - - QNetworkManagerConnectionActive *activeConn; - activeConn = new QNetworkManagerConnectionActive(conpath.path()); - -// qWarning() << activeConn->connection().path() /*<< activeConn->specificObject().path() */<< activeConn->devices()[0].path(); - - } -} - -QNetworkConfigurationPrivate * QNmWifiEngine::addAccessPoint( const QString &iPath, QDBusObjectPath path) -{ //foreach accessPoint - //qWarning() << Q_FUNC_INFO << iPath << path.path(); - - QNetworkManagerInterfaceDevice *devIface; - devIface = new QNetworkManagerInterfaceDevice(iPath); - QNetworkManagerInterfaceDeviceWireless *devWirelessIface; - devWirelessIface = new QNetworkManagerInterfaceDeviceWireless(iPath); - - QString activeAPPath = devWirelessIface->activeAccessPoint().path(); - - QNetworkManagerInterfaceAccessPoint *accessPointIface; - accessPointIface = new QNetworkManagerInterfaceAccessPoint(path.path()); - - QString ident = accessPointIface->connectionInterface()->path(); - quint32 nmState = devIface->state(); - - QString ssid = accessPointIface->ssid(); - QString hwAddy = accessPointIface->hwAddress(); - QString sInterface = devIface->interface().name(); - - QNetworkConfigurationPrivate* cpPriv = new QNetworkConfigurationPrivate(); - bool addIt = true; - //qWarning() << availableAccessPoints.count() << ssid; - -// if(availableAccessPoints.contains(ssid)) { -// addIt = false; -// -// } -// foreach (QNetworkConfigurationPrivate *cpPriv, foundConfigurations) { -// if (cpPriv->name == ssid) { //weed out duplicate ssid's ?? -// addIt = false; -// break; -// } -// } - - if(addIt) { - - cpPriv->name = ssid; - cpPriv->isValid = true; - cpPriv->id = ident; - cpPriv->internet = true; - cpPriv->type = QNetworkConfiguration::InternetAccessPoint; - cpPriv->serviceInterface = devIface->interface(); - - //qWarning() <<__FUNCTION__ << ssid; - - cpPriv->state = getAPState(nmState, knownSsids.contains(cpPriv->name)); - - if(activeAPPath == accessPointIface->connectionInterface()->path()) { - cpPriv->state = ( cpPriv->state | QNetworkConfiguration::Active); - } - if(accessPointIface->flags() == NM_802_11_AP_FLAGS_PRIVACY) - cpPriv->purpose = QNetworkConfiguration::PrivatePurpose; - else - cpPriv->purpose = QNetworkConfiguration::PublicPurpose; - return cpPriv; - } else { - cpPriv->isValid = false; - } - return cpPriv; -} - - - QNetworkConfiguration::StateFlags QNmWifiEngine::getAPState(qint32 nmState, bool isKnown) -{ - QNetworkConfiguration::StateFlags state = QNetworkConfiguration::Undefined; -//qWarning() << nmState << knownSsids; - // this is the state of the wifi device interface - if(isKnown) - state = ( QNetworkConfiguration::Defined); - - switch(nmState) { //device interface state, not AP state - case NM_DEVICE_STATE_UNKNOWN: - case NM_DEVICE_STATE_UNMANAGED: - case NM_DEVICE_STATE_UNAVAILABLE: - state = (QNetworkConfiguration::Undefined); - break; - case NM_DEVICE_STATE_DISCONNECTED: - { - if(isKnown) - state = ( state | QNetworkConfiguration::Discovered); - } - break; - case NM_DEVICE_STATE_PREPARE: - case NM_DEVICE_STATE_CONFIG: - case NM_DEVICE_STATE_NEED_AUTH: - case NM_DEVICE_STATE_IP_CONFIG: - if(isKnown) - state = ( state | QNetworkConfiguration::Discovered); - break; - case NM_DEVICE_STATE_ACTIVATED: - { - if(isKnown) - state = ( state | QNetworkConfiguration::Discovered); - } - break; - }; - return state; -} - -QString QNmWifiEngine::getActiveConnectionPath(const QString &id) -{ - //qWarning() << Q_FUNC_INFO << id; - QStringList connectionSettings = getConnectionPathForId(id); - //qWarning() << Q_FUNC_INFO << id << connectionSettings.count(); - QNetworkManagerInterface * ifaceD; - ifaceD = new QNetworkManagerInterface(); - QList<QDBusObjectPath> connections = ifaceD->activeConnections(); - foreach(QDBusObjectPath path, connections) { - QNetworkManagerConnectionActive *conDetailsD; - conDetailsD = new QNetworkManagerConnectionActive( path.path()); - if(conDetailsD->connection().path() == connectionSettings.at(1) - && conDetailsD->serviceName() == connectionSettings.at(0)) - return path.path(); - } - return QString(); -} - - QNetworkConfiguration::StateFlags QNmWifiEngine::getStateFlag(quint32 nmstate) - { -// qWarning() << Q_FUNC_INFO << nmstate; - QNetworkConfiguration::StateFlags flag; - switch (nmstate) { - case NM_DEVICE_STATE_UNKNOWN: - case NM_DEVICE_STATE_FAILED: - case NM_DEVICE_STATE_UNMANAGED: - flag = (QNetworkConfiguration::Undefined); - break; - case NM_DEVICE_STATE_PREPARE: - case NM_DEVICE_STATE_CONFIG: - case NM_DEVICE_STATE_NEED_AUTH: - case NM_DEVICE_STATE_IP_CONFIG: - case NM_DEVICE_STATE_UNAVAILABLE: - flag = (QNetworkConfiguration::Defined); - break; - case NM_DEVICE_STATE_DISCONNECTED: - flag = ( flag | QNetworkConfiguration::Discovered ); - break; - case NM_DEVICE_STATE_ACTIVATED: - { - flag = ( flag | QNetworkConfiguration::Discovered - | QNetworkConfiguration::Active ); - } - break; - default: - flag = ( QNetworkConfiguration::Defined); - break; - }; - return flag; - } - -void QNmWifiEngine::updateDeviceInterfaceState(const QString &/*path*/, quint32 nmState) -{ -// qWarning() << Q_FUNC_INFO << path << nmState; - - if(nmState == NM_DEVICE_STATE_ACTIVATED - || nmState == NM_DEVICE_STATE_DISCONNECTED - || nmState == NM_DEVICE_STATE_UNAVAILABLE - || nmState == NM_DEVICE_STATE_FAILED) { - -/* InterfaceLookupError = 0, - ConnectError, - OperationNotSupported, - DisconnectionError, -*/ -// qWarning() << Q_FUNC_INFO << ident; - QNetworkConfiguration::StateFlags state = (QNetworkConfiguration::Defined); - switch (nmState) { - case NM_DEVICE_STATE_UNKNOWN: - case NM_DEVICE_STATE_FAILED: - state = (QNetworkConfiguration::Undefined); - emit connectionError(activatingConnectionPath, ConnectError); - requestUpdate(); -// qWarning() << Q_FUNC_INFO; - break; - case NM_DEVICE_STATE_UNAVAILABLE: - state = (QNetworkConfiguration::Defined); -// emit connectionError(activatingConnectionPath, ConnectError); - requestUpdate(); - break; - case NM_DEVICE_STATE_DISCONNECTED: - state = ( state | QNetworkConfiguration::Discovered ); - requestUpdate(); - break; - case NM_DEVICE_STATE_ACTIVATED: - { - state = ( state | QNetworkConfiguration::Discovered - | QNetworkConfiguration::Active ); - requestUpdate(); - } - break; - default: - state = ( QNetworkConfiguration::Defined); - break; - }; - } -} - -void QNmWifiEngine::addDevice(QDBusObjectPath path) -{ - //qWarning() << Q_FUNC_INFO << path.path(); - QNetworkManagerInterfaceDevice *devIface = new QNetworkManagerInterfaceDevice(path.path()); - devIface->setConnections(); - connect(devIface,SIGNAL(stateChanged(const QString &, quint32)), - this, SLOT(updateDeviceInterfaceState(const QString&, quint32))); - - if(!devicePaths.contains(path.path())) - devicePaths << path.path(); - - switch(devIface->deviceType()) { - case DEVICE_TYPE_802_3_ETHERNET: - { - QNetworkManagerInterfaceDeviceWired * devWiredIface; - devWiredIface = new QNetworkManagerInterfaceDeviceWired(devIface->connectionInterface()->path()); - devWiredIface->setConnections(); - connect(devWiredIface, SIGNAL(propertiesChanged(const QString &,QMap<QString,QVariant>)), - this,SLOT(cmpPropertiesChanged( const QString &, QMap<QString,QVariant>))); - requestUpdate(); - } - break; - case DEVICE_TYPE_802_11_WIRELESS: - { - QNetworkManagerInterfaceDeviceWireless *devWirelessIface; - devWirelessIface = new QNetworkManagerInterfaceDeviceWireless(devIface->connectionInterface()->path()); - devWirelessIface->setConnections(); - - connect(devWirelessIface, SIGNAL(propertiesChanged(const QString &,QMap<QString,QVariant>)), - this,SLOT(cmpPropertiesChanged( const QString &, QMap<QString,QVariant>))); - - connect(devWirelessIface, SIGNAL(accessPointAdded(const QString &,QDBusObjectPath)), - this,SLOT(accessPointAdded(const QString &,QDBusObjectPath))); - - connect(devWirelessIface, SIGNAL(accessPointRemoved(const QString &,QDBusObjectPath)), - this,SLOT(accessPointRemoved(const QString &,QDBusObjectPath))); - requestUpdate(); - - } - break; - default: - break; - }; -} - -void QNmWifiEngine::removeDevice(QDBusObjectPath /*path*/) -{ -// qWarning() << Q_FUNC_INFO << path.path(); -// disconnect(devIface,SIGNAL(stateChanged(const QString &, quint32)), -// this, SLOT(updateDeviceInterfaceState(const QString&, quint32))); -// -// if(devIface->deviceType() == DEVICE_TYPE_802_11_WIRELESS) { -// // devWirelessIface = new QNetworkManagerInterfaceDeviceWireless(devIface->connectionInterface()->path()); -// // devWirelessIface->setConnections(); -// -// disconnect(devWirelessIface, SIGNAL(propertiesChanged(const QString &,QMap<QString,QVariant>)), -// this,SIGNAL(cmpPropertiesChanged( const QString &, QMap<QString,QVariant>))); -// -// disconnect(devWirelessIface, SIGNAL(accessPointAdded(const QString &,QDBusObjectPath)), -// this,SIGNAL(accessPointAdded(const QString &,QDBusObjectPath))); -// -// disconnect(devWirelessIface, SIGNAL(accessPointRemoved(const QString &,QDBusObjectPath)), -// this,SIGNAL(accessPointRemoved(const QString &,QDBusObjectPath))); -// -// } -} -void QNmWifiEngine::cmpPropertiesChanged(const QString &path, QMap<QString,QVariant> map) -{ - QMapIterator<QString, QVariant> i(map); - while (i.hasNext()) { - i.next(); -// qWarning() << Q_FUNC_INFO << path << i.key() << i.value().toUInt(); - if( i.key() == "State") { //only applies to device interfaces - updateDeviceInterfaceState(path, i.value().toUInt()); - } - if( i.key() == "ActiveAccessPoint") { - } - if( i.key() == "Carrier") { //someone got plugged in - // requestUpdate(); - } - } -} - -void QNmWifiEngine::accessPointRemoved( const QString &aPath, QDBusObjectPath /*oPath*/) -{ - //qWarning() << Q_FUNC_INFO << aPath << oPath.path(); - - if(aPath.contains("devices")) { - requestUpdate(); - } -} - -void QNmWifiEngine::accessPointAdded( const QString &aPath, QDBusObjectPath oPath) -{ - //qWarning() << Q_FUNC_INFO << aPath << oPath.path(); - - QNetworkConfigurationPrivate* cpPriv = new QNetworkConfigurationPrivate(); - cpPriv = addAccessPoint( aPath, oPath); - requestUpdate(); -} - -QNetworkConfiguration::StateFlags QNmWifiEngine::getStateForId(const QString &id) -{ - //qWarning() << Q_FUNC_INFO << id; - bool isAvailable = false; - QStringList conPath = getConnectionPathForId(id); - QString aconpath = getActiveConnectionPath(id); - - //qWarning() << Q_FUNC_INFO << id << aconpath; - - if(!aconpath.isEmpty()) { - //active connection - QNetworkManagerConnectionActive *aConn; - aConn = new QNetworkManagerConnectionActive(aconpath); - - QList <QDBusObjectPath> devs = aConn->devices(); - - foreach(QDBusObjectPath dev, devs) { - //qWarning() << "foreach" << dev.path(); - QNetworkManagerInterfaceDevice *ifaceDevice; - ifaceDevice = new QNetworkManagerInterfaceDevice(dev.path()); - - if(ifaceDevice->deviceType() == DEVICE_TYPE_802_3_ETHERNET) { - - if(isAddressOfConnection(id, ifaceDevice->ip4Address())) { - // this is it! - return getStateFlag(ifaceDevice->state()); - } else { - continue; - } - - if(ifaceDevice->state() == NM_DEVICE_STATE_UNAVAILABLE || - ifaceDevice->state() == NM_DEVICE_STATE_DISCONNECTED) { - isAvailable = true; - - QNetworkManagerInterfaceDeviceWired *devWiredIface; - devWiredIface = new QNetworkManagerInterfaceDeviceWired(ifaceDevice->connectionInterface()->path()); - if(!devWiredIface->carrier()) - return QNetworkConfiguration::Defined; - } //end eth - } else if(ifaceDevice->deviceType() == DEVICE_TYPE_802_11_WIRELESS) { - qWarning() << "FIXME!!!!!!!!!!!!!!!!!"; - } - - return getStateFlag(ifaceDevice->state()); - } - } else { - // not active - //qWarning() << Q_FUNC_INFO << "Not active"; - QNetworkManagerSettingsConnection *sysIface; - sysIface = new QNetworkManagerSettingsConnection(conPath.at(0),conPath.at(1)); - if(sysIface->isValid()) { - if(sysIface->getType() == DEVICE_TYPE_802_11_WIRELESS) { - QString ssid = sysIface->getSsid(); - bool ok = false; - - if(knownSsids.contains(ssid, Qt::CaseSensitive)) { - foreach(QString onessid, knownSsids) { - // qWarning() << ssid << onessid; - if(onessid == ssid && availableAccessPoints.contains(ssid)) { - // qWarning() <<ssid << "In known and available SSIDS"; - ok = true; - break; - } - } - }/* else { - }*/ - if(ok) { - return getStateFlag(NM_DEVICE_STATE_DISCONNECTED); - } else { - // qWarning() << "NOT In known or available SSIDS"; - return getStateFlag(NM_DEVICE_STATE_UNAVAILABLE); - } - } - } - } - - return QNetworkConfiguration::Defined; //not active, but we know this connection so just fake it -} - -bool QNmWifiEngine::isAddressOfConnection(const QString &id, quint32 ipaddress) -{ -// qWarning() << Q_FUNC_INFO << id; - QStringList conPath = getConnectionPathForId(id); - QString aConPath = getActiveConnectionPath(id); - if(aConPath.isEmpty()) { - // not active - return false; - } - QNetworkManagerConnectionActive *aConn; - aConn = new QNetworkManagerConnectionActive(aConPath); - QList<QDBusObjectPath> devices = aConn->devices(); - foreach(QDBusObjectPath device, devices) { - QNetworkManagerInterfaceDevice *ifaceDevice; - ifaceDevice = new QNetworkManagerInterfaceDevice(device.path()); - if(ifaceDevice->ip4Address() == ipaddress) { - return true; - } - } - return false; -} - -QNetworkInterface QNmWifiEngine::getBestInterface( quint32 type, const QString &id) -{ - // check active connections first. - QStringList conIdPath = getConnectionPathForId(id); -// qWarning() << Q_FUNC_INFO << id << conIdPath; - - QNetworkInterface interface; - foreach(QString conpath, activeConnectionPaths) { - QNetworkManagerConnectionActive *aConn; - aConn = new QNetworkManagerConnectionActive(conpath); - - if(aConn->connection().path() == conIdPath.at(1) - && aConn->serviceName() == conIdPath.at(0)) { - - QList <QDBusObjectPath> devs = aConn->devices(); - QNetworkManagerInterfaceDevice *ifaceDevice; - ifaceDevice = new QNetworkManagerInterfaceDevice(devs[0].path()); //just take the first one - interface = ifaceDevice->interface(); - return interface; - } - } - -//try guessing - QList<QDBusObjectPath> list = iface->getDevices(); - foreach(QDBusObjectPath path, list) { - QNetworkManagerInterfaceDevice *devIface = new QNetworkManagerInterfaceDevice(path.path()); - if(devIface->deviceType() == type /*&& devIface->managed()*/) { - interface = devIface->interface(); - if(devIface->state() == NM_STATE_DISCONNECTED) { - return interface; - } - } - } - return interface; -} - -quint64 QNmWifiEngine::receivedDataForId(const QString &id) const -{ - if(configurationInterface.count() > 1) - return 0; - quint64 result = 0; - - QString devFile; - devFile = configurationInterface.value(id); - QFile rx("/sys/class/net/"+devFile+"/statistics/rx_bytes"); - if(rx.exists() && rx.open(QIODevice::ReadOnly | QIODevice::Text)) { - QTextStream in(&rx); - in >> result; - rx.close(); - } - return result; -} - -quint64 QNmWifiEngine::sentDataForId(const QString &id) const -{ - if(configurationInterface.count() > 1) - return 0; - quint64 result = 0; - QString devFile; - devFile = configurationInterface.value(id); - - QFile tx("/sys/class/net/"+devFile+"/statistics/tx_bytes"); - if(tx.exists() && tx.open(QIODevice::ReadOnly | QIODevice::Text)) { - QTextStream in(&tx); - in >> result; - tx.close(); - } - return result; -} - -void QNmWifiEngine::newConnection(QDBusObjectPath /*path*/) -{ - //qWarning() << Q_FUNC_INFO; - requestUpdate(); -} - -void QNmWifiEngine::settingsConnectionRemoved(const QString &/*path*/) -{ - //qWarning() << Q_FUNC_INFO; - requestUpdate(); -} - -void QNmWifiEngine::slotActivationFinished(QDBusPendingCallWatcher *openCall) -{ - QDBusPendingReply<QDBusObjectPath> reply = *openCall; - if (reply.isError()) { - qWarning() <<"Error" << reply.error().name() << reply.error().message() - <<activatingConnectionPath; - emit connectionError(activatingConnectionPath, ConnectError); - } else { - QDBusObjectPath result = reply.value(); - //qWarning() << result.path(); - } -} - -void QNmWifiEngine::scanForAccessPoints() -{ - availableAccessPoints.clear(); - QList<QDBusObjectPath> list = iface->getDevices(); - - foreach(QDBusObjectPath path, list) { - QNetworkManagerInterfaceDevice *devIface; - devIface = new QNetworkManagerInterfaceDevice(path.path()); - - if(devIface->deviceType() == DEVICE_TYPE_802_11_WIRELESS) { - -// qWarning() << devIface->connectionInterface()->path(); - - QNetworkManagerInterfaceDeviceWireless *devWirelessIface; - devWirelessIface = new QNetworkManagerInterfaceDeviceWireless(devIface->connectionInterface()->path()); - ////////////// AccessPoints - QList<QDBusObjectPath> apList = devWirelessIface->getAccessPoints(); - - foreach(QDBusObjectPath path, apList) { - QNetworkManagerInterfaceAccessPoint *accessPointIface; - accessPointIface = new QNetworkManagerInterfaceAccessPoint(path.path()); - QString ssid = accessPointIface->ssid(); - availableAccessPoints.insert(ssid, path); - } - } - } -} - -QString QNmWifiEngine::deviceConnectionPath(const QString &mac) -{ -// qWarning() << __FUNCTION__ << mac; - QString newMac = mac; - newMac = newMac.replace(":","_").toLower(); - //device object path might not contain just mac address - //might contain extra numbers on the end. thanks HAL - foreach(QString device, devicePaths) { - if(device.contains(newMac)) { - newMac = device; - break; - } - } - return newMac; -} - -QStringList QNmWifiEngine::getConnectionPathForId(const QString &uuid) -{ - QStringList connectionServices; - connectionServices << NM_DBUS_SERVICE_SYSTEM_SETTINGS; - connectionServices << NM_DBUS_SERVICE_USER_SETTINGS; -//qWarning() << Q_FUNC_INFO; - foreach (QString service, connectionServices) { - QNetworkManagerSettings *settingsiface; - settingsiface = new QNetworkManagerSettings(service); - QList<QDBusObjectPath> list = settingsiface->listConnections(); - foreach(QDBusObjectPath path, list) { - QNetworkManagerSettingsConnection *sysIface; - sysIface = new QNetworkManagerSettingsConnection(service, path.path()); -// qWarning() << uuid << sysIface->getUuid(); - if(sysIface->getUuid() == uuid) { -// qWarning() <<__FUNCTION__ << service << sysIface->getId() << sysIface->connectionInterface()->path(); - return QStringList() << service << sysIface->connectionInterface()->path(); - } - } - } - return QStringList(); -} - -QT_END_NAMESPACE - diff --git a/src/plugins/bearer/networkmanager/qnmwifiengine.h b/src/plugins/bearer/networkmanager/qnmwifiengine.h deleted file mode 100644 index d651ef4..0000000 --- a/src/plugins/bearer/networkmanager/qnmwifiengine.h +++ /dev/null @@ -1,165 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the plugins of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** 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 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QNMWIFIENGINE_P_H -#define QNMWIFIENGINE_P_H - -// -// W A R N I N G -// ------------- -// -// This file is not part of the Qt API. It exists purely as an -// implementation detail. This header file may change from version to -// version without notice, or even be removed. -// -// We mean it. -// - -//#include <QtCore/qtimer.h> - -#include <QHash> -#include <QDBusPendingCallWatcher> -#include <QExplicitlySharedDataPointer> - -#include "qnetworkmanagerservice.h" - -#include <QtNetwork/private/qnetworksessionengine_p.h> -#include <qnetworksession.h> -#include <qnetworkconfiguration.h> -#include <QtNetwork/private/qnetworkconfigmanager_p.h> - - - -QT_BEGIN_NAMESPACE - -class QNetworkConfigurationPrivate; - -class QNmWifiEngine : public QNetworkSessionEngine -{ - Q_OBJECT - -public: - QNmWifiEngine(QObject *parent = 0); - ~QNmWifiEngine(); - - QList<QNetworkConfigurationPrivatePointer> getConfigurations(bool *ok = 0); - QString getInterfaceFromId(const QString &id); - bool hasIdentifier(const QString &id); - - QString bearerName(const QString &id); - - void connectToId(const QString &id); - void disconnectFromId(const QString &id); - - void requestUpdate(); - - static QNmWifiEngine *instance(); - - QStringList knownSsids; - //inline void emitConfigurationsChanged() { emit configurationsChanged(); } - QNetworkConfigurationPrivate * addAccessPoint(const QString &, QDBusObjectPath ); - - QStringList getConnectionPathForId(const QString &uuid); - //QString getConnectionPathForId(const QString &name = QString()); - quint64 sentDataForId(const QString &id) const; - quint64 receivedDataForId(const QString &id) const; - -private: - bool updated; - QString activatingConnectionPath; - QStringList activeConnectionPaths; - - - QMap<QString,QDBusObjectPath> availableAccessPoints; - void scanForAccessPoints(); - - QStringList devicePaths; - - void getActiveConnectionsPaths(); - void getKnownSsids(); - void accessPointConnections(); - void knownConnections(); - void findConnections(); - QString deviceConnectionPath(const QString &mac); - - QList<QNetworkConfigurationPrivate *> foundConfigurations; - // QHash<QString, QExplicitlySharedDataPointer<QNetworkConfigurationPrivate> > allConfigurations; - - QNetworkManagerInterface *iface; - - QNetworkConfiguration::StateFlags getAPState(qint32 vState, bool isKnown); - QNetworkConfiguration::StateFlags getStateFlag(quint32 nmstate); - - QString getActiveConnectionPath(const QString &identifier); - QString getNameForConfiguration(QNetworkManagerInterfaceDevice *devIface); - - QNetworkConfiguration::StateFlags getStateForId(const QString &id); - - QNetworkInterface getBestInterface(quint32 type, const QString &conPath); - - QMap<QString, QString> configurationInterface; - - bool isAddressOfConnection(const QString &conPath, quint32 ipaddress); - -private slots: - void updateDeviceInterfaceState(const QString &, quint32); - void addDevice(QDBusObjectPath path); - void removeDevice(QDBusObjectPath path); - -Q_SIGNALS: - void configurationChanged(const QNetworkConfiguration& config); - void updateAccessPointState(const QString &, quint32); -// void slotActivationFinished(QDBusPendingCallWatcher*); - -private slots: - void accessPointAdded( const QString &aPath, QDBusObjectPath oPath); - void accessPointRemoved( const QString &aPath, QDBusObjectPath oPath); - void cmpPropertiesChanged(const QString &, QMap<QString,QVariant> map); - void newConnection(QDBusObjectPath); - void settingsConnectionRemoved(const QString &); - void slotActivationFinished(QDBusPendingCallWatcher*); -}; - -QT_END_NAMESPACE - -#endif - - |