diff options
Diffstat (limited to 'src/qtdevicesettings/networksettingsplugin/networksettings/connman')
12 files changed, 1267 insertions, 731 deletions
diff --git a/src/qtdevicesettings/networksettingsplugin/networksettings/connman/connmancommon.cpp b/src/qtdevicesettings/networksettingsplugin/networksettings/connman/connmancommon.cpp new file mode 100644 index 0000000..94a1fa1 --- /dev/null +++ b/src/qtdevicesettings/networksettingsplugin/networksettings/connman/connmancommon.cpp @@ -0,0 +1,97 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Device Utilities module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#include "connmancommon.h" + +//Conversion operations for datatypes +const QDBusArgument &operator>>(const QDBusArgument &argument, ConnmanMap &obj) +{ + argument.beginStructure(); + argument >> obj.objectPath >> obj.propertyMap; + argument.endStructure(); + return argument; +} + +QDBusArgument &operator<<(QDBusArgument &argument, const ConnmanMap &obj) +{ + argument.beginStructure(); + argument << obj.objectPath << obj.propertyMap; + argument.endStructure(); + return argument; +} + +const QString &operator>>(const QString &argument, QNetworkSettingsType &obj) +{ + if (argument == AttributeEthernet) { + obj.setType(QNetworkSettingsType::Wired); + } + else if (argument == AttributeWifi) { + obj.setType(QNetworkSettingsType::Wifi); + } + else { + obj.setType(QNetworkSettingsType::Unknown); + } + + return argument; +} + +const QString &operator>>(const QString &argument, QNetworkSettingsState &obj) +{ + if (argument == AttributeIdle) { + obj.setState(QNetworkSettingsState::Idle); + } + else if (argument == AttributeFailure) { + obj.setState(QNetworkSettingsState::Failure); + } + else if (argument == AttributeAssociation) { + obj.setState(QNetworkSettingsState::Association); + } + else if (argument == AttributeConfiguration) { + obj.setState(QNetworkSettingsState::Configuration); + } + else if (argument == AttributeReady) { + obj.setState(QNetworkSettingsState::Ready); + } + else if (argument == AttributeDisconnect) { + obj.setState(QNetworkSettingsState::Disconnect); + } + else if (argument == AttributeOneline) { + obj.setState(QNetworkSettingsState::Online); + } + else { + obj.setState(QNetworkSettingsState::Undefined); + } + return argument; +} diff --git a/src/qtdevicesettings/networksettingsplugin/networksettings/connman/connmancommon.h b/src/qtdevicesettings/networksettingsplugin/networksettings/connman/connmancommon.h new file mode 100644 index 0000000..dd3e7af --- /dev/null +++ b/src/qtdevicesettings/networksettingsplugin/networksettings/connman/connmancommon.h @@ -0,0 +1,77 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Device Utilities module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#ifndef CONNMANCOMMON_H +#define CONNMANCOMMON_H + +#include <QtCore/QMetaType> +#include <QtDBus> +#include <qnetworksettings.h> + +#define AgentPath "/ConnmanAgent" +#define PropertyState "State" +#define PropertyName "Name" +#define PropertyType "Type" +#define PropertyConnected "Connected" +#define PropertyPowered "Powered" + +#define AttributeWifi "wifi" +#define AttributeEthernet "ethernet" +#define AttributeIdle "idle" +#define AttributeFailure "failure" +#define AttributeAssociation "association" +#define AttributeConfiguration "configuration" +#define AttributeReady "ready" +#define AttributeDisconnect "disconnect" +#define AttributeOneline "online" + +struct ConnmanMap { + QDBusObjectPath objectPath; + QVariantMap propertyMap; +}; + +QDBusArgument &operator<<(QDBusArgument &argument, const ConnmanMap &obj); +const QDBusArgument &operator>>(const QDBusArgument &argument, ConnmanMap &obj); + +const QString &operator>>(const QString &argument, QNetworkSettingsType &obj); +const QString &operator>>(const QString &argument, QNetworkSettingsState &obj); + +typedef QList<ConnmanMap> ConnmanMapList; + +Q_DECLARE_METATYPE( ConnmanMap ) +Q_DECLARE_METATYPE( ConnmanMapList ) + + +#endif // CONNMANCOMMON_H diff --git a/src/qtdevicesettings/networksettingsplugin/networksettings/connman/networksettingsmanager_linux.cpp b/src/qtdevicesettings/networksettingsplugin/networksettings/connman/networksettingsmanager_linux.cpp deleted file mode 100644 index c4973ea..0000000 --- a/src/qtdevicesettings/networksettingsplugin/networksettings/connman/networksettingsmanager_linux.cpp +++ /dev/null @@ -1,583 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2015 The Qt Company Ltd. -** Contact: http://www.qt.io/licensing/ -** -** This file is part of the Qt Device Utilities module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL3$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see http://www.qt.io/terms-conditions. For further -** information use the contact form at http://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPLv3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or later as published by the Free -** Software Foundation and appearing in the file LICENSE.GPL included in -** the packaging of this file. Please review the following information to -** ensure the GNU General Public License version 2.0 requirements will be -** met: http://www.gnu.org/licenses/gpl-2.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ -#include <QQmlPropertyMap> - -#include "networkconfig.h" -#include "networksettingsmanager_linux_p.h" -#include "connman_manager_interface.cpp" -#include "moc_connman_manager_interface.cpp" -#include "connman_service_interface.h" -#include "connman_technology_interface.h" - -const QString PropertyIPv4("IPv4"); -const QString PropertyIPv4Config("IPv4.Configuration"); -const QString PropertyIPv6("IPv6"); -const QString PropertyIPv6Config("IPv6.Configuration"); -const QString PropertyNameservers("Nameservers"); -const QString PropertyNameserversConfig("Nameservers.Configuration"); -const QString PropertyDomains("Domains"); -const QString PropertyDomainsConfig("Domains.Configuration"); -const QString PropertyProxy("Proxy"); -const QString PropertyProxyConfig("Proxy.Configuration"); -const QString PropertyState("State"); -const QString PropertyName("Name"); -const QString PropertyType("Type"); -const QString PropertyConnected("Connected"); -const QString PropertyPowered("Powered"); -const QString PropertyAddress("Address"); -const QString PropertyNetMask("Netmask"); -const QString PropertyGateway("Gateway"); -const QString PropertyPrefixLength("PrefixLength"); -const QString PropertyMethod("Method"); -const QString PropertyPrivacy("Privacy"); -const QString PropertyUrl("Url"); -const QString PropertyServers("Servers"); -const QString PropertyExcludes("Excludes"); -const QString AttributeAuto("auto"); -const QString AttributeDhcp("dhcp"); -const QString AttributeManual("manual"); -const QString AttributeOff("off"); -const QString AttributeDisabled("disabled"); -const QString AttributeEnabled("enabled"); -const QString AttributePreferred("preferred"); -const QString AttributeDirect("direct"); -const QString AttributeWifi("wifi"); -const QString AttributeEthernet("ethernet"); -const QString AttributeIdle("idle"); -const QString AttributeFailure("failure"); -const QString AttributeAssociation("association"); -const QString AttributeConfiguration("configuration"); -const QString AttributeReady("ready"); -const QString AttributeDisconnect("disconnect"); -const QString AttributeOneline("online"); - -//Conversion operations for datatypes -const QDBusArgument &operator>>(const QDBusArgument &argument, ConnmanMap &obj) -{ - argument.beginStructure(); - argument >> obj.objectPath >> obj.propertyMap; - argument.endStructure(); - return argument; -} - -QDBusArgument &operator<<(QDBusArgument &argument, const ConnmanMap &obj) -{ - argument.beginStructure(); - argument << obj.objectPath << obj.propertyMap; - argument.endStructure(); - return argument; -} - -const QVariantMap &operator>>(const QVariantMap &argument, IPv4Config &obj) -{ - obj.setAddress(argument[PropertyAddress].toString()); - obj.setMask(argument[PropertyNetMask].toString()); - obj.setGateway(argument[PropertyGateway].toString()); - - QString method = argument[PropertyMethod].toString(); - - if (method == AttributeDhcp) { - obj.setMethod(IPv4Config::Dhcp); - } - else if (method == AttributeManual) { - obj.setMethod(IPv4Config::Manual); - } - else if (method == AttributeOff) { - obj.setMethod(IPv4Config::Off); - } - else { - obj.setMethod(IPv4Config::Off); - } - return argument; -} - -const QVariantMap &operator<<(QVariantMap &argument, const IPv4Config &obj) -{ - argument.insert(PropertyAddress, QVariant::fromValue(obj.address())); - - argument.insert(PropertyNetMask, QVariant::fromValue(obj.mask())); - - argument.insert(PropertyGateway, QVariant::fromValue(obj.gateway())); - - QString method; - switch (obj.method()) { - case IPv4Config::Dhcp: - method = AttributeDhcp; - break; - case IPv4Config::Manual: - method = AttributeManual; - break; - case IPv4Config::Off: - method = AttributeOff; - break; - default: - break; - } - argument.insert(PropertyMethod, QVariant::fromValue(method)); - return argument; -} - -const QVariantMap &operator>>(const QVariantMap &argument, IPv6Config &obj) -{ - obj.setAddress(argument[PropertyAddress].toString()); - obj.setGateway(argument[PropertyGateway].toString()); - obj.setPrefixLength(argument[PropertyPrefixLength].toInt()); - QString method = argument[PropertyMethod].toString(); - if (method == AttributeAuto) { - obj.setMethod(IPv6Config::Auto); - } - else if (method == AttributeManual) { - obj.setMethod(IPv6Config::Manual); - } - else if (method == AttributeOff) { - obj.setMethod(IPv6Config::Off); - } - QString privacy = argument[PropertyPrivacy].toString(); - - if (privacy == AttributeDisabled) { - obj.setPrivacy(IPv6Config::Disabled); - } - else if (privacy == AttributeEnabled) { - obj.setPrivacy(IPv6Config::Enabled); - } - else if (privacy == AttributePreferred) { - obj.setPrivacy(IPv6Config::Preferred); - } - return argument; -} - -const QVariantMap &operator<<(QVariantMap &argument, const IPv6Config &obj) -{ - argument.insert(PropertyAddress, QVariant::fromValue(obj.address())); - argument.insert(PropertyGateway, QVariant::fromValue(obj.address())); - argument.insert(PropertyPrefixLength, QVariant::fromValue(obj.prefixLength())); - - QString method; - switch (obj.method()) { - case IPv6Config::Auto: - method = AttributeAuto; - break; - case IPv6Config::Manual: - method = AttributeManual; - break; - case IPv6Config::Off: - method = AttributeOff; - break; - default: - break; - } - argument.insert(PropertyMethod, QVariant::fromValue(method)); - - QString privacy; - switch (obj.privacy()) { - case IPv6Config::Disabled: - method = AttributeDisabled; - break; - case IPv6Config::Enabled: - method = AttributeEnabled; - break; - case IPv6Config::Preferred: - method = AttributePreferred; - break; - default: - break; - } - argument.insert(PropertyPrivacy, QVariant::fromValue(privacy)); - - return argument; -} - - -const QVariantMap &operator>>(const QVariantMap &argument, ProxyConfig &obj) -{ - QString method = argument[PropertyMethod].toString(); - if (method == AttributeDirect) { - obj.setMethod(ProxyConfig::Direct); - } - else if (method == AttributeAuto) { - obj.setMethod(ProxyConfig::Auto); - } - else if (method == AttributeManual) { - obj.setMethod(ProxyConfig::Manual); - } - - QString urlStr = argument[PropertyUrl].toString(); - obj.setUrl(QUrl(urlStr)); - - obj.setServers(argument[PropertyServers].toStringList()); - obj.setExcludes(argument[PropertyExcludes].toStringList()); - - return argument; -} - -const QVariantMap &operator<<(QVariantMap &argument, const ProxyConfig &obj) -{ - QString method; - switch (obj.method()) { - case ProxyConfig::Direct: - method = AttributeDirect; - break; - case ProxyConfig::Auto: - method = AttributeAuto; - break; - case ProxyConfig::Manual: - method = AttributeManual; - break; - default: - break; - } - argument.insert(PropertyMethod, QVariant::fromValue(method)); - argument.insert(PropertyUrl, QVariant::fromValue(obj.url().toString())); - argument.insert(PropertyServers, QVariant::fromValue(obj.servers())); - argument.insert(PropertyServers, QVariant::fromValue(obj.excludes())); - - return argument; -} - -const QString &operator>>(const QString &argument, NetworkType &obj) -{ - if (argument == AttributeEthernet) { - obj.setType(NetworkType::Wired); - } - else if (argument == AttributeWifi) { - obj.setType(NetworkType::Wifi); - } - else { - obj.setType(NetworkType::Unknown); - } - - return argument; -} - -const QString &operator>>(const QString &argument, NetworkState &obj) -{ - if (argument == AttributeIdle) { - obj.setState(NetworkState::Idle); - } - else if (argument == AttributeFailure) { - obj.setState(NetworkState::Failure); - } - else if (argument == AttributeAssociation) { - obj.setState(NetworkState::Association); - } - else if (argument == AttributeConfiguration) { - obj.setState(NetworkState::Configuration); - } - else if (argument == AttributeReady) { - obj.setState(NetworkState::Ready); - } - else if (argument == AttributeDisconnect) { - obj.setState(NetworkState::Disconnect); - } - else if (argument == AttributeOneline) { - obj.setState(NetworkState::Online); - } - else { - obj.setState(NetworkState::Undefined); - } - return argument; -} - -NetworkServicePrivate::NetworkServicePrivate(const QString& aPath, NetworkService *parent) : - QObject(parent) - ,q_ptr(parent) - ,m_path(aPath) -{ - qDBusRegisterMetaType<ConnmanMap>(); - qDBusRegisterMetaType<ConnmanMapList>(); - - m_service = new NetConnmanServiceInterface("net.connman", m_path, - QDBusConnection::systemBus(), this); - - connect(m_service, SIGNAL(PropertyChanged(QString,QDBusVariant)), - this, SLOT(updateProperty(QString,QDBusVariant))); - - QDBusPendingReply<QVariantMap> reply = m_service->GetProperties(); - QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(reply, this); - - connect(watcher, SIGNAL(finished(QDBusPendingCallWatcher*)), - this, SLOT(propertiesUpdated(QDBusPendingCallWatcher*))); -} - -void NetworkServicePrivate::setupIpv6Config() -{ - QVariantMap param; - param << m_ipv6config; - if (m_service) - m_service->SetProperty(PropertyIPv6Config, QDBusVariant(QVariant(param))); -} - -void NetworkServicePrivate::setupNameserversConfig() -{ - QVariant param = QVariant::fromValue(m_nameserverConfig.stringList()); - if (m_service) - m_service->SetProperty(PropertyNameserversConfig, QDBusVariant(QVariant(param))); -} - -void NetworkServicePrivate::setupDomainsConfig() -{ - QVariant param = QVariant::fromValue(m_domainsConfig.stringList()); - if (m_service) - m_service->SetProperty(PropertyDomainsConfig, QDBusVariant(QVariant(param))); -} - -void NetworkServicePrivate::setupProxyConfig() -{ - QVariantMap param; - param << m_proxyConfig; - if (m_service) - m_service->SetProperty(PropertyProxyConfig, QDBusVariant(QVariant(param))); -} - -void NetworkServicePrivate::setupIpv4Config() -{ - QVariantMap param; - param << m_ipv4config; - if (m_service) - m_service->SetProperty(PropertyIPv4Config, QDBusVariant(QVariant(param))); -} - - -void NetworkServicePrivate::propertiesUpdated(QDBusPendingCallWatcher *call) -{ - QDBusPendingReply<QVariantMap> reply = *call; - call->deleteLater(); - - if (!reply.isError()) - setupConfiguration(reply.value()); -} - -void NetworkServicePrivate::updateProperty(const QString &name, const QDBusVariant &value) -{ - updateProperty(name, value.variant()); -} - -void NetworkServicePrivate::updateProperty(const QString& key, const QVariant& val) -{ - Q_Q(NetworkService); - - if (key == PropertyIPv4) { - QVariantMap value = qdbus_cast<QVariantMap>(val); - value >> m_ipv4config; - emit q->ipv4Changed(); - } - else if (key == PropertyIPv6) { - QVariantMap value = qdbus_cast<QVariantMap>(val); - value >> m_ipv6config; - emit q->ipv6Changed(); - } - else if (key == PropertyNameservers) { - QStringList value = qdbus_cast<QStringList>(val); - m_nameserverConfig.setStringList(value); - emit q->nameserversChanged(); - } - else if (key == PropertyDomains) { - QStringList value = qdbus_cast<QStringList>(val); - m_domainsConfig.setStringList(value); - emit q->domainsChanged(); - } - else if (key == PropertyProxy) { - QVariantMap value = qdbus_cast<QVariantMap>(val); - value >> m_proxyConfig; - emit q->proxyChanged(); - } - else if (key == PropertyState) { - QString value = qdbus_cast<QString>(val); - value >> m_state; - emit q->stateChanged(); - } - else if (key == PropertyName) { - m_name = qdbus_cast<QString>(val); - emit q->nameChanged(); - } - else if (key == PropertyType) { - QString value = qdbus_cast<QString>(val); - value >> m_type; - } -} - -void NetworkServicePrivate::setupConfiguration(const QVariantMap &properties) -{ - QVariantMap::const_iterator it = properties.constBegin(), end = properties.constEnd(); - for ( ; it != end; ++it) { - updateProperty(it.key(), it.value()); - } -} - -NetworkTechnology::NetworkTechnology(const QString& path, const QVariantMap& properties, QObject* parent) - : NetworkItem(parent) - { - m_technology = new NetConnmanTechnologyInterface("net.connman", path, - QDBusConnection::systemBus(), this); - connect(m_technology, SIGNAL(PropertyChanged(QString,QDBusVariant)), - this, SLOT(updateProperty(QString,QDBusVariant))); - - updateProperty(PropertyName, properties[PropertyName]); - updateProperty(PropertyType, properties[PropertyType]); - updateProperty(PropertyConnected, properties[PropertyConnected]); - updateProperty(PropertyPowered, properties[PropertyPowered]); - } - -void NetworkTechnology::updateProperty(const QString &name, const QDBusVariant &value) -{ - updateProperty(name, value.variant()); -} - -void NetworkTechnology::updateProperty(const QString &name, const QVariant &value) -{ - if (name == PropertyName) { - m_name = qdbus_cast<QString>(value); - } - else if (name == PropertyType) { - qdbus_cast<QString>(value) >> m_type; - emit typeChanged(); - } - else if (name == PropertyConnected) { - bool connected = qdbus_cast<bool>(value); - if (connected) - m_state.setState(NetworkState::Online); - else - m_state.setState(NetworkState::Disconnect); - emit stateChanged(); - } - else if (name == PropertyPowered) { - m_powered = qdbus_cast<bool>(value); - emit poweredChanged(); - } -} - - -NetworkSettingsManagerPrivate::NetworkSettingsManagerPrivate(NetworkSettingsManager *parent) - :QObject(parent) - ,q_ptr(parent) -{ - m_manager = new NetConnmanManagerInterface("net.connman", "/", - QDBusConnection::systemBus(), this); - - if (m_manager->isValid()) { - //List technologies - QDBusPendingReply<ConnmanMapList> reply = m_manager->GetTechnologies(); - QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(reply, this); - connect(watcher, SIGNAL(finished(QDBusPendingCallWatcher*)), - this, SLOT(getTechnologiesFinished(QDBusPendingCallWatcher*))); - - reply = m_manager->GetServices(); - watcher = new QDBusPendingCallWatcher(reply, this); - connect(watcher, SIGNAL(finished(QDBusPendingCallWatcher*)), - this, SLOT(getServicesFinished(QDBusPendingCallWatcher*))); - } - else { - delete m_manager; - m_manager = NULL; - } -} - -void NetworkSettingsManagerPrivate::getServicesFinished(QDBusPendingCallWatcher *watcher) -{ - Q_Q(NetworkSettingsManager); - QDBusPendingReply<ConnmanMapList> reply = *watcher; - watcher->deleteLater(); - if (reply.isError()) - return; - - foreach (const ConnmanMap &object, reply.value()) { - const QString servicePath = object.objectPath.path(); - NetworkService *service = new NetworkService(servicePath, this); - m_services.append(service); - - //Update status property - QString n = qdbus_cast<QString>(object.propertyMap[PropertyName]); - QString t = qdbus_cast<QString>(object.propertyMap[PropertyType]); - QString s = qdbus_cast<QString>(object.propertyMap[PropertyState]); - - NetworkType type; - t >> type; - NetworkState state; - s >> state; - - foreach (NetworkItem* item, m_networksModel.getModel()) { - if (item->name() == n && item->type() == type.type()) { - item->setState(state.state()); - } - } - } - emit q->servicesChanged(); -} - -void NetworkSettingsManagerPrivate::getTechnologiesFinished(QDBusPendingCallWatcher *watcher) -{ - Q_Q(NetworkSettingsManager); - QDBusPendingReply<ConnmanMapList> reply = *watcher; - watcher->deleteLater(); - if (reply.isError()) - return; - - foreach (const ConnmanMap &object, reply.value()) { - NetworkTechnology *item = new NetworkTechnology(object.objectPath.path(), object.propertyMap, this); - - //Wired to the top - if (item->type() == NetworkType::Wired) - m_networksModel.insert(0, item); - else if (item->type() == NetworkType::Wifi) { - connect(item, &NetworkItem::poweredChanged, q, &NetworkSettingsManager::wifiPoweredChanged); - m_networksModel.append(item); - } - emit q->networksChanged(); - } -} - -bool NetworkSettingsManagerPrivate::wifiPowered() -{ - foreach (NetworkItem* item, m_networksModel.getModel()) { - if (item->type() == NetworkType::Wifi) { - return item->powered(); - } - } - return false; -} - -void NetworkSettingsManagerPrivate::setWifiPowered(const bool powered) -{ - foreach (NetworkItem* item, m_networksModel.getModel()) { - if (item->type() == NetworkType::Wifi) { - NetworkTechnology* technology = qobject_cast<NetworkTechnology*>(item); - if (technology) { - NetConnmanTechnologyInterface *connmantech = technology->getTechnology(); - connmantech->SetProperty(PropertyPowered, QDBusVariant(QVariant(powered))); - } - } - } -} diff --git a/src/qtdevicesettings/networksettingsplugin/networksettings/connman/networksettingsmanager_linux_p.h b/src/qtdevicesettings/networksettingsplugin/networksettings/connman/networksettingsmanager_linux_p.h deleted file mode 100644 index bccbed8..0000000 --- a/src/qtdevicesettings/networksettingsplugin/networksettings/connman/networksettingsmanager_linux_p.h +++ /dev/null @@ -1,148 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2015 The Qt Company Ltd. -** Contact: http://www.qt.io/licensing/ -** -** This file is part of the Qt Device Utilities module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL3$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see http://www.qt.io/terms-conditions. For further -** information use the contact form at http://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPLv3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or later as published by the Free -** Software Foundation and appearing in the file LICENSE.GPL included in -** the packaging of this file. Please review the following information to -** ensure the GNU General Public License version 2.0 requirements will be -** met: http://www.gnu.org/licenses/gpl-2.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ -#ifndef NETWORKSETTINGSMANAGERPRIVATE_H -#define NETWORKSETTINGSMANAGERPRIVATE_H - -#include <QObject> -#include <QtDBus> -#include <QList> -#include <QtDBus/QDBusObjectPath> -#include <QtCore/QMetaType> -#include "networkaddressmodel.h" -#include "networksettingsmanager.h" -#include "networksmodel.h" - -class NetConnmanManagerInterface; -class NetConnmanServiceInterface; -class NetworkService; -class NetConnmanTechnologyInterface; - -struct ConnmanMap { - QDBusObjectPath objectPath; - QVariantMap propertyMap; -}; - -QDBusArgument &operator<<(QDBusArgument &argument, const ConnmanMap &obj); - -const QDBusArgument &operator>>(const QDBusArgument &argument, ConnmanMap &obj); - -typedef QList<ConnmanMap> ConnmanMapList; - -Q_DECLARE_METATYPE( ConnmanMap ) -Q_DECLARE_METATYPE( ConnmanMapList ) - -class NetworkServicePrivate : public QObject -{ - Q_OBJECT - Q_DECLARE_PUBLIC(NetworkService) -public: - NetworkServicePrivate(const QString& aPath, NetworkService *parent=0); - - NetworkService *q_ptr; -private slots: - void propertiesUpdated(QDBusPendingCallWatcher *call); - void updateProperty(const QString &name, const QDBusVariant &value); - -private: - void setupConfiguration(const QVariantMap &properties); - void updateProperty(const QString& key, const QVariant& value); - -protected: - void setAutoConnect(const bool autoconnect); - void setupIpv4Config(); - void setupIpv6Config(); - void setupNameserversConfig(); - void setupDomainsConfig(); - void setupProxyConfig(); - - QString m_path; - QString m_name; - NetworkState m_state; - IPv4Config m_ipv4config; - IPv6Config m_ipv6config; - NetworkAddressModel m_domainsConfig; - NetworkAddressModel m_nameserverConfig; - ProxyConfig m_proxyConfig; - WifiConfig m_wifiConfig; - NetworkType m_type; - NetConnmanServiceInterface *m_service; -}; - -class NetworkTechnology : public NetworkItem -{ - Q_OBJECT -public: - explicit NetworkTechnology(const QString& path, const QVariantMap& properties, QObject* parent=0); - virtual ~NetworkTechnology() { - - } - - NetConnmanTechnologyInterface *getTechnology() { - return m_technology; - } - -public slots: - void updateProperty(const QString &name, const QDBusVariant &value); -protected: - void updateProperty(const QString &name, const QVariant &value); - -private: - NetConnmanTechnologyInterface *m_technology; -}; - - -class NetworkSettingsManagerPrivate : public QObject -{ - Q_OBJECT - Q_DECLARE_PUBLIC(NetworkSettingsManager) -public: - explicit NetworkSettingsManagerPrivate(NetworkSettingsManager *parent); - NetworkSettingsManager *q_ptr; - void setWifiPowered(const bool powered); - bool wifiPowered(); - -public slots: - void getServicesFinished(QDBusPendingCallWatcher *watcher); - void getTechnologiesFinished(QDBusPendingCallWatcher *watcher); - -protected: - QList<NetworkService*> m_services; - NetworksModel m_networksModel; -private: - NetConnmanManagerInterface *m_manager; -}; - -#endif // NETWORKSETTINGSMANAGERPRIVATE_H diff --git a/src/qtdevicesettings/networksettingsplugin/networksettings/connman/qnetworksettingsinterface_p.cpp b/src/qtdevicesettings/networksettingsplugin/networksettings/connman/qnetworksettingsinterface_p.cpp new file mode 100644 index 0000000..9a034d0 --- /dev/null +++ b/src/qtdevicesettings/networksettingsplugin/networksettings/connman/qnetworksettingsinterface_p.cpp @@ -0,0 +1,105 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Device Utilities module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#include "qnetworksettingsinterface_p.h" +#include "qnetworksettingsinterface.h" +#include "connman_technology_interface.h" +#include "connmancommon.h" + +QNetworkSettingsInterfacePrivate::QNetworkSettingsInterfacePrivate(QNetworkSettingsInterface* parent) + : QObject(parent) + ,q_ptr(parent) +{ + +} + +void QNetworkSettingsInterfacePrivate::initialize(const QString& path, const QVariantMap& properties) +{ + m_technology = new NetConnmanTechnologyInterface("net.connman", path, + QDBusConnection::systemBus(), this); + connect(m_technology, SIGNAL(PropertyChanged(QString,QDBusVariant)), + this, SLOT(updateProperty(QString,QDBusVariant))); + + updateProperty(PropertyName, properties[PropertyName]); + updateProperty(PropertyType, properties[PropertyType]); + updateProperty(PropertyConnected, properties[PropertyConnected]); + updateProperty(PropertyPowered, properties[PropertyPowered]); +} + +void QNetworkSettingsInterfacePrivate::updateProperty(const QString &name, const QDBusVariant &value) +{ + updateProperty(name, value.variant()); +} + +void QNetworkSettingsInterfacePrivate::updateProperty(const QString &name, const QVariant &value) +{ + Q_Q(QNetworkSettingsInterface); + if (name == PropertyName) { + m_name = qdbus_cast<QString>(value); + } + else if (name == PropertyType) { + qdbus_cast<QString>(value) >> m_type; + emit q->typeChanged(); + } + else if (name == PropertyConnected) { + bool connected = qdbus_cast<bool>(value); + if (connected) + m_state.setState(QNetworkSettingsState::Online); + else + m_state.setState(QNetworkSettingsState::Disconnect); + emit q->stateChanged(); + } + else if (name == PropertyPowered) { + m_powered = qdbus_cast<bool>(value); + emit q->poweredChanged(); + } +} + +void QNetworkSettingsInterfacePrivate::setState(QNetworkSettingsState::States aState) +{ + Q_Q(QNetworkSettingsInterface); + m_state.setState(aState); + emit q->stateChanged(); +} + +void QNetworkSettingsInterfacePrivate::setPowered(const bool aPowered) +{ + m_technology->SetProperty(PropertyPowered, QDBusVariant(QVariant(aPowered))); +} + +void QNetworkSettingsInterfacePrivate::scan() +{ + m_technology->Scan(); +} diff --git a/src/qtdevicesettings/networksettingsplugin/networksettings/connman/qnetworksettingsinterface_p.h b/src/qtdevicesettings/networksettingsplugin/networksettings/connman/qnetworksettingsinterface_p.h new file mode 100644 index 0000000..6e1d5ca --- /dev/null +++ b/src/qtdevicesettings/networksettingsplugin/networksettings/connman/qnetworksettingsinterface_p.h @@ -0,0 +1,92 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Device Utilities module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#ifndef QNETWORKSETTINGSINTERFACEPRIVATE_H +#define QNETWORKSETTINGSINTERFACEPRIVATE_H + +#include <QObject> +#include <QtDBus> +#include "qnetworksettings.h" +#include "qnetworksettingsinterface.h" + +class NetConnmanTechnologyInterface; + +class QNetworkSettingsInterfacePrivate : public QObject +{ + Q_OBJECT + Q_DECLARE_PUBLIC(QNetworkSettingsInterface) +public: + explicit QNetworkSettingsInterfacePrivate(QNetworkSettingsInterface* parent); + void initialize(const QString& path, const QVariantMap& properties); + void setPowered(const bool power); + void setState(QNetworkSettingsState::States aState); + void scan(); + +public slots: + void updateProperty(const QString &name, const QDBusVariant &value); +protected: + void updateProperty(const QString &name, const QVariant &value); + +protected: + NetConnmanTechnologyInterface *m_technology; + QString m_name; + QNetworkSettingsType m_type; + QNetworkSettingsState m_state; + bool m_powered; + QNetworkSettingsInterface *q_ptr; +}; + + +class ConnmanSettingsInterface : public QNetworkSettingsInterface +{ + Q_OBJECT +public: + ConnmanSettingsInterface(const QString& path, const QVariantMap& properties, QObject *parent=0) + :QNetworkSettingsInterface(parent) + { + if (d_ptr) + d_ptr->initialize(path, properties); + } + + void setState(QNetworkSettingsState::States aState) { + Q_D(QNetworkSettingsInterface); + d->setState(aState); + } + + virtual ~ConnmanSettingsInterface() { + + } +}; +#endif // QNETWORKSETTINGSINTERFACEPRIVATE_H diff --git a/src/qtdevicesettings/networksettingsplugin/networksettings/connman/qnetworksettingsmanager_p.cpp b/src/qtdevicesettings/networksettingsplugin/networksettings/connman/qnetworksettingsmanager_p.cpp new file mode 100644 index 0000000..2d4a0d3 --- /dev/null +++ b/src/qtdevicesettings/networksettingsplugin/networksettings/connman/qnetworksettingsmanager_p.cpp @@ -0,0 +1,163 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Device Utilities module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#include "qnetworksettingsmanager_p.h" +#include "connman_manager_interface.cpp" +#include "moc_connman_manager_interface.cpp" +#include "qnetworksettingsinterface.h" +#include "qnetworksettingsinterface_p.h" + +QNetworkSettingsManagerPrivate::QNetworkSettingsManagerPrivate(QNetworkSettingsManager *parent) + :QObject(parent) + ,q_ptr(parent) +{ + m_serviceFilter.setSourceModel(&m_serviceModel); + m_manager = new NetConnmanManagerInterface("net.connman", "/", + QDBusConnection::systemBus(), this); + + if (m_manager->isValid()) { + //List technologies + QDBusPendingReply<ConnmanMapList> reply = m_manager->GetTechnologies(); + QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(reply, this); + connect(watcher, SIGNAL(finished(QDBusPendingCallWatcher*)), + this, SLOT(getTechnologiesFinished(QDBusPendingCallWatcher*))); + + reply = m_manager->GetServices(); + watcher = new QDBusPendingCallWatcher(reply, this); + connect(watcher, SIGNAL(finished(QDBusPendingCallWatcher*)), + this, SLOT(getServicesFinished(QDBusPendingCallWatcher*))); + + connect(m_manager, &NetConnmanManagerInterface::ServicesChanged, this, &QNetworkSettingsManagerPrivate::servicesChanged); + + m_manager->RegisterAgent(QDBusObjectPath(AgentPath)); + } + else { + delete m_manager; + m_manager = NULL; + } +} + +void QNetworkSettingsManagerPrivate::requestInput(const QString& service, const QString& type) +{ + Q_UNUSED(type); + foreach (QNetworkSettingsService* servicePtr, m_serviceModel.getModel()) { + if (servicePtr->id() == service) + emit servicePtr->showCrendentialInput(); + } +} + +void QNetworkSettingsManagerPrivate::getServicesFinished(QDBusPendingCallWatcher *watcher) +{ + Q_Q(QNetworkSettingsManager); + QDBusPendingReply<ConnmanMapList> reply = *watcher; + watcher->deleteLater(); + if (reply.isError()) + return; + + foreach (const ConnmanMap &object, reply.value()) { + const QString servicePath = object.objectPath.path(); + QNetworkSettingsService *service = new QNetworkSettingsService(servicePath, this); + m_serviceModel.append(service); + + //Update status property + QString n = qdbus_cast<QString>(object.propertyMap[PropertyName]); + QString t = qdbus_cast<QString>(object.propertyMap[PropertyType]); + QString s = qdbus_cast<QString>(object.propertyMap[PropertyState]); + + QNetworkSettingsType type; + t >> type; + QNetworkSettingsState state; + s >> state; + + foreach (QNetworkSettingsInterface* item, m_interfaceModel.getModel()) { + ConnmanSettingsInterface* technology = qobject_cast<ConnmanSettingsInterface*>(item); + if (technology->name() == n && technology->type() == type.type()) { + technology->setState(state.state()); + } + } + } + emit q->servicesChanged(); +} + +void QNetworkSettingsManagerPrivate::getTechnologiesFinished(QDBusPendingCallWatcher *watcher) +{ + Q_Q(QNetworkSettingsManager); + + QDBusPendingReply<ConnmanMapList> reply = *watcher; + watcher->deleteLater(); + if (reply.isError()) + return; + + foreach (const ConnmanMap &object, reply.value()) { + ConnmanSettingsInterface *item = new ConnmanSettingsInterface(object.objectPath.path(), object.propertyMap, this); + + if (item->type() == QNetworkSettingsType::Wired) { + m_interfaceModel.insert(0, item); + } + else if (item->type() == QNetworkSettingsType::Wifi) { + m_interfaceModel.append(item); + } + emit q->interfacesChanged(); + } +} + +void QNetworkSettingsManagerPrivate::servicesChanged(ConnmanMapList changed, const QList<QDBusObjectPath> &removed) +{ + foreach (QDBusObjectPath path, removed) { + QList<QNetworkSettingsService*> serviceList = m_serviceModel.getModel(); + QMutableListIterator<QNetworkSettingsService*> i(serviceList); + while (i.hasNext()) { + if (i.next()->id() == path.path()) + i.remove(); + } + } + + QStringList newServices; + foreach (ConnmanMap map, changed) { + bool found = false; + foreach (QNetworkSettingsService* service, m_serviceModel.getModel()) { + if (service->id() == map.objectPath.path()) { + found =true; + break; + } + } + if (!found) + newServices.append(map.objectPath.path()); + } + foreach (QString newService, newServices) { + QNetworkSettingsService *service = new QNetworkSettingsService(newService, this); + m_serviceModel.append(service); + } +} diff --git a/src/qtdevicesettings/networksettingsplugin/networksettings/connman/qnetworksettingsmanager_p.h b/src/qtdevicesettings/networksettingsplugin/networksettings/connman/qnetworksettingsmanager_p.h new file mode 100644 index 0000000..6883d74 --- /dev/null +++ b/src/qtdevicesettings/networksettingsplugin/networksettings/connman/qnetworksettingsmanager_p.h @@ -0,0 +1,70 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Device Utilities module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#ifndef QNETWORKSETTINGSMANAGERPRIVATE_H +#define QNETWORKSETTINGSMANAGERPRIVATE_H + +#include <QObject> +#include <QtDBus> +#include "connmancommon.h" +#include "qnetworksettingsmanager.h" +#include "qnetworksettingsinterfacemodel.h" +#include "qnetworksettingsservicemodel.h" + +class NetConnmanManagerInterface; + +class QNetworkSettingsManagerPrivate : public QObject +{ + Q_OBJECT + Q_DECLARE_PUBLIC(QNetworkSettingsManager) +public: + explicit QNetworkSettingsManagerPrivate(QNetworkSettingsManager *parent); + QNetworkSettingsManager *q_ptr; + +public slots: + void getServicesFinished(QDBusPendingCallWatcher *watcher); + void getTechnologiesFinished(QDBusPendingCallWatcher *watcher); + void requestInput(const QString& service, const QString& type); + void servicesChanged(ConnmanMapList changed, const QList<QDBusObjectPath> &removed); + +protected: + QNetworkSettingsInterfaceModel m_interfaceModel; + QNetworkSettingsServiceModel m_serviceModel; + QNetworkSettingsServiceFilter m_serviceFilter; +private: + NetConnmanManagerInterface *m_manager; +}; + +#endif // QNETWORKSETTINGSMANAGERPRIVATE_H diff --git a/src/qtdevicesettings/networksettingsplugin/networksettings/connman/qnetworksettingsservice_p.cpp b/src/qtdevicesettings/networksettingsplugin/networksettings/connman/qnetworksettingsservice_p.cpp new file mode 100644 index 0000000..95181ed --- /dev/null +++ b/src/qtdevicesettings/networksettingsplugin/networksettings/connman/qnetworksettingsservice_p.cpp @@ -0,0 +1,405 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Device Utilities module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#include "qnetworksettingsservice_p.h" +#include "connman_service_interface.h" +#include "connmancommon.h" + +const QString PropertyIPv4("IPv4"); +const QString PropertyQNetworkSettingsIPv4("IPv4.Configuration"); +const QString PropertyIPv6("IPv6"); +const QString PropertyQNetworkSettingsIPv6("IPv6.Configuration"); +const QString PropertyNameservers("Nameservers"); +const QString PropertyNameserversConfig("Nameservers.Configuration"); +const QString PropertyDomains("Domains"); +const QString PropertyDomainsConfig("Domains.Configuration"); +const QString PropertyProxy("Proxy"); +const QString PropertyQNetworkSettingsProxy("Proxy.Configuration"); +const QString PropertyAddress("Address"); +const QString PropertyNetMask("Netmask"); +const QString PropertyGateway("Gateway"); +const QString PropertyPrefixLength("PrefixLength"); +const QString PropertyMethod("Method"); +const QString PropertyPrivacy("Privacy"); +const QString PropertyUrl("Url"); +const QString PropertyServers("Servers"); +const QString PropertyExcludes("Excludes"); +const QString PropertyStrength("Strength"); +const QString PropertySecurity("Security"); + +const QString AttributeAuto("auto"); +const QString AttributeDhcp("dhcp"); +const QString AttributeManual("manual"); +const QString AttributeOff("off"); +const QString AttributeDisabled("disabled"); +const QString AttributeEnabled("enabled"); +const QString AttributePreferred("preferred"); +const QString AttributeDirect("direct"); +const QString AttributeNone("none"); +const QString AttributeWep("wep"); +const QString AttributePsk("psk"); +const QString AttributeIeee("ieee8021x"); +const QString AttributeWps("wps"); +const QString AttributeInvalidKey("invalid-key"); + +const QVariantMap &operator>>(const QVariantMap &argument, QNetworkSettingsIPv4 &obj) +{ + obj.setAddress(argument[PropertyAddress].toString()); + obj.setMask(argument[PropertyNetMask].toString()); + obj.setGateway(argument[PropertyGateway].toString()); + + QString method = argument[PropertyMethod].toString(); + + if (method == AttributeDhcp) { + obj.setMethod(QNetworkSettingsIPv4::Dhcp); + } + else if (method == AttributeManual) { + obj.setMethod(QNetworkSettingsIPv4::Manual); + } + else if (method == AttributeOff) { + obj.setMethod(QNetworkSettingsIPv4::Off); + } + else { + obj.setMethod(QNetworkSettingsIPv4::Off); + } + return argument; +} + +const QVariantMap &operator<<(QVariantMap &argument, const QNetworkSettingsIPv4 &obj) +{ + argument.insert(PropertyAddress, QVariant::fromValue(obj.address())); + + argument.insert(PropertyNetMask, QVariant::fromValue(obj.mask())); + + argument.insert(PropertyGateway, QVariant::fromValue(obj.gateway())); + + QString method; + switch (obj.method()) { + case QNetworkSettingsIPv4::Dhcp: + method = AttributeDhcp; + break; + case QNetworkSettingsIPv4::Manual: + method = AttributeManual; + break; + case QNetworkSettingsIPv4::Off: + method = AttributeOff; + break; + default: + break; + } + argument.insert(PropertyMethod, QVariant::fromValue(method)); + return argument; +} + +const QVariantMap &operator>>(const QVariantMap &argument, QNetworkSettingsIPv6 &obj) +{ + obj.setAddress(argument[PropertyAddress].toString()); + obj.setGateway(argument[PropertyGateway].toString()); + obj.setPrefixLength(argument[PropertyPrefixLength].toInt()); + QString method = argument[PropertyMethod].toString(); + if (method == AttributeAuto) { + obj.setMethod(QNetworkSettingsIPv6::Auto); + } + else if (method == AttributeManual) { + obj.setMethod(QNetworkSettingsIPv6::Manual); + } + else if (method == AttributeOff) { + obj.setMethod(QNetworkSettingsIPv6::Off); + } + QString privacy = argument[PropertyPrivacy].toString(); + + if (privacy == AttributeDisabled) { + obj.setPrivacy(QNetworkSettingsIPv6::Disabled); + } + else if (privacy == AttributeEnabled) { + obj.setPrivacy(QNetworkSettingsIPv6::Enabled); + } + else if (privacy == AttributePreferred) { + obj.setPrivacy(QNetworkSettingsIPv6::Preferred); + } + return argument; +} + + +const QVariantMap &operator<<(QVariantMap &argument, const QNetworkSettingsIPv6 &obj) +{ + argument.insert(PropertyAddress, QVariant::fromValue(obj.address())); + argument.insert(PropertyGateway, QVariant::fromValue(obj.address())); + argument.insert(PropertyPrefixLength, QVariant::fromValue(obj.prefixLength())); + + QString method; + switch (obj.method()) { + case QNetworkSettingsIPv6::Auto: + method = AttributeAuto; + break; + case QNetworkSettingsIPv6::Manual: + method = AttributeManual; + break; + case QNetworkSettingsIPv6::Off: + method = AttributeOff; + break; + default: + break; + } + argument.insert(PropertyMethod, QVariant::fromValue(method)); + + QString privacy; + switch (obj.privacy()) { + case QNetworkSettingsIPv6::Disabled: + method = AttributeDisabled; + break; + case QNetworkSettingsIPv6::Enabled: + method = AttributeEnabled; + break; + case QNetworkSettingsIPv6::Preferred: + method = AttributePreferred; + break; + default: + break; + } + argument.insert(PropertyPrivacy, QVariant::fromValue(privacy)); + + return argument; +} + + +const QVariantMap &operator>>(const QVariantMap &argument, QNetworkSettingsProxy &obj) +{ + QString method = argument[PropertyMethod].toString(); + if (method == AttributeDirect) { + obj.setMethod(QNetworkSettingsProxy::Direct); + } + else if (method == AttributeAuto) { + obj.setMethod(QNetworkSettingsProxy::Auto); + } + else if (method == AttributeManual) { + obj.setMethod(QNetworkSettingsProxy::Manual); + } + + QString urlStr = argument[PropertyUrl].toString(); + obj.setUrl(QUrl(urlStr)); + + obj.setServers(argument[PropertyServers].toStringList()); + obj.setExcludes(argument[PropertyExcludes].toStringList()); + + return argument; +} + +const QVariantMap &operator<<(QVariantMap &argument, const QNetworkSettingsProxy &obj) +{ + QString method; + switch (obj.method()) { + case QNetworkSettingsProxy::Direct: + method = AttributeDirect; + break; + case QNetworkSettingsProxy::Auto: + method = AttributeAuto; + break; + case QNetworkSettingsProxy::Manual: + method = AttributeManual; + break; + default: + break; + } + argument.insert(PropertyMethod, QVariant::fromValue(method)); + argument.insert(PropertyUrl, QVariant::fromValue(obj.url().toString())); + argument.insert(PropertyServers, QVariant::fromValue(obj.servers())); + argument.insert(PropertyServers, QVariant::fromValue(obj.excludes())); + + return argument; +} + +QNetworkSettingsServicePrivate::QNetworkSettingsServicePrivate(const QString& id, QNetworkSettingsService *parent) : + QObject(parent) + ,q_ptr(parent) + ,m_id(id) +{ + qDBusRegisterMetaType<ConnmanMap>(); + qDBusRegisterMetaType<ConnmanMapList>(); + + m_service = new NetConnmanServiceInterface("net.connman", m_id, + QDBusConnection::systemBus(), this); + + connect(m_service, SIGNAL(PropertyChanged(QString,QDBusVariant)), + this, SLOT(updateProperty(QString,QDBusVariant))); + + QDBusPendingReply<QVariantMap> reply = m_service->GetProperties(); + QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(reply, this); + + connect(watcher, SIGNAL(finished(QDBusPendingCallWatcher*)), + this, SLOT(propertiesUpdated(QDBusPendingCallWatcher*))); +} + +void QNetworkSettingsServicePrivate::setupIpv6Config() +{ + QVariantMap param; + param << m_ipv6config; + if (m_service) + m_service->SetProperty(PropertyQNetworkSettingsIPv6, QDBusVariant(QVariant(param))); +} + +void QNetworkSettingsServicePrivate::setupNameserversConfig() +{ + QVariant param = QVariant::fromValue(m_nameserverConfig.stringList()); + if (m_service) + m_service->SetProperty(PropertyNameserversConfig, QDBusVariant(QVariant(param))); +} + +void QNetworkSettingsServicePrivate::setupDomainsConfig() +{ + QVariant param = QVariant::fromValue(m_domainsConfig.stringList()); + if (m_service) + m_service->SetProperty(PropertyDomainsConfig, QDBusVariant(QVariant(param))); +} + +void QNetworkSettingsServicePrivate::setupQNetworkSettingsProxy() +{ + QVariantMap param; + param << m_proxyConfig; + if (m_service) + m_service->SetProperty(PropertyQNetworkSettingsProxy, QDBusVariant(QVariant(param))); +} + +void QNetworkSettingsServicePrivate::setupIpv4Config() +{ + QVariantMap param; + param << m_ipv4config; + if (m_service) + m_service->SetProperty(PropertyQNetworkSettingsIPv4, QDBusVariant(QVariant(param))); +} + +void QNetworkSettingsServicePrivate::connectService() +{ + if (m_service) { + m_service->Connect(); + } +} + +void QNetworkSettingsServicePrivate::disconnectService() +{ + if (m_service) + m_service->Disconnect(); + +} + +void QNetworkSettingsServicePrivate::propertiesUpdated(QDBusPendingCallWatcher *call) +{ + QDBusPendingReply<QVariantMap> reply = *call; + call->deleteLater(); + + if (!reply.isError()) + setupConfiguration(reply.value()); +} + +void QNetworkSettingsServicePrivate::updateProperty(const QString &name, const QDBusVariant &value) +{ + updateProperty(name, value.variant()); +} + +void QNetworkSettingsServicePrivate::updateProperty(const QString& key, const QVariant& val) +{ + Q_Q(QNetworkSettingsService); + + if (key == PropertyIPv4) { + QVariantMap value = qdbus_cast<QVariantMap>(val); + value >> m_ipv4config; + emit q->ipv4Changed(); + } + else if (key == PropertyIPv6) { + QVariantMap value = qdbus_cast<QVariantMap>(val); + value >> m_ipv6config; + emit q->ipv6Changed(); + } + else if (key == PropertyNameservers) { + QStringList value = qdbus_cast<QStringList>(val); + m_nameserverConfig.setStringList(value); + emit q->nameserversChanged(); + } + else if (key == PropertyDomains) { + QStringList value = qdbus_cast<QStringList>(val); + m_domainsConfig.setStringList(value); + emit q->domainsChanged(); + } + else if (key == PropertyProxy) { + QVariantMap value = qdbus_cast<QVariantMap>(val); + value >> m_proxyConfig; + emit q->proxyChanged(); + } + else if (key == PropertyState) { + QString value = qdbus_cast<QString>(val); + value >> m_state; + emit q->stateChanged(); + } + else if (key == PropertyName) { + m_name = qdbus_cast<QString>(val); + emit q->nameChanged(); + } + else if (key == PropertyType) { + QString value = qdbus_cast<QString>(val); + value >> m_type; + } + else if (key == PropertyStrength) { + m_wifiConfig.setSignalStrength(val.toInt()); + } + else if (key == PropertySecurity) { + QStringList value = qdbus_cast<QStringList>(val); + foreach (const QString str, value) { + if (str == AttributeNone) { + m_wifiConfig.setSecurity(QNetworkSettingsWireless::None); + } + else if (str == AttributeWep) { + m_wifiConfig.setSecurity(QNetworkSettingsWireless::WEP); + } + else if (str == AttributePsk) { + m_wifiConfig.setSecurity(QNetworkSettingsWireless::WPA); + } + else if (str == AttributeIeee) { + m_wifiConfig.setSecurity(QNetworkSettingsWireless::WPA2); + } + else if (str == AttributeWps) { + m_wifiConfig.setSecurity(QNetworkSettingsWireless::WPS); + } + } + } +} + +void QNetworkSettingsServicePrivate::setupConfiguration(const QVariantMap &properties) +{ + QVariantMap::const_iterator it = properties.constBegin(), end = properties.constEnd(); + for ( ; it != end; ++it) { + updateProperty(it.key(), it.value()); + } +} + diff --git a/src/qtdevicesettings/networksettingsplugin/networksettings/connman/qnetworksettingsservice_p.h b/src/qtdevicesettings/networksettingsplugin/networksettings/connman/qnetworksettingsservice_p.h new file mode 100644 index 0000000..39a04bd --- /dev/null +++ b/src/qtdevicesettings/networksettingsplugin/networksettings/connman/qnetworksettingsservice_p.h @@ -0,0 +1,84 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Device Utilities module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#ifndef QNETWORKSETTINGSSERVICEPRIVATE_H +#define QNETWORKSETTINGSSERVICEPRIVATE_H + +#include <QtDBus> +#include "qnetworksettingsservice.h" +#include "qnetworksettings.h" + +class NetConnmanServiceInterface; + +class QNetworkSettingsServicePrivate : public QObject +{ + Q_OBJECT + Q_DECLARE_PUBLIC(QNetworkSettingsService) +public: + QNetworkSettingsServicePrivate(const QString& aPath, QNetworkSettingsService *parent=0); + + QNetworkSettingsService *q_ptr; +private slots: + void propertiesUpdated(QDBusPendingCallWatcher *call); + void updateProperty(const QString &name, const QDBusVariant &value); + +private: + void setupConfiguration(const QVariantMap &properties); + void updateProperty(const QString& key, const QVariant& value); + +protected: + void setAutoConnect(const bool autoconnect); + void setupIpv4Config(); + void setupIpv6Config(); + void setupNameserversConfig(); + void setupDomainsConfig(); + void setupQNetworkSettingsProxy(); + void connectService(); + void disconnectService(); + + QString m_id; + QString m_name; + QNetworkSettingsState m_state; + QNetworkSettingsIPv4 m_ipv4config; + QNetworkSettingsIPv6 m_ipv6config; + QNetworkSettingsAddressModel m_domainsConfig; + QNetworkSettingsAddressModel m_nameserverConfig; + QNetworkSettingsProxy m_proxyConfig; + QNetworkSettingsWireless m_wifiConfig; + QNetworkSettingsType m_type; + NetConnmanServiceInterface *m_service; +}; + +#endif // QNETWORKSETTINGSSERVICEPRIVATE_H diff --git a/src/qtdevicesettings/networksettingsplugin/networksettings/connman/qnetworksettingsuseragent_p.cpp b/src/qtdevicesettings/networksettingsplugin/networksettings/connman/qnetworksettingsuseragent_p.cpp new file mode 100644 index 0000000..918c8b8 --- /dev/null +++ b/src/qtdevicesettings/networksettingsplugin/networksettings/connman/qnetworksettingsuseragent_p.cpp @@ -0,0 +1,99 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Device Utilities module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#include "qnetworksettingsuseragent_p.h" +#include "connmancommon.h" + +const QString PropertyPassphrase("Passphrase"); + +QNetworkSettingsUserAgentPrivate::QNetworkSettingsUserAgentPrivate(QNetworkSettingsUserAgent *parent) + :QDBusAbstractAdaptor(parent) + ,q_ptr(parent) + ,m_pendingReply(false) +{ + + setAutoRelaySignals(true); + QMetaObject::invokeMethod(this, "registerAgent", Qt::QueuedConnection); +} + +void QNetworkSettingsUserAgentPrivate::cancel() +{ + // handle method call net.connman.Agent.Cancel + m_pendingReply = false; + QMetaObject::invokeMethod(parent(), "Cancel"); +} + +void QNetworkSettingsUserAgentPrivate::release() +{ + // handle method call net.connman.Agent.Release + QMetaObject::invokeMethod(parent(), "Release"); +} + +void QNetworkSettingsUserAgentPrivate::ReportError(const QDBusObjectPath &path, const QString ¶m) +{ + Q_Q(QNetworkSettingsUserAgent); + Q_UNUSED(path); + Q_UNUSED(param); + emit q->error(); +} + +void QNetworkSettingsUserAgentPrivate::registerAgent() +{ + Q_Q(QNetworkSettingsUserAgent); + QDBusConnection::systemBus().registerObject(AgentPath, q_ptr); +} + +QVariantMap QNetworkSettingsUserAgentPrivate::RequestInput(const QDBusObjectPath &path, const QVariantMap ¶ms, const QDBusMessage &msg) +{ + Q_Q(QNetworkSettingsUserAgent); + Q_UNUSED(path); + Q_UNUSED(params); + msg.setDelayedReply(true); + m_reply = msg.createReply(); + m_pendingReply = true; + emit q->showUserCredentialsInput(); + return QVariantMap(); +} + +void QNetworkSettingsUserAgentPrivate::setUserCredentials(const QString& username, + const QString& password) +{ + QVariantMap response; + response[PropertyName] = username; + response[PropertyPassphrase] = password; + m_reply << response; + m_pendingReply = false; + QDBusConnection::systemBus().send(m_reply); +} diff --git a/src/qtdevicesettings/networksettingsplugin/networksettings/connman/qnetworksettingsuseragent_p.h b/src/qtdevicesettings/networksettingsplugin/networksettings/connman/qnetworksettingsuseragent_p.h new file mode 100644 index 0000000..8c480a5 --- /dev/null +++ b/src/qtdevicesettings/networksettingsplugin/networksettings/connman/qnetworksettingsuseragent_p.h @@ -0,0 +1,75 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Device Utilities module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#ifndef QNETWORKSETTINGSUSERAGENTPRIVATE_H +#define QNETWORKSETTINGSUSERAGENTPRIVATE_H + +#include <QtCore/QObject> +#include <QtDBus/QtDBus> +#include "qnetworksettingsuseragent.h" + +QT_BEGIN_NAMESPACE +class QByteArray; +template<class T> class QList; +template<class Key, class Value> class QMap; +class QString; +class QStringList; +class QVariant; +QT_END_NAMESPACE + +const QString AgentPath("/ConnmanAgent"); + +class QNetworkSettingsUserAgentPrivate : public QDBusAbstractAdaptor +{ + Q_OBJECT + Q_CLASSINFO("D-Bus Interface", "net.connman.Agent") + Q_DECLARE_PUBLIC(QNetworkSettingsUserAgent) +public: + QNetworkSettingsUserAgentPrivate(QNetworkSettingsUserAgent *parent=0); + void setUserCredentials(const QString& aUsername, const QString& aPassword); + void cancel(); + void release(); +public Q_SLOTS: // Dbus methods + void ReportError(const QDBusObjectPath &path, const QString ¶m); + QVariantMap RequestInput(const QDBusObjectPath &path, const QVariantMap ¶ms, + const QDBusMessage &message); + void registerAgent(); +private: + QNetworkSettingsUserAgent *q_ptr; + QDBusMessage m_reply; + bool m_pendingReply; +}; + +#endif // QNETWORKSETTINGSUSERAGENTPRIVATE_H |