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 0.1
19 import Ubuntu.Components.ListItems 0.1
20 import "../Components"
24 anchors.top: parent.top
25 anchors.topMargin: units.gu(4)
26 anchors.horizontalCenter: parent.horizontalCenter
29 property string infoText
30 property string retryText
31 property string errorText
32 property int padWidth: units.gu(34)
33 property int padHeight: units.gu(28)
34 property int minPinLength: -1
35 property int maxPinLength: -1
36 property bool showCancelButton: true
38 signal entered(string passphrase)
41 property bool entryEnabled: true
43 function clear(showAnimation) {
44 pinentryField.text = "";
46 pinentryField.incorrectOverride = true;
47 wrongPasswordAnimation.start();
53 anchors.horizontalCenter: parent.horizontalCenter
59 objectName: "infoTextLabel"
62 anchors.horizontalCenter: parent.horizontalCenter
68 anchors { left: parent.left; right: parent.right; margins: units.gu(2) }
73 objectName: "pinentryField"
74 anchors.horizontalCenter: parent.horizontalCenter
75 anchors.verticalCenter: parent.verticalCenter
76 spacing: Math.max(0, Math.min(units.gu(3), (parent.width / root.maxPinLength) - units.gu(3)))
79 property bool incorrectOverride: false
82 model: pinentryField.text.length
85 width: Math.min(units.gu(2), (pinContainer.width - pinContainer.height*2 ) / (root.maxPinLength >= 0 ? root.maxPinLength : 16))
91 function appendNumber(number) {
92 if (incorrectOverride) {
93 incorrectOverride = false;
96 pinentryField.text = pinentryField.text + number
98 if (root.minPinLength > 0 && root.maxPinLength > 0
99 && root.minPinLength == root.maxPinLength && pinentryField.text.length == root.minPinLength) {
100 root.entered(pinentryField.text)
104 function backspace() {
105 pinentryField.text = pinentryField.text.substring(0, pinentryField.text.length-1)
110 objectName: "wrongNoticeLabel"
113 anchors.horizontalCenter: parent.horizontalCenter
114 horizontalAlignment: Text.AlignHCenter
116 visible: pinentryField.incorrectOverride
117 scale: Math.min(1, parent.width / width)
121 objectName: "backspaceIcon"
122 anchors { right: parent.right; top: parent.top; bottom: parent.bottom }
131 opacity: (pinentryField.text.length && !pinentryField.incorrectOverride) > 0 ? 1 : 0
133 Behavior on opacity {
134 UbuntuNumberAnimation {}
137 onClicked: pinentryField.backspace()
142 objectName: "retryLabel"
145 anchors.horizontalCenter: parent.horizontalCenter
146 text: root.retryText || " "
151 anchors { left: parent.left; right: parent.right; margins: units.gu(2) }
156 anchors { horizontalCenter: parent.horizontalCenter }
159 property int buttonHeight: units.gu(8)
160 property int buttonWidth: units.gu(12)
166 objectName: "pinPadButton" + text
168 height: numbersGrid.buttonHeight
169 width: numbersGrid.buttonWidth
170 enabled: root.entryEnabled && (root.maxPinLength == -1 ||
171 pinentryField.text.length < root.maxPinLength ||
172 pinentryField.incorrectOverride)
175 pinentryField.appendNumber(index + 1)
180 height: numbersGrid.buttonHeight
181 width: numbersGrid.buttonWidth
185 height: numbersGrid.buttonHeight
186 width: numbersGrid.buttonWidth
187 enabled: root.entryEnabled && (root.maxPinLength == -1 ||
188 pinentryField.text.length < root.maxPinLength ||
189 pinentryField.incorrectOverride)
192 pinentryField.appendNumber(0)
196 height: numbersGrid.buttonHeight
197 width: numbersGrid.buttonWidth
201 height: units.gu(5) // visual spec has this row a little closer in
202 width: numbersGrid.buttonWidth
204 onClicked: root.cancel()
205 visible: root.showCancelButton
209 width: numbersGrid.buttonWidth
213 objectName: "confirmButton"
215 width: numbersGrid.buttonWidth
216 enabled: root.enabled && pinentryField.text.length >= root.minPinLength
217 visible: root.minPinLength == -1 || root.minPinLength !== root.maxPinLength
219 onClicked: root.entered(pinentryField.text)
222 WrongPasswordAnimation {
223 id: wrongPasswordAnimation
224 objectName: "wrongPasswordAnimation"
225 target: shakeContainer