Added configurable path to extra configuration file.
[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                 case 5:
68                     configFilename.value = engine.selectedFilename
69                     break;
70             }
71             _fileDialogue = 0;
72         }
73     }
74
75
76     SilicaFlickable {
77         // ComboBox requires a flickable ancestor
78         width: parent.width
79         height: parent.height
80         interactive: true
81
82         anchors.fill: parent
83         contentHeight: configureColumn.height + Theme.paddingLarge
84
85         VerticalScrollDecorator {}
86
87         Column {
88             id: configureColumn
89             width: parent.width
90             spacing: Theme.paddingLarge
91
92             DialogHeader {
93                 acceptText: "Accept"
94             }
95
96             TextField {
97                 id: configureAddress
98                 width: parent.width
99                 text: VpnControl.server
100                 label: "Server address"
101                 placeholderText: "Server address"
102                 focus: true
103                 EnterKey.onClicked: configurePort.focus = true
104             }
105
106             TextField {
107                 id: configurePort
108                 width: parent.width
109                 text: VpnControl.port;
110                 inputMethodHints: Qt.ImhFormattedNumbersOnly
111                 label: "Port number"
112                 placeholderText: "Port number"
113                 EnterKey.onClicked: parent.focus = true
114             }
115
116             TextSwitch {
117                 id: configureCompression
118                 text: "Use Compression"
119                 checked: VpnControl.compressed
120                 automaticCheck: true
121             }
122
123             TextSwitch {
124                 id: configureTLS
125                 text: "Use TLS authentication"
126                 checked: VpnControl.useTLS
127                 automaticCheck: true
128             }
129             // set currentIndex to change the selected value
130             ComboBox {
131                 id: configureTLSdirection
132                 width: parent.width
133                 label: "TLS direction"
134                 currentIndex: VpnControl.tlsDirection;
135                 enabled: configureTLS.checked
136
137                 menu: ContextMenu {
138                     MenuItem { text: "0" }
139                     MenuItem { text: "1" }
140                 }
141             }
142
143             ValueButtonAlignRight {
144                 id: caCertFilename
145                 label: "CA cert"
146                 value: VpnControl.caCertFile
147                 placeholderText: "Select"
148                 width: parent.width
149                 onClicked: {
150                     _fileDialogue = 1
151                     Functions.goToInitial(Functions.folderFromFile(value), "crt")
152                 }
153             }
154
155             ValueButtonAlignRight {
156                 id: clientCertFilename
157                 label: "Client cert"
158                 value: VpnControl.clientCertFile
159                 placeholderText: "Select"
160                 width: parent.width
161                 onClicked: {
162                     _fileDialogue = 2;
163                     Functions.goToInitial(Functions.folderFromFile(value), "crt")
164                 }
165             }
166
167             ValueButtonAlignRight {
168                 id: clientKeyFilename
169                 label: "Client key"
170                 value: VpnControl.clientKeyFile
171                 placeholderText: "Select"
172                 width: parent.width
173                 onClicked: {
174                     _fileDialogue = 3;
175                     Functions.goToInitial(Functions.folderFromFile(value), "key")
176                 }
177             }
178
179             ValueButtonAlignRight {
180                 id: tlsKeyFilename
181                 label: "TLS key"
182                 value: VpnControl.tlsKeyFile
183                 placeholderText: "Select"
184                 width: parent.width
185                 enabled: configureTLS.checked
186                 onClicked: {
187                     _fileDialogue = 4;
188                     Functions.goToInitial(Functions.folderFromFile(value), "key")
189                 }
190             }
191
192             ValueButtonAlignRight {
193                 id: configFilename
194                 label: "Extra options"
195                 value: VpnControl.configFile
196                 placeholderText: "Select"
197                 width: parent.width
198                 onClicked: {
199                     _fileDialogue = 5;
200                     Functions.goToInitial(Functions.folderFromFile(value), "ovpn")
201                 }
202             }
203         }
204     }
205
206     onAccepted: {
207         VpnControl.setServer(configureAddress.text)
208         VpnControl.setPort(configurePort.text)
209         VpnControl.setCompressed(configureCompression.checked)
210         VpnControl.setUseTLS(configureTLS.checked)
211         VpnControl.setTlsDirection(configureTLSdirection.currentIndex)
212         VpnControl.updateConfiguration()
213         VpnControl.setCaCertFile(caCertFilename.value)
214         VpnControl.setClientCertFile(clientCertFilename.value)
215         VpnControl.setClientKeyFile(clientKeyFilename.value)
216         VpnControl.setTlsKeyFile(tlsKeyFilename.value)
217         VpnControl.setConfigFile(configFilename.value)
218     }
219 }