on a498661 help sign in
unity8/qml/Components/Lockscreen.qml
239 lines 7.1 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 1.0
19import Ubuntu.Components.Popups 1.0
21Showable {
22 id: root
24 // Determine if a numeric or alphanumeric pad is used.
25 property bool alphaNumeric: false
27 // Whether to show an emergency call button
28 property bool showEmergencyCallButton: true
30 // Whether to show a cancel button (not all lockscreen types normally do anyway)
31 property bool showCancelButton: true
33 // Informational text. (e.g. some text to tell which domain this is pin is entered for)
34 property string infoText: ""
36 // Retries text (e.g. 3 retries left)
37 property string retryText: ""
39 // The text to be displayed in case the login failed
40 property string errorText: ""
42 // In case the Lockscreen can show a greeter message, this is the username
43 property string username: ""
45 // Set those to a value greater 0 to restrict the pin length.
46 // If both are unset, the Lockscreen will show a confirm button and allow typing any length of pin before
47 // confirming. If minPinLength is set to a value > 0, the confirm button will only become active when the
48 // entered pin is at least that long. If maxPinLength is set, the lockscreen won't allow entering any
49 // more numbers than that. If both are set to the same value, the lockscreen will enter auto confirming
50 // behavior, hiding the confirmation button and triggering that automatically when the entered pin reached
51 // that length. This is ignored by the alphaNumeric lockscreen as that one is always confirmed by pressing
52 // enter on the OSK.
53 property int minPinLength: -1
54 property int maxPinLength: -1
56 property url background: ""
58 signal entered(string passphrase)
59 signal cancel()
60 signal emergencyCall()
61 signal infoPopupConfirmed()
63 onRequiredChanged: {
64 if (required && pinPadLoader.item) {
65 clear(false)
66 }
67 }
69 function forceDelay(delay) {
70 forcedDelayTimer.interval = delay
71 forcedDelayTimer.start()
72 }
74 function reset() {
75 // This causes the loader below to destry and recreate the source
76 pinPadLoader.resetting = true;
77 pinPadLoader.resetting = false;
78 }
80 function clear(showAnimation) {
81 if (pinPadLoader.item) {
82 pinPadLoader.item.clear(showAnimation);
83 }
84 pinPadLoader.showWrongText = showAnimation
85 pinPadLoader.waiting = false
86 }
88 function showInfoPopup(title, text) {
89 PopupUtils.open(infoPopupComponent, root, {title: title, text: text})
90 }
92 Timer {
93 id: forcedDelayTimer
94 onTriggered: pinPadLoader.showWrongText = false
95 }
97 Rectangle {
98 // In case background fails to load
99 id: backgroundBackup
100 anchors.fill: parent
101 color: "black"
102 visible: root.background.toString() !== ""
103 }
105 Image {
106 id: backgroundImage
107 objectName: "lockscreenBackground"
108 anchors {
109 fill: parent
110 }
111 source: root.required ? root.background : ""
112 fillMode: Image.PreserveAspectCrop
113 }
115 MouseArea {
116 anchors.fill: root
117 }
119 Loader {
120 id: pinPadLoader
121 objectName: "pinPadLoader"
122 anchors {
123 left: parent.left
124 right: parent.right
125 verticalCenter: parent.verticalCenter
126 verticalCenterOffset: root.alphaNumeric ? -units.gu(10) : 0
127 }
128 property bool resetting: false
129 property bool waiting: false
130 property bool showWrongText: false
132 source: (!resetting && root.required) ? (root.alphaNumeric ? "PassphraseLockscreen.qml" : "PinLockscreen.qml") : ""
133 onSourceChanged: {
134 waiting = false
135 showWrongText = false
136 }
137 onLoaded: {
138 if (forcedDelayTimer.running) {
139 pinPadLoader.item.clear(true)
140 }
141 }
143 Connections {
144 target: pinPadLoader.item
146 onEntered: {
147 pinPadLoader.waiting = true
148 root.entered(passphrase);
149 }
151 onCancel: {
152 root.cancel()
153 }
154 }
156 Binding {
157 target: pinPadLoader.item
158 property: "minPinLength"
159 value: root.minPinLength
160 }
161 Binding {
162 target: pinPadLoader.item
163 property: "maxPinLength"
164 value: root.maxPinLength
165 }
166 Binding {
167 target: pinPadLoader.item
168 property: "infoText"
169 value: root.infoText
170 }
171 Binding {
172 target: pinPadLoader.item
173 property: "retryText"
174 value: forcedDelayTimer.running ? i18n.tr("Please wait") : root.retryText
175 }
176 Binding {
177 target: pinPadLoader.item
178 property: "errorText"
179 value: forcedDelayTimer.running ? i18n.tr("Too many incorrect attempts") :
180 (pinPadLoader.showWrongText ? root.errorText : "")
181 }
182 Binding {
183 target: pinPadLoader.item
184 property: "username"
185 value: root.username
186 }
187 Binding {
188 target: pinPadLoader.item
189 property: "entryEnabled"
190 value: !pinPadLoader.waiting && !forcedDelayTimer.running
191 }
192 Binding {
193 target: pinPadLoader.item
194 property: "showCancelButton"
195 value: root.showCancelButton
196 }
197 }
199 Label {
200 id: emergencyCallLabel
201 objectName: "emergencyCallLabel"
203 visible: showEmergencyCallButton
205 anchors {
206 bottom: parent.bottom
207 bottomMargin: units.gu(4)
208 horizontalCenter: parent.horizontalCenter
209 }
211 text: i18n.tr("Emergency Call")
212 color: "#f3f3e7"
213 opacity: 0.6
214 }
216 MouseArea {
217 anchors.fill: emergencyCallLabel
218 onClicked: root.emergencyCall()
219 enabled: emergencyCallLabel.visible
220 }
222 Component {
223 id: infoPopupComponent
224 Dialog {
225 id: dialog
226 objectName: "infoPopup"
227 modal: true
229 Button {
230 objectName: "infoPopupOkButton"
231 text: i18n.tr("OK")
232 onClicked: {
233 PopupUtils.close(dialog)
234 root.infoPopupConfirmed();
235 }
236 }
237 }
238 }