21
21
import SystemSettings 1.0
22
22
import Ubuntu.Components 0.1
23
23
import Ubuntu.Components.ListItems 0.1 as ListItem
24
import Ubuntu.Connectivity 1.0
24
25
import Ubuntu.SystemSettings.Cellular 1.0
26
import Ubuntu.Components.Popups 0.1
29
title: i18n.tr("Change hotspot setup")
31
property var hotspotManager: null
40
text: i18n.tr("Hotspot name")
45
text: hotspotManager.getHotspotName()
46
anchors.left: parent.left
47
anchors.right: parent.right
48
anchors.leftMargin: units.gu(2)
49
anchors.rightMargin: units.gu(2)
54
text: i18n.tr("Key (must be 8 characters or longer)")
59
text: hotspotManager.getHotspotPassword()
60
echoMode: passwordVisibleSwitch.checked ? TextInput.Normal : TextInput.Password
61
anchors.left: parent.left
62
anchors.right: parent.right
63
anchors.leftMargin: units.gu(2)
64
anchors.rightMargin: units.gu(2)
68
text: i18n.tr("Show key")
71
id: passwordVisibleSwitch
32
id: hotspotSetupDialog
34
/* Connectivity.hotspotStored changes as soon as the user has added a
35
hotspot, and we use this value when we choose between e.g. "Change" and
36
"Setup". We'd like the narrative to be consistent, so we stick with
37
what the stored value was at component completion.
39
property bool stored: false
40
Component.onCompleted: stored = Connectivity.hotspotStored;
42
objectName: "hotspotSetup"
43
anchorToKeyboard: true
45
function settingsValid() {
46
return ssidField.text != "" && passwordField.length >= 8;
50
i18n.tr("Change hotspot setup") : i18n.tr("Setup hotspot")
51
text: feedback.enabled ? feedback.text : "";
61
target: workingIndicator
101
script: ssidField.forceActiveFocus()
112
target: successIndicator
124
target: passwordLabel
128
target: passwordField
132
target: confirmButton
78
141
right: parent.right
84
Layout.fillWidth: true
85
text: i18n.tr("Cancel")
93
Layout.fillWidth: true
94
text: i18n.tr("Change")
95
enabled: ssidField.text != "" && passwordField.length >= 8
97
hotspotManager.setupHotspot(ssidField.text, passwordField.text)
146
property bool enabled: false
148
horizontalAlignment: Text.AlignHCenter
149
height: contentHeight
150
wrapMode: Text.WordWrap
156
text: i18n.tr("Hotspot name")
159
color: Theme.palette.selected.backgroundText
160
elide: Text.ElideRight
165
objectName: "ssidField"
166
text: Connectivity.hotspotSsid
167
inputMethodHints: Qt.ImhNoAutoUppercase | Qt.ImhNoPredictiveText
168
Component.onCompleted: forceActiveFocus()
174
text: i18n.tr("Key (must be 8 characters or longer)")
177
color: Theme.palette.selected.backgroundText
178
wrapMode: Text.WordWrap
184
objectName: "passwordField"
185
text: Connectivity.hotspotPassword
186
echoMode: passwordVisibleSwitch.checked ?
187
TextInput.Normal : TextInput.Password
188
inputMethodHints: Qt.ImhNoAutoUppercase | Qt.ImhNoPredictiveText
193
text: i18n.tr("Show key")
195
onClicked: passwordVisibleSwitch.trigger()
197
id: passwordVisibleSwitch
198
activeFocusOnPress: false
213
width: (parent.width / 2) - units.gu(1)
214
text: i18n.tr("Cancel")
215
activeFocusOnPress: false
216
onClicked: PopupUtils.close(hotspotSetupDialog)
221
objectName: "confirmButton"
222
width: (parent.width / 2) - units.gu(1)
223
text: hotspotSetupDialog.stored ? i18n.tr("Change") :
225
enabled: settingsValid()
226
activeFocusOnPress: false
228
if (hotspotSetupDialog.stored) {
229
changeAction.trigger()
231
enableAction.trigger();
237
anchors.centerIn: parent
238
height: parent.height - units.gu(1.5)
239
width: parent.height - units.gu(1.5)
247
anchors.centerIn: parent
250
height: parent.height - units.gu(1.5)
258
enabled: settingsValid()
260
hotspotSetupDialog.state = "STARTING";
262
function hotspotEnabledHandler (enabled) {
264
hotspotSetupDialog.state = "SUCCEEDED";
265
Connectivity.hotspotEnabledUpdated.disconnect(
266
hotspotEnabledHandler);
270
Connectivity.hotspotSsid = ssidField.text;
271
Connectivity.hotspotPassword = passwordField.text;
272
Connectivity.hotspotEnabledUpdated.connect(hotspotEnabledHandler);
273
Connectivity.hotspotEnabled = true;
279
enabled: settingsValid()
282
function hotspotEnabledHandler (enabled) {
284
hotspotSetupDialog.state = "SUCCEEDED";
285
Connectivity.hotspotEnabledUpdated.disconnect(
286
hotspotEnabledHandler);
290
function hotspotDisabledHandler (enabled) {
292
Connectivity.hotspotEnabledUpdated.connect(hotspotEnabledHandler);
293
Connectivity.hotspotEnabled = true;
294
Connectivity.hotspotEnabledUpdated.disconnect(
295
hotspotDisabledHandler);
299
Connectivity.hotspotSsid = ssidField.text;
300
Connectivity.hotspotPassword = passwordField.text;
302
if (Connectivity.hotspotEnabled) {
303
hotspotSetupDialog.state = "STARTING";
304
Connectivity.hotspotEnabledUpdated.connect(
305
hotspotDisabledHandler);
306
Connectivity.hotspotEnabled = false;
308
PopupUtils.close(hotspotSetupDialog);
313
/* Timer that shows a tick in the connect button once we have
314
successfully changed/started a hotspot. */
320
onTriggered: PopupUtils.close(hotspotSetupDialog)
327
if (hotspotSetupDialog.state === "STARTING") {
328
hotspotSetupDialog.state = "FAILED";
329
feedback.text = common.reasonToString(reason);