Settings stored persistently using QSettings.
[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: VpnControl.vpnConnect()
126                 }
127                 Button {
128                     id : disconnect
129                     text: "Disconnect"
130                     enabled: true
131                     onClicked: VpnControl.vpnDisconnect();
132                 }
133             }
134             Label {
135                 id: statusText
136                 text: "No status"
137                 color: Theme.highlightColor
138                 anchors.horizontalCenter: parent.horizontalCenter
139                 font.family: Theme.fontFamilyHeading
140             }
141             Row {
142                 spacing: Theme.paddingLarge
143                 anchors.horizontalCenter: parent.horizontalCenter
144                 BusyIndicator {
145                     id: busy
146                     running: false
147                     size: BusyIndicatorSize.Large
148                     anchors.verticalCenter: parent.verticalCenter
149                 }
150             }
151         }
152     }
153 }
154
155