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