PinPage.qml 12.7 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
/*
 * Copyright (C) 2014-2016 CZ.NIC
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 *
 * In addition, as a special exception, the copyright holders give
 * permission to link the code of portions of this program with the
 * OpenSSL library under certain conditions as described in each
 * individual source file, and distribute linked combinations including
 * the two.
 */


import QtQuick 2.7
import QtQuick.Controls 2.0

Component {
    id: pinPage
    Item {
        id: mainItem
        Component.onCompleted: {
33
            currentPIN = settings.pinValue()
34
            actionName = "unspecified" /* Causes onChanged() to fire. */
35
36
        }
        property string currentPIN: ""
37
38
39
        property string actionName: "" /* Initial value left blank. */
        onActionNameChanged : { /* Handles actionName changes. */
            if (actionName == "unspecified") {
40
41
42
43
44
45
46
47
48
49
50
                if (currentPIN == "") {
                    topLineText.text = qsTr("Currently there is no PIN code set.")
                    setPinButton.visible = true
                    changePinButton.visible = false
                    disablePinButton.visible = false
                } else {
                    topLineText.text = qsTr("You will be asked to enter a PIN code on application start-up.")
                    setPinButton.visible = false
                    changePinButton.visible = true
                    disablePinButton.visible = true
                }
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
            } else if (actionName == "new") {
                acceptElement.visible = true
                topLineText.text = qsTr("Enter a new PIN code into both text fields:")
                setPinButton.visible = false
                pinValueField.visible = false
                pinConfirmField1.visible = true
                pinConfirmField1.focus = true
                pinConfirmField2.visible = true
            } else if (actionName == "change") {
                acceptElement.visible = true
                topLineText.text = qsTr("In order to change the PIN code you must enter the current and a new PIN code:")
                changePinButton.visible = false
                disablePinButton.visible = false
                pinValueField.visible = true
                pinValueField.focus = true
                pinConfirmField1.visible = true
                pinConfirmField2.visible = true
            } else if (actionName == "disable") {
                acceptElement.visible = true
                topLineText.text = qsTr("In order to change the PIN code you must enter the current and a new PIN code:")
                changePinButton.visible = false
                disablePinButton.visible = false
                pinValueField.visible = true
                pinValueField.focus = true
                pinConfirmField1.visible = false
                pinConfirmField2.visible = false
            } else {
            }
        }
80
        property int myWidht: mainItem.width - 2 * defaultMargin
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
        Rectangle {
            id: header
            anchors.top: parent.top
            width: parent.width
            height: headerHeight
            color: datovkaPalette.highlight
            Image {
                id: backElement
                anchors.verticalCenter: parent.verticalCenter
                anchors.left: parent.left
                anchors.leftMargin: defaultMargin
                sourceSize.height: navImgHeight
                source: "qrc:/ui/back.svg"
            }
            Rectangle {
                anchors.left: parent.left
                width: parent.width * 0.5
                height: parent.height
                color: "transparent"
                MouseArea {
                    anchors.fill: parent
                    onClicked: {
                            pageView.pop(StackView.Immediate)
                    }
                }
            }
            Label {
Karel Slaný's avatar
Karel Slaný committed
108
                text: qsTr("PIN Settings")
109
110
111
112
113
114
115
116
117
118
119
120
                anchors.verticalCenter: parent.verticalCenter
                anchors.left: backElement.right
                anchors.leftMargin: defaultMargin
                font.bold: true
                color: datovkaPalette.text
            }
            Row {
                anchors.verticalCenter: parent.verticalCenter
                spacing: defaultMargin
                anchors.right: parent.right
                anchors.rightMargin: defaultMargin
                Image {
121
                    id: acceptElement
122
123
124
125
126
127
128
129
130
                    visible: false
                    anchors.verticalCenter: parent.verticalCenter
                    sourceSize.height: imgHeight
                    source: "qrc:/ui/checkbox-marked-circle.svg"
                    MouseArea {
                        anchors.fill: parent
                        onClicked: {
                            /* set new pin code */
                            if (actionName == "new") {
131
132
133
134
135
136
137
                                if (pinConfirmField1.text == "" || pinConfirmField2.text == "") {
                                    errLineText.text = qsTr("Error: Both new PIN code fields must be filled in!")
                                    errLineText.visible = true
                                    if (pinConfirmField1.text == "") {
                                        pinConfirmField1.focus = true
                                    } else if (pinConfirmField2.text == "") {
                                        pinConfirmField2.focus = true
138
                                    }
139
140
141
142
                                } else if (pinConfirmField2.text != pinConfirmField1.text) {
                                    pinConfirmField2.focus = true
                                    errLineText.text = qsTr("Error: Newly entered PIN codes are different!")
                                    errLineText.visible = true
143
                                } else {
144
145
                                    errLineText.visible = false
                                    settings.updatePinSettings(pinConfirmField1.text.toString())
146
147
148
149
                                    pageView.pop(StackView.Immediate)
                                }
                            /* change current pin code */
                            } else if (actionName == "change") {
150
151
152
153
154
155
156
157
158
                                if (pinValueField.text == currentPIN) {
                                    errLineText.visible = false
                                    if (pinConfirmField1.text == "" || pinConfirmField2.text == "") {
                                        errLineText.text = qsTr("Error: Both new PIN code fields must be filled in!")
                                        errLineText.visible = true
                                        if (pinConfirmField1.text == "") {
                                            pinConfirmField1.focus = true
                                        } else if (pinConfirmField2.text == "") {
                                            pinConfirmField2.focus = true
159
                                        }
160
161
162
163
                                    } else if (pinConfirmField2.text != pinConfirmField1.text) {
                                        pinConfirmField2.focus = true
                                        errLineText.text = qsTr("Error: Newly entered PIN codes are different!")
                                        errLineText.visible = true
164
                                    } else {
165
166
                                        errLineText.visible = false
                                        settings.updatePinSettings(pinConfirmField1.text.toString())
167
168
169
                                        pageView.pop(StackView.Immediate)
                                    }
                                } else {
170
171
172
173
                                    pinValueField.text = ""
                                    pinValueField.focus = true
                                    errLineText.text = qsTr("Error: Current PIN code is wrong!")
                                    errLineText.visible = true
174
175
176
                                }
                            /* remove/disable current pin code */
                            } else if (actionName == "disable") {
177
178
                                if (pinValueField.text == currentPIN) {
                                    errLineText.visible = false
179
                                    settings.updatePinSettings("")
180
181
                                    pageView.pop(StackView.Immediate)
                                } else {
182
183
184
185
                                    pinValueField.text = ""
                                    pinValueField.focus = true
                                    errLineText.text = qsTr("Error: Current PIN code is wrong!")
                                    errLineText.visible = true
186
187
188
189
190
191
192
193
                                }
                            }
                        }
                    }
                }
            }
        }
        Rectangle {
194
            id: pinComponent
195
196
197
198
            anchors.top: header.bottom
            anchors.bottom: parent.bottom
            width: parent.width
            color: "transparent"
199
200
            Column {
                spacing: formItemVerticalSpacing
201
                Text {
202
                    id: topLineText
203
204
205
206
207
208
209
210
                    anchors.horizontalCenter: parent.horizontalCenter
                    color: datovkaPalette.mid
                    width: myWidht
                    text: ""
                    horizontalAlignment: Text.AlignHCenter
                    wrapMode: Text.Wrap
                }
                Button {
211
                    id: setPinButton
212
213
214
215
                    anchors.horizontalCenter: parent.horizontalCenter
                    text: qsTr("Set PIN")
                    onClicked: {
                        actionName = "new"
216
                    }
217
218
                }
                Button {
219
                    id: changePinButton
220
221
222
223
                    anchors.horizontalCenter: parent.horizontalCenter
                    text: qsTr("Change PIN")
                    onClicked: {
                        actionName = "change"
224
                    }
225
226
                }
                Button {
227
                    id: disablePinButton
228
229
230
231
                    anchors.horizontalCenter: parent.horizontalCenter
                    text: qsTr("Disable PIN")
                    onClicked: {
                        actionName = "disable"
232
                    }
233
234
                }
                TextField {
235
                    id: pinValueField
236
237
238
239
240
241
242
243
244
245
                    anchors.horizontalCenter: parent.horizontalCenter
                    visible: false
                    width: myWidht * 0.5
                    echoMode: TextInput.Password
                    passwordMaskDelay: 500 // milliseconds
                    inputMethodHints: Qt.ImhDigitsOnly
                    placeholderText: qsTr("Current PIN code")
                    text: ""
                }
                TextField {
246
                    id: pinConfirmField1
247
248
249
250
251
252
253
254
255
256
                    anchors.horizontalCenter: parent.horizontalCenter
                    visible: false
                    width: myWidht * 0.5
                    echoMode: TextInput.Password
                    passwordMaskDelay: 500 // milliseconds
                    inputMethodHints: Qt.ImhDigitsOnly
                    placeholderText: qsTr("New PIN code")
                    text: ""
                }
                TextField {
257
                    id: pinConfirmField2
258
259
260
261
262
263
                    anchors.horizontalCenter: parent.horizontalCenter
                    visible: false
                    width: myWidht * 0.5
                    echoMode: TextInput.Password
                    passwordMaskDelay: 500 // milliseconds
                    inputMethodHints: Qt.ImhDigitsOnly
264
                    placeholderText: qsTr("Confirm new PIN code")
265
266
267
                    text: ""
                }
                Text {
268
                    id: errLineText
269
270
271
272
                    visible: false
                    anchors.horizontalCenter: parent.horizontalCenter
                    font.bold: true
                    color: datovkaPalette.text
273
                    width: myWidht
274
                    text: ""
275
276
                    horizontalAlignment: Text.AlignHCenter
                    wrapMode: Text.Wrap
277
278
279
280
281
                }
            }
        }
    }
}