88d0b8e610aa51545abf51fa7c461159d871a3ac
[openvpnui.git] / qml / pages / ConnectPage.qml
1 /*
2   Copyright (C) 2013 Jolla Ltd.
3   Contact: Thomas Perl <thomas.perl@jollamobile.com>
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
31 import QtQuick 2.0
32 import Sailfish.Silica 1.0
33
34
35 Page {
36     id: connectPage
37
38     Connections {
39         target:VpnControl
40         onStatusChanged: {
41             updateStatus(status)
42         }
43     }
44
45     function updateStatus(status) {
46         switch (status) {
47         case 0:
48             statusText.text = "Disconnected"
49             busy.running = false
50             connect.enabled = true
51             disconnect.enabled = false
52             break
53         case 1:
54             statusText.text = "Initialising"
55             busy.running = true
56             connect.enabled = false
57             disconnect.enabled = true
58             break
59         case 2:
60             statusText.text = "Connecting"
61             busy.running = true
62             connect.enabled = false
63             disconnect.enabled = true
64             break
65         case 3:
66             statusText.text = "Connected"
67             busy.running = false
68             connect.enabled = false
69             disconnect.enabled = true
70             break
71         case 4:
72             statusText.text = "Disconnecting"
73             busy.running = true
74             connect.enabled = false
75             disconnect.enabled = false
76             break
77         default:
78             statusText.text = "Invalid"
79             busy.running = false
80             connect.enabled = true
81             disconnect.enabled = false
82             break
83         }
84     }
85
86     // To enable PullDownMenu, place our content in a SilicaFlickable
87     SilicaFlickable {
88         anchors.fill: parent
89
90         // PullDownMenu and PushUpMenu must be declared in SilicaFlickable, SilicaListView or SilicaGridView
91         PullDownMenu {
92             MenuItem {
93                 text: "Configure"
94                 onClicked: pageStack.push(Qt.resolvedUrl("ConfigurePage.qml"))
95             }
96         }
97
98         contentHeight: column.height + Theme.paddingLarge
99
100         // Why is this necessary?
101         contentWidth: parent.width
102
103         VerticalScrollDecorator {}
104         // Place our content in a Column.  The PageHeader is always placed at the top
105         // of the page, followed by our content.
106         Column {
107             id: column
108
109             width: parent.width
110             spacing: Theme.paddingLarge
111
112             PageHeader {
113                 title: "OpenVPN Control"
114             }
115             Row {
116                 spacing: Theme.paddingLarge
117                 anchors.horizontalCenter: parent.horizontalCenter
118                 Button {
119                     id: connect
120                     text: "Connect"
121                     enabled: true
122                     onClicked: VpnControl.vpnConnect()
123                 }
124                 Button {
125                     id : disconnect
126                     text: "Disconnect"
127                     enabled: true
128                     onClicked: VpnControl.vpnDisconnect();
129                 }
130             }
131             Label {
132                 id: statusText
133                 text: "No status"
134                 color: Theme.highlightColor
135                 anchors.horizontalCenter: parent.horizontalCenter
136                 font.family: Theme.fontFamilyHeading
137             }
138             Row {
139                 spacing: Theme.paddingLarge
140                 anchors.horizontalCenter: parent.horizontalCenter
141                 BusyIndicator {
142                     id: busy
143                     running: false
144                     size: BusyIndicatorSize.Large
145                     anchors.verticalCenter: parent.verticalCenter
146                 }
147             }
148         }
149     }
150 }
151
152