Lomiri
Loading...
Searching...
No Matches
30-wifi.qml
1/*
2 * Copyright (C) 2013-2016 Canonical Ltd.
3 *
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.
7 *
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.
12 *
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/>.
15 */
16
17import QtQuick 2.12
18import QtQuick.Layouts 1.1
19import QMenuModel 1.0 as QMenuModel
20import Lomiri.Components 1.3
21import Wizard 0.1
22import Lomiri.Connectivity 1.0
23import Lomiri.SystemSettings.Update 1.0
24import ".." as LocalComponents
25import "../../Components"
26
27LocalComponents.Page {
28 id: wifiPage
29 objectName: "wifiPage"
30
31 title: i18n.tr("Connect to Wi‑Fi")
32 forwardButtonSourceComponent: forwardButton
33
34 readonly property bool connected: Connectivity.online
35 skip: connected && !Connectivity.limitedBandwidth
36
37 onConnectedChanged: {
38 if (connected && !Connectivity.limitedBandwidth && wifiPage.visible) {
39 pageStack.next()
40 }
41 }
42
43 function getExtendedProperty(object, propertyName, defaultValue) {
44 if (object && object.hasOwnProperty(propertyName)) {
45 return object[propertyName];
46 }
47 return defaultValue;
48 }
49
50 function getAPIcon(adHoc, signalStrength, secure) {
51 var imageName = "nm-no-connection";
52
53 if (adHoc) {
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";
65 }
66
67 if (secure) {
68 imageName += "-secure";
69 }
70 return imageName;
71 }
72
73 QMenuModel.AyatanaMenuModel {
74 id: menuModel
75 busName: "com.lomiri.indicator.network"
76 actions: { "indicator": "/com/lomiri/indicator/network" }
77 menuObjectPath: "/com/lomiri/indicator/network/phone_wifi_settings"
78 }
79
80 Component {
81 id: accessPointComponent
82 ListItem {
83 id: accessPoint
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
89
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
95 index: menuIndex
96 name: getExtendedProperty(extendedData, "xAyatanaWifiApStrengthAction", "")
97 }
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
104
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'});
111 }
112
113 Icon {
114 id: apIcon
115 anchors {
116 left: parent.left
117 verticalCenter: parent.verticalCenter
118 leftMargin: column.anchors.leftMargin == 0 ? staticMargin : 0
119 }
120 height: units.gu(2.5)
121 width: height
122 name: getAPIcon(accessPoint.adHoc, accessPoint.signalStrength, accessPoint.secure)
123 color: textColor
124 }
125
126 Column {
127 anchors.verticalCenter: parent.verticalCenter
128 anchors.left: apIcon.right
129 anchors.leftMargin: units.gu(2)
130 Label {
131 id: apName
132 text: menuData && menuData.label || ""
133 font.weight: accessPoint.isConnected ? Font.Normal : Font.Light
134 fontSize: "medium"
135 color: textColor
136 }
137 Label {
138 id: connectedLabel
139 text: i18n.tr("Connected")
140 font.weight: Font.Light
141 fontSize: "small"
142 color: okColor
143 visible: accessPoint.isConnected
144 }
145 }
146
147 onClicked: {
148 lomiriMenuModel.activate(menuIndex);
149 listview.positionViewAtBeginning();
150 }
151 }
152 }
153
154 ColumnLayout {
155 id: column
156 spacing: units.gu(2)
157 anchors {
158 fill: content
159 topMargin: customMargin
160 leftMargin: wideMode ? parent.leftMargin : 0
161 rightMargin: wideMode ? parent.rightMargin : 0
162 }
163
164 Label {
165 id: label
166 Layout.fillWidth: true
167 Layout.fillHeight: false
168 anchors.leftMargin: column.anchors.leftMargin == 0 ? staticMargin : 0
169 font.weight: Font.Light
170 color: textColor
171 wrapMode: Text.Wrap
172 text: listview.count > 0 ? i18n.tr("Available Wi-Fi networks")
173 : i18n.tr("No available Wi-Fi networks")
174 }
175
176 ListView {
177 id: listview
178 objectName: "accessPointsListView"
179 Layout.fillWidth: true
180 Layout.fillHeight: true
181 clip: true
182 model: menuModel
183
184 delegate: Loader {
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
188
189 height: !!sourceComponent ? (isConnected ? units.gu(9) : units.gu(7)) : 0
190 anchors.left: parent.left
191 anchors.right: parent.right
192
193 asynchronous: true
194 sourceComponent: {
195 if (isAccessPoint && !isEnterprise) {
196 return accessPointComponent;
197 }
198 return null;
199 }
200
201 onLoaded: {
202 item.menuData = Qt.binding(function() { return model; });
203 item.menuIndex = Qt.binding(function() { return index; });
204 item.loadAttributes();
205 }
206 }
207 }
208 }
209
210 Component {
211 id: forwardButton
212 LocalComponents.StackButton {
213 text: (root.connected || listview.count === 0) ? i18n.tr("Next") : i18n.tr("Skip")
214 onClicked: {
215 pageStack.next();
216 }
217 }
218 }
219}