Integrated file selection dialogue with the main code. Improved the
[openvpnui.git] / qml / filebrowse / pages / ConsolePage.qml
1 import QtQuick 2.0
2 import Sailfish.Silica 1.0
3 import harbour.file.browser.FileInfo 1.0
4 import "../components"
5
6 Page {
7     id: page
8     allowedOrientations: Orientation.All
9     property string title: ""
10     property string command: ""
11     property variant arguments // this must be set to a string list, e.g. [ "arg1", "arg2" ]
12     property string initialText: qsTr("Installing...")
13     property string successText: qsTr("Successful")
14     property string infoText: ""
15     property color consoleColor: Theme.secondaryColor
16
17     // execute command when page activates
18     onStatusChanged: {
19         if (status === PageStatus.Activating) {
20             fileInfo.executeCommand(page.command, page.arguments);
21         }
22     }
23
24     FileInfo {
25         id: fileInfo
26
27         // called when command exits
28         onProcessExited: {
29             busyIndicator.running = false;
30             if (exitCode == 0) {
31                 statusLabel.text = page.successText;
32                 infoLabel.text = page.infoText;
33             } else {
34                 statusLabel.text = qsTr("Failed! Error code: %1").arg(exitCode);
35             }
36         }
37     }
38
39     SilicaFlickable {
40         id: flickable
41         anchors.fill: parent
42         contentHeight: column.height
43         VerticalScrollDecorator { flickable: flickable }
44
45         Column {
46             id: column
47             width: parent.width
48
49             PageHeader { title: page.title }
50
51             BusyIndicator {
52                 id: busyIndicator
53                 anchors.horizontalCenter: parent.horizontalCenter
54                 running: true
55                 size: BusyIndicatorSize.Small
56             }
57             Label {
58                 id: statusLabel
59                 anchors.horizontalCenter: parent.horizontalCenter
60                 text: page.initialText
61                 color: Theme.highlightColor
62             }
63             Label {
64                 id: infoLabel
65                 visible: text !== ""
66                 text: ""
67                 anchors.left: parent.left
68                 anchors.right: parent.right
69                 anchors.leftMargin: Theme.paddingLarge
70                 anchors.rightMargin: Theme.paddingLarge
71                 wrapMode: Text.Wrap
72                 font.pixelSize: Theme.fontSizeTiny
73                 horizontalAlignment: Text.AlignHCenter
74                 color: Theme.secondaryColor
75             }
76
77             Spacer { height: 40 }
78
79             // command line text
80             Label {
81                 width: parent.width
82                 text: "$ "+page.command+" "+page.arguments.join(" ")
83                 wrapMode: Text.WrapAnywhere
84                 font.pixelSize: Theme.fontSizeTiny
85                 font.family: "Monospace"
86                 color: Theme.secondaryColor
87             }
88
89             // command output
90             Label {
91                 width: parent.width
92                 text: fileInfo.processOutput
93                 wrapMode: Text.WrapAnywhere
94                 font.pixelSize: Theme.fontSizeTiny
95                 font.family: "Monospace"
96                 color: page.consoleColor
97             }
98         }
99     }
100 }
101
102