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 ".." as LocalComponents
24import "../../Components"
28 objectName: "wifiPage"
30 title: i18n.tr("Connect to Wi‑Fi")
31 forwardButtonSourceComponent: forwardButton
33 readonly property bool connected: Connectivity.online
34 skip: connected && !Connectivity.limitedBandwidth
37 if (connected && !Connectivity.limitedBandwidth && wifiPage.visible) {
42 function getExtendedProperty(object, propertyName, defaultValue) {
43 if (object && object.hasOwnProperty(propertyName)) {
44 return object[propertyName];
49 function getAPIcon(adHoc, signalStrength, secure) {
50 var imageName = "nm-no-connection";
53 imageName = "nm-adhoc";
54 } else if (signalStrength == 0) {
55 imageName = "nm-signal-00";
56 } else if (signalStrength <= 25) {
57 imageName = "nm-signal-25";
58 } else if (signalStrength <= 50) {
59 imageName = "nm-signal-50";
60 } else if (signalStrength <= 75) {
61 imageName = "nm-signal-75";
62 } else if (signalStrength <= 100) {
63 imageName = "nm-signal-100";
67 imageName += "-secure";
72 QMenuModel.AyatanaMenuModel {
74 busName: "com.lomiri.indicator.network"
75 actions: { "indicator": "/com/lomiri/indicator/network" }
76 menuObjectPath: "/com/lomiri/indicator/network/phone_wifi_settings"
80 id: accessPointComponent
83 objectName: "accessPoint_" + apName.text.toLowerCase().replace(/\s+/g, '_')
84 highlightColor: backgroundColor
85 enabled: menuData && menuData.sensitive || false
86 divider.colorFrom: dividerColor
87 divider.colorTo: backgroundColor
89 property QtObject menuData: null
90 property var lomiriMenuModel: menuModel
91 property var extendedData: menuData && menuData.ext || undefined
92 property var strengthAction: QMenuModel.AyatanaMenuAction {
93 model: lomiriMenuModel
95 name: getExtendedProperty(extendedData, "xAyatanaWifiApStrengthAction", "")
97 readonly property bool secure: getExtendedProperty(extendedData, "xAyatanaWifiApIsSecure", false)
98 readonly property bool adHoc: getExtendedProperty(extendedData, "xAyatanaWifiApIsAdhoc", false)
99 readonly property bool isConnected: menuData && menuData.actionState
100 readonly property bool isEnterprise: getExtendedProperty(extendedData, "xAyatanaWifiApIsEnterprise", false)
101 readonly property int signalStrength: strengthAction.valid ? strengthAction.state : 0
102 property int menuIndex: -1
104 function loadAttributes() {
105 if (!lomiriMenuModel || menuIndex == -1) return;
106 lomiriMenuModel.loadExtendedAttributes(menuIndex, {'x-ayatana-wifi-ap-is-adhoc': 'bool',
107 'x-ayatana-wifi-ap-is-secure': 'bool',
108 'x-ayatana-wifi-ap-is-enterprise': 'bool',
109 'x-ayatana-wifi-ap-strength-action': 'string'});
116 verticalCenter: parent.verticalCenter
117 leftMargin: column.anchors.leftMargin == 0 ? staticMargin : 0
119 height: units.gu(2.5)
121 name: getAPIcon(accessPoint.adHoc, accessPoint.signalStrength, accessPoint.secure)
126 anchors.verticalCenter: parent.verticalCenter
127 anchors.left: apIcon.right
128 anchors.leftMargin: units.gu(2)
131 text: menuData && menuData.label || ""
132 font.weight: accessPoint.isConnected ? Font.Normal : Font.Light
138 text: i18n.tr("Connected")
139 font.weight: Font.Light
142 visible: accessPoint.isConnected
147 lomiriMenuModel.activate(menuIndex);
148 listview.positionViewAtBeginning();
158 topMargin: customMargin
159 leftMargin: wideMode ? parent.leftMargin : 0
160 rightMargin: wideMode ? parent.rightMargin : 0
165 Layout.fillWidth: true
166 Layout.fillHeight: false
167 anchors.leftMargin: column.anchors.leftMargin == 0 ? staticMargin : 0
168 font.weight: Font.Light
171 text: listview.count > 0 ? i18n.tr("Available Wi-Fi networks")
172 : i18n.tr("No available Wi-Fi networks")
177 objectName: "accessPointsListView"
178 Layout.fillWidth: true
179 Layout.fillHeight: true
184 readonly property bool isAccessPoint: model.type === "lomiri.widgets.systemsettings.tablet.accesspoint"
185 readonly property bool isConnected: item && item.menuData && item.menuData.actionState
186 readonly property bool isEnterprise: item && item.isEnterprise
188 height: !!sourceComponent ? (isConnected ? units.gu(9) : units.gu(7)) : 0
189 anchors.left: parent.left
190 anchors.right: parent.right
194 if (isAccessPoint && !isEnterprise) {
195 return accessPointComponent;
201 item.menuData = Qt.binding(function() { return model; });
202 item.menuIndex = Qt.binding(function() { return index; });
203 item.loadAttributes();
211 LocalComponents.StackButton {
212 text: (root.connected || listview.count === 0) ? i18n.tr("Next") : i18n.tr("Skip")