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();
49 function showText(text) {
50 pinentryField.text = text;
54 if (pinentryField.text.length == root.maxPinLength)
57 if (event.key === Qt.Key_Backspace) {
58 pinentryField.backspace();
59 } else if (event.key === Qt.Key_Delete || event.key === Qt.Key_Escape) {
61 } else if (event.key === Qt.Key_Enter || event.key === Qt.Key_Return) {
62 confirmButton.clicked()
64 var digit = parseInt(event.text);
65 if (!isNaN(digit) && typeof digit == "number") {
66 pinentryField.appendNumber(digit);
75 verticalCenter: parent.verticalCenter;
76 verticalCenterOffset: Math.max(-units.gu(10), -(root.height - height) / 2) + units.gu(4)
82 anchors.horizontalCenter: parent.horizontalCenter
88 objectName: "infoTextLabel"
90 color: root.foregroundColor
91 anchors.horizontalCenter: parent.horizontalCenter
97 anchors { left: parent.left; right: parent.right; margins: units.gu(2) }
102 objectName: "pinentryField"
103 anchors.horizontalCenter: parent.horizontalCenter
104 anchors.verticalCenter: parent.verticalCenter
105 spacing: Math.max(0, Math.min(units.gu(3), (parent.width / root.maxPinLength) - units.gu(3)))
108 property bool incorrectOverride: false
111 model: pinentryField.text.length
112 delegate: Rectangle {
113 color: root.foregroundColor
114 width: Math.min(units.gu(2), (pinContainer.width - pinContainer.height*2 ) / (root.maxPinLength >= 0 ? root.maxPinLength : 16))
120 function appendNumber(number) {
121 if (incorrectOverride) {
122 incorrectOverride = false;
125 pinentryField.text = pinentryField.text + number
127 if (root.minPinLength > 0 && root.maxPinLength > 0
128 && root.minPinLength == root.maxPinLength && pinentryField.text.length == root.minPinLength) {
129 root.entered(pinentryField.text)
133 function backspace() {
134 pinentryField.text = pinentryField.text.substring(0, pinentryField.text.length-1)
139 objectName: "wrongNoticeLabel"
141 color: root.foregroundColor
142 anchors.horizontalCenter: parent.horizontalCenter
143 horizontalAlignment: Text.AlignHCenter
145 visible: pinentryField.incorrectOverride
146 scale: Math.min(1, parent.width / width)
150 objectName: "backspaceIcon"
151 anchors { right: parent.right; top: parent.top; bottom: parent.bottom; margins: -units.gu(1) }
153 enabled: root.entryEnabled
157 anchors.margins: units.gu(1)
159 color: root.foregroundColor
162 opacity: (pinentryField.text.length > 0 && !pinentryField.incorrectOverride) ? 1 : 0
164 Behavior on opacity {
165 UbuntuNumberAnimation {}
168 onClicked: pinentryField.backspace()
173 objectName: "retryLabel"
175 color: root.foregroundColor
176 anchors.horizontalCenter: parent.horizontalCenter
177 text: root.retryText || " "
183 objectName: "numbersGrid"
184 anchors { horizontalCenter: parent.horizontalCenter }
187 property int maxWidth: Math.min(units.gu(50), root.width - units.gu(8))
188 property int buttonWidth: maxWidth / 3
189 property int buttonHeight: buttonWidth * 2 / 3
195 objectName: "pinPadButton" + text
197 height: numbersGrid.buttonHeight
198 width: numbersGrid.buttonWidth
199 foregroundColor: root.foregroundColor
200 enabled: root.entryEnabled && (root.maxPinLength == -1 ||
201 pinentryField.text.length < root.maxPinLength ||
202 pinentryField.incorrectOverride)
205 pinentryField.appendNumber(index + 1)
210 height: numbersGrid.buttonHeight
211 width: numbersGrid.buttonWidth
215 height: numbersGrid.buttonHeight
216 width: numbersGrid.buttonWidth
217 foregroundColor: root.foregroundColor
218 enabled: root.entryEnabled && (root.maxPinLength == -1 ||
219 pinentryField.text.length < root.maxPinLength ||
220 pinentryField.incorrectOverride)
223 pinentryField.appendNumber(0)
227 height: numbersGrid.buttonHeight
228 width: numbersGrid.buttonWidth
233 height: units.gu(5) // visual spec has this row a little closer in
234 width: numbersGrid.buttonWidth
235 foregroundColor: root.foregroundColor
236 onClicked: root.cancel()
237 visible: root.showCancelButton
241 width: numbersGrid.buttonWidth
246 objectName: "confirmButton"
248 width: numbersGrid.buttonWidth
249 foregroundColor: root.foregroundColor
250 enabled: root.enabled && pinentryField.text.length >= root.minPinLength
251 visible: root.minPinLength == -1 || root.minPinLength !== root.maxPinLength
253 onClicked: root.entered(pinentryField.text)
256 WrongPasswordAnimation {
257 id: wrongPasswordAnimation
258 objectName: "wrongPasswordAnimation"
259 target: shakeContainer