diff options
author | Teemu Holappa <teemu.holappa@theqtcompany.com> | 2015-11-09 16:39:08 +0200 |
---|---|---|
committer | Teemu Holappa <teemu.holappa@theqtcompany.com> | 2016-01-22 14:04:19 +0000 |
commit | ccbfa0884072c26979a6475de71635c19a474cca (patch) | |
tree | 288fe756bef423237931023973a91ca469643e11 /src/qtdevicesettings/networksettingsplugin | |
parent | 887c8bffd05a3784d83e8280f8c725eead4c7a5c (diff) |
Device settings UI.
Implemented settings application for changing device settings.
There are implemented settings UI for network, time and date, locale, bluetooth, audio and display.
Change-Id: I26077ce1f2356eb8520fad61cf07407c6a0f98c1
Reviewed-by: Kimmo Ollila <kimmo.ollila@theqtcompany.com>
Reviewed-by: Risto Avila <risto.avila@theqtcompany.com>
Diffstat (limited to 'src/qtdevicesettings/networksettingsplugin')
25 files changed, 3338 insertions, 0 deletions
diff --git a/src/qtdevicesettings/networksettingsplugin/icons.qrc b/src/qtdevicesettings/networksettingsplugin/icons.qrc new file mode 100644 index 0000000..af8a564 --- /dev/null +++ b/src/qtdevicesettings/networksettingsplugin/icons.qrc @@ -0,0 +1,4 @@ +<RCC> + <qresource prefix="/"> + </qresource> +</RCC> diff --git a/src/qtdevicesettings/networksettingsplugin/imports/NetworkSettings/EditWiredSettings.qml b/src/qtdevicesettings/networksettingsplugin/imports/NetworkSettings/EditWiredSettings.qml new file mode 100644 index 0000000..a09bdf8 --- /dev/null +++ b/src/qtdevicesettings/networksettingsplugin/imports/NetworkSettings/EditWiredSettings.qml @@ -0,0 +1,640 @@ +/**************************************************************************** +** +** 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$ +** +****************************************************************************/ +import QtQuick 2.5 +import QtQuick.Layouts 1.1 +import QtQuick.Controls 1.4 +import QtQuick.Controls.Styles.Flat 1.0 as Flat +import com.theqtcompany.settings.common 1.0 +import com.theqtcompany.settings.network 1.0 + +Item { + id: root + property string title: qsTr("Ethernet Settings") + property var service: undefined + + property bool ipv4Changed: false + property bool ipv6Changed: false + property bool nameserversChanged: false + property bool domainsChanged: false + property bool proxyChanged: false + + Component.onDestruction: { + //Clear all unsaved changes from models + service.proxy.excludes.resetChanges(); + service.nameservers.resetChanges(); + service.domains.resetChanges(); + } + + Component.onCompleted: titlebar.title = service.name; + + Flickable { + anchors.fill: parent + anchors.top: saveButton.bottom + anchors.margins: Math.round(40 * Flat.FlatStyle.scaleFactor) + anchors.bottomMargin: Math.round(20 * Flat.FlatStyle.scaleFactor) + contentHeight: content.height + contentWidth: width + interactive: !ipv4Method.popupVisible && !ipv6Method.popupVisible && !proxyMethodSel.popupVisible + Column { + id: content + width: parent.width + spacing: Math.round(10 * Flat.FlatStyle.scaleFactor) + property int titleWidth: Math.round(width * 0.382) + property int groupWidth: Math.round(width - saveButton.width - 10 * Flat.FlatStyle.scaleFactor) + + //IPv4 Config + GroupBox { + flat: false + width: content.groupWidth + Layout.fillWidth: true + title: qsTr("IPv4") + + ColumnLayout { + anchors.fill: parent + + ListModel { + id: methodsModel + + ListElement { + text: "DHCP" + method: IPv4Config.Dhcp + } + ListElement { + text: "Manual" + method: IPv4Config.Manual + } + ListElement { + text: "Off" + method: IPv4Config.Off + } + } + + Row { + spacing: Math.round(10 * Flat.FlatStyle.scaleFactor) + TextLabel { + text: qsTr("Connection method") + width: content.titleWidth + horizontalAlignment: Text.AlignRight + } + + CustomCombobox { + id: ipv4Method + model: methodsModel + Component.onCompleted: selectedIndex = service.ipv4.method + + onSelectedIndexChanged : { + ipv4Changed = true; + service.ipv4.method = model.get(selectedIndex).method; + } + delegate: FlatStyledDropdownDelegate { } + } + } + + Column { + spacing: Math.round(10 * Flat.FlatStyle.scaleFactor) + visible: service.ipv4.method === IPv4Config.Dhcp + + Row { + spacing: Math.round(10 * Flat.FlatStyle.scaleFactor) + TextLabel { + text: qsTr("Address") + width: content.titleWidth + horizontalAlignment: Text.AlignRight + } + TextLabel { + text: service.ipv4.address + } + } + + Row { + spacing: Math.round(10 * Flat.FlatStyle.scaleFactor) + TextLabel { + text: qsTr("Mask") + width: content.titleWidth + horizontalAlignment: Text.AlignRight + } + TextLabel { + text: service.ipv4.mask + } + } + + Row { + spacing: Math.round(10 * Flat.FlatStyle.scaleFactor) + TextLabel { + text: qsTr("Router") + width: content.titleWidth + horizontalAlignment: Text.AlignRight + } + TextLabel { + text: service.ipv4.gateway + } + } + } + + Column { + spacing: Math.round(10 * Flat.FlatStyle.scaleFactor) + visible: service.ipv4.method === IPv4Config.Manual + + Row { + spacing: Math.round(10 * Flat.FlatStyle.scaleFactor) + TextLabel { + text: qsTr("Address") + width: content.titleWidth + horizontalAlignment: Text.AlignRight + } + IpAddressTextField { + id: ipv4Address + text: service.ipv4.address + onTextChanged: ipv4Changed = true; + + onAccepted: if (text.length > 0) service.ipv4.address = text + } + } + + Row { + spacing: Math.round(10 * Flat.FlatStyle.scaleFactor) + TextLabel { + text: qsTr("Mask") + width: content.titleWidth + horizontalAlignment: Text.AlignRight + } + IpAddressTextField { + id: ipv4Mask + text: service.ipv4.mask + onTextChanged: ipv4Changed = true; + onAccepted: if (text.length > 0) service.ipv4.mask = text + } + } + + Row { + spacing: Math.round(10 * Flat.FlatStyle.scaleFactor) + TextLabel { + text: qsTr("Router") + width: content.titleWidth + horizontalAlignment: Text.AlignRight + } + IpAddressTextField { + id: ipv4Gateway + text: service.ipv4.gateway + + onTextChanged: ipv4Changed = true + + onAccepted: if (text.length > 0) service.ipv4.gateway = text + } + } + } + } + } + + //IPv6 Config + GroupBox { + flat: false + width: content.groupWidth + Layout.fillWidth: true + title: qsTr("IPv6") + + ColumnLayout { + anchors.fill: parent + + ListModel { + id: ipv6methodsmodel + + ListElement { + text: qsTr("Auto") + method: IPv6Config.Auto + } + ListElement { + text: qsTr("Manual") + method: IPv6Config.Manual + } + ListElement { + text: qsTr("Off") + method: IPv6Config.Off + } + } + + Row { + spacing: Math.round(10 * Flat.FlatStyle.scaleFactor) + TextLabel { + text: qsTr("Connection method: ") + width: content.titleWidth + horizontalAlignment: Text.AlignRight + } + + CustomCombobox { + id: ipv6Method + model: ipv6methodsmodel + Component.onCompleted: selectedIndex = service.ipv6.method + onSelectedIndexChanged : { + ipv6Changed = true; + service.ipv6.method = model.get(selectedIndex).method; + } + delegate: FlatStyledDropdownDelegate { } + } + } + + Column { + spacing: Math.round(10 * Flat.FlatStyle.scaleFactor) + visible: service.ipv6.method === IPv6Config.Auto + Row { + spacing: Math.round(10 * Flat.FlatStyle.scaleFactor) + TextLabel { + text: qsTr("Address") + width: content.titleWidth + horizontalAlignment: Text.AlignRight + } + TextLabel { + text: service.ipv6.address + } + } + + Row { + spacing: Math.round(10 * Flat.FlatStyle.scaleFactor) + TextLabel { + text: qsTr("Router") + width: content.titleWidth + horizontalAlignment: Text.AlignRight + } + TextLabel { + text: service.ipv6.gateway + } + } + + Row { + spacing: Math.round(10 * Flat.FlatStyle.scaleFactor) + TextLabel { + text: qsTr("Prefix length") + width: content.titleWidth + horizontalAlignment: Text.AlignRight + } + TextLabel { + text: service.ipv6.prefixLength + } + } + } + + Column { + spacing: Math.round(10 * Flat.FlatStyle.scaleFactor) + visible: service.ipv6.method === IPv6Config.Manual + Row { + spacing: Math.round(10 * Flat.FlatStyle.scaleFactor) + TextLabel { + text: qsTr("Address") + width: content.titleWidth + horizontalAlignment: Text.AlignRight + } + TextField { + id: ipv6Address + text: service.ipv6.address + onTextChanged: ipv6Changed = true; + onAccepted: if (text.length > 0) service.ipv6.address = text + } + } + + Row { + spacing: Math.round(10 * Flat.FlatStyle.scaleFactor) + TextLabel { + text: qsTr("Router") + width: content.titleWidth + horizontalAlignment: Text.AlignRight + } + TextField { + id: ipv6Gateway + text: service.ipv6.gateway + onTextChanged: ipv6Changed = true; + onAccepted: if (text.length > 0) service.ipv4.gateway = text + } + } + + Row { + spacing: Math.round(10 * Flat.FlatStyle.scaleFactor) + TextLabel { + text: qsTr("Prefix length") + width: content.titleWidth + horizontalAlignment: Text.AlignRight + } + TextField { + id: ipv6PrefixLength + text: service.ipv6.prefixLength + validator: IntValidator { bottom: 0; top: 255 } + + onTextChanged: ipv6Changed = true + + onAccepted: if (text.length > 0) service.ipv6.prefixLength = parseInt(text) + } + } + } + } + } + + GroupBox { + flat: false + width: content.groupWidth + Layout.fillWidth: true + title: qsTr("Name servers") + + ColumnLayout { + anchors.fill: parent + Row { + spacing: Math.round(10 * Flat.FlatStyle.scaleFactor) + TextLabel { + text: qsTr("Address") + width: content.titleWidth + horizontalAlignment: Text.AlignRight + } + Column { + Repeater { + model: service.nameservers + + Row { + TextField { + text: edit + onTextChanged: { + nameserversChanged = true; + edit = text; + } + } + Button { + implicitWidth: height + text: "-" + onClicked: { + service.nameservers.remove(index); + nameserversChanged = true; + } + } + Button { + implicitWidth: height + visible: index==service.nameservers.count-1 + text: "+" + onClicked: service.nameservers.append("") + } + } + } + } + Row { + TextField { + id: nameServerEntryItem + visible: service.nameservers.count === 0 + text: "" + onAccepted: service.nameservers.append(text) + } + Button { + implicitWidth: height + visible: nameServerEntryItem.visible + text: "+" + onClicked: nameServerEntryItem.accepted() + } + } + } + } + } + + GroupBox { + flat: false + width: content.groupWidth + Layout.fillWidth: true + title: qsTr("Domains") + + ColumnLayout { + anchors.fill: parent + Row { + spacing: Math.round(10 * Flat.FlatStyle.scaleFactor) + TextLabel { + text: qsTr("Address") + width: content.titleWidth + horizontalAlignment: Text.AlignRight + } + Column { + Repeater { + model: service.domains + Row { + TextField { + text: edit + onTextChanged: { + root.domainsChanged = true; + edit = text; + } + } + Button { + implicitWidth: height + text: "-" + onClicked: { + service.domains.remove(index); + domainsChanged.domainsChanged = true; + } + } + Button { + implicitWidth: height + visible: index==service.domains.count-1 + text: "+" + onClicked: service.domains.append("") + } + } + } + } + Row { + TextField { + id: domainsEntryItem + visible: service.domains.count === 0 + text: "" + onAccepted: service.domains.append(text) + } + Button { + implicitWidth: height + visible: domainsEntryItem.visible + text: "+" + onClicked: domainsEntryItem.accepted() + } + } + } + } + } + + GroupBox { + flat: false + width: content.groupWidth + Layout.fillWidth: true + title: qsTr("Proxy Settings") + + ColumnLayout { + anchors.fill: parent + + ListModel { + id: proxyMethodModel + + ListElement { + text: qsTr("Direct") + method: ProxyConfig.Direct + } + ListElement { + text: qsTr("Auto") + method: ProxyConfig.Auto + } + ListElement { + text: qsTr("Manual") + method: ProxyConfig.Manual + } + } + + Row { + spacing: Math.round(10 * Flat.FlatStyle.scaleFactor) + TextLabel { + text: qsTr("Configuration") + width: content.titleWidth + horizontalAlignment: Text.AlignRight + } + + CustomCombobox { + id: proxyMethodSel + model: proxyMethodModel + Component.onCompleted: selectedIndex = service.proxy.method + onSelectedIndexChanged : { + proxyChanged = true; + service.proxy.method = model.get(selectedIndex).method; + } + delegate: FlatStyledDropdownDelegate { } + } + } + + Row { + spacing: Math.round(10 * Flat.FlatStyle.scaleFactor) + visible: service.proxy.method !== ProxyConfig.Direct + TextLabel { + text: service.proxy.method === ProxyConfig.Manual ? qsTr("Proxy address") : qsTr("Automatic configuration URL") + width: content.titleWidth + horizontalAlignment: Text.AlignRight + } + TextField { + id: proxyUrl + text: service.proxy.url + onTextChanged: proxyChanged = true; + onAccepted: service.proxy.url = text; + } + } + Row { + spacing: Math.round(10 * Flat.FlatStyle.scaleFactor) + visible: service.proxy.method === ProxyConfig.Manual + + TextLabel { + text: qsTr("No proxy for") + width: content.titleWidth + horizontalAlignment: Text.AlignRight + } + + Column { + Repeater { + model: service.proxy.excludes + + Row { + TextField { + text: edit + onTextChanged: edit = text + } + Button { + implicitWidth: height + text: "-" + onClicked: { + service.proxy.excludes.remove(index); + proxyChanged = true; + } + } + Button { + implicitWidth: height + visible: index==service.proxy.excludes.count-1 + text: "+" + onClicked: service.proxy.excludes.append("") + } + } + } + } + Row { + TextField { + id: proxyEntryItem + visible: service.proxy.excludes.count === 0 + text: "" + onAccepted: service.proxy.excludes.append(text) + } + Button { + implicitWidth: height + visible: proxyEntryItem.visible + text: "+" + onClicked: proxyEntryItem.accepted() + } + } + } + } + } + } + } + + Button { + id: saveButton + anchors.right: parent.right + anchors.top: parent.top + anchors.margins: Math.round(10 * Flat.FlatStyle.scaleFactor) + anchors.rightMargin: Math.round(40 * Flat.FlatStyle.scaleFactor) + text: qsTr("Save") + + onClicked: { + if (ipv4Changed) { + ipv4Address.accepted(); + ipv4Mask.accepted(); + ipv4Gateway.accepted(); + service.setupIpv4Config(); + } + + if (ipv6Changed) { + ipv6Address.accepted(); + ipv6Gateway.accepted(); + ipv6PrefixLength.accepted(); + service.setupIpv6Config(); + } + + if (nameserversChanged) { + service.setupNameserversConfig(); + } + + if (domainsChanged) { + service.setupDomainsConfig(); + } + if (proxyChanged) { + proxyUrl.accepted(); + service.setupProxyConfig(); + } + stackView.pop(); + } + } +} diff --git a/src/qtdevicesettings/networksettingsplugin/imports/NetworkSettings/IpAddressTextField.qml b/src/qtdevicesettings/networksettingsplugin/imports/NetworkSettings/IpAddressTextField.qml new file mode 100644 index 0000000..102d458 --- /dev/null +++ b/src/qtdevicesettings/networksettingsplugin/imports/NetworkSettings/IpAddressTextField.qml @@ -0,0 +1,43 @@ +/**************************************************************************** +** +** 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$ +** +****************************************************************************/ +import QtQuick 2.5 +import QtQuick.Layouts 1.1 +import QtQuick.Controls 1.4 + +TextField { + Layout.fillWidth: true + validator: RegExpValidator { regExp: /^(\d|[1-9]\d|1\d\d|2([0-4]\d|5[0-5]))\.(\d|[1-9]\d|1\d\d|2([0-4]\d|5[0-5]))\.(\d|[1-9]\d|1\d\d|2([0-4]\d|5[0-5]))\.(\d|[1-9]\d|1\d\d|2([0-4]\d|5[0-5]))$/ } +} diff --git a/src/qtdevicesettings/networksettingsplugin/imports/NetworkSettings/NetworkDetails.qml b/src/qtdevicesettings/networksettingsplugin/imports/NetworkSettings/NetworkDetails.qml new file mode 100644 index 0000000..1540e03 --- /dev/null +++ b/src/qtdevicesettings/networksettingsplugin/imports/NetworkSettings/NetworkDetails.qml @@ -0,0 +1,42 @@ +/**************************************************************************** +** +** 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$ +** +****************************************************************************/ +import QtQuick 2.5 + +Loader { + id: root + property var service: undefined + anchors.fill: parent +} diff --git a/src/qtdevicesettings/networksettingsplugin/imports/NetworkSettings/NetworkSettings.qml b/src/qtdevicesettings/networksettingsplugin/imports/NetworkSettings/NetworkSettings.qml new file mode 100644 index 0000000..daf3d1d --- /dev/null +++ b/src/qtdevicesettings/networksettingsplugin/imports/NetworkSettings/NetworkSettings.qml @@ -0,0 +1,135 @@ +/**************************************************************************** +** +** 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$ +** +****************************************************************************/ +import QtQuick 2.5 +import QtQuick.Layouts 1.1 +import QtQuick.Controls 1.4 +import QtQuick.Controls.Styles.Flat 1.0 as Flat +import com.theqtcompany.settings.common 1.0 +import com.theqtcompany.settings.network 1.0 + +Item { + property string title: qsTr("Network Settings") + GroupBox { + id: networkSelect + anchors.fill: parent + anchors.rightMargin: parent.width * 0.618 + anchors.leftMargin: Math.round(20 * Flat.FlatStyle.scaleFactor) + anchors.topMargin: Math.round(20 * Flat.FlatStyle.scaleFactor) + title: qsTr("Select Connection") + + function stateToStr(serviceState) { + switch (serviceState) { + case NetworkService.Idle: + return qsTr("Idle"); + case NetworkService.Failure: + return qsTr("Failure"); + case NetworkService.Association: + return qsTr("Association"); + case NetworkService.Configuration: + return qsTr("Configuration"); + case NetworkService.Ready: + return qsTr("Ready"); + case NetworkService.Disconnect: + return qsTr("Disconnect"); + case NetworkService.Online: + return qsTr("Online"); + default: + return qsTr("Undefined"); + } + } + + ColumnLayout { + width: networkSelect.width + ExclusiveGroup { + id: exgroup + } + + Repeater { + model: NetworkSettingsManager.networks + + Button { + implicitWidth: networkSelect.width - Math.round(20 * Flat.FlatStyle.scaleFactor) + implicitHeight: Math.round(54 * Flat.FlatStyle.scaleFactor) + checkable: true + exclusiveGroup: exgroup + + Row { + anchors.fill: parent + spacing: Math.round(10 * Flat.FlatStyle.scaleFactor) + + Image { + id: typeId + height: parent.height + width: height + } + + Column { + height: Math.round(parent.height * 0.7) + spacing: 0 + anchors.verticalCenter: parent.verticalCenter + TextLabel { + text: name + } + + TextLabel { + text: networkSelect.stateToStr(status) + font.pixelSize: Math.round(12 * Flat.FlatStyle.scaleFactor) + } + } + } + + onCheckedChanged: { + if (checked) { + networkDetails.service = NetworkSettingsManager.getService(name, type); + if (type === NetworkType.Wired) { + networkDetails.source = "WiredSettings.qml"; + } + else if (type === NetworkType.Wifi) { + networkDetails.source = "WifiSettings.qml"; + } + } + } + } + } + } + } + + NetworkDetails { + id: networkDetails + anchors.fill: parent + anchors.leftMargin: networkSelect.width + Math.round(20 * Flat.FlatStyle.scaleFactor) + } +} diff --git a/src/qtdevicesettings/networksettingsplugin/imports/NetworkSettings/WifiSettings.qml b/src/qtdevicesettings/networksettingsplugin/imports/NetworkSettings/WifiSettings.qml new file mode 100644 index 0000000..3221e88 --- /dev/null +++ b/src/qtdevicesettings/networksettingsplugin/imports/NetworkSettings/WifiSettings.qml @@ -0,0 +1,94 @@ +/**************************************************************************** +** +** 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$ +** +****************************************************************************/ +import QtQuick 2.5 +import QtQuick.Layouts 1.1 +import QtQuick.Controls 1.4 +import QtQuick.Controls.Styles.Flat 1.0 as Flat +import com.theqtcompany.settings.common 1.0 +import com.theqtcompany.settings.network 1.0 +import com.theqtcompany.settings.wifi 1.0 + +Item { + id: root + anchors.fill: parent + anchors.margins: Math.round(20 * Flat.FlatStyle.scaleFactor) + GroupBox { + id: content + title: qsTr("Wireless Settings") + anchors.fill: parent + Layout.fillWidth: true + flat: true + width: parent.width + + Row { + id: enableSwitch + width: parent.width + spacing: Math.round(10 * Flat.FlatStyle.scaleFactor) + TextLabel { + width: root.width*0.382 + horizontalAlignment: Text.AlignRight + text: NetworkSettingsManager.wifiPowered ? qsTr("Disable Wifi") : qsTr("Enable Wifi") + } + Switch { + checked: NetworkSettingsManager.wifiPowered + onCheckedChanged: NetworkSettingsManager.wifiPowered = checked + } + } + + Item { + id: wifiManagerContainer + anchors.left: parent.left + anchors.right: parent.right + anchors.top: enableSwitch.bottom + anchors.topMargin: Math.round(10 * Flat.FlatStyle.scaleFactor) + anchors.bottom: parent.bottom + Loader { + id: wifiManagerLoader + asynchronous: true + sourceComponent: NetworkSettingsManager.wifiPowered ? wifiManager : undefined + } + } + } + + Component { + id: wifiManager + WifiManagerView { + id: wifiSettings + width: root.width + visible: true + } + } +} diff --git a/src/qtdevicesettings/networksettingsplugin/imports/NetworkSettings/WiredSettings.qml b/src/qtdevicesettings/networksettingsplugin/imports/NetworkSettings/WiredSettings.qml new file mode 100644 index 0000000..5a7e860 --- /dev/null +++ b/src/qtdevicesettings/networksettingsplugin/imports/NetworkSettings/WiredSettings.qml @@ -0,0 +1,205 @@ +/**************************************************************************** +** +** 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$ +** +****************************************************************************/ +import QtQuick 2.5 +import QtQuick.Layouts 1.1 +import QtQuick.Controls 1.4 +import QtQuick.Controls.Styles.Flat 1.0 as Flat +import com.theqtcompany.settings.common 1.0 +import com.theqtcompany.settings.network 1.0 + +Item { + id: root + anchors.fill: parent + anchors.margins: Math.round(20 * Flat.FlatStyle.scaleFactor) + property bool editMode: false + + onVisibleChanged: { + if (visible) + titlebar.title = qsTr("Network"); + } + + ListModel { + id: methodsModel + + ListElement { + text: "DHCP" + method: IPv4Config.Dhcp + } + ListElement { + text: "Manual" + method: IPv4Config.Manual + } + ListElement { + text: "Off" + method: IPv4Config.Off + } + } + + GroupBox { + title: qsTr("Ethernet Connection") + anchors.fill: parent + Layout.fillWidth: true + flat: true + Column { + spacing: Math.round(10 * Flat.FlatStyle.scaleFactor) + Row { + TextLabel { + text: qsTr("Connection method: ") + } + + CustomCombobox { + id: ipv4Method + model: methodsModel + Component.onCompleted: selectedIndex = service.ipv4.method + onSelectedIndexChanged : { + if (model.get(selectedIndex).method !== IPv4Config.Dhcp) { + service.ipv4.method = model.get(selectedIndex).method; + editMode = true; + } + else { + //Enable DHCP + if (service.ipv4.method !== model.get(selectedIndex).method) { + service.ipv4.method = model.get(selectedIndex).method; + service.setupIpv4Config(); + } + + editMode = false; + } + } + delegate: FlatStyledDropdownDelegate { } + } + } + + Row { + visible: service.ipv4.method !== IPv4Config.Off + TextLabel { + text: qsTr("IP Address: ") + } + TextLabel { + text: service.ipv4.address + visible: !editMode + } + IpAddressTextField { + id: ipv4Address + placeholderText: service.ipv4.address + visible: editMode + onAccepted: if (text.length > 0) service.ipv4.address = text + } + } + + Row { + visible: service.ipv4.method !== IPv4Config.Off + TextLabel { + text: qsTr("Mask: ") + } + TextLabel { + text: service.ipv4.mask + visible: !editMode + } + IpAddressTextField { + id: ipv4Mask + placeholderText: service.ipv4.mask + visible: editMode + onAccepted: if (text.length > 0) service.ipv4.mask = text + } + } + + Row { + visible: service.ipv4.method !== IPv4Config.Off + TextLabel { + text: qsTr("Router: ") + } + TextLabel { + text: service.ipv4.gateway + visible: !editMode + } + IpAddressTextField { + id: ipv4Gateway + placeholderText: service.ipv4.gateway + visible: editMode + onAccepted: if (text.length > 0) service.ipv4.gateway = text + } + } + + Row { + visible: service.ipv4.method !== IPv4Config.Off + TextLabel { + text: qsTr("DNS server: ") + } + Row { + spacing: Math.round(10 * Flat.FlatStyle.scaleFactor) + Repeater { + model: service.nameservers + + TextLabel { + text: display + } + } + } + } + + Row { + Button { + text: qsTr("Save") + visible: editMode + + onClicked: { + ipv4Address.accepted(); + ipv4Mask.accepted(); + ipv4Gateway.accepted(); + service.setupIpv4Config(); + editMode = false; + } + } + Button { + text: qsTr("Cancel") + visible: editMode + onClicked: { + editMode = false; + methodSelection.currentIndex = service.ipv4.method + } + } + } + Button { + text: qsTr("Edit") + visible: !editMode + + onClicked: stackView.push( { item : Qt.resolvedUrl("EditWiredSettings.qml"), properties : { service: service } } ) + } + } + } +} + diff --git a/src/qtdevicesettings/networksettingsplugin/networksettings/connman/connman_manager.xml b/src/qtdevicesettings/networksettingsplugin/networksettings/connman/connman_manager.xml new file mode 100644 index 0000000..5c52b27 --- /dev/null +++ b/src/qtdevicesettings/networksettingsplugin/networksettings/connman/connman_manager.xml @@ -0,0 +1,108 @@ +<?xml version="1.0" encoding="utf-8"?> +<node name="/Manager" xmlns:tp="http://telepathy.freedesktop.org/wiki/DbusSpec#extensions-v0"> + <interface name="net.connman.Manager"> + + <method name="GetProperties" tp:name-for-bindings="Get_Properties"> + <arg name="properties" type="a{sv}" direction="out"/> + <annotation name="org.qtproject.QtDBus.QtTypeName.Out0" value="QVariantMap"/> + </method> + + <method name="SetProperty" tp:name-for-bindings="Set_Property"> + <arg name="name" type="s"/> + <arg name="value" type="v"/> + </method> + + <method name="GetTechnologies" tp:name-for-bindings="Get_Technologies"> + <arg name="technologies" type="a(oa{sv})" direction="out"/> + <annotation name="org.qtproject.QtDBus.QtTypeName.Out0" value="ConnmanMapList"/> + </method> + + <method name="GetServices" tp:name-for-bindings="Get_Services"> + <arg name="services" type="a(oa{sv})" direction="out"/> + <annotation name="org.qtproject.QtDBus.QtTypeName.Out0" value="ConnmanMapList"/> + </method> + + <method name="GetSavedServices" tp:name-for-bindings="Get_Saved_Services"> + <arg name="services" type="a(oa{sv})" direction="out"/> + <annotation name="org.qtproject.QtDBus.QtTypeName.Out0" value="ConnmanMapList"/> + </method> + + <method name="RemoveSavedService" tp:name-for-bindings="Remove_Saved_Services"> + <arg name="identifier" type="s" direction="in"/> + </method> + + <method name="RegisterAgent" tp:name-for-bindings="Register_Agent"> + <arg name="path" type="o"/> + </method> + + <method name="UnregisterAgent" tp:name-for-bindings="Unregister_Agent"> + <arg name="path" type="o"/> + </method> + + <method name="RegisterCounter" tp:name-for-bindings="Register_Counter"> + <arg name="path" type="o"/> + <arg name="accuracy" type="u"/> + <arg name="period" type="u"/> + </method> + + <method name="UnregisterCounter" tp:name-for-bindings="Unregister_Counter"> + <arg name="path" type="o"/> + </method> + + <method name="ResetCounters" tp:name-for-bindings="Reset_Counters"> + <arg name="type" type="s"/> + </method> + + <method name="CreateSession" tp:name-for-bindings="Create_Session"> + <arg name="settings" type="a{sv}"/> + <annotation name="org.qtproject.QtDBus.QtTypeName.In0" value="QVariantMap"/> + <arg name="notifier" type="o"/> + <arg name="session" type="o" direction="out"/> + </method> + + <method name="DestroySession" tp:name-for-bindings="Destroy_Session"> + <arg name="session" type="o"/> + </method> + + <method name="RequestPrivateNetwork" tp:name-for-bindings="Request_Private_Network"> + <arg name="options" type="a{sv}"/> + <annotation name="org.qtproject.QtDBus.QtTypeName.In0" value="QVariantMap"/> + <arg name="path" type="o" direction="out"/> + <arg name="dict" type="a{sv}" direction="out"/> + <annotation name="org.qtproject.QtDBus.QtTypeName.Out1" value="QVariantMap"/> + <arg name="fd" type="i" direction="out"/> + <annotation name="org.qtproject.QtDBus.QtTypeName.In0" value="QVariantMap"/> + </method> + + <method name="ReleasePrivateNetwork" tp:name-for-bindings="Release_Private_Network"> + <arg name="path" type="o"/> + </method> + + <signal name="NetworkTypeAdded" tp:name-for-bindings="NetworkType_Added"> + <arg name="technology" type="o"/> + <arg name="properties" type="a{sv}"/> + <annotation name="org.qtproject.QtDBus.QtTypeName.In1" value="QVariantMap"/> + </signal> + + <signal name="NetworkTypeRemoved" tp:name-for-bindings="NetworkType_Removed"> + <arg name="technology" type="o"/> + </signal> + + <signal name="ServicesChanged" tp:name-for-bindings="Services_Changed"> + <arg name="changed" type="a(oa{sv})"/> + <annotation name="org.qtproject.QtDBus.QtTypeName.In0" value="ConnmanMapList"/> + <arg name="removed" type="ao"/> + </signal> + + <signal name="SavedServicesChanged" tp:name-for-bindings="SavedServices_Changed"> + <arg name="changed" type="a(oa{sv})"/> + <annotation name="org.qtproject.QtDBus.QtTypeName.In0" value="ConnmanMapList"/> + </signal> + + <signal name="PropertyChanged" tp:name-for-bindings="Property_Changed"> + <arg name="name" type="s"/> + <arg name="value" type="v"/> + </signal> + + </interface> +</node> diff --git a/src/qtdevicesettings/networksettingsplugin/networksettings/connman/connman_service.xml b/src/qtdevicesettings/networksettingsplugin/networksettings/connman/connman_service.xml new file mode 100644 index 0000000..c41aca4 --- /dev/null +++ b/src/qtdevicesettings/networksettingsplugin/networksettings/connman/connman_service.xml @@ -0,0 +1,41 @@ +<?xml version="1.0" encoding="utf-8"?> +<node name="/Service" xmlns:tp="http://telepathy.freedesktop.org/wiki/DbusSpec#extensions-v0"> + <interface name="net.connman.Service"> + + <method name="GetProperties" tp:name-for-bindings="Get_Properties"> + <arg name="properties" type="a{sv}" direction="out"/> + <annotation name="org.qtproject.QtDBus.QtTypeName.Out0" value="QVariantMap"/> + </method> + + <method name="SetProperty" tp:name-for-bindings="Set_Property"> + <arg name="name" type="s"/> + <arg name="value" type="v"/> + </method> + + <method name="ClearProperty" tp:name-for-bindings="Clear_Property"> + <arg name="name" type="s" /> + </method> + + <method name="Connect" tp:name-for-bindings="Connect" /> + + <method name="Disconnect" tp:name-for-bindings="Disconnect" /> + + <method name="Remove" tp:name-for-bindings="Remove" /> + + <method name="MoveBefore" tp:name-for-bindings="Move_Before"> + <arg name="service" type="o"/> + </method> + + <method name="MoveAfter" tp:name-for-bindings="Move_After"> + <arg name="service" type="o"/> + </method> + + <method name="ResetCounters" tp:name-for-bindings="Reset_Counters" /> + + <signal name="PropertyChanged" tp:name-for-bindings="Property_Changed"> + <arg name="name" type="s"/> + <arg name="value" type="v"/> + </signal> + + </interface> +</node> diff --git a/src/qtdevicesettings/networksettingsplugin/networksettings/connman/connman_technology.xml b/src/qtdevicesettings/networksettingsplugin/networksettings/connman/connman_technology.xml new file mode 100644 index 0000000..08d780f --- /dev/null +++ b/src/qtdevicesettings/networksettingsplugin/networksettings/connman/connman_technology.xml @@ -0,0 +1,23 @@ +<?xml version="1.0" encoding="utf-8"?> +<node name="/Service" xmlns:tp="http://telepathy.freedesktop.org/wiki/DbusSpec#extensions-v0"> + <interface name="net.connman.Technology"> + + <method name="GetProperties" tp:name-for-bindings="Get_Properties"> + <arg name="properties" type="a{sv}" direction="out"/> + <annotation name="org.qtproject.QtDBus.QtTypeName.Out0" value="QVariantMap"/> + </method> + + <method name="SetProperty" tp:name-for-bindings="Set_Property"> + <arg name="name" type="s"/> + <arg name="value" type="v"/> + </method> + + <method name="Scan" tp:name-for-bindings="Scan"/> + + <signal name="PropertyChanged" tp:name-for-bindings="Property_Changed"> + <arg name="name" type="s"/> + <arg name="value" type="v"/> + </signal> + + </interface> +</node> diff --git a/src/qtdevicesettings/networksettingsplugin/networksettings/connman/networksettingsmanager_linux.cpp b/src/qtdevicesettings/networksettingsplugin/networksettings/connman/networksettingsmanager_linux.cpp new file mode 100644 index 0000000..c4973ea --- /dev/null +++ b/src/qtdevicesettings/networksettingsplugin/networksettings/connman/networksettingsmanager_linux.cpp @@ -0,0 +1,583 @@ +/**************************************************************************** +** +** 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 new file mode 100644 index 0000000..bccbed8 --- /dev/null +++ b/src/qtdevicesettings/networksettingsplugin/networksettings/connman/networksettingsmanager_linux_p.h @@ -0,0 +1,148 @@ +/**************************************************************************** +** +** 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/networkaddressmodel.cpp b/src/qtdevicesettings/networksettingsplugin/networksettings/networkaddressmodel.cpp new file mode 100644 index 0000000..3df67ab --- /dev/null +++ b/src/qtdevicesettings/networksettingsplugin/networksettings/networkaddressmodel.cpp @@ -0,0 +1,83 @@ +/**************************************************************************** +** +** 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 "networkaddressmodel.h" + +NetworkAddressModel::NetworkAddressModel(QObject *parent) + :QStringListModel(parent) +{ +} + +NetworkAddressModel::NetworkAddressModel(const QStringList &strings, QObject *parent) + :QStringListModel(parent) +{ + setStringList(strings); +} + +void NetworkAddressModel::setStringList(const QStringList &addresses) +{ + m_addresses = addresses; + QStringListModel::setStringList(m_addresses); + emit countChanged(); +} + +void NetworkAddressModel::append(const QString& address) +{ + int row = rowCount(); + + bool succeed = insertRows(row, 1); + if (succeed) + succeed = setData(index(row), QVariant::fromValue(address)); + + Q_ASSERT(succeed == true); + + emit countChanged(); +} + +void NetworkAddressModel::remove(int index) +{ + removeRows(index, 1); + emit countChanged(); +} + +int NetworkAddressModel::count() const +{ + return rowCount(); +} + +void NetworkAddressModel::resetChanges() +{ + QStringListModel::setStringList(m_addresses); +} diff --git a/src/qtdevicesettings/networksettingsplugin/networksettings/networkaddressmodel.h b/src/qtdevicesettings/networksettingsplugin/networksettings/networkaddressmodel.h new file mode 100644 index 0000000..b90958f --- /dev/null +++ b/src/qtdevicesettings/networksettingsplugin/networksettings/networkaddressmodel.h @@ -0,0 +1,60 @@ +/**************************************************************************** +** +** 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 NETWORKADDRESSMODEL_H +#define NETWORKADDRESSMODEL_H + +#include <QStringListModel> + +class NetworkAddressModel : public QStringListModel +{ + Q_OBJECT + Q_PROPERTY(int count READ count NOTIFY countChanged) +public: + explicit NetworkAddressModel(QObject *parent = 0); + explicit NetworkAddressModel(const QStringList &strings, QObject *parent = 0); + Q_INVOKABLE void append(const QString& address); + Q_INVOKABLE void remove(int index); + Q_INVOKABLE void resetChanges(); + void setStringList(const QStringList &addresses); + int count() const; + +signals: + void countChanged(); +private: + QStringList m_addresses; +}; + +#endif // NETWORKADDRESSMODEL_H diff --git a/src/qtdevicesettings/networksettingsplugin/networksettings/networkconfig.h b/src/qtdevicesettings/networksettingsplugin/networksettings/networkconfig.h new file mode 100644 index 0000000..cdff473 --- /dev/null +++ b/src/qtdevicesettings/networksettingsplugin/networksettings/networkconfig.h @@ -0,0 +1,394 @@ +/**************************************************************************** +** +** 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 NETWORKCONFIG_H +#define NETWORKCONFIG_H + +#include <QObject> +#include <QUrl> +#include <QVariantMap> +#include "networkaddressmodel.h" + +class NetworkState : public QObject +{ + Q_OBJECT + Q_ENUMS(States) + Q_PROPERTY(States state READ state WRITE setState NOTIFY stateChanged) + +public: + enum States {Idle, Failure, Association, Configuration, Ready, Disconnect, Online, Undefined}; + + explicit NetworkState(States aState, QObject *parent = 0) + : QObject(parent) + { + m_state = aState; + } + + explicit NetworkState(QObject *parent = 0) + : QObject(parent) + { + m_state = Undefined; + } + + States state() const { + return m_state; + } + + void setState(const States aState) { + m_state = aState; + emit stateChanged(); + } + +signals: + void stateChanged(); + +private: + States m_state; +}; + +class NetworkType : public QObject +{ + Q_OBJECT + Q_ENUMS(Types) + Q_PROPERTY(Types type READ type WRITE setType NOTIFY typeChanged) + +public: + enum Types { + Wired, + Wifi, + Bluetooth, + Unknown + }; + + explicit NetworkType(Types aType, QObject *parent = 0) + : QObject(parent) + { + m_type = aType; + } + + explicit NetworkType(QObject *parent = 0) + : QObject(parent) + { + m_type = Unknown; + } + + + Types type() const { + return m_type; + } + + void setType(const Types aType) { + m_type = aType; + emit typeChanged(); + } + +signals: + void typeChanged(); + +private: + Types m_type; +}; + +class IPv4Config : public QObject +{ + Q_OBJECT + Q_ENUMS(MethodType) + Q_PROPERTY(QString address READ address WRITE setAddress NOTIFY addressChanged) + Q_PROPERTY(QString gateway READ gateway WRITE setGateway NOTIFY gatewayChanged) + Q_PROPERTY(MethodType method READ method WRITE setMethod NOTIFY methodChanged) + Q_PROPERTY(QString mask READ mask WRITE setMask NOTIFY maskChanged) + +public: + explicit IPv4Config(QObject *parent = 0) + : QObject(parent) + { + + } + + enum MethodType {Dhcp, Manual, Off}; + + QString address() const { + return m_address; + } + void setAddress(const QString& aAdderess) { + m_address = aAdderess; + emit addressChanged(); + } + + QString gateway() const { + return m_gateway; + } + + void setGateway(const QString& aGateway) { + m_gateway = aGateway; + emit gatewayChanged(); + } + + MethodType method() const { + return m_method; + } + + void setMethod(const MethodType aMethod) { + m_method = aMethod; + emit methodChanged(); + } + + QString mask() const { + return m_mask; + } + + void setMask(const QString& aMask) { + m_mask = aMask; + emit maskChanged(); + } + +signals: + void addressChanged(); + void gatewayChanged(); + void methodChanged(); + void maskChanged(); + +private: + QString m_address; + QString m_gateway; + MethodType m_method; + QString m_mask; +}; + + +class IPv6Config : public QObject +{ + Q_OBJECT + Q_ENUMS(MethodType PrivacyType) + Q_PROPERTY(QString address READ address WRITE setAddress NOTIFY addressChanged) + Q_PROPERTY(QString gateway READ gateway WRITE setGateway NOTIFY gatewayChanged) + Q_PROPERTY(MethodType method READ method WRITE setMethod NOTIFY methodChanged) + Q_PROPERTY(PrivacyType privacy READ privacy WRITE setPrivacy NOTIFY privacyChanged) + Q_PROPERTY(int prefixLength READ prefixLength WRITE setPrefixLength NOTIFY prefixLengthChanged) + +public: + explicit IPv6Config(QObject *parent = 0) + : QObject(parent) + { + + } + + enum MethodType {Auto, Manual, Off}; + enum PrivacyType {Disabled, Enabled, Preferred}; + + QString address() const { + return m_address; + } + void setAddress(const QString& aAdderess) { + m_address = aAdderess; + emit addressChanged(); + } + + QString gateway() const { + return m_gateway; + } + + void setGateway(const QString& aGateway) { + m_gateway = aGateway; + emit gatewayChanged(); + } + + MethodType method() const { + return m_method; + } + + void setMethod(const MethodType aMethod) { + m_method = aMethod; + emit methodChanged(); + } + + PrivacyType privacy() const { + return m_privacy; + } + + void setPrivacy(const PrivacyType aPrivacy) { + m_privacy = aPrivacy; + emit privacyChanged(); + } + + int prefixLength() const { + return m_prefixLength; + } + + void setPrefixLength(const int& aPrefixLength) { + m_prefixLength = aPrefixLength; + emit prefixLengthChanged(); + } + +signals: + void addressChanged(); + void gatewayChanged(); + void methodChanged(); + void privacyChanged(); + void prefixLengthChanged(); + +private: + QString m_address; + QString m_gateway; + MethodType m_method; + PrivacyType m_privacy; + int m_prefixLength; +}; + +class ProxyConfig : public QObject +{ + Q_OBJECT + Q_ENUMS(MethodType) +public: + Q_PROPERTY(QUrl url READ url WRITE setUrl NOTIFY urlChanged) + Q_PROPERTY(QAbstractItemModel* servers READ servers NOTIFY serversChanged) + Q_PROPERTY(QAbstractItemModel* excludes READ excludes NOTIFY excludesChanged) + Q_PROPERTY(MethodType method READ method WRITE setMethod NOTIFY methodChanged) + + explicit ProxyConfig(QObject *parent=NULL) + : QObject(parent) + { + + } + + enum MethodType {Direct, Auto, Manual}; + + QUrl url() const { + return m_url; + } + + void setUrl(const QUrl& aUrl) { + m_url = aUrl; + emit urlChanged(); + } + + QAbstractItemModel* servers(void) { + return &m_servers; + } + + void setServers(const QStringList& aServers) { + m_servers.setStringList(aServers); + emit serversChanged(); + } + + QStringList servers() const { + return m_servers.stringList(); + } + + QAbstractItemModel* excludes(void) { + return &m_excludes; + } + + QStringList excludes() const { + return m_excludes.stringList(); + } + + void setExcludes(const QStringList& aExcludes) { + m_excludes.setStringList(aExcludes); + emit excludesChanged(); + } + + MethodType method(void) const { + return m_method; + } + + void setMethod(const MethodType& aMethod) { + m_method = aMethod; + emit methodChanged(); + } + +signals: + void urlChanged(); + void serversChanged(); + void excludesChanged(); + void methodChanged(); +private: + QUrl m_url; + NetworkAddressModel m_servers; + NetworkAddressModel m_excludes; + MethodType m_method; +}; + +class WifiConfig : public QObject +{ + Q_OBJECT + Q_PROPERTY(QString bssid READ bssid NOTIFY bssidChanged) + Q_PROPERTY(int maxRate READ maxRate NOTIFY maxRateChanged) + Q_PROPERTY(int frequency READ frequency NOTIFY frequencyChanged) + Q_PROPERTY(QString encryptionMode READ encryptionMode NOTIFY encryptionModeChanged) + Q_PROPERTY(bool hidden READ hidden NOTIFY hiddenChanged) +public: + explicit WifiConfig(QObject* parent = 0) : + QObject(parent) { + + } + + const QString bssid() { + return m_bssid; + } + + int maxRate() { + return m_maxRate; + } + + int frequency() { + return m_frequency; + } + + const QString encryptionMode() { + return m_encryptionMode; + } + + bool hidden() const { + return m_hidden; + } + +signals: + void bssidChanged(const QString &bssid); + void maxRateChanged(quint32 rate); + void frequencyChanged(quint16 frequency); + void encryptionModeChanged(const QString &mode); + void hiddenChanged(bool); + +private: + QString m_bssid; + quint32 m_maxRate; + quint16 m_frequency; + QString m_encryptionMode; + bool m_hidden; +}; + + +#endif diff --git a/src/qtdevicesettings/networksettingsplugin/networksettings/networksettings.pri b/src/qtdevicesettings/networksettingsplugin/networksettings/networksettings.pri new file mode 100644 index 0000000..7a81571 --- /dev/null +++ b/src/qtdevicesettings/networksettingsplugin/networksettings/networksettings.pri @@ -0,0 +1,28 @@ +#------------------------------------------------- +# +# Project created by QtCreator 2015-11-03T13:52:45 +# +#------------------------------------------------- + +QT += core network dbus + +INCLUDEPATH += $${PWD}/connman +INCLUDEPATH += $${PWD} + +DBUS_INTERFACES = \ + networksettings/connman/connman_manager.xml \ + networksettings/connman/connman_service.xml \ + networksettings/connman/connman_technology.xml + + +SOURCES += networksettings/networksettingsmanager.cpp \ + networksettings/connman/networksettingsmanager_linux.cpp \ + networksettings/networkaddressmodel.cpp \ + networksettings/networksmodel.cpp + +HEADERS += \ + networksettings/networkconfig.h \ + networksettings/connman/networksettingsmanager_linux_p.h \ + networksettings/networkaddressmodel.h \ + networksettings/networksettingsmanager.h \ + networksettings/networksmodel.h diff --git a/src/qtdevicesettings/networksettingsplugin/networksettings/networksettingsmanager.cpp b/src/qtdevicesettings/networksettingsplugin/networksettings/networksettingsmanager.cpp new file mode 100644 index 0000000..6df0f22 --- /dev/null +++ b/src/qtdevicesettings/networksettingsplugin/networksettings/networksettingsmanager.cpp @@ -0,0 +1,167 @@ +/**************************************************************************** +** +** 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 "networksettingsmanager.h" +#include "connman/networksettingsmanager_linux_p.h" +#include <QStringListModel> + +NetworkService::NetworkService(const QString& aServiceId, QObject* parent) : + QObject(parent) + ,d_ptr(new NetworkServicePrivate(aServiceId, this)) +{ + +} + +QString NetworkService::name() const +{ + Q_D(const NetworkService); + return d->m_name; +} + +NetworkState::States NetworkService::state() +{ + Q_D(NetworkService); + return d->m_state.state(); +} + +NetworkType::Types NetworkService::type() +{ + Q_D(NetworkService); + return d->m_type.type(); +} + +IPv4Config* NetworkService::ipv4() +{ + Q_D(NetworkService); + return &d->m_ipv4config; +} + +IPv6Config* NetworkService::ipv6() +{ + Q_D(NetworkService); + return &d->m_ipv6config; +} + +ProxyConfig* NetworkService::proxy() +{ + Q_D(NetworkService); + return &d->m_proxyConfig; +} + +QAbstractItemModel* NetworkService::domains() +{ + Q_D(NetworkService); + return &d->m_domainsConfig; +} + +QAbstractItemModel* NetworkService::nameservers() +{ + Q_D(NetworkService); + return &d->m_nameserverConfig; +} + +void NetworkService::setupIpv4Config() +{ + Q_D(NetworkService); + d->setupIpv4Config(); +} + +void NetworkService::setupIpv6Config() +{ + Q_D(NetworkService); + d->setupIpv6Config(); +} + +void NetworkService::setupNameserversConfig() +{ + Q_D(NetworkService); + d->setupNameserversConfig(); +} + +void NetworkService::setupDomainsConfig() +{ + Q_D(NetworkService); + d->setupDomainsConfig(); +} + +void NetworkService::setupProxyConfig() +{ + Q_D(NetworkService); + d->setupProxyConfig(); +} + +NetworkSettingsManager::NetworkSettingsManager(QObject *parent) : + QObject(parent) + ,d_ptr(new NetworkSettingsManagerPrivate(this)) +{ + +} + +QQmlListProperty<NetworkService> NetworkSettingsManager::services() +{ + Q_D(NetworkSettingsManager); + return QQmlListProperty<NetworkService>(this, d->m_services); +} + +QAbstractItemModel* NetworkSettingsManager::networks() +{ + Q_D(NetworkSettingsManager); + return &d->m_networksModel; +} + +NetworkService* NetworkSettingsManager::getService(const QString& aName, const int aType) +{ + Q_D(NetworkSettingsManager); + + foreach (NetworkService* service, d->m_services) { + if (service->name() == aName && service->type() == aType) { + return service; + } + } + return NULL; +} + + +bool NetworkSettingsManager::wifiPowered() +{ + Q_D(NetworkSettingsManager); + return d->wifiPowered(); +} + +void NetworkSettingsManager::setWifiPowered(const bool power) +{ + Q_D(NetworkSettingsManager); + d->setWifiPowered(power); +} diff --git a/src/qtdevicesettings/networksettingsplugin/networksettings/networksettingsmanager.h b/src/qtdevicesettings/networksettingsplugin/networksettings/networksettingsmanager.h new file mode 100644 index 0000000..8e51258 --- /dev/null +++ b/src/qtdevicesettings/networksettingsplugin/networksettings/networksettingsmanager.h @@ -0,0 +1,127 @@ +/**************************************************************************** +** +** 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 NETWORKSETTINGSMANAGER_H +#define NETWORKSETTINGSMANAGER_H + +#include "networkconfig.h" +#include <QObject> +#include <QQmlListProperty> +#include <QStringListModel> + +QT_FORWARD_DECLARE_CLASS(NetworkSettingsManagerPrivate) +QT_FORWARD_DECLARE_CLASS(NetworkServicePrivate) +QT_FORWARD_DECLARE_CLASS(NetworkNetworkTypePrivate) + +class NetworkService : public QObject +{ + Q_OBJECT + Q_ENUMS(StateTypes) + Q_PROPERTY(QString name READ name NOTIFY nameChanged) + Q_PROPERTY(NetworkState::States state READ state NOTIFY stateChanged) + Q_PROPERTY(NetworkType::Types type READ type NOTIFY typeChanged) + Q_PROPERTY(IPv4Config* ipv4 READ ipv4 NOTIFY ipv4Changed) + Q_PROPERTY(IPv6Config* ipv6 READ ipv6 NOTIFY ipv6Changed) + Q_PROPERTY(ProxyConfig* proxy READ proxy NOTIFY proxyChanged) + Q_PROPERTY(QAbstractItemModel* domains READ domains NOTIFY domainsChanged) + Q_PROPERTY(QAbstractItemModel* nameservers READ nameservers NOTIFY nameserversChanged) +public: + explicit NetworkService(const QString& aServiceId, QObject* parent = 0); + + QString name() const; + NetworkState::States state(); + NetworkType::Types type(); + IPv4Config* ipv4(); + IPv6Config* ipv6(); + ProxyConfig* proxy(); + QAbstractItemModel* domains(); + QAbstractItemModel* nameservers(); + + Q_INVOKABLE void setAutoConnect(const bool autoconnect); + Q_INVOKABLE void setupIpv4Config(); + Q_INVOKABLE void setupIpv6Config(); + Q_INVOKABLE void setupNameserversConfig(); + Q_INVOKABLE void setupDomainsConfig(); + Q_INVOKABLE void setupProxyConfig(); + +Q_SIGNALS: + void nameChanged(); + void stateChanged(); + void typeChanged(); + void proxyChanged(); + void ipv4Changed(); + void ipv6Changed(); + void domainsChanged(); + void nameserversChanged(); + +protected: + NetworkServicePrivate *d_ptr; + + Q_DISABLE_COPY(NetworkService) + Q_DECLARE_PRIVATE(NetworkService) +}; + +class NetworkSettingsManager : public QObject +{ + Q_OBJECT + Q_ENUMS(StateTypes NetworkTypeTypes) + Q_PROPERTY(QQmlListProperty<NetworkService> services READ services NOTIFY servicesChanged) + Q_PROPERTY(QAbstractItemModel* networks READ networks NOTIFY networksChanged) + Q_PROPERTY(bool wifiPowered READ wifiPowered WRITE setWifiPowered NOTIFY wifiPoweredChanged) +public: + explicit NetworkSettingsManager(QObject* parent = 0); + QQmlListProperty<NetworkService> services(); + + QAbstractItemModel* networks(); + + Q_INVOKABLE NetworkService* getService(const QString& aName, const int aType); + + bool wifiPowered(); + void setWifiPowered(const bool power); + +Q_SIGNALS: + void servicesChanged(); + void wifiPoweredChanged(); + void networksChanged(); + +protected: + NetworkSettingsManagerPrivate *d_ptr; + +private: + Q_DISABLE_COPY(NetworkSettingsManager) + Q_DECLARE_PRIVATE(NetworkSettingsManager) +}; + +#endif // NETWORKSETTINGSMANAGER_H diff --git a/src/qtdevicesettings/networksettingsplugin/networksettings/networksmodel.cpp b/src/qtdevicesettings/networksettingsplugin/networksettings/networksmodel.cpp new file mode 100644 index 0000000..8524417 --- /dev/null +++ b/src/qtdevicesettings/networksettingsplugin/networksettings/networksmodel.cpp @@ -0,0 +1,111 @@ +/**************************************************************************** +** +** 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 "networksmodel.h" + +NetworksModel::NetworksModel(QObject *parent) + : QAbstractListModel(parent) +{ + m_roleNames.insert(Qt::UserRole, "modelData"); + m_roleNames.insert(Type, "type"); + m_roleNames.insert(Status, "status"); + m_roleNames.insert(Name, "name"); +} + +NetworksModel::~NetworksModel() +{ + +} + +QHash<int, QByteArray> NetworksModel::roleNames() const +{ + return m_roleNames; +} + + +int NetworksModel::rowCount(const QModelIndex & parent) const +{ + Q_UNUSED(parent); + return m_items.count(); +} + +QVariant NetworksModel::data(const QModelIndex & index, int role) const +{ + if (!index.isValid()) return QVariant(); + + NetworkItem *item = m_items[index.row()]; + if (role == Qt::UserRole) { + return QVariant::fromValue(static_cast<QObject*>(item)); + } + + switch (role) { + case Type: + return item->type(); + break; + case Name: + return item->name(); + break; + case Status: + return item->state(); + break; + default: + return ""; + } + +} + +void NetworksModel::append(NetworkItem* item) +{ + item->setParent(this); + + beginInsertRows(QModelIndex(), rowCount(), rowCount()); + m_items.append(item); + endInsertRows(); +} + +void NetworksModel::insert(int row, NetworkItem* item) +{ + item->setParent(this); + + beginInsertRows(QModelIndex(), row, row); + m_items.insert(row, item); + endInsertRows(); +} + +QList<NetworkItem*> NetworksModel::getModel() +{ + return m_items; +} diff --git a/src/qtdevicesettings/networksettingsplugin/networksettings/networksmodel.h b/src/qtdevicesettings/networksettingsplugin/networksettings/networksmodel.h new file mode 100644 index 0000000..d4c389c --- /dev/null +++ b/src/qtdevicesettings/networksettingsplugin/networksettings/networksmodel.h @@ -0,0 +1,131 @@ +/**************************************************************************** +** +** 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 NETWORKSMODEL_H +#define NETWORKSMODEL_H + +#include <QAbstractListModel> +#include "networkconfig.h" + +QT_FORWARD_DECLARE_CLASS(NetworksModelPrivate) +QT_FORWARD_DECLARE_CLASS(QQmlPropertyMap) + +class NetworkItem : public QObject { + Q_OBJECT + Q_PROPERTY(QString name READ name NOTIFY nameChanged) + Q_PROPERTY(NetworkState::States state READ state NOTIFY stateChanged) + Q_PROPERTY(NetworkType::Types type READ type NOTIFY typeChanged) + Q_PROPERTY(bool powered READ powered NOTIFY poweredChanged) + +public: + explicit NetworkItem(QObject* parent=0) : + QObject(parent) { + + } + + QString name() const { + return m_name; + } + + void setName(const QString& aName) { + m_name = aName; + } + + NetworkState::States state() const { + return m_state.state(); + } + + NetworkType::Types type() const { + return m_type.type(); + } + + void setState(const NetworkState::States aState) { + m_state.setState(aState); + } + + void setType(const NetworkType::Types aType) { + m_type.setType(aType); + } + + bool powered() const { + return m_powered; + } + + void setPowered(const bool aPowered) { + m_powered = aPowered; + } + +signals: + void nameChanged(); + void stateChanged(); + void typeChanged(); + void poweredChanged(); + +protected: + QString m_name; + NetworkState m_state; + NetworkType m_type; + bool m_powered; + friend class NetworksModel; +}; + +class NetworksModel : public QAbstractListModel +{ + Q_OBJECT + +public: + explicit NetworksModel(QObject *parent=0); + virtual ~NetworksModel(); + // from QAbstractItemModel + int rowCount(const QModelIndex & parent = QModelIndex()) const; + QVariant data(const QModelIndex & index, int role = Qt::DisplayRole) const; + QHash<int, QByteArray> roleNames() const; + + void append(NetworkItem* networkItem); + void insert(int row, NetworkItem* networkItem); + QList<NetworkItem*> getModel(); + + enum Roles { + Type = Qt::UserRole + 1, + Status, + Name + }; + +private: + QList<NetworkItem*> m_items; + QHash<int, QByteArray> m_roleNames; +}; + +#endif // NETWORKSMODEL_H diff --git a/src/qtdevicesettings/networksettingsplugin/networksettingsplugin.pro b/src/qtdevicesettings/networksettingsplugin/networksettingsplugin.pro new file mode 100644 index 0000000..c514393 --- /dev/null +++ b/src/qtdevicesettings/networksettingsplugin/networksettingsplugin.pro @@ -0,0 +1,45 @@ +TEMPLATE = lib +TARGET = networksettingsplugin +QT += qml quick +CONFIG += qt plugin + +uri = com.theqtcompany.settings.network + +include(networksettings/networksettings.pri) + +# Input +SOURCES += \ + networksettingsplugin_plugin.cpp +HEADERS += \ + networksettingsplugin_plugin.h + +DISTFILES = qmldir + +!equals(_PRO_FILE_PWD_, $$OUT_PWD) { + copy_qmldir.target = $$OUT_PWD/qmldir + copy_qmldir.depends = $$_PRO_FILE_PWD_/qmldir + copy_qmldir.commands = $(COPY_FILE) \"$$replace(copy_qmldir.depends, /, $$QMAKE_DIR_SEP)\" \"$$replace(copy_qmldir.target, /, $$QMAKE_DIR_SEP)\" + QMAKE_EXTRA_TARGETS += copy_qmldir + PRE_TARGETDEPS += $$copy_qmldir.target +} + +qmldir.files = qmldir + +pluginfiles.files += \ + imports/NetworkSettings/EditWiredSettings.qml \ + imports/NetworkSettings/NetworkDetails.qml \ + imports/NetworkSettings/WifiSettings.qml \ + imports/NetworkSettings/IpAddressTextField.qml \ + imports/NetworkSettings/NetworkSettings.qml \ + imports/NetworkSettings/WiredSettings.qml + +installPath = $$[QT_INSTALL_QML]/$$replace(uri, \\., /) + +pluginfiles.path = $$installPath +qmldir.path = $$installPath +target.path = $$installPath +INSTALLS += target qmldir pluginfiles + +RESOURCES += \ + icons.qrc + diff --git a/src/qtdevicesettings/networksettingsplugin/networksettingsplugin_plugin.cpp b/src/qtdevicesettings/networksettingsplugin/networksettingsplugin_plugin.cpp new file mode 100644 index 0000000..684cef0 --- /dev/null +++ b/src/qtdevicesettings/networksettingsplugin/networksettingsplugin_plugin.cpp @@ -0,0 +1,61 @@ +/**************************************************************************** +** +** 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 "networksettingsplugin_plugin.h" +#include "networkconfig.h" +#include "networksettingsmanager.h" + +#include <qqml.h> +#include <QQmlEngine> + +template <typename T> +QObject *instance(QQmlEngine *engine, QJSEngine *) { + T *t = new T(engine); + t->setObjectName(T::staticMetaObject.className()); + return t; +} + +void NetworksettingspluginPlugin::registerTypes(const char *uri) +{ + Q_ASSERT(QLatin1String(uri) == QLatin1String("com.theqtcompany.settings.network")); + qmlRegisterUncreatableType<NetworkService>(uri, 1, 0, "NetworkService", "Cannot be instantiated directly."); + qmlRegisterUncreatableType<IPv4Config>(uri, 1, 0, "IPv4Config", "Cannot be instantiated directly."); + qmlRegisterUncreatableType<IPv6Config>(uri, 1, 0, "IPv6Config", "Cannot be instantiated directly."); + qmlRegisterUncreatableType<ProxyConfig>(uri, 1, 0, "ProxyConfig", "Cannot be instantiated directly."); + qmlRegisterUncreatableType<NetworkType>(uri, 1, 0, "NetworkType", "Cannot be instantiated directly."); + qmlRegisterSingletonType<NetworkSettingsManager>(uri, 1, 0, "NetworkSettingsManager", &instance<NetworkSettingsManager>); +} + + diff --git a/src/qtdevicesettings/networksettingsplugin/networksettingsplugin_plugin.h b/src/qtdevicesettings/networksettingsplugin/networksettingsplugin_plugin.h new file mode 100644 index 0000000..40e02e2 --- /dev/null +++ b/src/qtdevicesettings/networksettingsplugin/networksettingsplugin_plugin.h @@ -0,0 +1,51 @@ +/**************************************************************************** +** +** 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 NETWORKSETTINGSPLUGIN_PLUGIN_H +#define NETWORKSETTINGSPLUGIN_PLUGIN_H + +#include <QQmlExtensionPlugin> + +class NetworksettingspluginPlugin : public QQmlExtensionPlugin +{ + Q_OBJECT + Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QQmlExtensionInterface") + +public: + void registerTypes(const char *uri); +}; + +#endif // NETWORKSETTINGSPLUGIN_PLUGIN_H + diff --git a/src/qtdevicesettings/networksettingsplugin/qml.qrc b/src/qtdevicesettings/networksettingsplugin/qml.qrc new file mode 100644 index 0000000..87c3639 --- /dev/null +++ b/src/qtdevicesettings/networksettingsplugin/qml.qrc @@ -0,0 +1,10 @@ +<RCC> + <qresource prefix="/"> + <file>qml/EditWiredSettings.qml</file> + <file>qml/IpAddressTextField.qml</file> + <file>qml/NetworkDetails.qml</file> + <file>qml/NetworkSettings.qml</file> + <file>qml/WifiSettings.qml</file> + <file>qml/WiredSettings.qml</file> + </qresource> +</RCC> diff --git a/src/qtdevicesettings/networksettingsplugin/qmldir b/src/qtdevicesettings/networksettingsplugin/qmldir new file mode 100644 index 0000000..71f3726 --- /dev/null +++ b/src/qtdevicesettings/networksettingsplugin/qmldir @@ -0,0 +1,4 @@ +module com.theqtcompany.settings.network +NetworkSettings 1.0 NetworkSettings.qml +plugin networksettingsplugin + |