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.3
19 import Ubuntu.Components.Popups 1.3
20 import Ubuntu.Telephony 0.1 as Telephony
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
55 property int minPinLength: -1
56 property int maxPinLength: -1
58 property url background: ""
59 // Use this to put a black overlay above the background
60 // 0: normal background, 1: black background
61 property real darkenBackground: 0
63 property color foregroundColor: "#f3f3e7"
65 readonly property string passphrase: (pinPadLoader.item && pinPadLoader.item.passphrase) ? pinPadLoader.item.passphrase : ""
67 signal entered(string passphrase)
69 signal emergencyCall()
70 signal infoPopupConfirmed()
72 onActiveFocusChanged: if (activeFocus && pinPadLoader.item) pinPadLoader.item.forceActiveFocus()
75 // This causes the loader below to destry and recreate the source
76 pinPadLoader.resetting = true;
77 pinPadLoader.resetting = false;
80 function clear(showAnimation) {
81 if (pinPadLoader.item) {
82 pinPadLoader.item.clear(showAnimation);
84 pinPadLoader.showWrongText = showAnimation
85 pinPadLoader.waiting = false
88 function showInfoPopup(title, text) {
89 var popup = PopupUtils.open(infoPopupComponent, root, {title: title, text: text})
90 // FIXME: SDK will do this internally soonish
91 popup.z = Number.MAX_VALUE
95 // In case background fails to load
99 visible: root.background.toString() !== ""
104 objectName: "lockscreenBackground"
108 // Limit how much memory we'll reserve for this image
109 sourceSize.height: height
110 sourceSize.width: width
111 source: root.required ? root.background : ""
112 fillMode: Image.PreserveAspectCrop
116 // a) align it with the greeter and
117 // b) keep the white fonts readable on bright backgrounds
121 opacity: root.darkenBackground
127 if (pinPadLoader.item)
128 pinPadLoader.item.forceActiveFocus()
138 objectName: "pinPadLoader"
140 property bool resetting: false
141 property bool waiting: false
142 property bool showWrongText: false
145 if (resetting || !root.required) {
147 } else if (root.delayMinutes > 0) {
148 return "DelayedLockscreen.qml"
149 } else if (root.alphaNumeric) {
150 return "PassphraseLockscreen.qml"
152 return "PinLockscreen.qml"
157 showWrongText = false
158 if (loaderScope.activeFocus && pinPadLoader.item)
159 pinPadLoader.item.forceActiveFocus()
163 target: pinPadLoader.item
166 pinPadLoader.waiting = true
167 root.entered(passphrase);
176 target: pinPadLoader.item
177 property: "minPinLength"
178 value: root.minPinLength
181 target: pinPadLoader.item
182 property: "maxPinLength"
183 value: root.maxPinLength
186 target: pinPadLoader.item
191 target: pinPadLoader.item
192 property: "retryText"
193 value: root.retryText
196 target: pinPadLoader.item
197 property: "errorText"
198 value: pinPadLoader.showWrongText ? root.errorText : ""
201 target: pinPadLoader.item
202 property: "entryEnabled"
203 value: !pinPadLoader.waiting
206 target: pinPadLoader.item
207 property: "alphaNumeric"
208 value: root.alphaNumeric
211 target: pinPadLoader.item
212 property: "delayMinutes"
213 value: root.delayMinutes
216 target: pinPadLoader.item
217 property: "showCancelButton"
218 value: root.showCancelButton
221 target: pinPadLoader.item
222 property: "foregroundColor"
223 value: root.foregroundColor
231 visible: showEmergencyCallButton
234 bottom: parent.bottom
235 bottomMargin: units.gu(7) + (Qt.inputMethod.visible ? Qt.inputMethod.keyboardRectangle.height : 0)
241 id: emergencyCallLabel
242 objectName: "emergencyCallLabel"
243 anchors.horizontalCenter: parent.horizontalCenter
245 text: callManager.hasCalls ? i18n.tr("Return to Call") : i18n.tr("Emergency Call")
246 color: root.foregroundColor
250 id: emergencyCallIcon
251 anchors.left: emergencyCallLabel.right
252 anchors.leftMargin: units.gu(1)
253 width: emergencyCallLabel.height
254 height: emergencyCallLabel.height
256 color: root.foregroundColor
260 anchors.top: emergencyCallLabel.top
261 anchors.bottom: emergencyCallLabel.bottom
262 anchors.left: emergencyCallLabel.left
263 anchors.right: emergencyCallIcon.right
264 onClicked: root.emergencyCall()
269 id: infoPopupComponent
272 objectName: "infoPopup"
276 objectName: "infoPopupOkButton"
279 PopupUtils.close(dialog)
280 root.infoPopupConfirmed();