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 Ubuntu.SystemImage 0.1
24 import ".." as LocalComponents
25 import "../../Components"
27 LocalComponents.Page {
29 objectName: "wifiPage"
31 title: i18n.tr("Connect to Wi‑Fi")
32 forwardButtonSourceComponent: forwardButton
34 readonly property bool connected: Connectivity.online
36 function getExtendedProperty(object, propertyName, defaultValue) {
37 if (object && object.hasOwnProperty(propertyName)) {
38 return object[propertyName];
43 function getAPIcon(adHoc, signalStrength, secure) {
44 var imageName = "nm-no-connection";
47 imageName = "nm-adhoc";
48 } else if (signalStrength == 0) {
49 imageName = "nm-signal-00";
50 } else if (signalStrength <= 25) {
51 imageName = "nm-signal-25";
52 } else if (signalStrength <= 50) {
53 imageName = "nm-signal-50";
54 } else if (signalStrength <= 75) {
55 imageName = "nm-signal-75";
56 } else if (signalStrength <= 100) {
57 imageName = "nm-signal-100";
61 imageName += "-secure";
66 QMenuModel.UnityMenuModel {
68 busName: "com.canonical.indicator.network"
69 actions: { "indicator": "/com/canonical/indicator/network" }
70 menuObjectPath: "/com/canonical/indicator/network/phone_wifi_settings"
74 id: accessPointComponent
77 objectName: "accessPoint_" + apName.text.toLowerCase().replace(/\s+/g, '_')
78 highlightColor: backgroundColor
79 enabled: menuData && menuData.sensitive || false
80 divider.colorFrom: dividerColor
81 divider.colorTo: backgroundColor
83 property QtObject menuData: null
84 property var unityMenuModel: menuModel
85 property var extendedData: menuData && menuData.ext || undefined
86 property var strengthAction: QMenuModel.UnityMenuAction {
89 name: getExtendedProperty(extendedData, "xCanonicalWifiApStrengthAction", "")
91 readonly property bool secure: getExtendedProperty(extendedData, "xCanonicalWifiApIsSecure", false)
92 readonly property bool adHoc: getExtendedProperty(extendedData, "xCanonicalWifiApIsAdhoc", false)
93 readonly property bool isConnected: menuData && menuData.actionState
94 readonly property bool isEnterprise: getExtendedProperty(extendedData, "xCanonicalWifiApIsEnterprise", false)
95 readonly property int signalStrength: strengthAction.valid ? strengthAction.state : 0
96 property int menuIndex: -1
98 function loadAttributes() {
99 if (!unityMenuModel || menuIndex == -1) return;
100 unityMenuModel.loadExtendedAttributes(menuIndex, {'x-canonical-wifi-ap-is-adhoc': 'bool',
101 'x-canonical-wifi-ap-is-secure': 'bool',
102 'x-canonical-wifi-ap-is-enterprise': 'bool',
103 'x-canonical-wifi-ap-strength-action': 'string'});
110 verticalCenter: parent.verticalCenter
111 leftMargin: column.anchors.leftMargin == 0 ? staticMargin : 0
113 height: units.gu(2.5)
115 name: getAPIcon(accessPoint.adHoc, accessPoint.signalStrength, accessPoint.secure)
120 anchors.verticalCenter: parent.verticalCenter
121 anchors.left: apIcon.right
122 anchors.leftMargin: units.gu(2)
125 text: menuData && menuData.label || ""
126 font.weight: accessPoint.isConnected ? Font.Normal : Font.Light
132 text: i18n.tr("Connected")
133 font.weight: Font.Light
136 visible: accessPoint.isConnected
141 unityMenuModel.activate(menuIndex);
142 listview.positionViewAtBeginning();
152 topMargin: customMargin
153 leftMargin: wideMode ? parent.leftMargin : 0
154 rightMargin: wideMode ? parent.rightMargin : 0
159 anchors.left: parent.left
160 anchors.right: parent.right
161 anchors.leftMargin: column.anchors.leftMargin == 0 ? staticMargin : 0
162 font.weight: Font.Light
165 text: listview.count > 0 ? i18n.tr("Available Wi-Fi networks")
166 : i18n.tr("No available Wi-Fi networks")
171 objectName: "accessPointsListView"
172 anchors.left: parent.left
173 anchors.right: parent.right
176 Layout.fillHeight: true
179 readonly property bool isAccessPoint: model.type === "unity.widgets.systemsettings.tablet.accesspoint"
180 readonly property bool isConnected: item && item.menuData && item.menuData.actionState
181 readonly property bool isEnterprise: item && item.isEnterprise
183 height: !!sourceComponent ? (isConnected ? units.gu(9) : units.gu(7)) : 0
184 anchors.left: parent.left
185 anchors.right: parent.right
189 if (isAccessPoint && !isEnterprise) {
190 return accessPointComponent;
196 item.menuData = Qt.binding(function() { return model; });
197 item.menuIndex = Qt.binding(function() { return index; });
198 item.loadAttributes();
206 LocalComponents.StackButton {
207 text: (connected || listview.count === 0) ? i18n.tr("Next") : i18n.tr("Skip")
210 SystemImage.checkForUpdate(); // initiate the background check for System Update