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
25 LocalComponents.Page {
27 objectName: "wifiPage"
29 title: i18n.tr("Connect to Wi‑Fi")
30 forwardButtonSourceComponent: forwardButton
32 readonly property bool connected: Connectivity.online
34 function getExtendedProperty(object, propertyName, defaultValue) {
35 if (object && object.hasOwnProperty(propertyName)) {
36 return object[propertyName];
41 function getAPIcon(adHoc, signalStrength, secure) {
42 var imageName = "nm-no-connection";
45 imageName = "nm-adhoc";
46 } else if (signalStrength == 0) {
47 imageName = "nm-signal-00";
48 } else if (signalStrength <= 25) {
49 imageName = "nm-signal-25";
50 } else if (signalStrength <= 50) {
51 imageName = "nm-signal-50";
52 } else if (signalStrength <= 75) {
53 imageName = "nm-signal-75";
54 } else if (signalStrength <= 100) {
55 imageName = "nm-signal-100";
59 imageName += "-secure";
64 QMenuModel.UnityMenuModel {
66 busName: "com.canonical.indicator.network"
67 actions: { "indicator": "/com/canonical/indicator/network" }
68 menuObjectPath: "/com/canonical/indicator/network/phone_wifi_settings"
72 id: accessPointComponent
75 objectName: "accessPoint"
76 highlightColor: backgroundColor
77 enabled: menuData && menuData.sensitive || false
78 divider.colorFrom: dividerColor
79 divider.colorTo: backgroundColor
81 property QtObject menuData: null
82 property var unityMenuModel: menuModel
83 property var extendedData: menuData && menuData.ext || undefined
84 property var strengthAction: QMenuModel.UnityMenuAction {
87 name: getExtendedProperty(extendedData, "xCanonicalWifiApStrengthAction", "")
89 readonly property bool secure: getExtendedProperty(extendedData, "xCanonicalWifiApIsSecure", false)
90 readonly property bool adHoc: getExtendedProperty(extendedData, "xCanonicalWifiApIsAdhoc", false)
91 readonly property bool isConnected: menuData && menuData.actionState
92 readonly property bool isEnterprise: getExtendedProperty(extendedData, "xCanonicalWifiApIsEnterprise", false)
93 readonly property int signalStrength: strengthAction.valid ? strengthAction.state : 0
94 property int menuIndex: -1
96 function loadAttributes() {
97 if (!unityMenuModel || menuIndex == -1) return;
98 unityMenuModel.loadExtendedAttributes(menuIndex, {'x-canonical-wifi-ap-is-adhoc': 'bool',
99 'x-canonical-wifi-ap-is-secure': 'bool',
100 'x-canonical-wifi-ap-is-enterprise': 'bool',
101 'x-canonical-wifi-ap-strength-action': 'string'});
108 verticalCenter: parent.verticalCenter
109 leftMargin: column.anchors.leftMargin == 0 ? staticMargin : 0
111 height: units.gu(2.5)
113 name: getAPIcon(accessPoint.adHoc, accessPoint.signalStrength, accessPoint.secure)
118 anchors.verticalCenter: parent.verticalCenter
119 anchors.left: apIcon.right
120 anchors.leftMargin: units.gu(2)
123 text: menuData && menuData.label || ""
124 font.weight: accessPoint.isConnected ? Font.Normal : Font.Light
130 text: i18n.tr("Connected")
131 font.weight: Font.Light
134 visible: accessPoint.isConnected
139 unityMenuModel.activate(menuIndex);
140 listview.positionViewAtBeginning();
150 topMargin: customMargin
151 leftMargin: wideMode ? parent.leftMargin : 0
152 rightMargin: wideMode ? parent.rightMargin : 0
157 anchors.left: parent.left
158 anchors.right: parent.right
159 anchors.leftMargin: column.anchors.leftMargin == 0 ? staticMargin : 0
160 font.weight: Font.Light
163 text: listview.count > 0 ? i18n.tr("Available Wi-Fi networks")
164 : i18n.tr("No available Wi-Fi networks")
169 anchors.left: parent.left
170 anchors.right: parent.right
173 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")
207 onClicked: pageStack.next()