on a498661 help sign in
unity8/qml/Components/PinLockscreen.qml
224 lines 7.3 kB history raw
1/*
2 * Copyright (C) 2013 Canonical, Ltd.
3 *
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.
7 *
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.
12 *
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/>.
15 */
17import QtQuick 2.0
18import Ubuntu.Components 0.1
19import Ubuntu.Components.ListItems 0.1
20import "../Components"
22Column {
23 id: root
24 anchors.centerIn: parent
25 spacing: units.gu(2)
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
34 property bool showCancelButton: true
36 signal entered(string passphrase)
37 signal cancel()
39 property bool entryEnabled: true
41 function clear(showAnimation) {
42 pinentryField.text = "";
43 if (showAnimation) {
44 pinentryField.incorrectOverride = true;
45 wrongPasswordAnimation.start();
46 }
47 }
49 Column {
50 id: shakeContainer
51 anchors.horizontalCenter: parent.horizontalCenter
52 width: parent.width
53 spacing: units.gu(2)
55 Label {
56 id: infoField
57 objectName: "infoTextLabel"
58 fontSize: "large"
59 color: "#f3f3e7"
60 anchors.horizontalCenter: parent.horizontalCenter
61 text: root.infoText
62 }
64 Item {
65 id: pinContainer
66 anchors { left: parent.left; right: parent.right; margins: units.gu(2) }
67 height: units.gu(4)
69 Row {
70 id: pinentryField
71 objectName: "pinentryField"
72 anchors.horizontalCenter: parent.horizontalCenter
73 anchors.verticalCenter: parent.verticalCenter
74 spacing: Math.max(0, Math.min(units.gu(3), (parent.width / root.maxPinLength) - units.gu(3)))
76 property string text
77 property bool incorrectOverride: false
79 Repeater {
80 model: pinentryField.text.length
81 delegate: Rectangle {
82 color: "#f3f3e7"
83 width: Math.min(units.gu(2), (pinContainer.width - pinContainer.height*2 ) / (root.maxPinLength >= 0 ? root.maxPinLength : 16))
84 height: width
85 radius: width / 2
86 }
87 }
89 function appendNumber(number) {
90 if (incorrectOverride) {
91 incorrectOverride = false;
92 }
94 pinentryField.text = pinentryField.text + number
96 if (root.minPinLength > 0 && root.maxPinLength > 0
97 && root.minPinLength == root.maxPinLength && pinentryField.text.length == root.minPinLength) {
98 root.entered(pinentryField.text)
99 }
100 }
102 function backspace() {
103 pinentryField.text = pinentryField.text.substring(0, pinentryField.text.length-1)
104 }
105 }
106 Label {
107 id: wrongNoticeLabel
108 objectName: "wrongNoticeLabel"
109 fontSize: "x-large"
110 color: "#f3f3e7"
111 anchors.horizontalCenter: parent.horizontalCenter
112 horizontalAlignment: Text.AlignHCenter
113 text: root.errorText
114 visible: pinentryField.incorrectOverride
115 }
117 AbstractButton {
118 objectName: "backspaceIcon"
119 anchors { right: parent.right; top: parent.top; bottom: parent.bottom }
120 width: height
122 Icon {
123 anchors.fill: parent
124 name: "erase"
125 color: "#f3f3e7"
126 }
128 opacity: (pinentryField.text.length && !pinentryField.incorrectOverride) > 0 ? 1 : 0
130 Behavior on opacity {
131 UbuntuNumberAnimation {}
132 }
134 onClicked: pinentryField.backspace()
135 }
136 }
138 Label {
139 objectName: "retryLabel"
140 fontSize: "x-small"
141 color: "#f3f3e7"
142 anchors.horizontalCenter: parent.horizontalCenter
143 text: root.retryText || " "
144 }
145 }
147 ThinDivider {
148 anchors { left: parent.left; right: parent.right; margins: units.gu(2) }
149 }
151 Grid {
152 id: numbersGrid
153 anchors { horizontalCenter: parent.horizontalCenter }
154 columns: 3
156 property int buttonHeight: units.gu(8)
157 property int buttonWidth: units.gu(12)
159 Repeater {
160 model: 9
162 PinPadButton {
163 objectName: "pinPadButton" + text
164 text: index + 1
165 height: numbersGrid.buttonHeight
166 width: numbersGrid.buttonWidth
167 enabled: root.entryEnabled && (root.maxPinLength == -1 ||
168 pinentryField.text.length < root.maxPinLength ||
169 pinentryField.incorrectOverride)
171 onClicked: {
172 pinentryField.appendNumber(index + 1)
173 }
174 }
175 }
176 Item {
177 height: numbersGrid.buttonHeight
178 width: numbersGrid.buttonWidth
179 }
180 PinPadButton {
181 text: "0"
182 height: numbersGrid.buttonHeight
183 width: numbersGrid.buttonWidth
184 enabled: root.entryEnabled && (root.maxPinLength == -1 ||
185 pinentryField.text.length < root.maxPinLength ||
186 pinentryField.incorrectOverride)
188 onClicked: {
189 pinentryField.appendNumber(0)
190 }
191 }
192 Item {
193 height: numbersGrid.buttonHeight
194 width: numbersGrid.buttonWidth
195 }
196 PinPadButton {
197 iconName: "close"
198 height: numbersGrid.buttonHeight
199 width: numbersGrid.buttonWidth
201 onClicked: root.cancel()
202 visible: root.showCancelButton
203 }
204 Item {
205 height: numbersGrid.buttonHeight
206 width: numbersGrid.buttonWidth
207 }
208 PinPadButton {
209 iconName: "tick"
210 objectName: "confirmButton"
211 height: numbersGrid.buttonHeight
212 width: numbersGrid.buttonWidth
213 enabled: root.enabled && pinentryField.text.length >= root.minPinLength
214 visible: root.minPinLength == -1 || root.minPinLength !== root.maxPinLength
216 onClicked: root.entered(pinentryField.text)
217 }
218 }
219 WrongPasswordAnimation {
220 id: wrongPasswordAnimation
221 objectName: "wrongPasswordAnimation"
222 target: shakeContainer
223 }