on e268fff help sign in
unity8/qml/Components/Lockscreen.qml
260 lines 8.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 // (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 var popup = PopupUtils.open(infoPopupComponent, root, {title: title, text: text})
82 // FIXME: SDK will do this internally soonish
83 popup.z = Number.MAX_VALUE
84 }
86 Rectangle {
87 // In case background fails to load
88 id: backgroundBackup
89 anchors.fill: parent
90 color: "black"
91 visible: root.background.toString() !== ""
92 }
94 Image {
95 id: backgroundImage
96 objectName: "lockscreenBackground"
97 anchors {
98 fill: parent
99 }
100 source: root.required ? root.background : ""
101 fillMode: Image.PreserveAspectCrop
102 }
104 MouseArea {
105 anchors.fill: root
106 onClicked: {
107 if (pinPadLoader.item)
108 pinPadLoader.item.forceActiveFocus()
109 }
110 }
112 FocusScope {
113 id: loaderScope
114 anchors.fill: parent
116 Loader {
117 id: pinPadLoader
118 objectName: "pinPadLoader"
119 anchors.fill: parent
120 property bool resetting: false
121 property bool waiting: false
122 property bool showWrongText: false
124 source: {
125 if (resetting || !root.required) {
126 return ""
127 } else if (root.delayMinutes > 0) {
128 return "DelayedLockscreen.qml"
129 } else if (root.alphaNumeric) {
130 return "PassphraseLockscreen.qml"
131 } else {
132 return "PinLockscreen.qml"
133 }
134 }
135 onSourceChanged: {
136 waiting = false
137 showWrongText = false
138 if (loaderScope.activeFocus && pinPadLoader.item)
139 pinPadLoader.item.forceActiveFocus()
140 }
142 Connections {
143 target: pinPadLoader.item
145 onEntered: {
146 pinPadLoader.waiting = true
147 root.entered(passphrase);
148 }
150 onCancel: {
151 root.cancel()
152 }
153 }
155 Binding {
156 target: pinPadLoader.item
157 property: "minPinLength"
158 value: root.minPinLength
159 }
160 Binding {
161 target: pinPadLoader.item
162 property: "maxPinLength"
163 value: root.maxPinLength
164 }
165 Binding {
166 target: pinPadLoader.item
167 property: "infoText"
168 value: root.infoText
169 }
170 Binding {
171 target: pinPadLoader.item
172 property: "retryText"
173 value: root.retryText
174 }
175 Binding {
176 target: pinPadLoader.item
177 property: "errorText"
178 value: pinPadLoader.showWrongText ? root.errorText : ""
179 }
180 Binding {
181 target: pinPadLoader.item
182 property: "entryEnabled"
183 value: !pinPadLoader.waiting
184 }
185 Binding {
186 target: pinPadLoader.item
187 property: "alphaNumeric"
188 value: root.alphaNumeric
189 }
190 Binding {
191 target: pinPadLoader.item
192 property: "delayMinutes"
193 value: root.delayMinutes
194 }
195 }
196 Binding {
197 target: pinPadLoader.item
198 property: "showCancelButton"
199 value: root.showCancelButton
200 }
201 }
203 Item {
204 id: emergencyCallRow
206 visible: showEmergencyCallButton
208 anchors {
209 bottom: parent.bottom
210 bottomMargin: units.gu(7) + (Qt.inputMethod.visible ? Qt.inputMethod.keyboardRectangle.height : 0)
211 left: parent.left
212 right: parent.right
213 }
215 Label {
216 id: emergencyCallLabel
217 objectName: "emergencyCallLabel"
218 anchors.horizontalCenter: parent.horizontalCenter
220 text: i18n.tr("Emergency Call")
221 color: "#f3f3e7"
222 }
224 Icon {
225 id: emergencyCallIcon
226 anchors.left: emergencyCallLabel.right
227 anchors.leftMargin: units.gu(1)
228 width: emergencyCallLabel.height
229 height: emergencyCallLabel.height
230 name: "call-start"
231 color: "#f3f3e7"
232 }
234 MouseArea {
235 anchors.top: emergencyCallLabel.top
236 anchors.bottom: emergencyCallLabel.bottom
237 anchors.left: emergencyCallLabel.left
238 anchors.right: emergencyCallIcon.right
239 onClicked: root.emergencyCall()
240 }
241 }
243 Component {
244 id: infoPopupComponent
245 Dialog {
246 id: dialog
247 objectName: "infoPopup"
248 modal: true
250 Button {
251 objectName: "infoPopupOkButton"
252 text: i18n.tr("OK")
253 onClicked: {
254 PopupUtils.close(dialog)
255 root.infoPopupConfirmed();
256 }
257 }
258 }
259 }