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"
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 || " "
158 anchors { left: parent.left; right: parent.right; margins: units.gu(2) }
163 objectName: "numbersGrid"
164 anchors { horizontalCenter: parent.horizontalCenter }
167 property int maxWidth: Math.min(units.gu(50), root.width - units.gu(8))
168 property int buttonWidth: maxWidth / 3
169 property int buttonHeight: buttonWidth * 2 / 3
175 objectName: "pinPadButton" + text
177 height: numbersGrid.buttonHeight
178 width: numbersGrid.buttonWidth
179 foregroundColor: root.foregroundColor
180 enabled: root.entryEnabled && (root.maxPinLength == -1 ||
181 pinentryField.text.length < root.maxPinLength ||
182 pinentryField.incorrectOverride)
185 pinentryField.appendNumber(index + 1)
190 height: numbersGrid.buttonHeight
191 width: numbersGrid.buttonWidth
195 height: numbersGrid.buttonHeight
196 width: numbersGrid.buttonWidth
197 foregroundColor: root.foregroundColor
198 enabled: root.entryEnabled && (root.maxPinLength == -1 ||
199 pinentryField.text.length < root.maxPinLength ||
200 pinentryField.incorrectOverride)
203 pinentryField.appendNumber(0)
207 height: numbersGrid.buttonHeight
208 width: numbersGrid.buttonWidth
212 height: units.gu(5) // visual spec has this row a little closer in
213 width: numbersGrid.buttonWidth
214 foregroundColor: root.foregroundColor
215 onClicked: root.cancel()
216 visible: root.showCancelButton
220 width: numbersGrid.buttonWidth
224 objectName: "confirmButton"
226 width: numbersGrid.buttonWidth
227 foregroundColor: root.foregroundColor
228 enabled: root.enabled && pinentryField.text.length >= root.minPinLength
229 visible: root.minPinLength == -1 || root.minPinLength !== root.maxPinLength
231 onClicked: root.entered(pinentryField.text)
234 WrongPasswordAnimation {
235 id: wrongPasswordAnimation
236 objectName: "wrongPasswordAnimation"
237 target: shakeContainer