Fixed log output window. Rearranted components to increase space for the
[openvpnui.git] / qml / pages / ConnectPage.qml
1 /*
2   Copyright (C) 2014 David Llewellyn-Jones
3   Contact: David Llewellyn-Jones <david@flypig.co.uk>
4   All rights reserved.
5
6   You may use this file under the terms of BSD license as follows:
7
8   Redistribution and use in source and binary forms, with or without
9   modification, are permitted provided that the following conditions are met:
10     * Redistributions of source code must retain the above copyright
11       notice, this list of conditions and the following disclaimer.
12     * Redistributions in binary form must reproduce the above copyright
13       notice, this list of conditions and the following disclaimer in the
14       documentation and/or other materials provided with the distribution.
15     * Neither the name of the Jolla Ltd nor the
16       names of its contributors may be used to endorse or promote products
17       derived from this software without specific prior written permission.
18
19   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
20   ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21   WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22   DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR
23   ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24   (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25   LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
26   ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28   SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29
30   Built using the standard template from Jolla
31   Copyright (C) 2013 Jolla Ltd.
32   Contact: Thomas Perl <thomas.perl@jollamobile.com>
33 */
34
35 import QtQuick 2.0
36 import Sailfish.Silica 1.0
37
38 Page {
39     id: connectPage
40
41     Connections {
42         target:VpnControl
43         onStatusChanged: {
44             updateStatus(status)
45         }
46     }
47
48     function updateStatus(status) {
49         switch (status) {
50         case 0:
51             statusText.text = "Disconnected"
52             busy.running = false
53             connect.enabled = true
54             disconnect.enabled = false
55             break
56         case 1:
57             statusText.text = "Initialising"
58             busy.running = true
59             connect.enabled = false
60             disconnect.enabled = true
61             break
62         case 2:
63             statusText.text = "Connecting"
64             busy.running = true
65             connect.enabled = false
66             disconnect.enabled = true
67             break
68         case 3:
69             statusText.text = "Connected"
70             busy.running = false
71             connect.enabled = false
72             disconnect.enabled = true
73             break
74         case 4:
75             statusText.text = "Disconnecting"
76             busy.running = true
77             connect.enabled = false
78             disconnect.enabled = false
79             break
80         default:
81             statusText.text = "Invalid"
82             busy.running = false
83             connect.enabled = true
84             disconnect.enabled = false
85             break
86         }
87     }
88
89     // To enable PullDownMenu, place our content in a SilicaFlickable
90     SilicaFlickable {
91         anchors.fill: parent
92
93         // PullDownMenu and PushUpMenu must be declared in SilicaFlickable, SilicaListView or SilicaGridView
94         PullDownMenu {
95             MenuItem {
96                 text: "Configure"
97                 onClicked: pageStack.push(Qt.resolvedUrl("ConfigurePage.qml"))
98             }
99         }
100
101         contentHeight: column.height + Theme.paddingLarge
102
103         // Why is this necessary?
104         contentWidth: parent.width
105
106         VerticalScrollDecorator {}
107         // Place our content in a Column.  The PageHeader is always placed at the top
108         // of the page, followed by our content.
109         Column {
110             id: column
111
112             width: parent.width
113             spacing: Theme.paddingLarge
114
115             PageHeader {
116                 title: "OpenVPN Control"
117             }
118             Row {
119                 spacing: Theme.paddingLarge
120                 anchors.horizontalCenter: parent.horizontalCenter
121                 Button {
122                     id: connect
123                     text: "Connect"
124                     enabled: true
125                     onClicked: {
126                         VpnControl.logAppend('\n')
127                         VpnControl.vpnConnect()
128                     }
129                 }
130                 Button {
131                     id : disconnect
132                     text: "Disconnect"
133                     enabled: true
134                     onClicked: VpnControl.vpnDisconnect();
135                 }
136             }
137
138             Label {
139                 id: statusText
140                 text: "No status"
141                 color: Theme.highlightColor
142                 anchors.horizontalCenter: parent.horizontalCenter
143                 font.family: Theme.fontFamilyHeading
144             }
145             Row {
146                 spacing: Theme.paddingLarge
147                 anchors.horizontalCenter: parent.horizontalCenter
148                 BusyIndicator {
149                     id: busy
150                     running: false
151                     size: BusyIndicatorSize.Medium
152                     anchors.verticalCenter: parent.verticalCenter
153                 }
154             }
155
156             Rectangle {
157                 color: "transparent"
158                 border {
159                     color: Theme.highlightBackgroundColor
160                     width: 1
161                 }
162                 //radius: Theme.paddingSmall
163                 anchors.horizontalCenter: parent.horizontalCenter
164                 height: (24 * Theme.fontSizeTiny) + (2 * Theme.paddingLarge)
165                 width: parent.width - 2 * Theme.paddingLarge
166                 x: Theme.paddingLarge
167
168                 //TextEdit {
169                 Label {
170                     id: logOutput
171                     textFormat: Text.PlainText
172                     width: parent.width - 2 * Theme.paddingSmall
173                     height: parent.height - 0 * Theme.paddingSmall
174                     wrapMode: Text.WrapAnywhere
175                     font.pixelSize: Theme.fontSizeTiny * 0.6
176                     font.family: "Monospace"
177                     color: Theme.highlightColor
178                     visible: true
179                     text: VpnControl.logText
180                     verticalAlignment: Text.AlignBottom
181                     x: Theme.paddingSmall
182                     y: Theme.paddingSmall
183                     //readOnly: true
184                     clip: true
185                 }
186             }
187         }
188     }
189 }
190
191