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.centerIn: parent
27 property string infoText
28 property string retryText
29 property string errorText
30 property int padWidth: units.gu(34)
31 property int padHeight: units.gu(28)
32 property int minPinLength: -1
33 property int maxPinLength: -1
35 signal entered(string passphrase)
38 property bool entryEnabled: true
40 function clear(showAnimation) {
41 pinentryField.text = "";
43 pinentryField.incorrectOverride = true;
44 wrongPasswordAnimation.start();
50 anchors.horizontalCenter: parent.horizontalCenter
56 objectName: "infoTextLabel"
59 anchors.horizontalCenter: parent.horizontalCenter
65 anchors { left: parent.left; right: parent.right; margins: units.gu(2) }
70 objectName: "pinentryField"
71 anchors.horizontalCenter: parent.horizontalCenter
72 anchors.verticalCenter: parent.verticalCenter
73 spacing: Math.max(0, Math.min(units.gu(3), (parent.width / root.maxPinLength) - units.gu(3)))
76 property bool incorrectOverride: false
79 model: pinentryField.text.length
82 width: Math.min(units.gu(2), (pinContainer.width - pinContainer.height*2 ) / (root.maxPinLength >= 0 ? root.maxPinLength : 16))
88 function appendNumber(number) {
89 if (incorrectOverride) {
90 incorrectOverride = false;
93 pinentryField.text = pinentryField.text + number
95 if (root.minPinLength > 0 && root.maxPinLength > 0
96 && root.minPinLength == root.maxPinLength && pinentryField.text.length == root.minPinLength) {
97 root.entered(pinentryField.text)
101 function backspace() {
102 pinentryField.text = pinentryField.text.substring(0, pinentryField.text.length-1)
107 objectName: "wrongNoticeLabel"
110 anchors.horizontalCenter: parent.horizontalCenter
112 visible: pinentryField.incorrectOverride
116 objectName: "backspaceIcon"
117 anchors { right: parent.right; top: parent.top; bottom: parent.bottom }
126 opacity: (pinentryField.text.length && !pinentryField.incorrectOverride) > 0 ? 1 : 0
128 Behavior on opacity {
129 UbuntuNumberAnimation {}
132 onClicked: pinentryField.backspace()
137 objectName: "retryLabel"
140 anchors.horizontalCenter: parent.horizontalCenter
141 text: root.retryText || " "
146 anchors { left: parent.left; right: parent.right; margins: units.gu(2) }
151 anchors { horizontalCenter: parent.horizontalCenter }
154 property int buttonHeight: units.gu(8)
155 property int buttonWidth: units.gu(12)
161 objectName: "pinPadButton" + text
163 height: numbersGrid.buttonHeight
164 width: numbersGrid.buttonWidth
165 enabled: root.entryEnabled && (root.maxPinLength == -1 ||
166 pinentryField.text.length < root.maxPinLength ||
167 pinentryField.incorrectOverride)
170 pinentryField.appendNumber(index + 1)
175 height: numbersGrid.buttonHeight
176 width: numbersGrid.buttonWidth
180 height: numbersGrid.buttonHeight
181 width: numbersGrid.buttonWidth
182 enabled: root.entryEnabled && (root.maxPinLength == -1 ||
183 pinentryField.text.length < root.maxPinLength ||
184 pinentryField.incorrectOverride)
187 pinentryField.appendNumber(0)
191 height: numbersGrid.buttonHeight
192 width: numbersGrid.buttonWidth
196 height: numbersGrid.buttonHeight
197 width: numbersGrid.buttonWidth
199 onClicked: root.cancel()
202 height: numbersGrid.buttonHeight
203 width: numbersGrid.buttonWidth
207 objectName: "confirmButton"
208 height: numbersGrid.buttonHeight
209 width: numbersGrid.buttonWidth
210 enabled: root.enabled && pinentryField.text.length >= root.minPinLength
211 visible: root.minPinLength == -1 || root.minPinLength !== root.maxPinLength
213 onClicked: root.entered(pinentryField.text)
216 WrongPasswordAnimation {
217 id: wrongPasswordAnimation
218 objectName: "wrongPasswordAnimation"
219 target: shakeContainer