Integrated file selection dialogue with the main code. Improved the
[openvpnui.git] / qml / pages / ConfigurePage.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 import "../components"
38 import "../filebrowse/pages/functions.js" as Functions
39
40 Dialog {
41     id: configurePage
42     canAccept: true
43     acceptDestinationAction: PageStackAction.Pop
44     property int _fileDialogue: 0
45
46     Connections {
47         target:VpnControl
48     }
49
50     // connect signals from engine to panels
51     Connections {
52         target: engine
53         onSelectedFilenameChanged: {
54             switch (_fileDialogue) {
55                 case 1:
56                     caCertFilename.value = engine.selectedFilename
57                     break;
58                 case 2:
59                     clientCertFilename.value = engine.selectedFilename
60                     break;
61                 case 3:
62                     clientKeyFilename.value = engine.selectedFilename
63                     break;
64                 case 4:
65                     tlsKeyFilename.value = engine.selectedFilename
66                     break;
67             }
68             _fileDialogue = 0;
69         }
70     }
71
72
73     SilicaFlickable {
74         // ComboBox requires a flickable ancestor
75         width: parent.width
76         height: parent.height
77         interactive: true
78
79         anchors.fill: parent
80         contentHeight: configureColumn.height + Theme.paddingLarge
81
82         VerticalScrollDecorator {}
83
84         Column {
85             id: configureColumn
86             width: parent.width
87             spacing: Theme.paddingLarge
88
89             DialogHeader {
90                 acceptText: "Accept"
91             }
92
93             TextField {
94                 id: configureAddress
95                 width: parent.width
96                 text: VpnControl.server
97                 label: "Server address"
98                 placeholderText: "Server address"
99                 focus: true
100                 EnterKey.onClicked: configurePort.focus = true
101             }
102
103             TextField {
104                 id: configurePort
105                 width: parent.width
106                 text: VpnControl.port;
107                 inputMethodHints: Qt.ImhFormattedNumbersOnly
108                 label: "Port number"
109                 placeholderText: "Port number"
110                 EnterKey.onClicked: parent.focus = true
111             }
112
113             TextSwitch {
114                 id: configureCompression
115                 text: "Use Compression"
116                 checked: VpnControl.compressed
117                 automaticCheck: true
118             }
119
120             TextSwitch {
121                 id: configureTLS
122                 text: "Use TLS authentication"
123                 checked: VpnControl.useTLS
124                 automaticCheck: true
125             }
126             // set currentIndex to change the selected value
127             ComboBox {
128                 id: configureTLSdirection
129                 width: parent.width
130                 label: "TLS direction"
131                 currentIndex: VpnControl.tlsDirection;
132                 enabled: configureTLS.checked
133
134                 menu: ContextMenu {
135                     MenuItem { text: "0" }
136                     MenuItem { text: "1" }
137                 }
138             }
139
140             ValueButtonAlignRight {
141                 id: caCertFilename
142                 label: "CA cert"
143                 value: "Select"
144                 width: parent.width
145                 onClicked: {
146                     _fileDialogue = 1
147                     Functions.goToInitial(Functions.folderFromFile(value), "crt")
148                 }
149             }
150
151             ValueButtonAlignRight {
152                 id: clientCertFilename
153                 value: "Select"
154                 label: "Client cert"
155                 width: parent.width
156                 onClicked: {
157                     _fileDialogue = 2;
158                     Functions.goToInitial(Functions.folderFromFile(value), "crt")
159                 }
160             }
161
162             ValueButtonAlignRight {
163                 id: clientKeyFilename
164                 value: "Select"
165                 label: "Client key"
166                 width: parent.width
167                 onClicked: {
168                     _fileDialogue = 3;
169                     Functions.goToInitial(Functions.folderFromFile(value), "key")
170                 }
171             }
172
173             ValueButtonAlignRight {
174                 id: tlsKeyFilename
175                 value: "Select"
176                 label: "TLS key"
177                 width: parent.width
178                 enabled: configureTLS.checked
179                 onClicked: {
180                     _fileDialogue = 4;
181                     Functions.goToInitial(Functions.folderFromFile(value), "key")
182                 }
183             }
184         }
185     }
186
187     onAccepted: {
188         VpnControl.setServer(configureAddress.text)
189         VpnControl.setPort(configurePort.text)
190         VpnControl.setCompressed(configureCompression.checked)
191         VpnControl.setUseTLS(configureTLS.checked)
192         VpnControl.setTlsDirection(configureTLSdirection.currentIndex)
193         VpnControl.updateConfiguration()
194     }
195
196 }
197
198
199
200
201