~ubuntu-branches/ubuntu/vivid/qtcreator-plugin-ubuntu/vivid

« back to all changes in this revision

Viewing changes to share/qtcreator/ubuntu/qml/DevicesPage/DevicePage.qml

  • Committer: Package Import Robot
  • Author(s): Ubuntu daily release, Benjamin Zeller
  • Date: 2015-01-30 06:05:59 UTC
  • mfrom: (1.1.81)
  • Revision ID: package-import@ubuntu.com-20150130060559-1kirdtmm6bl6eb26
Tags: 3.1.1+15.04.20150130-0ubuntu1
[ Benjamin Zeller ]
Refactoring of the publish Tab

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
import QtQuick 2.0
 
2
import QtQuick.Layouts 1.0
 
3
import QtQuick.Controls 1.0 as Controls
 
4
 
 
5
import Ubuntu.Components 1.0
 
6
import Ubuntu.Components.ListItems 1.0 as ListItem
 
7
import Ubuntu.DevicesModel 0.1
 
8
import Ubuntu.Components.Popups 1.0
 
9
 
 
10
import "../Components"
 
11
 
 
12
Page {
 
13
    id: devicePage
 
14
    flickable: null
 
15
 
 
16
    Item {
 
17
        anchors.fill: parent
 
18
        anchors.topMargin: units.gu(2)
 
19
        anchors.bottomMargin: units.gu(2)
 
20
        anchors.leftMargin: units.gu(2)
 
21
        anchors.rightMargin: units.gu(4)
 
22
        visible: devicesModel.busy
 
23
        RowLayout {
 
24
            //anchors.centerIn: parent
 
25
            id: busyIndicator
 
26
            anchors.left: parent.left
 
27
            anchors.top:  parent.top
 
28
            anchors.right: parent.right
 
29
 
 
30
            spacing: units.gu(1)
 
31
            height: childrenRect.height * 2
 
32
 
 
33
            ActivityIndicator{
 
34
                anchors.verticalCenter: parent.verticalCenter
 
35
                running: devicesModel.busy
 
36
            }
 
37
            Label {
 
38
                Layout.fillWidth: true
 
39
                anchors.verticalCenter: parent.verticalCenter
 
40
                text: i18n.tr("There is currently a process running in the background, please check the logs for details")
 
41
                fontSize: "large"
 
42
            }
 
43
            Button {
 
44
                visible: devicesModel.cancellable
 
45
                anchors.verticalCenter: parent.verticalCenter
 
46
                color: UbuntuColors.warmGrey
 
47
                text: "Cancel"
 
48
                onClicked: devicesModel.cancel()
 
49
            }
 
50
        }
 
51
        Controls.TextArea {
 
52
            id: logArea
 
53
            anchors.left: parent.left
 
54
            anchors.top:  busyIndicator.bottom
 
55
            anchors.right: parent.right
 
56
            anchors.bottom: parent.bottom
 
57
 
 
58
            readOnly: true
 
59
            textFormat: TextEdit.AutoText
 
60
            Component.onCompleted: {
 
61
                deviceMode.appendText.connect(appendToLog);
 
62
            }
 
63
 
 
64
            function appendToLog (txt) {
 
65
                append(txt);
 
66
            }
 
67
 
 
68
            Connections{
 
69
                target: devicesModel
 
70
                onBusyChanged: {
 
71
                    if(!devicesModel.busy)
 
72
                        logArea.text = ""
 
73
                }
 
74
            }
 
75
        }
 
76
    }
 
77
 
 
78
    Controls.SplitView {
 
79
        orientation: Qt.Horizontal
 
80
        anchors.fill: parent
 
81
        visible: !devicesModel.busy
 
82
        Controls.SplitView {
 
83
            orientation: Qt.Vertical
 
84
            width: 200
 
85
            Layout.minimumWidth: 200
 
86
            Layout.maximumWidth: 400
 
87
 
 
88
            Controls.ScrollView {
 
89
                Layout.fillHeight: true
 
90
                UbuntuListView {
 
91
                    id: devicesList
 
92
                    objectName: "devicesList"
 
93
                    model: devicesModel
 
94
                    currentIndex: 0
 
95
                    delegate: ListItem.Standard {
 
96
                        id: delegate
 
97
                        text: display
 
98
                        selected: devicesList.currentIndex == index
 
99
                        onClicked: devicesList.currentIndex = index
 
100
                        property alias editor: editor
 
101
 
 
102
                        TextField{
 
103
                            id: editor
 
104
                            anchors.fill: parent
 
105
                            visible: false
 
106
 
 
107
                            property bool changed: false
 
108
                            Keys.onEscapePressed: {
 
109
                                close();
 
110
                            }
 
111
                            Keys.onTabPressed: {
 
112
                                commit();
 
113
                                devicesList.incrementCurrentIndex();
 
114
                            }
 
115
                            Keys.onReturnPressed: {
 
116
                                commit();
 
117
                            }
 
118
 
 
119
                            onActiveFocusChanged: {
 
120
                                if(!activeFocus)
 
121
                                    close();
 
122
                            }
 
123
 
 
124
                            onTextChanged: {
 
125
                                changed = true;
 
126
                            }
 
127
 
 
128
                            function open (){
 
129
                                visible = true;
 
130
                                forceActiveFocus();
 
131
                                text = display;
 
132
                                changed = false;
 
133
                            }
 
134
 
 
135
                            function close (){
 
136
                                changed = false;
 
137
                                visible = false;
 
138
                            }
 
139
 
 
140
                            function commit (){
 
141
                                if(changed)
 
142
                                    edit = text;
 
143
                                close();
 
144
                            }
 
145
 
 
146
                            InverseMouseArea {
 
147
                                enabled: parent.visible
 
148
                                anchors.fill: parent
 
149
                                topmostItem: true
 
150
                                acceptedButtons: Qt.AllButtons
 
151
                                onPressed: parent.close()
 
152
                            }
 
153
                        }
 
154
 
 
155
                        Connections{
 
156
                            target: delegate.__mouseArea
 
157
                            onDoubleClicked: {
 
158
                                editor.open();
 
159
                            }
 
160
                        }
 
161
 
 
162
                    }
 
163
                    onCurrentIndexChanged: deviceMode.deviceSelected(currentIndex)
 
164
                }
 
165
            }
 
166
            Controls.ToolBar {
 
167
                Layout.fillWidth: true
 
168
                Layout.minimumHeight: units.gu(5)
 
169
                Layout.maximumHeight: units.gu(5)
 
170
                Row{
 
171
                    anchors.fill: parent
 
172
                    spacing: units.gu(2)
 
173
                    Controls.ToolButton {
 
174
                        text: i18n.tr("Refresh devices")
 
175
                        tooltip: text
 
176
                        iconSource: "qrc:/ubuntu/images/reload.svg"
 
177
                        onClicked: devicesModel.refresh()
 
178
                    }
 
179
                    Controls.ToolButton {
 
180
                        text: i18n.tr("Add Emulator")
 
181
                        tooltip: text
 
182
                        iconSource: "qrc:/ubuntu/images/list-add.svg"
 
183
                        onClicked: {
 
184
                            if(!devicesModel.emulatorInstalled){
 
185
                                PopupUtils.open(resourceRoot+"/EmulatorNotInstalled.qml",devicePage);
 
186
                                return;
 
187
                            }
 
188
                            PopupUtils.open(resourceRoot+"/NewEmulatorDialog.qml",devicePage);
 
189
                        }
 
190
                    }
 
191
 
 
192
                    Connections{
 
193
                        target: deviceMode
 
194
                        onOpenAddEmulatorDialog: PopupUtils.open(resourceRoot+"/NewEmulatorDialog.qml",devicePage);
 
195
                    }
 
196
                }
 
197
            }
 
198
        }
 
199
 
 
200
        Item {
 
201
            id: centerItem
 
202
            Layout.minimumWidth: 400
 
203
            Layout.fillWidth: true
 
204
 
 
205
            Repeater {
 
206
                property int currentIndex: devicesList.currentIndex
 
207
                model: devicesModel
 
208
 
 
209
                Rectangle {
 
210
                    id: deviceItemView
 
211
                    property bool deviceConnected: connectionState === DeviceConnectionState.ReadyToUse || connectionState === DeviceConnectionState.Connected
 
212
                    property bool deviceBusy: (detectionState != DeviceDetectionState.Done && detectionState != DeviceDetectionState.NotStarted)
 
213
                    property bool deviceBooting: detectionState === DeviceDetectionState.Booting || detectionState === DeviceDetectionState.WaitForEmulator
 
214
                    property bool detectionError: detectionState === DeviceDetectionState.Error
 
215
                    anchors.fill: parent
 
216
 
 
217
                    color: Qt.rgba(0.0, 0.0, 0.0, 0.01)
 
218
                    visible: index == devicesList.currentIndex
 
219
 
 
220
 
 
221
                    Controls.ToolBar {
 
222
                        id: emulatorToolBar
 
223
                        height: visible ? units.gu(5) : 0
 
224
                        anchors.left: parent.left
 
225
                        anchors.right: parent.right
 
226
                        anchors.top: parent.top
 
227
                        Row{
 
228
                            anchors.fill: parent
 
229
                            spacing: units.gu(2)
 
230
                            Controls.ToolButton {
 
231
                                text: i18n.tr("Run Emulator")
 
232
                                tooltip: text
 
233
                                iconSource: "qrc:/projectexplorer/images/run.png"
 
234
                                onClicked: devicesModel.startEmulator(emulatorImageName)
 
235
                                visible: connectionState === DeviceConnectionState.Disconnected && machineType === DeviceMachineType.Emulator
 
236
                            }
 
237
                            Controls.ToolButton {
 
238
                                text: i18n.tr("Stop Emulator")
 
239
                                tooltip: text
 
240
                                iconSource: "qrc:/projectexplorer/images/stop.png"
 
241
                                onClicked: devicesModel.stopEmulator(emulatorImageName)
 
242
                                visible: connectionState !== DeviceConnectionState.Disconnected && machineType === DeviceMachineType.Emulator
 
243
                            }
 
244
                            Controls.ToolButton {
 
245
                                text: i18n.tr("Delete")
 
246
                                tooltip: text
 
247
                                iconSource: "qrc:/core/images/clear.png"
 
248
                                onClicked: {
 
249
                                    if(machineType === DeviceMachineType.Emulator)
 
250
                                        PopupUtils.open(resourceRoot+"/DeleteDeviceDialog.qml",devicePage, {"emulatorImageName": emulatorImageName,"deviceId": -1 });
 
251
                                    else
 
252
                                        PopupUtils.open(resourceRoot+"/DeleteDeviceDialog.qml",devicePage, {"deviceId": deviceId});
 
253
                                }
 
254
                                enabled: connectionState === DeviceConnectionState.Disconnected
 
255
                            }
 
256
                        }
 
257
                    }
 
258
 
 
259
                    ScrollableView {
 
260
                        id: deviceView
 
261
                        anchors.left: parent.left
 
262
                        anchors.right: parent.right
 
263
                        anchors.top: emulatorToolBar.bottom
 
264
                        anchors.bottom: parent.bottom
 
265
                        clip: true
 
266
 
 
267
                        ListItem.Empty {
 
268
                            id: errorContainer
 
269
                            divider.visible: false
 
270
                            visible: detectionError
 
271
                            height: errorText.contentHeight + units.gu(4)
 
272
                            RowLayout {
 
273
                                anchors.fill: parent
 
274
                                anchors.rightMargin: units.gu(4)
 
275
                                Image {
 
276
                                    id: errorIcon
 
277
                                    source: "qrc:/ubuntu/images/security-alert.svg"
 
278
                                    fillMode: Image.PreserveAspectFit
 
279
                                    Layout.maximumHeight: errorContainer.height
 
280
                                }
 
281
                                Label {
 
282
                                    id: errorText
 
283
                                    text: i18n.tr("There was a error in the device detection, check the log for details.")
 
284
                                    fontSize: "large"
 
285
                                    wrapMode: Text.Wrap
 
286
                                    Layout.fillWidth: true
 
287
                                }
 
288
                                Button {
 
289
                                    id: deviceRedetectButton
 
290
                                    text: "Redetect"
 
291
                                    onClicked: devicesModel.triggerRedetect(deviceId)
 
292
                                }
 
293
                            }
 
294
                        }
 
295
 
 
296
                        ListItem.Empty {
 
297
                            divider.visible: false
 
298
                            visible: deviceItemView.deviceBooting
 
299
                            RowLayout {
 
300
                                anchors.fill: parent
 
301
                                anchors.leftMargin: units.gu(2)
 
302
                                anchors.rightMargin: units.gu(4)
 
303
                                ActivityIndicator {
 
304
                                    running: deviceItemView.deviceBooting
 
305
                                    height:parent.height - units.gu(2)
 
306
                                    width: height
 
307
                                }
 
308
                                Label {
 
309
                                    text: i18n.tr("The device is currently booting, if this text is still shown after the device has booted, press the refresh button.")
 
310
                                    fontSize: "large"
 
311
                                    wrapMode: Text.Wrap
 
312
                                    Layout.fillWidth: true
 
313
                                }
 
314
                                Button {
 
315
                                    text: "Redetect"
 
316
                                    onClicked: devicesModel.triggerRedetect(deviceId)
 
317
                                }
 
318
                            }
 
319
                        }
 
320
 
 
321
                        SectionItem {
 
322
                            title: deviceItemView.deviceConnected ? "Device Status: "+detectionStateString : "Device Status: Disconnected"
 
323
                            expanded: true
 
324
 
 
325
                            Column {
 
326
                                anchors.left: parent.left
 
327
                                anchors.right: parent.right
 
328
 
 
329
                                ListItem.SingleValue {
 
330
                                    visible: deviceItemView.deviceConnected || machineType !== DeviceMachineType.Emulator
 
331
                                    text:i18n.tr("Serial ID")
 
332
                                    value: serial
 
333
                                }
 
334
                                ListItem.SingleValue {
 
335
                                    text: i18n.tr("Ubuntu version")
 
336
                                    value: emuUbuntuVersion
 
337
                                    visible: machineType === DeviceMachineType.Emulator
 
338
                                }
 
339
                                ListItem.SingleValue {
 
340
                                    text: i18n.tr("Device version")
 
341
                                    value: emuDeviceVersion
 
342
                                    visible: machineType === DeviceMachineType.Emulator
 
343
                                }
 
344
                                ListItem.SingleValue {
 
345
                                    text: i18n.tr("Image version")
 
346
                                    value: emuImageVersion
 
347
                                    visible: machineType === DeviceMachineType.Emulator
 
348
                                }
 
349
                                ListItem.Standard {
 
350
                                    //show this listitem only when device is not connected
 
351
                                    visible: machineType === DeviceMachineType.Emulator && !deviceItemView.deviceConnected
 
352
                                    text: "Scale"
 
353
                                    control: Controls.ComboBox {
 
354
                                        id: emulatorScaleComboBox
 
355
                                        model: ["1.0", "0.9", "0.8", "0.7", "0.6","0.5", "0.4", "0.3", "0.2","0.1"]
 
356
                                        currentIndex: {
 
357
                                            var idx = find(emulatorScaleFactor);
 
358
                                            return idx >= 0 ? idx : 0;
 
359
                                        }
 
360
                                        onActivated: {
 
361
                                            emulatorScaleFactor = textAt(index);
 
362
                                        }
 
363
                                    }
 
364
                                }
 
365
 
 
366
                                ListItem.Standard {
 
367
                                    //show this listitem only when device is not connected
 
368
                                    visible: machineType === DeviceMachineType.Emulator && !deviceItemView.deviceConnected
 
369
                                    text: "Memory"
 
370
                                    control: Controls.ComboBox {
 
371
                                        id: emulatorMemoryComboBox
 
372
                                        model: ["512", "768", "1024"]
 
373
 
 
374
                                        currentIndex: {
 
375
                                            var idx = find(emulatorMemorySetting);
 
376
                                            return idx >= 0 ? idx : 0;
 
377
                                        }
 
378
                                        onActivated: {
 
379
                                            emulatorMemorySetting = textAt(index);
 
380
                                        }
 
381
                                    }
 
382
                                }
 
383
                                ListItem.SingleValue {
 
384
                                    text:i18n.tr("Device")
 
385
                                    value: deviceInfo
 
386
                                    visible: deviceItemView.deviceConnected
 
387
                                }
 
388
                                ListItem.SingleValue {
 
389
                                    text:i18n.tr("Model")
 
390
                                    value: modelInfo
 
391
                                    visible: deviceItemView.deviceConnected
 
392
                                }
 
393
                                ListItem.SingleValue {
 
394
                                    text:i18n.tr("Product")
 
395
                                    value: productInfo
 
396
                                    visible: deviceItemView.deviceConnected
 
397
                                }
 
398
 
 
399
                                FeatureStateItem {
 
400
                                    text: "Has network connection"
 
401
                                    input: hasNetworkConnection
 
402
                                    inputRole: "hasNetworkConnection"
 
403
                                    checkable: hasNetworkConnection == FeatureState.NotAvailable && !deviceItemView.deviceBusy && !deviceItemView.detectionError
 
404
                                    visible: deviceItemView.deviceConnected
 
405
                                }
 
406
                                FeatureStateItem {
 
407
                                    text: "Has developer mode enabled"
 
408
                                    input: developerModeEnabled
 
409
                                    inputRole: "developerModeEnabled"
 
410
                                    checkable: !deviceItemView.deviceBusy && !deviceItemView.detectionError
 
411
                                    visible: deviceItemView.deviceConnected
 
412
                                }
 
413
                                /*
 
414
                                FeatureStateItem {
 
415
                                    text: "Has writeable image"
 
416
                                    input: hasWriteableImage
 
417
                                    inputRole: "hasWriteableImage"
 
418
                                    checkable: false
 
419
                                    visible: deviceItemView.deviceConnected
 
420
                                }
 
421
                                */
 
422
                            }
 
423
                        }
 
424
 
 
425
                        SectionItem {
 
426
                            title: "Kits"
 
427
                            expanded: true
 
428
 
 
429
                            Column {
 
430
                                anchors.left: parent.left
 
431
                                anchors.right: parent.right
 
432
 
 
433
                                Repeater {
 
434
                                    model: kits
 
435
                                    delegate: ListItem.Standard {
 
436
                                        text: modelData.displayName
 
437
                                        Layout.fillWidth: true
 
438
                                        control: Button{
 
439
                                            text: "Remove"
 
440
                                            enabled: !deviceItemView.deviceBusy
 
441
                                            onClicked: devicesModel.triggerKitRemove(deviceId,modelData.id)
 
442
                                        }
 
443
                                    }
 
444
                                }
 
445
 
 
446
                                Item {
 
447
                                    clip: true
 
448
                                    visible: kits.length === 0
 
449
                                    height: label.contentHeight + units.gu(15)
 
450
                                    width: parent.width
 
451
                                    Label {
 
452
                                        id:label
 
453
                                        anchors.centerIn: parent
 
454
                                        anchors.bottom: button.top
 
455
                                        fontSize: "large"
 
456
                                        text: "There is currently no Kit defined for your device.\n In order to use the device in your Projects,\n you can either add a existing Kit "
 
457
                                              +"\nor let Qt Creator autocreate one for you."
 
458
                                    }
 
459
                                    Button {
 
460
                                        id: button
 
461
                                        anchors.left: label.left
 
462
                                        anchors.right: label.right
 
463
                                        anchors.top: label.bottom
 
464
                                        anchors.bottom: parent.bottom
 
465
                                        anchors.topMargin: units.gu(2)
 
466
                                        text: "Autocreate"
 
467
                                        enabled: !deviceItemView.deviceBusy
 
468
                                        onClicked: devicesModel.triggerKitAutocreate(deviceId)
 
469
                                    }
 
470
                                }
 
471
 
 
472
 
 
473
                            }
 
474
                        }
 
475
 
 
476
                        SectionItem {
 
477
                            title: "Control"
 
478
                            visible: deviceItemView.deviceConnected
 
479
 
 
480
                            Column {
 
481
                                anchors.left: parent.left
 
482
                                anchors.right: parent.right
 
483
 
 
484
                                ListItem.Standard {
 
485
                                    text:"Clone time config from Host to Device"
 
486
                                    control: Button{
 
487
                                        text: "Execute"
 
488
                                        enabled: !deviceItemView.deviceBusy && !deviceItemView.detectionError
 
489
                                        onClicked: devicesModel.triggerCloneTimeConfig(deviceId)
 
490
                                    }
 
491
                                }
 
492
                                ListItem.Standard {
 
493
                                    text:"Enable port forwarding"
 
494
                                    control: Button{
 
495
                                        text: "Execute"
 
496
                                        enabled: !deviceItemView.deviceBusy && !deviceItemView.detectionError
 
497
                                        onClicked: devicesModel.triggerPortForwarding(deviceId)
 
498
                                    }
 
499
                                }
 
500
                                ListItem.Standard {
 
501
                                    text:"Setup public key authentication"
 
502
                                    control: Button{
 
503
                                        text: "Execute"
 
504
                                        enabled: !deviceItemView.deviceBusy && !deviceItemView.detectionError
 
505
                                        onClicked: devicesModel.triggerSSHSetup(deviceId)
 
506
                                    }
 
507
                                }
 
508
                                ListItem.Standard {
 
509
                                    text:"Open SSH connection to the device"
 
510
                                    control: Button{
 
511
                                        text: "Execute"
 
512
                                        enabled: !deviceItemView.deviceBusy && !deviceItemView.detectionError
 
513
                                        onClicked: devicesModel.triggerSSHConnection(deviceId)
 
514
                                    }
 
515
                                }
 
516
                                ListItem.Standard {
 
517
                                    text:"Restart"
 
518
                                    control: Button{
 
519
                                        text: "Execute"
 
520
                                        enabled: !deviceItemView.deviceBusy && !deviceItemView.detectionError
 
521
                                        onClicked: devicesModel.triggerReboot(deviceId)
 
522
                                    }
 
523
                                }
 
524
                                ListItem.Standard {
 
525
                                    text:"Restart to bootloader"
 
526
                                    control: Button{
 
527
                                        text: "Execute"
 
528
                                        enabled: !deviceItemView.deviceBusy && !deviceItemView.detectionError
 
529
                                        onClicked: devicesModel.triggerRebootBootloader(deviceId)
 
530
                                    }
 
531
                                }
 
532
                                ListItem.Standard {
 
533
                                    text:"Restart to recovery"
 
534
                                    control: Button{
 
535
                                        text: "Execute"
 
536
                                        enabled: !deviceItemView.deviceBusy && !deviceItemView.detectionError
 
537
                                        onClicked: devicesModel.triggerRebootRecovery(deviceId)
 
538
                                    }
 
539
                                }
 
540
                                ListItem.Standard {
 
541
                                    text:"Shut down"
 
542
                                    control: Button{
 
543
                                        text: "Execute"
 
544
                                        enabled: !deviceItemView.deviceBusy && !deviceItemView.detectionError
 
545
                                        onClicked: devicesModel.triggerShutdown(deviceId)
 
546
                                    }
 
547
                                }
 
548
                            }
 
549
                        }
 
550
 
 
551
                        SectionItem {
 
552
                            title: "Log"
 
553
                            Column {
 
554
                                anchors.left: parent.left
 
555
                                anchors.right: parent.right
 
556
                                TextArea {
 
557
                                    autoSize: true
 
558
                                    maximumLineCount: 0
 
559
                                    anchors.left: parent.left
 
560
                                    anchors.right: parent.right
 
561
                                    height: units.gu(60)
 
562
                                    highlighted: true
 
563
 
 
564
                                    readOnly: true
 
565
                                    text: deviceLog
 
566
                                    textFormat: TextEdit.AutoText
 
567
                                }
 
568
                            }
 
569
                        }
 
570
                    }
 
571
                }
 
572
            }
 
573
        }
 
574
    }
 
575
}
 
576