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/>.
18import QtQuick.Layouts 1.1
19import QMenuModel 1.0 as QMenuModel
20import Lomiri.Components 1.3
22import Lomiri.Connectivity 1.0
23import Lomiri.SystemSettings.Update 1.0
24import ".." as LocalComponents
25import "../../Components"
29 objectName: "wifiPage"
31 title: i18n.tr("Connect to Wi‑Fi")
32 forwardButtonSourceComponent: forwardButton
34 readonly property bool connected: Connectivity.online
35 skip: connected && !Connectivity.limitedBandwidth
38 if (connected && !Connectivity.limitedBandwidth && wifiPage.visible) {
43 function getExtendedProperty(object, propertyName, defaultValue) {
44 if (object && object.hasOwnProperty(propertyName)) {
45 return object[propertyName];
50 function getAPIcon(adHoc, signalStrength, secure) {
51 var imageName = "nm-no-connection";
54 imageName = "nm-adhoc";
55 } else if (signalStrength == 0) {
56 imageName = "nm-signal-00";
57 } else if (signalStrength <= 25) {
58 imageName = "nm-signal-25";
59 } else if (signalStrength <= 50) {
60 imageName = "nm-signal-50";
61 } else if (signalStrength <= 75) {
62 imageName = "nm-signal-75";
63 } else if (signalStrength <= 100) {
64 imageName = "nm-signal-100";
68 imageName += "-secure";
73 QMenuModel.AyatanaMenuModel {
75 busName: "com.lomiri.indicator.network"
76 actions: { "indicator": "/com/lomiri/indicator/network" }
77 menuObjectPath: "/com/lomiri/indicator/network/phone_wifi_settings"
81 id: accessPointComponent
84 objectName: "accessPoint_" + apName.text.toLowerCase().replace(/\s+/g, '_')
85 highlightColor: backgroundColor
86 enabled: menuData && menuData.sensitive || false
87 divider.colorFrom: dividerColor
88 divider.colorTo: backgroundColor
90 property QtObject menuData: null
91 property var lomiriMenuModel: menuModel
92 property var extendedData: menuData && menuData.ext || undefined
93 property var strengthAction: QMenuModel.AyatanaMenuAction {
94 model: lomiriMenuModel
96 name: getExtendedProperty(extendedData, "xAyatanaWifiApStrengthAction", "")
98 readonly property bool secure: getExtendedProperty(extendedData, "xAyatanaWifiApIsSecure", false)
99 readonly property bool adHoc: getExtendedProperty(extendedData, "xAyatanaWifiApIsAdhoc", false)
100 readonly property bool isConnected: menuData && menuData.actionState
101 readonly property bool isEnterprise: getExtendedProperty(extendedData, "xAyatanaWifiApIsEnterprise", false)
102 readonly property int signalStrength: strengthAction.valid ? strengthAction.state : 0
103 property int menuIndex: -1
105 function loadAttributes() {
106 if (!lomiriMenuModel || menuIndex == -1) return;
107 lomiriMenuModel.loadExtendedAttributes(menuIndex, {'x-ayatana-wifi-ap-is-adhoc': 'bool',
108 'x-ayatana-wifi-ap-is-secure': 'bool',
109 'x-ayatana-wifi-ap-is-enterprise': 'bool',
110 'x-ayatana-wifi-ap-strength-action': 'string'});
117 verticalCenter: parent.verticalCenter
118 leftMargin: column.anchors.leftMargin == 0 ? staticMargin : 0
120 height: units.gu(2.5)
122 name: getAPIcon(accessPoint.adHoc, accessPoint.signalStrength, accessPoint.secure)
127 anchors.verticalCenter: parent.verticalCenter
128 anchors.left: apIcon.right
129 anchors.leftMargin: units.gu(2)
132 text: menuData && menuData.label || ""
133 font.weight: accessPoint.isConnected ? Font.Normal : Font.Light
139 text: i18n.tr("Connected")
140 font.weight: Font.Light
143 visible: accessPoint.isConnected
148 lomiriMenuModel.activate(menuIndex);
149 listview.positionViewAtBeginning();
159 topMargin: customMargin
160 leftMargin: wideMode ? parent.leftMargin : 0
161 rightMargin: wideMode ? parent.rightMargin : 0
166 Layout.fillWidth: true
167 Layout.fillHeight: false
168 anchors.leftMargin: column.anchors.leftMargin == 0 ? staticMargin : 0
169 font.weight: Font.Light
172 text: listview.count > 0 ? i18n.tr("Available Wi-Fi networks")
173 : i18n.tr("No available Wi-Fi networks")
178 objectName: "accessPointsListView"
179 Layout.fillWidth: true
180 Layout.fillHeight: true
185 readonly property bool isAccessPoint: model.type === "lomiri.widgets.systemsettings.tablet.accesspoint"
186 readonly property bool isConnected: item && item.menuData && item.menuData.actionState
187 readonly property bool isEnterprise: item && item.isEnterprise
189 height: !!sourceComponent ? (isConnected ? units.gu(9) : units.gu(7)) : 0
190 anchors.left: parent.left
191 anchors.right: parent.right
195 if (isAccessPoint && !isEnterprise) {
196 return accessPointComponent;
202 item.menuData = Qt.binding(function() { return model; });
203 item.menuIndex = Qt.binding(function() { return index; });
204 item.loadAttributes();
212 LocalComponents.StackButton {
213 text: (root.connected || listview.count === 0) ? i18n.tr("Next") : i18n.tr("Skip")