on b91d075 help sign in
unity8/qml/Components/Lockscreen.qml
258 lines 8.0 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 // (This is not currently used, but will be necessary for SIM unlock screen)
38 property string retryText: ""
40 // The text to be displayed in case the login failed
41 property string errorText: ""
43 // If > 0, a forced delay is happening
44 property int delayMinutes: 0
46 // Set those to a value greater 0 to restrict the pin length.
47 // If both are unset, the Lockscreen will show a confirm button and allow typing any length of pin before
48 // confirming. If minPinLength is set to a value > 0, the confirm button will only become active when the
49 // entered pin is at least that long. If maxPinLength is set, the lockscreen won't allow entering any
50 // more numbers than that. If both are set to the same value, the lockscreen will enter auto confirming
51 // behavior, hiding the confirmation button and triggering that automatically when the entered pin reached
52 // that length. This is ignored by the alphaNumeric lockscreen as that one is always confirmed by pressing
53 // enter on the OSK.
54 property int minPinLength: -1
55 property int maxPinLength: -1
57 property url background: ""
59 signal entered(string passphrase)
60 signal cancel()
61 signal emergencyCall()
62 signal infoPopupConfirmed()
64 onActiveFocusChanged: if (activeFocus && pinPadLoader.item) pinPadLoader.item.forceActiveFocus()
66 function reset() {
67 // This causes the loader below to destry and recreate the source
68 pinPadLoader.resetting = true;
69 pinPadLoader.resetting = false;
70 }
72 function clear(showAnimation) {
73 if (pinPadLoader.item) {
74 pinPadLoader.item.clear(showAnimation);
75 }
76 pinPadLoader.showWrongText = showAnimation
77 pinPadLoader.waiting = false
78 }
80 function showInfoPopup(title, text) {
81 PopupUtils.open(infoPopupComponent, root, {title: title, text: text})
82 }
84 Rectangle {
85 // In case background fails to load
86 id: backgroundBackup
87 anchors.fill: parent
88 color: "black"
89 visible: root.background.toString() !== ""
90 }
92 Image {
93 id: backgroundImage
94 objectName: "lockscreenBackground"
95 anchors {
96 fill: parent
97 }
98 source: root.required ? root.background : ""
99 fillMode: Image.PreserveAspectCrop
100 }
102 MouseArea {
103 anchors.fill: root
104 onClicked: {
105 if (pinPadLoader.item)
106 pinPadLoader.item.forceActiveFocus()
107 }
108 }
110 FocusScope {
111 id: loaderScope
112 anchors.fill: parent
114 Loader {
115 id: pinPadLoader
116 objectName: "pinPadLoader"
117 anchors.fill: parent
118 property bool resetting: false
119 property bool waiting: false
120 property bool showWrongText: false
122 source: {
123 if (resetting || !root.required) {
124 return ""
125 } else if (root.delayMinutes > 0) {
126 return "DelayedLockscreen.qml"
127 } else if (root.alphaNumeric) {
128 return "PassphraseLockscreen.qml"
129 } else {
130 return "PinLockscreen.qml"
131 }
132 }
133 onSourceChanged: {
134 waiting = false
135 showWrongText = false
136 if (loaderScope.activeFocus && pinPadLoader.item)
137 pinPadLoader.item.forceActiveFocus()
138 }
140 Connections {
141 target: pinPadLoader.item
143 onEntered: {
144 pinPadLoader.waiting = true
145 root.entered(passphrase);
146 }
148 onCancel: {
149 root.cancel()
150 }
151 }
153 Binding {
154 target: pinPadLoader.item
155 property: "minPinLength"
156 value: root.minPinLength
157 }
158 Binding {
159 target: pinPadLoader.item
160 property: "maxPinLength"
161 value: root.maxPinLength
162 }
163 Binding {
164 target: pinPadLoader.item
165 property: "infoText"
166 value: root.infoText
167 }
168 Binding {
169 target: pinPadLoader.item
170 property: "retryText"
171 value: root.retryText
172 }
173 Binding {
174 target: pinPadLoader.item
175 property: "errorText"
176 value: pinPadLoader.showWrongText ? root.errorText : ""
177 }
178 Binding {
179 target: pinPadLoader.item
180 property: "entryEnabled"
181 value: !pinPadLoader.waiting
182 }
183 Binding {
184 target: pinPadLoader.item
185 property: "alphaNumeric"
186 value: root.alphaNumeric
187 }
188 Binding {
189 target: pinPadLoader.item
190 property: "delayMinutes"
191 value: root.delayMinutes
192 }
193 }
194 Binding {
195 target: pinPadLoader.item
196 property: "showCancelButton"
197 value: root.showCancelButton
198 }
199 }
201 Item {
202 id: emergencyCallRow
204 visible: showEmergencyCallButton
206 anchors {
207 bottom: parent.bottom
208 bottomMargin: units.gu(7) + (Qt.inputMethod.visible ? Qt.inputMethod.keyboardRectangle.height : 0)
209 left: parent.left
210 right: parent.right
211 }
213 Label {
214 id: emergencyCallLabel
215 objectName: "emergencyCallLabel"
216 anchors.horizontalCenter: parent.horizontalCenter
218 text: i18n.tr("Emergency Call")
219 color: "#f3f3e7"
220 }
222 Icon {
223 id: emergencyCallIcon
224 anchors.left: emergencyCallLabel.right
225 anchors.leftMargin: units.gu(1)
226 width: emergencyCallLabel.height
227 height: emergencyCallLabel.height
228 name: "call-start"
229 color: "#f3f3e7"
230 }
232 MouseArea {
233 anchors.top: emergencyCallLabel.top
234 anchors.bottom: emergencyCallLabel.bottom
235 anchors.left: emergencyCallLabel.left
236 anchors.right: emergencyCallIcon.right
237 onClicked: root.emergencyCall()
238 }
239 }
241 Component {
242 id: infoPopupComponent
243 Dialog {
244 id: dialog
245 objectName: "infoPopup"
246 modal: true
248 Button {
249 objectName: "infoPopupOkButton"
250 text: i18n.tr("OK")
251 onClicked: {
252 PopupUtils.close(dialog)
253 root.infoPopupConfirmed();
254 }
255 }
256 }
257 }