2 * Copyright (C) 2013-2016 Canonical, Ltd.
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; version 3.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 import QtQuick.Layouts 1.1
19 import QMenuModel 0.1 as QMenuModel
20 import Ubuntu.Components 1.3
22 import Ubuntu.Connectivity 1.0
23 import ".." as LocalComponents
24 import "../../Components"
26 LocalComponents.Page {
28 objectName: "wifiPage"
30 title: i18n.tr("Connect to Wi‑Fi")
31 forwardButtonSourceComponent: forwardButton
33 readonly property bool connected: Connectivity.online
35 function getExtendedProperty(object, propertyName, defaultValue) {
36 if (object && object.hasOwnProperty(propertyName)) {
37 return object[propertyName];
42 function getAPIcon(adHoc, signalStrength, secure) {
43 var imageName = "nm-no-connection";
46 imageName = "nm-adhoc";
47 } else if (signalStrength == 0) {
48 imageName = "nm-signal-00";
49 } else if (signalStrength <= 25) {
50 imageName = "nm-signal-25";
51 } else if (signalStrength <= 50) {
52 imageName = "nm-signal-50";
53 } else if (signalStrength <= 75) {
54 imageName = "nm-signal-75";
55 } else if (signalStrength <= 100) {
56 imageName = "nm-signal-100";
60 imageName += "-secure";
65 QMenuModel.UnityMenuModel {
67 busName: "com.canonical.indicator.network"
68 actions: { "indicator": "/com/canonical/indicator/network" }
69 menuObjectPath: "/com/canonical/indicator/network/phone_wifi_settings"
73 id: accessPointComponent
76 objectName: "accessPoint_" + apName.text.toLowerCase().replace(/\s+/g, '_')
77 highlightColor: backgroundColor
78 enabled: menuData && menuData.sensitive || false
79 divider.colorFrom: dividerColor
80 divider.colorTo: backgroundColor
82 property QtObject menuData: null
83 property var unityMenuModel: menuModel
84 property var extendedData: menuData && menuData.ext || undefined
85 property var strengthAction: QMenuModel.UnityMenuAction {
88 name: getExtendedProperty(extendedData, "xCanonicalWifiApStrengthAction", "")
90 readonly property bool secure: getExtendedProperty(extendedData, "xCanonicalWifiApIsSecure", false)
91 readonly property bool adHoc: getExtendedProperty(extendedData, "xCanonicalWifiApIsAdhoc", false)
92 readonly property bool isConnected: menuData && menuData.actionState
93 readonly property bool isEnterprise: getExtendedProperty(extendedData, "xCanonicalWifiApIsEnterprise", false)
94 readonly property int signalStrength: strengthAction.valid ? strengthAction.state : 0
95 property int menuIndex: -1
97 function loadAttributes() {
98 if (!unityMenuModel || menuIndex == -1) return;
99 unityMenuModel.loadExtendedAttributes(menuIndex, {'x-canonical-wifi-ap-is-adhoc': 'bool',
100 'x-canonical-wifi-ap-is-secure': 'bool',
101 'x-canonical-wifi-ap-is-enterprise': 'bool',
102 'x-canonical-wifi-ap-strength-action': 'string'});
109 verticalCenter: parent.verticalCenter
110 leftMargin: column.anchors.leftMargin == 0 ? staticMargin : 0
112 height: units.gu(2.5)
114 name: getAPIcon(accessPoint.adHoc, accessPoint.signalStrength, accessPoint.secure)
119 anchors.verticalCenter: parent.verticalCenter
120 anchors.left: apIcon.right
121 anchors.leftMargin: units.gu(2)
124 text: menuData && menuData.label || ""
125 font.weight: accessPoint.isConnected ? Font.Normal : Font.Light
131 text: i18n.tr("Connected")
132 font.weight: Font.Light
135 visible: accessPoint.isConnected
140 unityMenuModel.activate(menuIndex);
141 listview.positionViewAtBeginning();
151 topMargin: customMargin
152 leftMargin: wideMode ? parent.leftMargin : 0
153 rightMargin: wideMode ? parent.rightMargin : 0
158 anchors.left: parent.left
159 anchors.right: parent.right
160 anchors.leftMargin: column.anchors.leftMargin == 0 ? staticMargin : 0
161 font.weight: Font.Light
164 text: listview.count > 0 ? i18n.tr("Available Wi-Fi networks")
165 : i18n.tr("No available Wi-Fi networks")
170 objectName: "accessPointsListView"
171 anchors.left: parent.left
172 anchors.right: parent.right
175 Layout.fillHeight: true
178 readonly property bool isAccessPoint: model.type === "unity.widgets.systemsettings.tablet.accesspoint"
179 readonly property bool isConnected: item && item.menuData && item.menuData.actionState
180 readonly property bool isEnterprise: item && item.isEnterprise
182 height: !!sourceComponent ? (isConnected ? units.gu(9) : units.gu(7)) : 0
183 anchors.left: parent.left
184 anchors.right: parent.right
188 if (isAccessPoint && !isEnterprise) {
189 return accessPointComponent;
195 item.menuData = Qt.binding(function() { return model; });
196 item.menuIndex = Qt.binding(function() { return index; });
197 item.loadAttributes();
205 LocalComponents.StackButton {
206 text: (connected || listview.count === 0) ? i18n.tr("Next") : i18n.tr("Skip")