2
* Copyright (C) 2013 Canonical, Ltd.
4
* This program is free software; you can redistribute it and/or modify
5
* it under the terms of the GNU General Public License as published by
6
* the Free Software Foundation; version 3.
8
* This program is distributed in the hope that it will be useful,
9
* but WITHOUT ANY WARRANTY; without even the implied warranty of
10
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
* GNU General Public License for more details.
13
* You should have received a copy of the GNU General Public License
14
* along with this program. If not, see <http://www.gnu.org/licenses/>.
18
import Ubuntu.Components 1.3
19
import Ubuntu.Components.ListItems 1.3
20
import "../Components"
26
property string infoText
27
property string retryText
28
property string errorText
29
property int minPinLength: -1
30
property int maxPinLength: -1
31
property bool showCancelButton: true
32
property color foregroundColor: "#000000"
34
readonly property string passphrase: pinentryField.text
36
signal entered(string passphrase)
39
property bool entryEnabled: true
41
function clear(showAnimation) {
42
pinentryField.text = "";
44
pinentryField.incorrectOverride = true;
45
wrongPasswordAnimation.start();
50
if (pinentryField.text.length == root.maxPinLength)
53
if (event.key === Qt.Key_Backspace) {
54
pinentryField.backspace();
55
} else if (event.key === Qt.Key_Delete || event.key === Qt.Key_Escape) {
57
} else if (event.key === Qt.Key_Enter || event.key === Qt.Key_Return) {
58
confirmButton.clicked()
60
var digit = parseInt(event.text);
61
if (!isNaN(digit) && typeof digit == "number") {
62
pinentryField.appendNumber(digit);
71
verticalCenter: parent.verticalCenter;
72
verticalCenterOffset: Math.max(-units.gu(10), -(root.height - height) / 2) + units.gu(4)
78
anchors.horizontalCenter: parent.horizontalCenter
84
objectName: "infoTextLabel"
86
color: root.foregroundColor
87
anchors.horizontalCenter: parent.horizontalCenter
93
anchors { left: parent.left; right: parent.right; margins: units.gu(2) }
98
objectName: "pinentryField"
99
anchors.horizontalCenter: parent.horizontalCenter
100
anchors.verticalCenter: parent.verticalCenter
101
spacing: Math.max(0, Math.min(units.gu(3), (parent.width / root.maxPinLength) - units.gu(3)))
104
property bool incorrectOverride: false
107
model: pinentryField.text.length
108
delegate: Rectangle {
109
color: root.foregroundColor
110
width: Math.min(units.gu(2), (pinContainer.width - pinContainer.height*2 ) / (root.maxPinLength >= 0 ? root.maxPinLength : 16))
116
function appendNumber(number) {
117
if (incorrectOverride) {
118
incorrectOverride = false;
121
pinentryField.text = pinentryField.text + number
123
if (root.minPinLength > 0 && root.maxPinLength > 0
124
&& root.minPinLength == root.maxPinLength && pinentryField.text.length == root.minPinLength) {
125
root.entered(pinentryField.text)
129
function backspace() {
130
pinentryField.text = pinentryField.text.substring(0, pinentryField.text.length-1)
135
objectName: "wrongNoticeLabel"
137
color: root.foregroundColor
138
anchors.horizontalCenter: parent.horizontalCenter
139
horizontalAlignment: Text.AlignHCenter
141
visible: pinentryField.incorrectOverride
142
scale: Math.min(1, parent.width / width)
146
objectName: "backspaceIcon"
147
anchors { right: parent.right; top: parent.top; bottom: parent.bottom; margins: -units.gu(1) }
149
enabled: root.entryEnabled
153
anchors.margins: units.gu(1)
155
color: root.foregroundColor
158
opacity: (pinentryField.text.length > 0 && !pinentryField.incorrectOverride) ? 1 : 0
160
Behavior on opacity {
161
UbuntuNumberAnimation {}
164
onClicked: pinentryField.backspace()
169
objectName: "retryLabel"
171
color: root.foregroundColor
172
anchors.horizontalCenter: parent.horizontalCenter
173
text: root.retryText || " "
179
objectName: "numbersGrid"
180
anchors { horizontalCenter: parent.horizontalCenter }
183
property int maxWidth: Math.min(units.gu(50), root.width - units.gu(8))
184
property int buttonWidth: maxWidth / 3
185
property int buttonHeight: buttonWidth * 2 / 3
191
objectName: "pinPadButton" + text
193
height: numbersGrid.buttonHeight
194
width: numbersGrid.buttonWidth
195
foregroundColor: root.foregroundColor
196
enabled: root.entryEnabled && (root.maxPinLength == -1 ||
197
pinentryField.text.length < root.maxPinLength ||
198
pinentryField.incorrectOverride)
201
pinentryField.appendNumber(index + 1)
206
height: numbersGrid.buttonHeight
207
width: numbersGrid.buttonWidth
211
height: numbersGrid.buttonHeight
212
width: numbersGrid.buttonWidth
213
foregroundColor: root.foregroundColor
214
enabled: root.entryEnabled && (root.maxPinLength == -1 ||
215
pinentryField.text.length < root.maxPinLength ||
216
pinentryField.incorrectOverride)
219
pinentryField.appendNumber(0)
223
height: numbersGrid.buttonHeight
224
width: numbersGrid.buttonWidth
229
height: units.gu(5) // visual spec has this row a little closer in
230
width: numbersGrid.buttonWidth
231
foregroundColor: root.foregroundColor
232
onClicked: root.cancel()
233
visible: root.showCancelButton
237
width: numbersGrid.buttonWidth
242
objectName: "confirmButton"
244
width: numbersGrid.buttonWidth
245
foregroundColor: root.foregroundColor
246
enabled: root.enabled && pinentryField.text.length >= root.minPinLength
247
visible: root.minPinLength == -1 || root.minPinLength !== root.maxPinLength
249
onClicked: root.entered(pinentryField.text)
252
WrongPasswordAnimation {
253
id: wrongPasswordAnimation
254
objectName: "wrongPasswordAnimation"
255
target: shakeContainer