~osomon/ubuntu-system-settings/autopkgtest

« back to all changes in this revision

Viewing changes to plugins/bluetooth/PageComponent.qml

  • Committer: CI bot
  • Author(s): Mathieu Trudel-Lapierre
  • Date: 2014-08-01 17:09:43 UTC
  • mfrom: (806.1.27 ubuntu-system-settings)
  • Revision ID: ps-jenkins@lists.canonical.com-20140801170943-v2wcmrfuz1lfrn0q
Bluetooth UI redesign Fixes: 1272317, 1287293, 1336197
Approved by: Manuel de la Peña

Show diffs side-by-side

added added

removed removed

Lines of Context:
65
65
        }
66
66
    }
67
67
 
68
 
    function getDisplayName(connection, displayName) {
69
 
      if (connection == Device.Connecting)
70
 
        // TRANSLATORS: %1 is the display name of the device that is connecting
71
 
        return i18n.tr("%1 (Connecting…)").arg(displayName);
72
 
      else if (connection == Device.Disconnecting)
73
 
        // TRANSLATORS: %1 is the display name of the device that is disconnecting
74
 
        return i18n.tr("%1 (Disconnecting…)").arg(displayName);
75
 
      else
 
68
    function getDisplayName(type, displayName) {
 
69
        /* TODO: If the device requires a PIN, show ellipsis.
 
70
         * Right now we don't have a way to check this, just return the name
 
71
         */
76
72
        return displayName;
77
73
    }
78
74
 
 
75
    function getStatusString(connection) {
 
76
      switch (connection) {
 
77
      case Device.Connected:     return i18n.tr("Connected");
 
78
      case Device.Connecting:    return i18n.tr("Connecting…");
 
79
      case Device.Disconnecting: return i18n.tr("Disconnecting…");
 
80
      case Device.Disconnected:  return i18n.tr("Disconnected");
 
81
      default:                   return i18n.tr("Unknown");
 
82
      }
 
83
    }
 
84
 
79
85
    function getTypeString(type) {
80
86
        switch (type) {
81
87
        case Device.Computer:   return i18n.tr("Computer");
132
138
                    id: btSwitch
133
139
                    // Cannot use onCheckedChanged as this triggers a loop
134
140
                    onClicked: bluetoothActionGroup.enabled.activate()
 
141
                    checked: backend.powered
135
142
                }
136
143
                Component.onCompleted: clicked.connect(btSwitch.clicked)
137
144
            }
143
150
            }
144
151
 
145
152
            // Discoverability
146
 
            ListItem.Subtitled {
 
153
            ListItem.Standard {
147
154
                enabled: bluetoothActionGroup.enabled
 
155
                showDivider: false
148
156
 
149
157
                Rectangle {
150
158
                    color: "transparent"
151
159
                    anchors.fill: parent
152
160
                    anchors.topMargin: units.gu(1)
 
161
                    anchors.leftMargin: units.gu(2)
 
162
                    anchors.rightMargin: units.gu(2)
153
163
 
154
164
                    Label {
155
165
                        anchors {
180
190
                            right: parent.right
181
191
                            topMargin: units.gu(1)
182
192
                        }
183
 
                        visible: !backend.discoverable
184
 
                        running: !backend.discoverable
 
193
                        visible: backend.powered && !backend.discoverable
 
194
                        running: true
185
195
                    }
186
196
                }
187
197
            }
204
214
 
205
215
                model: backend.connectedDevices
206
216
                delegate: ListItem.Standard {
207
 
                    iconName: iconName
208
 
                    text: getDisplayName(connection, displayName)
 
217
                    iconSource: iconPath
 
218
                    iconFrame: false
 
219
                    text: getDisplayName(type, displayName)
 
220
                    control: ActivityIndicator {
 
221
                        visible: connection == Device.Connecting
 
222
                        running: true
 
223
                    }
209
224
                    onClicked: {
210
225
                        backend.setSelectedDevice(addressName);
211
226
                        pageStack.push(connectedDevicePage);
212
227
                    }
 
228
                    progression: true
213
229
                }
214
230
            }
215
231
 
217
233
 
218
234
            ListItem.Standard {
219
235
                id: disconnectedHeader
220
 
                text: connectedList.visible ? i18n.tr("Connect a different device:") : i18n.tr("Connect another device:")
 
236
                text: connectedList.visible ? i18n.tr("Connect another device:") : i18n.tr("Connect a device:")
221
237
                enabled: bluetoothActionGroup.enabled
222
238
                control: ActivityIndicator {
223
 
                    visible: backend.discovering
 
239
                    visible: backend.powered && backend.discovering
224
240
                    running: true
225
241
                }
226
242
            }
234
250
 
235
251
                model: backend.disconnectedDevices
236
252
                delegate: ListItem.Standard {
237
 
                    iconName: iconName
238
 
                    text: getDisplayName(connection, displayName)
 
253
                    iconSource: iconPath
 
254
                    iconFrame: false
 
255
                    text: getDisplayName(type, displayName)
 
256
                    enabled: backend.isSupportedType(type)
239
257
                    onClicked: {
240
 
                        backend.stopDiscovery();
241
 
                        backend.connectDevice(addressName);
 
258
                        backend.setSelectedDevice(addressName);
 
259
                        pageStack.push(connectedDevicePage);
242
260
                    }
 
261
                    progression: true
243
262
                }
244
263
            }
245
264
            ListItem.Standard {
246
265
                id: disconnectedNone
247
266
                text: i18n.tr("None detected")
248
267
                visible: !disconnectedList.visible
249
 
                enabled: !backend.discovering
 
268
                enabled: false
 
269
            }
 
270
 
 
271
            //  Devices that connect automatically
 
272
            ListItem.Standard {
 
273
                id: autoconnectHeader
 
274
                text: i18n.tr("Connect automatically when detected:")
 
275
                visible: autoconnectList.visible
 
276
                enabled: bluetoothActionGroup.enabled
 
277
            }
 
278
            ListView {
 
279
                id: autoconnectList
 
280
                width: parent.width
 
281
                height: autoconnectHeader.height * count
 
282
 
 
283
                visible: bluetoothActionGroup.enabled && (count > 0)
 
284
 
 
285
                model: backend.autoconnectDevices
 
286
                delegate: ListItem.Standard {
 
287
                    iconSource: iconPath
 
288
                    iconFrame: false
 
289
                    text: getDisplayName(type, displayName)
 
290
                    onClicked: {
 
291
                        backend.setSelectedDevice(addressName);
 
292
                        pageStack.push(connectedDevicePage);
 
293
                    }
 
294
                    progression: true
 
295
                }
250
296
            }
251
297
        }
252
298
    }
263
309
                text: i18n.tr("Name")
264
310
                value: backend.selectedDevice ? backend.selectedDevice.name : i18n.tr("None")
265
311
            }
 
312
            ListItem.Standard {
 
313
                Rectangle {
 
314
                    color: "transparent"
 
315
                    anchors.fill: parent
 
316
                    anchors.topMargin: units.gu(1)
 
317
                    anchors.leftMargin: units.gu(2)
 
318
                    anchors.rightMargin: units.gu(2)
 
319
 
 
320
                    Label {
 
321
                        anchors {
 
322
                            top: parent.top
 
323
                            left: parent.left
 
324
                            topMargin: units.gu(1)
 
325
                        }
 
326
                        height: units.gu(3)
 
327
                        text: i18n.tr("Type")
 
328
                    }
 
329
                    Image {
 
330
                        anchors {
 
331
                            right: deviceType.left
 
332
                            rightMargin: units.gu(1)
 
333
                        }
 
334
                        height: units.gu(4)
 
335
                        width: units.gu(4)
 
336
                        source: backend.selectedDevice ? backend.selectedDevice.iconName : ""
 
337
                    }
 
338
                    Label {
 
339
                        id: deviceType
 
340
                        anchors {
 
341
                            top: parent.top
 
342
                            right: parent.right
 
343
                            topMargin: units.gu(1)
 
344
                        }
 
345
                        height: units.gu(3)
 
346
                        text: getTypeString(backend.selectedDevice ? backend.selectedDevice.type : Device.OTHER)
 
347
                    }
 
348
                }
 
349
            }
266
350
            ListItem.SingleValue {
267
 
                text: i18n.tr("Type")
268
 
                value: getTypeString(backend.selectedDevice ? backend.selectedDevice.type : Device.OTHER)
 
351
                text: i18n.tr("Status")
 
352
                value: getStatusString(backend.selectedDevice ? backend.selectedDevice.connection : Device.Disconnected)
269
353
            }
270
354
            ListItem.SingleValue {
271
355
                text: i18n.tr("Signal Strength")
272
356
                value: getSignalString(backend.selectedDevice ? backend.selectedDevice.strength : Device.None)
273
357
            }
274
 
            ListItem.SingleControl {
275
 
                control: Button {
276
 
                    text: i18n.tr("Disconnect")
277
 
                    width: parent.width - units.gu(8)
278
 
                    onClicked: {
279
 
                        backend.disconnectDevice();
280
 
                        pageStack.pop();
281
 
                    }
 
358
            ListItem.Standard {
 
359
                id: trustedCheck
 
360
                text: i18n.tr("Connect automatically when detected:")
 
361
                control: CheckBox {
 
362
                    onClicked: {
 
363
                        if (backend.selectedDevice) {
 
364
                            backend.selectedDevice.trusted = !backend.selectedDevice.trusted
 
365
                        }
 
366
                    }
 
367
                    checked: backend.selectedDevice ? backend.selectedDevice.trusted : false
 
368
                }
 
369
                Component.onCompleted:
 
370
                    clicked.connect(trustedCheck.clicked)
 
371
            }
 
372
            ListItem.SingleControl {
 
373
                control: Button {
 
374
                    text: backend.selectedDevice && (backend.selectedDevice.connection == Device.Connected || backend.selectedDevice.connection == Device.Connecting) ? i18n.tr("Disconnect") : i18n.tr("Connect")
 
375
                    width: parent.width - units.gu(8)
 
376
                    onClicked: {
 
377
                        if (backend.selectedDevice
 
378
                            && (backend.selectedDevice.connection == Device.Connected
 
379
                                || backend.selectedDevice.connection == Device.Connecting)) {
 
380
                            backend.disconnectDevice();
 
381
                        } else {
 
382
                            backend.stopDiscovery()
 
383
                            backend.connectDevice(backend.selectedDevice.address);
 
384
                        }
 
385
                        pageStack.pop();
 
386
                    }
 
387
                    visible: backend.selectedDevice ? true : false
 
388
                }
 
389
            }
 
390
            ListItem.SingleControl {
 
391
                control: Button {
 
392
                    text: i18n.tr("Forget this device")
 
393
                    width: parent.width - units.gu(8)
 
394
                    onClicked: {
 
395
                        backend.removeDevice();
 
396
                        pageStack.pop();
 
397
                    }
 
398
                    enabled: backend.selectedDevice && backend.selectedDevice.path.length > 0 ? true : false
282
399
                }
283
400
            }
284
401
        }