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"
25 property string infoText
26 property string retryText
27 property string errorText
28 property int minPinLength: -1
29 property int maxPinLength: -1
30 property bool showCancelButton: true
31 property color foregroundColor: "#000000"
33 readonly property string passphrase: pinentryField.text
35 signal entered(string passphrase)
38 property bool entryEnabled: true
40 function clear(showAnimation) {
41 pinentryField.text = "";
43 pinentryField.incorrectOverride = true;
44 wrongPasswordAnimation.start();
52 verticalCenter: parent.verticalCenter;
53 verticalCenterOffset: Math.max(-units.gu(10), -(root.height - height) / 2) + units.gu(4)
59 anchors.horizontalCenter: parent.horizontalCenter
65 objectName: "infoTextLabel"
67 color: root.foregroundColor
68 anchors.horizontalCenter: parent.horizontalCenter
74 anchors { left: parent.left; right: parent.right; margins: units.gu(2) }
79 objectName: "pinentryField"
80 anchors.horizontalCenter: parent.horizontalCenter
81 anchors.verticalCenter: parent.verticalCenter
82 spacing: Math.max(0, Math.min(units.gu(3), (parent.width / root.maxPinLength) - units.gu(3)))
85 property bool incorrectOverride: false
88 model: pinentryField.text.length
90 color: root.foregroundColor
91 width: Math.min(units.gu(2), (pinContainer.width - pinContainer.height*2 ) / (root.maxPinLength >= 0 ? root.maxPinLength : 16))
97 function appendNumber(number) {
98 if (incorrectOverride) {
99 incorrectOverride = false;
102 pinentryField.text = pinentryField.text + number
104 if (root.minPinLength > 0 && root.maxPinLength > 0
105 && root.minPinLength == root.maxPinLength && pinentryField.text.length == root.minPinLength) {
106 root.entered(pinentryField.text)
110 function backspace() {
111 pinentryField.text = pinentryField.text.substring(0, pinentryField.text.length-1)
116 objectName: "wrongNoticeLabel"
118 color: root.foregroundColor
119 anchors.horizontalCenter: parent.horizontalCenter
120 horizontalAlignment: Text.AlignHCenter
122 visible: pinentryField.incorrectOverride
123 scale: Math.min(1, parent.width / width)
127 objectName: "backspaceIcon"
128 anchors { right: parent.right; top: parent.top; bottom: parent.bottom }
130 enabled: root.entryEnabled
135 color: root.foregroundColor
138 opacity: (pinentryField.text.length > 0 && !pinentryField.incorrectOverride) ? 1 : 0
140 Behavior on opacity {
141 UbuntuNumberAnimation {}
144 onClicked: pinentryField.backspace()
149 objectName: "retryLabel"
151 color: root.foregroundColor
152 anchors.horizontalCenter: parent.horizontalCenter
153 text: root.retryText || " "
159 objectName: "numbersGrid"
160 anchors { horizontalCenter: parent.horizontalCenter }
163 property int maxWidth: Math.min(units.gu(50), root.width - units.gu(8))
164 property int buttonWidth: maxWidth / 3
165 property int buttonHeight: buttonWidth * 2 / 3
171 objectName: "pinPadButton" + text
173 height: numbersGrid.buttonHeight
174 width: numbersGrid.buttonWidth
175 foregroundColor: root.foregroundColor
176 enabled: root.entryEnabled && (root.maxPinLength == -1 ||
177 pinentryField.text.length < root.maxPinLength ||
178 pinentryField.incorrectOverride)
181 pinentryField.appendNumber(index + 1)
186 height: numbersGrid.buttonHeight
187 width: numbersGrid.buttonWidth
191 height: numbersGrid.buttonHeight
192 width: numbersGrid.buttonWidth
193 foregroundColor: root.foregroundColor
194 enabled: root.entryEnabled && (root.maxPinLength == -1 ||
195 pinentryField.text.length < root.maxPinLength ||
196 pinentryField.incorrectOverride)
199 pinentryField.appendNumber(0)
203 height: numbersGrid.buttonHeight
204 width: numbersGrid.buttonWidth
208 height: units.gu(5) // visual spec has this row a little closer in
209 width: numbersGrid.buttonWidth
210 foregroundColor: root.foregroundColor
211 onClicked: root.cancel()
212 visible: root.showCancelButton
216 width: numbersGrid.buttonWidth
220 objectName: "confirmButton"
222 width: numbersGrid.buttonWidth
223 foregroundColor: root.foregroundColor
224 enabled: root.enabled && pinentryField.text.length >= root.minPinLength
225 visible: root.minPinLength == -1 || root.minPinLength !== root.maxPinLength
227 onClicked: root.entered(pinentryField.text)
230 WrongPasswordAnimation {
231 id: wrongPasswordAnimation
232 objectName: "wrongPasswordAnimation"
233 target: shakeContainer