2 * Copyright (C) 2013 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 QMenuModel 0.1 as QMenuModel
19 import QtSystemInfo 5.0
20 import Ubuntu.Components 1.3
21 import Ubuntu.Components.ListItems 1.3 as ListItem
22 import Ubuntu.Settings.Menus 0.1 as Menus
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: networkInfo.accessPointName
34 function getExtendedProperty(object, propertyName, defaultValue) {
35 if (object && object.hasOwnProperty(propertyName)) {
36 return object[propertyName];
41 QMenuModel.UnityMenuModel {
43 busName: "com.canonical.indicator.network"
44 actions: { "indicator": "/com/canonical/indicator/network" }
45 menuObjectPath: "/com/canonical/indicator/network/phone_wifi_settings"
51 property string accessPointName
53 monitorCurrentNetworkMode: true
54 monitorNetworkName: true
55 monitorNetworkStatus: true
57 onCurrentNetworkModeChanged: getAccessPointName()
58 onNetworkNameChanged: getAccessPointName()
59 onNetworkStatusChanged: if (status !== NetworkInfo.HomeNetwork) accessPointName = ""
61 Component.onCompleted: getAccessPointName()
63 function getAccessPointName() {
65 if (currentNetworkMode === NetworkInfo.WlanMode &&
66 networkStatus(NetworkInfo.WlanMode, 0) === NetworkInfo.HomeNetwork)
67 accessPointName = networkName(NetworkInfo.WlanMode, 0);
74 id: accessPointComponent
77 objectName: "accessPoint"
79 property QtObject menuData: null
80 property var unityMenuModel: menuModel
81 property var extendedData: menuData && menuData.ext || undefined
82 property var strengthAction: QMenuModel.UnityMenuAction {
85 name: getExtendedProperty(extendedData, "xCanonicalWifiApStrengthAction", "")
87 property bool checked: menuData && menuData.isToggled || false
88 property bool secure: getExtendedProperty(extendedData, "xCanonicalWifiApIsSecure", false)
89 property bool adHoc: getExtendedProperty(extendedData, "xCanonicalWifiApIsAdhoc", false)
90 property int signalStrength: strengthAction.valid ? strengthAction.state : 0
91 property int menuIndex: -1
93 function loadAttributes() {
94 if (!unityMenuModel || menuIndex == -1) return;
95 unityMenuModel.loadExtendedAttributes(menuIndex, {'x-canonical-wifi-ap-is-adhoc': 'bool',
96 'x-canonical-wifi-ap-is-secure': 'bool',
97 'x-canonical-wifi-ap-strength-action': 'string'});
102 text: menuData && menuData.label || ""
103 enabled: menuData && menuData.sensitive || false
105 var imageName = "nm-signal-100";
108 imageName = "nm-adhoc";
109 } else if (signalStrength == 0) {
110 imageName = "nm-signal-00";
111 } else if (signalStrength <= 25) {
112 imageName = "nm-signal-25";
113 } else if (signalStrength <= 50) {
114 imageName = "nm-signal-50";
115 } else if (signalStrength <= 75) {
116 imageName = "nm-signal-75";
120 imageName += "-secure";
129 accessPoint.activate();
136 Component.onCompleted: {
139 onUnityMenuModelChanged: {
142 onMenuIndexChanged: {
146 // Can't rely on binding. Checked is assigned on click.
147 checkBoxActive.checked = checked;
149 onActivate: unityMenuModel.activate(menuIndex);
156 anchors.top: content.top
157 anchors.bottom: content.bottom
158 anchors.left: wifiPage.left
159 anchors.right: wifiPage.right
163 anchors.left: parent.left
164 anchors.leftMargin: leftMargin
165 anchors.right: parent.right
166 anchors.rightMargin: rightMargin
168 text: mainMenu.count > 0 ? i18n.tr("Available networks…")
169 : i18n.tr("No available networks.")
173 anchors.left: parent.left
174 anchors.right: parent.right
175 height: column.height - label.height - column.spacing
176 contentHeight: contentItem.childrenRect.height
178 flickDeceleration: 1500 * units.gridUnit / 8
179 maximumFlickVelocity: 2500 * units.gridUnit / 8
180 boundsBehavior: (contentHeight > height) ? Flickable.DragAndOvershootBounds : Flickable.StopAtBounds
183 anchors.left: parent.left
184 anchors.right: parent.right
194 readonly property bool isAccessPoint: model.type === "unity.widgets.systemsettings.tablet.accesspoint"
196 anchors.left: parent.left
197 anchors.right: parent.right
198 height: isAccessPoint ? units.gu(6) : 0
200 sourceComponent: isAccessPoint ? accessPointComponent : null
203 item.menuData = Qt.binding(function() { return model; });
204 item.menuIndex = Qt.binding(function() { return index; });
214 LocalComponents.StackButton {
215 text: (connected || mainMenu.count === 0) ? i18n.tr("Continue") : i18n.tr("Skip")
216 onClicked: pageStack.next()