2 * Copyright (C) 2013 Canonical, Ltd.
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.
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.
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/>.
18 import Ubuntu.Components 1.0
19 import Ubuntu.Components.Popups 1.0
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
54 property int minPinLength: -1
55 property int maxPinLength: -1
57 property url background: ""
59 signal entered(string passphrase)
61 signal emergencyCall()
62 signal infoPopupConfirmed()
64 onActiveFocusChanged: if (activeFocus && pinPadLoader.item) pinPadLoader.item.forceActiveFocus()
67 // This causes the loader below to destry and recreate the source
68 pinPadLoader.resetting = true;
69 pinPadLoader.resetting = false;
72 function clear(showAnimation) {
73 if (pinPadLoader.item) {
74 pinPadLoader.item.clear(showAnimation);
76 pinPadLoader.showWrongText = showAnimation
77 pinPadLoader.waiting = false
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
87 // In case background fails to load
91 visible: root.background.toString() !== ""
96 objectName: "lockscreenBackground"
100 source: root.required ? root.background : ""
101 fillMode: Image.PreserveAspectCrop
107 if (pinPadLoader.item)
108 pinPadLoader.item.forceActiveFocus()
118 objectName: "pinPadLoader"
120 property bool resetting: false
121 property bool waiting: false
122 property bool showWrongText: false
125 if (resetting || !root.required) {
127 } else if (root.delayMinutes > 0) {
128 return "DelayedLockscreen.qml"
129 } else if (root.alphaNumeric) {
130 return "PassphraseLockscreen.qml"
132 return "PinLockscreen.qml"
137 showWrongText = false
138 if (loaderScope.activeFocus && pinPadLoader.item)
139 pinPadLoader.item.forceActiveFocus()
143 target: pinPadLoader.item
146 pinPadLoader.waiting = true
147 root.entered(passphrase);
156 target: pinPadLoader.item
157 property: "minPinLength"
158 value: root.minPinLength
161 target: pinPadLoader.item
162 property: "maxPinLength"
163 value: root.maxPinLength
166 target: pinPadLoader.item
171 target: pinPadLoader.item
172 property: "retryText"
173 value: root.retryText
176 target: pinPadLoader.item
177 property: "errorText"
178 value: pinPadLoader.showWrongText ? root.errorText : ""
181 target: pinPadLoader.item
182 property: "entryEnabled"
183 value: !pinPadLoader.waiting
186 target: pinPadLoader.item
187 property: "alphaNumeric"
188 value: root.alphaNumeric
191 target: pinPadLoader.item
192 property: "delayMinutes"
193 value: root.delayMinutes
197 target: pinPadLoader.item
198 property: "showCancelButton"
199 value: root.showCancelButton
206 visible: showEmergencyCallButton
209 bottom: parent.bottom
210 bottomMargin: units.gu(7) + (Qt.inputMethod.visible ? Qt.inputMethod.keyboardRectangle.height : 0)
216 id: emergencyCallLabel
217 objectName: "emergencyCallLabel"
218 anchors.horizontalCenter: parent.horizontalCenter
220 text: i18n.tr("Emergency Call")
225 id: emergencyCallIcon
226 anchors.left: emergencyCallLabel.right
227 anchors.leftMargin: units.gu(1)
228 width: emergencyCallLabel.height
229 height: emergencyCallLabel.height
235 anchors.top: emergencyCallLabel.top
236 anchors.bottom: emergencyCallLabel.bottom
237 anchors.left: emergencyCallLabel.left
238 anchors.right: emergencyCallIcon.right
239 onClicked: root.emergencyCall()
244 id: infoPopupComponent
247 objectName: "infoPopup"
251 objectName: "infoPopupOkButton"
254 PopupUtils.close(dialog)
255 root.infoPopupConfirmed();