on b24b6ca help sign in
unity8/qml/Components/Lockscreen.qml
263 lines 8.4 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
20import Ubuntu.Telephony 0.1 as Telephony
22Showable {
23 id: root
25 // Determine if a numeric or alphanumeric pad is used.
26 property bool alphaNumeric: false
28 // Whether to show an emergency call button
29 property bool showEmergencyCallButton: true
31 // Whether to show a cancel button (not all lockscreen types normally do anyway)
32 property bool showCancelButton: true
34 // Informational text. (e.g. some text to tell which domain this is pin is entered for)
35 property string infoText: ""
37 // Retries text (e.g. 3 retries left)
38 // (This is not currently used, but will be necessary for SIM unlock screen)
39 property string retryText: ""
41 // The text to be displayed in case the login failed
42 property string errorText: ""
44 // If > 0, a forced delay is happening
45 property int delayMinutes: 0
47 // Set those to a value greater 0 to restrict the pin length.
48 // If both are unset, the Lockscreen will show a confirm button and allow typing any length of pin before
49 // confirming. If minPinLength is set to a value > 0, the confirm button will only become active when the
50 // entered pin is at least that long. If maxPinLength is set, the lockscreen won't allow entering any
51 // more numbers than that. If both are set to the same value, the lockscreen will enter auto confirming
52 // behavior, hiding the confirmation button and triggering that automatically when the entered pin reached
53 // that length. This is ignored by the alphaNumeric lockscreen as that one is always confirmed by pressing
54 // enter on the OSK.
55 property int minPinLength: -1
56 property int maxPinLength: -1
58 property url background: ""
60 readonly property string passphrase: (pinPadLoader.item && pinPadLoader.item.passphrase) ? pinPadLoader.item.passphrase : ""
62 signal entered(string passphrase)
63 signal cancel()
64 signal emergencyCall()
65 signal infoPopupConfirmed()
67 onActiveFocusChanged: if (activeFocus && pinPadLoader.item) pinPadLoader.item.forceActiveFocus()
69 function reset() {
70 // This causes the loader below to destry and recreate the source
71 pinPadLoader.resetting = true;
72 pinPadLoader.resetting = false;
73 }
75 function clear(showAnimation) {
76 if (pinPadLoader.item) {
77 pinPadLoader.item.clear(showAnimation);
78 }
79 pinPadLoader.showWrongText = showAnimation
80 pinPadLoader.waiting = false
81 }
83 function showInfoPopup(title, text) {
84 var popup = PopupUtils.open(infoPopupComponent, root, {title: title, text: text})
85 // FIXME: SDK will do this internally soonish
86 popup.z = Number.MAX_VALUE
87 }
89 Rectangle {
90 // In case background fails to load
91 id: backgroundBackup
92 anchors.fill: parent
93 color: "black"
94 visible: root.background.toString() !== ""
95 }
97 Image {
98 id: backgroundImage
99 objectName: "lockscreenBackground"
100 anchors {
101 fill: parent
102 }
103 source: root.required ? root.background : ""
104 fillMode: Image.PreserveAspectCrop
105 }
107 MouseArea {
108 anchors.fill: root
109 onClicked: {
110 if (pinPadLoader.item)
111 pinPadLoader.item.forceActiveFocus()
112 }
113 }
115 FocusScope {
116 id: loaderScope
117 anchors.fill: parent
119 Loader {
120 id: pinPadLoader
121 objectName: "pinPadLoader"
122 anchors.fill: parent
123 property bool resetting: false
124 property bool waiting: false
125 property bool showWrongText: false
127 source: {
128 if (resetting || !root.required) {
129 return ""
130 } else if (root.delayMinutes > 0) {
131 return "DelayedLockscreen.qml"
132 } else if (root.alphaNumeric) {
133 return "PassphraseLockscreen.qml"
134 } else {
135 return "PinLockscreen.qml"
136 }
137 }
138 onSourceChanged: {
139 waiting = false
140 showWrongText = false
141 if (loaderScope.activeFocus && pinPadLoader.item)
142 pinPadLoader.item.forceActiveFocus()
143 }
145 Connections {
146 target: pinPadLoader.item
148 onEntered: {
149 pinPadLoader.waiting = true
150 root.entered(passphrase);
151 }
153 onCancel: {
154 root.cancel()
155 }
156 }
158 Binding {
159 target: pinPadLoader.item
160 property: "minPinLength"
161 value: root.minPinLength
162 }
163 Binding {
164 target: pinPadLoader.item
165 property: "maxPinLength"
166 value: root.maxPinLength
167 }
168 Binding {
169 target: pinPadLoader.item
170 property: "infoText"
171 value: root.infoText
172 }
173 Binding {
174 target: pinPadLoader.item
175 property: "retryText"
176 value: root.retryText
177 }
178 Binding {
179 target: pinPadLoader.item
180 property: "errorText"
181 value: pinPadLoader.showWrongText ? root.errorText : ""
182 }
183 Binding {
184 target: pinPadLoader.item
185 property: "entryEnabled"
186 value: !pinPadLoader.waiting
187 }
188 Binding {
189 target: pinPadLoader.item
190 property: "alphaNumeric"
191 value: root.alphaNumeric
192 }
193 Binding {
194 target: pinPadLoader.item
195 property: "delayMinutes"
196 value: root.delayMinutes
197 }
198 }
199 Binding {
200 target: pinPadLoader.item
201 property: "showCancelButton"
202 value: root.showCancelButton
203 }
204 }
206 Item {
207 id: emergencyCallRow
209 visible: showEmergencyCallButton
211 anchors {
212 bottom: parent.bottom
213 bottomMargin: units.gu(7) + (Qt.inputMethod.visible ? Qt.inputMethod.keyboardRectangle.height : 0)
214 left: parent.left
215 right: parent.right
216 }
218 Label {
219 id: emergencyCallLabel
220 objectName: "emergencyCallLabel"
221 anchors.horizontalCenter: parent.horizontalCenter
223 text: callManager.hasCalls ? i18n.tr("Return to Call") : i18n.tr("Emergency Call")
224 color: "#f3f3e7"
225 }
227 Icon {
228 id: emergencyCallIcon
229 anchors.left: emergencyCallLabel.right
230 anchors.leftMargin: units.gu(1)
231 width: emergencyCallLabel.height
232 height: emergencyCallLabel.height
233 name: "call-start"
234 color: "#f3f3e7"
235 }
237 MouseArea {
238 anchors.top: emergencyCallLabel.top
239 anchors.bottom: emergencyCallLabel.bottom
240 anchors.left: emergencyCallLabel.left
241 anchors.right: emergencyCallIcon.right
242 onClicked: root.emergencyCall()
243 }
244 }
246 Component {
247 id: infoPopupComponent
248 Dialog {
249 id: dialog
250 objectName: "infoPopup"
251 modal: true
253 Button {
254 objectName: "infoPopupOkButton"
255 text: i18n.tr("OK")
256 onClicked: {
257 PopupUtils.close(dialog)
258 root.infoPopupConfirmed();
259 }
260 }
261 }
262 }