diff options
author | Aaron McCarthy <aaron.mccarthy@nokia.com> | 2009-12-22 05:08:34 (GMT) |
---|---|---|
committer | Aaron McCarthy <aaron.mccarthy@nokia.com> | 2009-12-22 05:08:34 (GMT) |
commit | 5c07b6b24144774f16a20115eec1a6700d0db254 (patch) | |
tree | 0bd004ec8151036e38f212512c549ddfb956679c /src/plugins | |
parent | 70d0623570936696ca28536a46a3be63c691f50b (diff) | |
download | Qt-5c07b6b24144774f16a20115eec1a6700d0db254.zip Qt-5c07b6b24144774f16a20115eec1a6700d0db254.tar.gz Qt-5c07b6b24144774f16a20115eec1a6700d0db254.tar.bz2 |
Convert NetworkManager engine into a plugin.
Conflicts:
src/plugins/bearer/networkmanager/qnetworkmanagerservice.cpp
src/plugins/bearer/networkmanager/qnetworkmanagerservice.h
src/plugins/bearer/networkmanager/qnmdbushelper.cpp
src/plugins/bearer/networkmanager/qnmdbushelper.h
src/plugins/bearer/networkmanager/qnmwifiengine.cpp
src/plugins/bearer/networkmanager/qnmwifiengine.h
Diffstat (limited to 'src/plugins')
-rw-r--r-- | src/plugins/bearer/bearer.pro | 1 | ||||
-rw-r--r-- | src/plugins/bearer/networkmanager/main.cpp | 88 | ||||
-rw-r--r-- | src/plugins/bearer/networkmanager/networkmanager.pro | 19 | ||||
-rw-r--r-- | src/plugins/bearer/networkmanager/qnetworkmanagerservice.cpp | 1009 | ||||
-rw-r--r-- | src/plugins/bearer/networkmanager/qnetworkmanagerservice.h | 397 | ||||
-rw-r--r-- | src/plugins/bearer/networkmanager/qnmdbushelper.cpp | 114 | ||||
-rw-r--r-- | src/plugins/bearer/networkmanager/qnmdbushelper.h | 87 | ||||
-rw-r--r-- | src/plugins/bearer/networkmanager/qnmwifiengine.cpp | 1128 | ||||
-rw-r--r-- | src/plugins/bearer/networkmanager/qnmwifiengine.h | 165 |
9 files changed, 3008 insertions, 0 deletions
diff --git a/src/plugins/bearer/bearer.pro b/src/plugins/bearer/bearer.pro index 0e3ef48..60ba81b 100644 --- a/src/plugins/bearer/bearer.pro +++ b/src/plugins/bearer/bearer.pro @@ -1,3 +1,4 @@ TEMPLATE = subdirs SUBDIRS += generic +contains(QT_CONFIG, dbus):contains(QT_CONFIG, networkmanager):SUBDIRS += networkmanager diff --git a/src/plugins/bearer/networkmanager/main.cpp b/src/plugins/bearer/networkmanager/main.cpp new file mode 100644 index 0000000..c79fe91 --- /dev/null +++ b/src/plugins/bearer/networkmanager/main.cpp @@ -0,0 +1,88 @@ +/**************************************************************************** +** +** 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/qbearerplugin.h> + +#include <QtCore/qdebug.h> + +QT_BEGIN_NAMESPACE + +class QNetworkManagerEnginePlugin : public QBearerEnginePlugin +{ +public: + QNetworkManagerEnginePlugin(); + ~QNetworkManagerEnginePlugin(); + + QStringList keys() const; + QBearerEngine *create(const QString &key) const; +}; + +QNetworkManagerEnginePlugin::QNetworkManagerEnginePlugin() +{ +} + +QNetworkManagerEnginePlugin::~QNetworkManagerEnginePlugin() +{ +} + +QStringList QNetworkManagerEnginePlugin::keys() const +{ + qDebug() << Q_FUNC_INFO; + + return QStringList() << QLatin1String("networkmanager"); +} + +QBearerEngine *QNetworkManagerEnginePlugin::create(const QString &key) const +{ + qDebug() << Q_FUNC_INFO; + + if (key == QLatin1String("networkmanager")) + return new QNmWifiEngine; + else + return 0; +} + +Q_EXPORT_STATIC_PLUGIN(QNetworkManagerEnginePlugin) +Q_EXPORT_PLUGIN2(qnmbearer, QNetworkManagerEnginePlugin) + +QT_END_NAMESPACE diff --git a/src/plugins/bearer/networkmanager/networkmanager.pro b/src/plugins/bearer/networkmanager/networkmanager.pro new file mode 100644 index 0000000..36d150a --- /dev/null +++ b/src/plugins/bearer/networkmanager/networkmanager.pro @@ -0,0 +1,19 @@ +TARGET = qnmbearer +include(../../qpluginbase.pri) + +QT += network dbus + +DEFINES += BEARER_ENGINE BACKEND_NM + +HEADERS += qnmdbushelper.h \ + qnetworkmanagerservice.h \ + qnmwifiengine.h + +SOURCES += main.cpp \ + qnmdbushelper.cpp \ + qnetworkmanagerservice.cpp \ + qnmwifiengine.cpp + +QTDIR_build:DESTDIR = $$QT_BUILD_TREE/plugins/bearer +target.path += $$[QT_INSTALL_PLUGINS]/bearer +INSTALLS += target diff --git a/src/plugins/bearer/networkmanager/qnetworkmanagerservice.cpp b/src/plugins/bearer/networkmanager/qnetworkmanagerservice.cpp new file mode 100644 index 0000000..e95c2e6 --- /dev/null +++ b/src/plugins/bearer/networkmanager/qnetworkmanagerservice.cpp @@ -0,0 +1,1009 @@ +/**************************************************************************** +** +** 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 <QObject> +#include <QList> +#include <QtDBus> +#include <QDBusConnection> +#include <QDBusError> +#include <QDBusInterface> +#include <QDBusMessage> +#include <QDBusReply> +#include <QDBusPendingCallWatcher> +#include <QDBusObjectPath> +#include <QDBusPendingCall> + +#include <NetworkManager/NetworkManager.h> + +#include "qnmdbushelper.h" +#include "qnetworkmanagerservice.h" + +//Q_DECLARE_METATYPE(QList<uint>) +QT_BEGIN_NAMESPACE + +static QDBusConnection dbusConnection = QDBusConnection::systemBus(); +//static QDBusInterface iface(NM_DBUS_SERVICE, NM_DBUS_PATH, NM_DBUS_INTERFACE, dbusConnection); + +class QNetworkManagerInterfacePrivate +{ +public: + QDBusInterface *connectionInterface; + bool valid; +}; + +QNetworkManagerInterface::QNetworkManagerInterface(QObject *parent) + : QObject(parent) +{ + d = new QNetworkManagerInterfacePrivate(); + d->connectionInterface = new QDBusInterface(NM_DBUS_SERVICE, + NM_DBUS_PATH, + NM_DBUS_INTERFACE, + dbusConnection); + if (!d->connectionInterface->isValid()) { + qWarning() << "Could not find NetworkManager"; + d->valid = false; + return; + } + d->valid = true; + nmDBusHelper = new QNmDBusHelper; + connect(nmDBusHelper, SIGNAL(pathForPropertiesChanged(const QString &,QMap<QString,QVariant>)), + this,SIGNAL(propertiesChanged( const QString &, QMap<QString,QVariant>))); + connect(nmDBusHelper,SIGNAL(pathForStateChanged(const QString &, quint32)), + this, SIGNAL(stateChanged(const QString&, quint32))); + +} + +QNetworkManagerInterface::~QNetworkManagerInterface() +{ + delete d->connectionInterface; + delete d; +} + +bool QNetworkManagerInterface::isValid() +{ + return d->valid; +} + +bool QNetworkManagerInterface::setConnections() +{ + if(!isValid() ) + return false; + bool allOk = false; + if (!dbusConnection.connect(NM_DBUS_SERVICE, + NM_DBUS_PATH, + NM_DBUS_INTERFACE, + "PropertiesChanged", + nmDBusHelper,SLOT(slotPropertiesChanged( QMap<QString,QVariant>)))) { + allOk = true; + } + if (!dbusConnection.connect(NM_DBUS_SERVICE, + NM_DBUS_PATH, + NM_DBUS_INTERFACE, + "DeviceAdded", + this,SIGNAL(deviceAdded(QDBusObjectPath)))) { + allOk = true; + } + if (!dbusConnection.connect(NM_DBUS_SERVICE, + NM_DBUS_PATH, + NM_DBUS_INTERFACE, + "DeviceRemoved", + this,SIGNAL(deviceRemoved(QDBusObjectPath)))) { + allOk = true; + } + + return allOk; +} + +QDBusInterface *QNetworkManagerInterface::connectionInterface() const +{ + return d->connectionInterface; +} + +QList <QDBusObjectPath> QNetworkManagerInterface::getDevices() const +{ + QDBusReply<QList<QDBusObjectPath> > reply = d->connectionInterface->call("GetDevices"); + return reply.value(); +} + +void QNetworkManagerInterface::activateConnection( const QString &serviceName, + QDBusObjectPath connectionPath, + QDBusObjectPath devicePath, + QDBusObjectPath specificObject) +{ + QDBusPendingCall pendingCall = d->connectionInterface->asyncCall("ActivateConnection", + QVariant(serviceName), + QVariant::fromValue(connectionPath), + QVariant::fromValue(devicePath), + QVariant::fromValue(specificObject)); + + QDBusPendingCallWatcher *callWatcher = new QDBusPendingCallWatcher(pendingCall, this); + connect(callWatcher, SIGNAL(finished(QDBusPendingCallWatcher*)), + this, SIGNAL(activationFinished(QDBusPendingCallWatcher*))); +} + +void QNetworkManagerInterface::deactivateConnection(QDBusObjectPath connectionPath) const +{ + d->connectionInterface->call("DeactivateConnection", QVariant::fromValue(connectionPath)); +} + +bool QNetworkManagerInterface::wirelessEnabled() const +{ + return d->connectionInterface->property("WirelessEnabled").toBool(); +} + +bool QNetworkManagerInterface::wirelessHardwareEnabled() const +{ + return d->connectionInterface->property("WirelessHardwareEnabled").toBool(); +} + +QList <QDBusObjectPath> QNetworkManagerInterface::activeConnections() const +{ + QVariant prop = d->connectionInterface->property("ActiveConnections"); + return prop.value<QList<QDBusObjectPath> >(); +} + +quint32 QNetworkManagerInterface::state() +{ + return d->connectionInterface->property("State").toUInt(); +} + +///////////// +class QNetworkManagerInterfaceAccessPointPrivate +{ +public: + QDBusInterface *connectionInterface; + QString path; + bool valid; +}; + +QNetworkManagerInterfaceAccessPoint::QNetworkManagerInterfaceAccessPoint(const QString &dbusPathName, QObject *parent) + : QObject(parent) +{ + d = new QNetworkManagerInterfaceAccessPointPrivate(); + d->path = dbusPathName; + d->connectionInterface = new QDBusInterface(NM_DBUS_SERVICE, + d->path, + NM_DBUS_INTERFACE_ACCESS_POINT, + dbusConnection); + if (!d->connectionInterface->isValid()) { + d->valid = false; + qWarning() << "Could not find InterfaceAccessPoint"; + return; + } + d->valid = true; + +} + +QNetworkManagerInterfaceAccessPoint::~QNetworkManagerInterfaceAccessPoint() +{ + delete d->connectionInterface; + delete d; +} + +bool QNetworkManagerInterfaceAccessPoint::isValid() +{ + return d->valid; +} + +bool QNetworkManagerInterfaceAccessPoint::setConnections() +{ + if(!isValid() ) + return false; + + bool allOk = false; + nmDBusHelper = new QNmDBusHelper; + connect(nmDBusHelper, SIGNAL(pathForPropertiesChanged(const QString &,QMap<QString,QVariant>)), + this,SIGNAL(propertiesChanged( const QString &, QMap<QString,QVariant>))); + + if(dbusConnection.connect(NM_DBUS_SERVICE, + d->path, + NM_DBUS_INTERFACE_ACCESS_POINT, + "PropertiesChanged", + nmDBusHelper,SLOT(slotPropertiesChanged( QMap<QString,QVariant>))) ) { + allOk = true; + + } + return allOk; +} + +QDBusInterface *QNetworkManagerInterfaceAccessPoint::connectionInterface() const +{ + return d->connectionInterface; +} + +quint32 QNetworkManagerInterfaceAccessPoint::flags() const +{ + return d->connectionInterface->property("Flags").toUInt(); +} + +quint32 QNetworkManagerInterfaceAccessPoint::wpaFlags() const +{ + return d->connectionInterface->property("WpaFlags").toUInt(); +} + +quint32 QNetworkManagerInterfaceAccessPoint::rsnFlags() const +{ + return d->connectionInterface->property("RsnFlags").toUInt(); +} + +QString QNetworkManagerInterfaceAccessPoint::ssid() const +{ + return d->connectionInterface->property("Ssid").toString(); +} + +quint32 QNetworkManagerInterfaceAccessPoint::frequency() const +{ + return d->connectionInterface->property("Frequency").toUInt(); +} + +QString QNetworkManagerInterfaceAccessPoint::hwAddress() const +{ + return d->connectionInterface->property("HwAddress").toString(); +} + +quint32 QNetworkManagerInterfaceAccessPoint::mode() const +{ + return d->connectionInterface->property("Mode").toUInt(); +} + +quint32 QNetworkManagerInterfaceAccessPoint::maxBitrate() const +{ + return d->connectionInterface->property("MaxBitrate").toUInt(); +} + +quint32 QNetworkManagerInterfaceAccessPoint::strength() const +{ + return d->connectionInterface->property("Strength").toUInt(); +} + +///////////// +class QNetworkManagerInterfaceDevicePrivate +{ +public: + QDBusInterface *connectionInterface; + QString path; + bool valid; +}; + +QNetworkManagerInterfaceDevice::QNetworkManagerInterfaceDevice(const QString &deviceObjectPath, QObject *parent) + : QObject(parent) +{ + d = new QNetworkManagerInterfaceDevicePrivate(); + d->path = deviceObjectPath; + d->connectionInterface = new QDBusInterface(NM_DBUS_SERVICE, + d->path, + NM_DBUS_INTERFACE_DEVICE, + dbusConnection); + if (!d->connectionInterface->isValid()) { + d->valid = false; + qWarning() << "Could not find NetworkManager"; + return; + } + d->valid = true; +} + +QNetworkManagerInterfaceDevice::~QNetworkManagerInterfaceDevice() +{ + delete d->connectionInterface; + delete d; +} + +bool QNetworkManagerInterfaceDevice::isValid() +{ + return d->valid; +} + +bool QNetworkManagerInterfaceDevice::setConnections() +{ + if(!isValid() ) + return false; + + bool allOk = false; + nmDBusHelper = new QNmDBusHelper; + connect(nmDBusHelper,SIGNAL(pathForStateChanged(const QString &, quint32)), + this, SIGNAL(stateChanged(const QString&, quint32))); + if(dbusConnection.connect(NM_DBUS_SERVICE, + d->path, + NM_DBUS_INTERFACE_DEVICE, + "StateChanged", + nmDBusHelper,SLOT(deviceStateChanged(quint32)))) { + allOk = true; + } + return allOk; +} + +QDBusInterface *QNetworkManagerInterfaceDevice::connectionInterface() const +{ + return d->connectionInterface; +} + +QString QNetworkManagerInterfaceDevice::udi() const +{ + return d->connectionInterface->property("Udi").toString(); +} + +QNetworkInterface QNetworkManagerInterfaceDevice::interface() const +{ + return QNetworkInterface::interfaceFromName(d->connectionInterface->property("Interface").toString()); +} + +quint32 QNetworkManagerInterfaceDevice::ip4Address() const +{ + return d->connectionInterface->property("Ip4Address").toUInt(); +} + +quint32 QNetworkManagerInterfaceDevice::state() const +{ + return d->connectionInterface->property("State").toUInt(); +} + +quint32 QNetworkManagerInterfaceDevice::deviceType() const +{ + return d->connectionInterface->property("DeviceType").toUInt(); +} + +QDBusObjectPath QNetworkManagerInterfaceDevice::ip4config() const +{ + QVariant prop = d->connectionInterface->property("Ip4Config"); + return prop.value<QDBusObjectPath>(); +} + +///////////// +class QNetworkManagerInterfaceDeviceWiredPrivate +{ +public: + QDBusInterface *connectionInterface; + QString path; + bool valid; +}; + +QNetworkManagerInterfaceDeviceWired::QNetworkManagerInterfaceDeviceWired(const QString &ifaceDevicePath, QObject *parent) +{ + d = new QNetworkManagerInterfaceDeviceWiredPrivate(); + d->path = ifaceDevicePath; + d->connectionInterface = new QDBusInterface(NM_DBUS_SERVICE, + d->path, + NM_DBUS_INTERFACE_DEVICE_WIRED, + dbusConnection, parent); + if (!d->connectionInterface->isValid()) { + d->valid = false; + qWarning() << "Could not find InterfaceDeviceWired"; + return; + } + d->valid = true; +} + +QNetworkManagerInterfaceDeviceWired::~QNetworkManagerInterfaceDeviceWired() +{ + delete d->connectionInterface; + delete d; +} + +bool QNetworkManagerInterfaceDeviceWired::isValid() +{ + + return d->valid; +} + +bool QNetworkManagerInterfaceDeviceWired::setConnections() +{ + if(!isValid() ) + return false; + + bool allOk = false; + + nmDBusHelper = new QNmDBusHelper; + connect(nmDBusHelper, SIGNAL(pathForPropertiesChanged(const QString &,QMap<QString,QVariant>)), + this,SIGNAL(propertiesChanged( const QString &, QMap<QString,QVariant>))); + if(dbusConnection.connect(NM_DBUS_SERVICE, + d->path, + NM_DBUS_INTERFACE_DEVICE_WIRED, + "PropertiesChanged", + nmDBusHelper,SLOT(slotPropertiesChanged( QMap<QString,QVariant>))) ) { + allOk = true; + } + return allOk; +} + +QDBusInterface *QNetworkManagerInterfaceDeviceWired::connectionInterface() const +{ + return d->connectionInterface; +} + +QString QNetworkManagerInterfaceDeviceWired::hwAddress() const +{ + return d->connectionInterface->property("HwAddress").toString(); +} + +quint32 QNetworkManagerInterfaceDeviceWired::speed() const +{ + return d->connectionInterface->property("Speed").toUInt(); +} + +bool QNetworkManagerInterfaceDeviceWired::carrier() const +{ + return d->connectionInterface->property("Carrier").toBool(); +} + +///////////// +class QNetworkManagerInterfaceDeviceWirelessPrivate +{ +public: + QDBusInterface *connectionInterface; + QString path; + bool valid; +}; + +QNetworkManagerInterfaceDeviceWireless::QNetworkManagerInterfaceDeviceWireless(const QString &ifaceDevicePath, QObject *parent) +{ + d = new QNetworkManagerInterfaceDeviceWirelessPrivate(); + d->path = ifaceDevicePath; + d->connectionInterface = new QDBusInterface(NM_DBUS_SERVICE, + d->path, + NM_DBUS_INTERFACE_DEVICE_WIRELESS, + dbusConnection, parent); + if (!d->connectionInterface->isValid()) { + d->valid = false; + qWarning() << "Could not find InterfaceDeviceWireless"; + return; + } + d->valid = true; +} + +QNetworkManagerInterfaceDeviceWireless::~QNetworkManagerInterfaceDeviceWireless() +{ + delete d->connectionInterface; + delete d; +} + +bool QNetworkManagerInterfaceDeviceWireless::isValid() +{ + return d->valid; +} + +bool QNetworkManagerInterfaceDeviceWireless::setConnections() +{ + if(!isValid() ) + return false; + + bool allOk = false; + nmDBusHelper = new QNmDBusHelper; + connect(nmDBusHelper, SIGNAL(pathForPropertiesChanged(const QString &,QMap<QString,QVariant>)), + this,SIGNAL(propertiesChanged( const QString &, QMap<QString,QVariant>))); + + connect(nmDBusHelper, SIGNAL(pathForAccessPointAdded(const QString &,QDBusObjectPath)), + this,SIGNAL(accessPointAdded(const QString &,QDBusObjectPath))); + + connect(nmDBusHelper, SIGNAL(pathForAccessPointRemoved(const QString &,QDBusObjectPath)), + this,SIGNAL(accessPointRemoved(const QString &,QDBusObjectPath))); + + if(!dbusConnection.connect(NM_DBUS_SERVICE, + d->path, + NM_DBUS_INTERFACE_DEVICE_WIRELESS, + "AccessPointAdded", + nmDBusHelper, SLOT(slotAccessPointAdded( QDBusObjectPath )))) { + allOk = true; + } + + + if(!dbusConnection.connect(NM_DBUS_SERVICE, + d->path, + NM_DBUS_INTERFACE_DEVICE_WIRELESS, + "AccessPointRemoved", + nmDBusHelper, SLOT(slotAccessPointRemoved( QDBusObjectPath )))) { + allOk = true; + } + + + if(!dbusConnection.connect(NM_DBUS_SERVICE, + d->path, + NM_DBUS_INTERFACE_DEVICE_WIRELESS, + "PropertiesChanged", + nmDBusHelper,SLOT(slotPropertiesChanged( QMap<QString,QVariant>)))) { + allOk = true; + } + + return allOk; +} + +QDBusInterface *QNetworkManagerInterfaceDeviceWireless::connectionInterface() const +{ + return d->connectionInterface; +} + +QList <QDBusObjectPath> QNetworkManagerInterfaceDeviceWireless::getAccessPoints() +{ + QDBusReply<QList<QDBusObjectPath> > reply = d->connectionInterface->call("GetAccessPoints"); + return reply.value(); +} + +QString QNetworkManagerInterfaceDeviceWireless::hwAddress() const +{ + return d->connectionInterface->property("HwAddress").toString(); +} + +quint32 QNetworkManagerInterfaceDeviceWireless::mode() const +{ + return d->connectionInterface->property("Mode").toUInt(); +} + +quint32 QNetworkManagerInterfaceDeviceWireless::bitrate() const +{ + return d->connectionInterface->property("Bitrate").toUInt(); +} + +QDBusObjectPath QNetworkManagerInterfaceDeviceWireless::activeAccessPoint() const +{ + return d->connectionInterface->property("ActiveAccessPoint").value<QDBusObjectPath>(); +} + +quint32 QNetworkManagerInterfaceDeviceWireless::wirelessCapabilities() const +{ + return d->connectionInterface->property("WirelelessCapabilities").toUInt(); +} + +///////////// +class QNetworkManagerSettingsPrivate +{ +public: + QDBusInterface *connectionInterface; + QString path; + bool valid; +}; + +QNetworkManagerSettings::QNetworkManagerSettings(const QString &settingsService, QObject *parent) + : QObject(parent) +{ +// qWarning() << __PRETTY_FUNCTION__; + d = new QNetworkManagerSettingsPrivate(); + d->path = settingsService; + d->connectionInterface = new QDBusInterface(settingsService, + NM_DBUS_PATH_SETTINGS, + NM_DBUS_IFACE_SETTINGS, + dbusConnection); + if (!d->connectionInterface->isValid()) { + d->valid = false; + qWarning() << "Could not find NetworkManagerSettings"; + return; + } + d->valid = true; +} + +QNetworkManagerSettings::~QNetworkManagerSettings() +{ + delete d->connectionInterface; + delete d; +} + +bool QNetworkManagerSettings::isValid() +{ + return d->valid; +} + +bool QNetworkManagerSettings::setConnections() +{ + bool allOk = false; + + if (!dbusConnection.connect(d->path, NM_DBUS_PATH_SETTINGS, + NM_DBUS_IFACE_SETTINGS, "NewConnection", + this, SIGNAL(newConnection(QDBusObjectPath)))) { + allOk = true; + } + + return allOk; +} + +QList <QDBusObjectPath> QNetworkManagerSettings::listConnections() +{ + QDBusReply<QList<QDBusObjectPath> > reply = d->connectionInterface->call("ListConnections"); + return reply.value(); +} + +QDBusInterface *QNetworkManagerSettings::connectionInterface() const +{ + return d->connectionInterface; +} + + +///////////// +class QNetworkManagerSettingsConnectionPrivate +{ +public: + QDBusInterface *connectionInterface; + QString path; + QString service; + QNmSettingsMap settingsMap; + bool valid; +}; + +QNetworkManagerSettingsConnection::QNetworkManagerSettingsConnection(const QString &settingsService, const QString &connectionObjectPath, QObject *parent) +{ + qDBusRegisterMetaType<QNmSettingsMap>(); + d = new QNetworkManagerSettingsConnectionPrivate(); + d->path = connectionObjectPath; + d->service = settingsService; + d->connectionInterface = new QDBusInterface(settingsService, + d->path, + NM_DBUS_IFACE_SETTINGS_CONNECTION, + dbusConnection, parent); + if (!d->connectionInterface->isValid()) { + qWarning() << "Could not find NetworkManagerSettingsConnection"; + d->valid = false; + return; + } + d->valid = true; + QDBusReply< QNmSettingsMap > rep = d->connectionInterface->call("GetSettings"); + d->settingsMap = rep.value(); +} + +QNetworkManagerSettingsConnection::~QNetworkManagerSettingsConnection() +{ + delete d->connectionInterface; + delete d; +} + +bool QNetworkManagerSettingsConnection::isValid() +{ + return d->valid; +} + +bool QNetworkManagerSettingsConnection::setConnections() +{ + if(!isValid() ) + return false; + + bool allOk = false; + if(!dbusConnection.connect(d->service, d->path, + NM_DBUS_IFACE_SETTINGS_CONNECTION, "NewConnection", + this, SIGNAL(updated(QNmSettingsMap)))) { + allOk = true; + } + + nmDBusHelper = new QNmDBusHelper; + connect(nmDBusHelper, SIGNAL(pathForSettingsRemoved(const QString &)), + this,SIGNAL(removed( const QString &))); + + if (!dbusConnection.connect(d->service, d->path, + NM_DBUS_IFACE_SETTINGS_CONNECTION, "Removed", + nmDBusHelper, SIGNAL(slotSettingsRemoved()))) { + allOk = true; + } + + return allOk; +} +//QNetworkManagerSettingsConnection::update(QNmSettingsMap map) +//{ +// d->connectionInterface->call("Update", QVariant::fromValue(map)); +//} + +QDBusInterface *QNetworkManagerSettingsConnection::connectionInterface() const +{ + return d->connectionInterface; +} + +QNmSettingsMap QNetworkManagerSettingsConnection::getSettings() +{ + QDBusReply< QNmSettingsMap > rep = d->connectionInterface->call("GetSettings"); + d->settingsMap = rep.value(); + return d->settingsMap; +} + +NMDeviceType QNetworkManagerSettingsConnection::getType() +{ + QNmSettingsMap::const_iterator i = d->settingsMap.find("connection"); + while (i != d->settingsMap.end() && i.key() == "connection") { + QMap<QString,QVariant> innerMap = i.value(); + QMap<QString,QVariant>::const_iterator ii = innerMap.find("type"); + while (ii != innerMap.end() && ii.key() == "type") { + QString devType = ii.value().toString(); + if (devType == "802-3-ethernet") { + return DEVICE_TYPE_802_3_ETHERNET; + } + if (devType == "802-11-wireless") { + return DEVICE_TYPE_802_11_WIRELESS; + } + ii++; + } + i++; + } + return DEVICE_TYPE_UNKNOWN; +} + +bool QNetworkManagerSettingsConnection::isAutoConnect() +{ + QNmSettingsMap::const_iterator i = d->settingsMap.find("connection"); + while (i != d->settingsMap.end() && i.key() == "connection") { + QMap<QString,QVariant> innerMap = i.value(); + QMap<QString,QVariant>::const_iterator ii = innerMap.find("autoconnect"); + while (ii != innerMap.end() && ii.key() == "autoconnect") { + return ii.value().toBool(); + ii++; + } + i++; + } + return true; //default networkmanager is autoconnect +} + +quint64 QNetworkManagerSettingsConnection::getTimestamp() +{ + QNmSettingsMap::const_iterator i = d->settingsMap.find("connection"); + while (i != d->settingsMap.end() && i.key() == "connection") { + QMap<QString,QVariant> innerMap = i.value(); + QMap<QString,QVariant>::const_iterator ii = innerMap.find("timestamp"); + while (ii != innerMap.end() && ii.key() == "timestamp") { + return ii.value().toUInt(); + ii++; + } + i++; + } + return 0; +} + +QString QNetworkManagerSettingsConnection::getId() +{ + QNmSettingsMap::const_iterator i = d->settingsMap.find("connection"); + while (i != d->settingsMap.end() && i.key() == "connection") { + QMap<QString,QVariant> innerMap = i.value(); + QMap<QString,QVariant>::const_iterator ii = innerMap.find("id"); + while (ii != innerMap.end() && ii.key() == "id") { + return ii.value().toString(); + ii++; + } + i++; + } + return QString(); +} + +QString QNetworkManagerSettingsConnection::getUuid() +{ + QNmSettingsMap::const_iterator i = d->settingsMap.find("connection"); + while (i != d->settingsMap.end() && i.key() == "connection") { + QMap<QString,QVariant> innerMap = i.value(); + QMap<QString,QVariant>::const_iterator ii = innerMap.find("uuid"); + while (ii != innerMap.end() && ii.key() == "uuid") { + return ii.value().toString(); + ii++; + } + i++; + } + // is no uuid, return the connection path + return d->connectionInterface->path(); +} + +QString QNetworkManagerSettingsConnection::getSsid() +{ + QNmSettingsMap::const_iterator i = d->settingsMap.find("802-11-wireless"); + while (i != d->settingsMap.end() && i.key() == "802-11-wireless") { + QMap<QString,QVariant> innerMap = i.value(); + QMap<QString,QVariant>::const_iterator ii = innerMap.find("ssid"); + while (ii != innerMap.end() && ii.key() == "ssid") { + return ii.value().toString(); + ii++; + } + i++; + } + return QString(); +} + +QString QNetworkManagerSettingsConnection::getMacAddress() +{ + if(getType() == DEVICE_TYPE_802_3_ETHERNET) { + QNmSettingsMap::const_iterator i = d->settingsMap.find("802-3-ethernet"); + while (i != d->settingsMap.end() && i.key() == "802-3-ethernet") { + QMap<QString,QVariant> innerMap = i.value(); + QMap<QString,QVariant>::const_iterator ii = innerMap.find("mac-address"); + while (ii != innerMap.end() && ii.key() == "mac-address") { + return ii.value().toString(); + ii++; + } + i++; + } + } + + else if(getType() == DEVICE_TYPE_802_11_WIRELESS) { + QNmSettingsMap::const_iterator i = d->settingsMap.find("802-11-wireless"); + while (i != d->settingsMap.end() && i.key() == "802-11-wireless") { + QMap<QString,QVariant> innerMap = i.value(); + QMap<QString,QVariant>::const_iterator ii = innerMap.find("mac-address"); + while (ii != innerMap.end() && ii.key() == "mac-address") { + return ii.value().toString(); + ii++; + } + i++; + } + } + return QString(); +} + +QStringList QNetworkManagerSettingsConnection::getSeenBssids() +{ + if(getType() == DEVICE_TYPE_802_11_WIRELESS) { + QNmSettingsMap::const_iterator i = d->settingsMap.find("802-11-wireless"); + while (i != d->settingsMap.end() && i.key() == "802-11-wireless") { + QMap<QString,QVariant> innerMap = i.value(); + QMap<QString,QVariant>::const_iterator ii = innerMap.find("seen-bssids"); + while (ii != innerMap.end() && ii.key() == "seen-bssids") { + return ii.value().toStringList(); + ii++; + } + i++; + } + } + return QStringList(); +} + +///////////// +class QNetworkManagerConnectionActivePrivate +{ +public: + QDBusInterface *connectionInterface; + QString path; + bool valid; +}; + +QNetworkManagerConnectionActive::QNetworkManagerConnectionActive( const QString &activeConnectionObjectPath, QObject *parent) +{ + d = new QNetworkManagerConnectionActivePrivate(); + d->path = activeConnectionObjectPath; + d->connectionInterface = new QDBusInterface(NM_DBUS_SERVICE, + d->path, + NM_DBUS_INTERFACE_ACTIVE_CONNECTION, + dbusConnection, parent); + if (!d->connectionInterface->isValid()) { + d->valid = false; + qWarning() << "Could not find NetworkManagerSettingsConnection"; + return; + } + d->valid = true; +} + +QNetworkManagerConnectionActive::~QNetworkManagerConnectionActive() +{ + delete d->connectionInterface; + delete d; +} + +bool QNetworkManagerConnectionActive::isValid() +{ + return d->valid; +} + +bool QNetworkManagerConnectionActive::setConnections() +{ + if(!isValid() ) + return false; + + bool allOk = false; + nmDBusHelper = new QNmDBusHelper; + connect(nmDBusHelper, SIGNAL(pathForPropertiesChanged(const QString &,QMap<QString,QVariant>)), + this,SIGNAL(propertiesChanged( const QString &, QMap<QString,QVariant>))); + if(dbusConnection.connect(NM_DBUS_SERVICE, + d->path, + NM_DBUS_INTERFACE_ACTIVE_CONNECTION, + "PropertiesChanged", + nmDBusHelper,SLOT(slotPropertiesChanged( QMap<QString,QVariant>))) ) { + allOk = true; + } + + return allOk; +} + +QDBusInterface *QNetworkManagerConnectionActive::connectionInterface() const +{ + return d->connectionInterface; +} + +QString QNetworkManagerConnectionActive::serviceName() const +{ + return d->connectionInterface->property("ServiceName").toString(); +} + +QDBusObjectPath QNetworkManagerConnectionActive::connection() const +{ + QVariant prop = d->connectionInterface->property("Connection"); + return prop.value<QDBusObjectPath>(); +} + +QDBusObjectPath QNetworkManagerConnectionActive::specificObject() const +{ + QVariant prop = d->connectionInterface->property("SpecificObject"); + return prop.value<QDBusObjectPath>(); +} + +QList<QDBusObjectPath> QNetworkManagerConnectionActive::devices() const +{ + QVariant prop = d->connectionInterface->property("Devices"); + return prop.value<QList<QDBusObjectPath> >(); +} + +quint32 QNetworkManagerConnectionActive::state() const +{ + return d->connectionInterface->property("State").toUInt(); +} + +bool QNetworkManagerConnectionActive::defaultRoute() const +{ + return d->connectionInterface->property("Default").toBool(); +} + + +//// +class QNetworkManagerIp4ConfigPrivate +{ +public: + QDBusInterface *connectionInterface; + QString path; + bool valid; +}; + +QNetworkManagerIp4Config::QNetworkManagerIp4Config( const QString &deviceObjectPath, QObject *parent) +{ + d = new QNetworkManagerIp4ConfigPrivate(); + d->path = deviceObjectPath; + d->connectionInterface = new QDBusInterface(NM_DBUS_SERVICE, + d->path, + NM_DBUS_INTERFACE_IP4_CONFIG, + dbusConnection, parent); + if (!d->connectionInterface->isValid()) { + d->valid = false; + qWarning() << "Could not find NetworkManagerIp4Config"; + return; + } + d->valid = true; +} + +QNetworkManagerIp4Config::~QNetworkManagerIp4Config() +{ + delete d->connectionInterface; + delete d; +} + +bool QNetworkManagerIp4Config::isValid() +{ + return d->valid; +} + +QStringList QNetworkManagerIp4Config::domains() const +{ + return d->connectionInterface->property("Domains").toStringList(); +} + +QT_END_NAMESPACE diff --git a/src/plugins/bearer/networkmanager/qnetworkmanagerservice.h b/src/plugins/bearer/networkmanager/qnetworkmanagerservice.h new file mode 100644 index 0000000..8bed45b --- /dev/null +++ b/src/plugins/bearer/networkmanager/qnetworkmanagerservice.h @@ -0,0 +1,397 @@ +/**************************************************************************** +** +** 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 QNETWORKMANAGERSERVICE_H +#define QNETWORKMANAGERSERVICE_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 <NetworkManager/NetworkManager.h> +#include <QtDBus> +#include <QDBusConnection> +#include <QDBusError> +#include <QDBusInterface> +#include <QDBusMessage> +#include <QDBusReply> +#include <QNetworkInterface> + + +#include <QDBusPendingCallWatcher> +#include "qnmdbushelper.h" + +QT_BEGIN_NAMESPACE + +typedef QMap< QString, QMap<QString,QVariant> > QNmSettingsMap; +typedef QList<quint32> ServerThing; + +Q_DECLARE_METATYPE(QNmSettingsMap) +Q_DECLARE_METATYPE(ServerThing) + +class QNetworkManagerInterfacePrivate; +class QNetworkManagerInterface : public QObject +{ + Q_OBJECT + +public: + + QNetworkManagerInterface(QObject *parent = 0); + ~QNetworkManagerInterface(); + + QList <QDBusObjectPath> getDevices() const; + void activateConnection(const QString &serviceName, QDBusObjectPath connection, QDBusObjectPath device, QDBusObjectPath specificObject); + void deactivateConnection(QDBusObjectPath connectionPath) const; + + QDBusObjectPath path() const; + QDBusInterface *connectionInterface() const; + + bool wirelessEnabled() const; + bool wirelessHardwareEnabled() const; + QList <QDBusObjectPath> activeConnections() const; + quint32 state(); + bool setConnections(); + bool isValid(); + +Q_SIGNALS: + void deviceAdded(QDBusObjectPath); + void deviceRemoved(QDBusObjectPath); + void propertiesChanged( const QString &, QMap<QString,QVariant>); + void stateChanged(const QString&, quint32); + void activationFinished(QDBusPendingCallWatcher*); + +private Q_SLOTS: +private: +// Q_DISABLE_COPY(QNetworkManagerInterface); ?? + QNetworkManagerInterfacePrivate *d; + QNmDBusHelper *nmDBusHelper; +}; //end QNetworkManagerInterface + +//////// +class QNetworkManagerInterfaceAccessPointPrivate; +class QNetworkManagerInterfaceAccessPoint : public QObject +{ + Q_OBJECT + +public: + + // NM_DEVICE_STATE + enum DeviceState { + Unknown = 0, + Unmanaged, + Unavailable, + Disconnected, + Prepare, + Config, + NeedAuthentication, + IpConfig, + Activated, + Failed + }; + + enum ApFlag { + ApNone = 0x0, + Privacy = 0x1 + }; + + Q_DECLARE_FLAGS(ApFlags, ApFlag); + + enum ApSecurityFlag { + ApSecurityNone = 0x0, + PairWep40 = 0x1, + PairWep104 = 0x2, + PairTkip = 0x4, + PairCcmp = 0x8, + GroupWep40 = 0x10, + GroupWep104 = 0x20, + GroupTkip = 0x40, + GroupCcmp = 0x80, + KeyPsk = 0x100, + Key8021x = 0x200 + }; + + Q_DECLARE_FLAGS(ApSecurityFlags, ApSecurityFlag); + + QNetworkManagerInterfaceAccessPoint(const QString &dbusPathName, QObject *parent = 0); + ~QNetworkManagerInterfaceAccessPoint(); + + QDBusInterface *connectionInterface() const; + + quint32 flags() const; + quint32 wpaFlags() const; + quint32 rsnFlags() const; + QString ssid() const; + quint32 frequency() const; + QString hwAddress() const; + quint32 mode() const; + quint32 maxBitrate() const; + quint32 strength() const; + bool setConnections(); + bool isValid(); + +Q_SIGNALS: + void propertiesChanged(QMap <QString,QVariant>); + void propertiesChanged( const QString &, QMap<QString,QVariant>); +private: + QNetworkManagerInterfaceAccessPointPrivate *d; + QNmDBusHelper *nmDBusHelper; + +}; //end QNetworkManagerInterfaceAccessPoint + +//////// +class QNetworkManagerInterfaceDevicePrivate; +class QNetworkManagerInterfaceDevice : public QObject +{ + Q_OBJECT + +public: + + QNetworkManagerInterfaceDevice(const QString &deviceObjectPath, QObject *parent = 0); + ~QNetworkManagerInterfaceDevice(); + + QString udi() const; + QNetworkInterface interface() const; + QDBusInterface *connectionInterface() const; + quint32 ip4Address() const; + quint32 state() const; + quint32 deviceType() const; + + QDBusObjectPath ip4config() const; + bool setConnections(); + bool isValid(); + +Q_SIGNALS: + void stateChanged(const QString &, quint32); + +private: + QNetworkManagerInterfaceDevicePrivate *d; + QNmDBusHelper *nmDBusHelper; +}; //end QNetworkManagerInterfaceDevice + +//////// +class QNetworkManagerInterfaceDeviceWiredPrivate; +class QNetworkManagerInterfaceDeviceWired : public QObject +{ + Q_OBJECT + +public: + + QNetworkManagerInterfaceDeviceWired(const QString &ifaceDevicePath, QObject *parent = 0); + ~QNetworkManagerInterfaceDeviceWired(); + + QDBusInterface *connectionInterface() const; + QString hwAddress() const; + quint32 speed() const; + bool carrier() const; + bool setConnections(); + bool isValid(); + +Q_SIGNALS: + void propertiesChanged( const QString &, QMap<QString,QVariant>); +private: + QNetworkManagerInterfaceDeviceWiredPrivate *d; + QNmDBusHelper *nmDBusHelper; +}; // end QNetworkManagerInterfaceDeviceWired + +//// +class QNetworkManagerInterfaceDeviceWirelessPrivate; +class QNetworkManagerInterfaceDeviceWireless : public QObject +{ + Q_OBJECT + +public: + + enum DeviceCapability { + None = 0x0, + Wep40 = 0x1, + Wep104 = 0x2, + Tkip = 0x4, + Ccmp = 0x8, + Wpa = 0x10, + Rsn = 0x20 + }; + + QNetworkManagerInterfaceDeviceWireless(const QString &ifaceDevicePath, QObject *parent = 0); + ~QNetworkManagerInterfaceDeviceWireless(); + + QDBusObjectPath path() const; + QList <QDBusObjectPath> getAccessPoints(); + QDBusInterface *connectionInterface() const; + + QString hwAddress() const; + quint32 mode() const; + quint32 bitrate() const; + QDBusObjectPath activeAccessPoint() const; + quint32 wirelessCapabilities() const; + bool setConnections(); + bool isValid(); + +Q_SIGNALS: + void propertiesChanged( const QString &, QMap<QString,QVariant>); + void accessPointAdded(const QString &,QDBusObjectPath); + void accessPointRemoved(const QString &,QDBusObjectPath); +private: + QNetworkManagerInterfaceDeviceWirelessPrivate *d; + QNmDBusHelper *nmDBusHelper; +}; // end QNetworkManagerInterfaceDeviceWireless + +//// +class QNetworkManagerSettingsPrivate; +class QNetworkManagerSettings : public QObject +{ + Q_OBJECT + +public: + + QNetworkManagerSettings(const QString &settingsService, QObject *parent = 0); + ~QNetworkManagerSettings(); + + QDBusInterface *connectionInterface() const; + QList <QDBusObjectPath> listConnections(); + bool setConnections(); + bool isValid(); + +Q_SIGNALS: + void newConnection(QDBusObjectPath); +private: + QNetworkManagerSettingsPrivate *d; +}; //end QNetworkManagerSettings + +//// +class QNetworkManagerSettingsConnectionPrivate; +class QNetworkManagerSettingsConnection : public QObject +{ + Q_OBJECT + +public: + + QNetworkManagerSettingsConnection(const QString &settingsService, const QString &connectionObjectPath, QObject *parent = 0); + ~QNetworkManagerSettingsConnection(); + + QDBusInterface *connectionInterface() const; + QNmSettingsMap getSettings(); + // void update(QNmSettingsMap map); + bool setConnections(); + NMDeviceType getType(); + bool isAutoConnect(); + quint64 getTimestamp(); + QString getId(); + QString getUuid(); + QString getSsid(); + QString getMacAddress(); + QStringList getSeenBssids(); + bool isValid(); + +Q_SIGNALS: + + void updated(QMap< QString, QMap<QString,QVariant> > s); + void removed(const QString &); + +private: + QNmDBusHelper *nmDBusHelper; + QNetworkManagerSettingsConnectionPrivate *d; +}; //end QNetworkManagerSettingsConnection + +//// +class QNetworkManagerConnectionActivePrivate; +class QNetworkManagerConnectionActive : public QObject +{ + Q_OBJECT + +public: + + enum ActiveConnectionState { + Unknown = 0, + Activating = 1, + Activated = 2 + }; + + QNetworkManagerConnectionActive(const QString &dbusPathName, QObject *parent = 0); + ~ QNetworkManagerConnectionActive(); + + QDBusInterface *connectionInterface() const; + QString serviceName() const; + QDBusObjectPath connection() const; + QDBusObjectPath specificObject() const; + QList<QDBusObjectPath> devices() const; + quint32 state() const; + bool defaultRoute() const; + bool setConnections(); + bool isValid(); + + +Q_SIGNALS: + void propertiesChanged(QList<QDBusObjectPath>); + void propertiesChanged( const QString &, QMap<QString,QVariant>); +private: + QNetworkManagerConnectionActivePrivate *d; + QNmDBusHelper *nmDBusHelper; +}; //QNetworkManagerConnectionActive + +//// +class QNetworkManagerIp4ConfigPrivate; +class QNetworkManagerIp4Config : public QObject +{ + Q_OBJECT + +public: + QNetworkManagerIp4Config(const QString &dbusPathName, QObject *parent = 0); + ~QNetworkManagerIp4Config(); + + // QList<quint32> nameservers(); + QStringList domains() const; + bool isValid(); + + private: + QNetworkManagerIp4ConfigPrivate *d; +}; +//// + +QT_END_NAMESPACE + +#endif //QNETWORKMANAGERSERVICE_H diff --git a/src/plugins/bearer/networkmanager/qnmdbushelper.cpp b/src/plugins/bearer/networkmanager/qnmdbushelper.cpp new file mode 100644 index 0000000..1d16e55 --- /dev/null +++ b/src/plugins/bearer/networkmanager/qnmdbushelper.cpp @@ -0,0 +1,114 @@ +/**************************************************************************** +** +** 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$ +** +****************************************************************************/ + +// this class is for helping qdbus get stuff + +#include "qnmdbushelper.h" + +#include <NetworkManager/NetworkManager.h> + +#include <QDBusError> +#include <QDBusInterface> +#include <QDBusMessage> +#include <QDBusReply> + +#include <QDebug> + +QT_BEGIN_NAMESPACE + +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) { + QDBusMessage msg = this->message(); + emit pathForAccessPointAdded(msg.path(), path); + } +} + +void QNmDBusHelper::slotAccessPointRemoved(QDBusObjectPath path) +{ + if(path.path().length() > 2) { + QDBusMessage msg = this->message(); + emit pathForAccessPointRemoved(msg.path(), path); + } +} + +void QNmDBusHelper::slotPropertiesChanged(QMap<QString,QVariant> map) +{ + QDBusMessage msg = this->message(); + QMapIterator<QString, QVariant> i(map); + while (i.hasNext()) { + i.next(); + if( i.key() == "State") { //state only applies to device interfaces + 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() == "ActiveAccessPoint") { + // 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(); + } + } +} + +void QNmDBusHelper::slotSettingsRemoved() +{ + QDBusMessage msg = this->message(); + emit pathForSettingsRemoved(msg.path()); +} + +QT_END_NAMESPACE diff --git a/src/plugins/bearer/networkmanager/qnmdbushelper.h b/src/plugins/bearer/networkmanager/qnmdbushelper.h new file mode 100644 index 0000000..9794f98 --- /dev/null +++ b/src/plugins/bearer/networkmanager/qnmdbushelper.h @@ -0,0 +1,87 @@ +/**************************************************************************** +** +** 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 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 + public: + + public slots: + void deviceStateChanged(quint32); + void slotAccessPointAdded( QDBusObjectPath ); + void slotAccessPointRemoved( QDBusObjectPath ); + void slotPropertiesChanged( QMap<QString,QVariant>); + void slotSettingsRemoved(); + +Q_SIGNALS: + void pathForStateChanged(const QString &, quint32); + void pathForAccessPointAdded(const QString &, QDBusObjectPath ); + void pathForAccessPointRemoved(const QString &, QDBusObjectPath ); + void pathForPropertiesChanged(const QString &, QMap<QString,QVariant>); + void pathForSettingsRemoved(const QString &); +}; +#endif + +QT_END_NAMESPACE + +#endif// QNMDBUSHELPERPRIVATE_H diff --git a/src/plugins/bearer/networkmanager/qnmwifiengine.cpp b/src/plugins/bearer/networkmanager/qnmwifiengine.cpp new file mode 100644 index 0000000..4a814ec --- /dev/null +++ b/src/plugins/bearer/networkmanager/qnmwifiengine.cpp @@ -0,0 +1,1128 @@ +/**************************************************************************** +** +** 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<QNetworkConfigurationPrivate *> 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 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 (QNetworkConfigurationPrivate *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 new file mode 100644 index 0000000..4d514e7 --- /dev/null +++ b/src/plugins/bearer/networkmanager/qnmwifiengine.h @@ -0,0 +1,165 @@ +/**************************************************************************** +** +** 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<QNetworkConfigurationPrivate *> 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 + + |