2 * Copyright (C) 2013-2017 Canonical Ltd.
3 * Copyright (C) 2021 UBports Foundation
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; version 3.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19import Lomiri.Components 1.3
20import Lomiri.Components.Popups 1.3
21import Lomiri.Telephony 0.1 as Telephony
26 // Determine if a numeric or alphanumeric pad is used.
27 property bool alphaNumeric: false
29 // Whether to show an emergency call button
30 property bool showEmergencyCallButton: true
32 // Whether to show a cancel button (not all lockscreen types normally do anyway)
33 property bool showCancelButton: true
35 // Informational text. (e.g. some text to tell which domain this is pin is entered for)
36 property string infoText: ""
38 // Retries text (e.g. 3 retries left)
39 // (This is not currently used, but will be necessary for SIM unlock screen)
40 property string retryText: ""
42 // The text to be displayed in case the login failed
43 property string errorText: ""
45 // Set those to a value greater 0 to restrict the pin length.
46 // If both are unset, the Lockscreen will show a confirm button and allow typing any length of pin before
47 // confirming. If minPinLength is set to a value > 0, the confirm button will only become active when the
48 // entered pin is at least that long. If maxPinLength is set, the lockscreen won't allow entering any
49 // more numbers than that. If both are set to the same value, the lockscreen will enter auto confirming
50 // behavior, hiding the confirmation button and triggering that automatically when the entered pin reached
51 // that length. This is ignored by the alphaNumeric lockscreen as that one is always confirmed by pressing
53 property int minPinLength: -1
54 property int maxPinLength: -1
56 property url background: ""
57 property alias backgroundSourceSize: backgroundImage.sourceSize
58 // Use this to put a black overlay above the background
59 // 0: normal background, 1: black background
60 property real darkenBackground: 0
62 property color foregroundColor: "#f3f3e7"
64 readonly property string passphrase: (pinPadLoader.item && pinPadLoader.item.passphrase) ? pinPadLoader.item.passphrase : ""
66 signal entered(string passphrase)
68 signal emergencyCall()
69 signal infoPopupConfirmed()
71 onActiveFocusChanged: if (activeFocus && pinPadLoader.item) pinPadLoader.item.forceActiveFocus()
74 // This causes the loader below to destry and recreate the source
75 pinPadLoader.resetting = true;
76 pinPadLoader.resetting = false;
79 function clear(showAnimation) {
80 if (pinPadLoader.item) {
81 pinPadLoader.item.clear(showAnimation);
83 pinPadLoader.showWrongText = showAnimation
84 pinPadLoader.waiting = false
87 function showInfoPopup(title, text) {
88 var popup = PopupUtils.open(infoPopupComponent, root, {title: title, text: text})
89 // FIXME: SDK will do this internally soonish
90 popup.z = Number.MAX_VALUE
94 // In case background fails to load
98 visible: root.background.toString() !== ""
103 objectName: "lockscreenBackground"
107 source: root.required ? root.background : ""
111 // a) align it with the greeter and
112 // b) keep the white fonts readable on bright backgrounds
116 opacity: root.darkenBackground
121 objectName: "pinPadLoader"
123 property bool resetting: false
124 property bool waiting: false
125 property bool showWrongText: false
129 if (resetting || !root.required) {
131 } else if (root.alphaNumeric) {
132 return "PassphraseLockscreen.qml"
134 return "PinLockscreen.qml"
139 showWrongText = false
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: "showCancelButton"
188 value: root.showCancelButton
191 target: pinPadLoader.item
192 property: "foregroundColor"
193 value: root.foregroundColor
200 visible: showEmergencyCallButton
203 bottom: parent.bottom
204 bottomMargin: units.gu(7) + (Qt.inputMethod.visible ? Qt.inputMethod.keyboardRectangle.height : 0)
210 id: emergencyCallLabel
211 objectName: "emergencyCallLabel"
212 anchors.horizontalCenter: parent.horizontalCenter
214 text: callManager.hasCalls ? i18n.tr("Return to Call") : i18n.tr("Emergency Call")
215 color: root.foregroundColor
219 id: emergencyCallIcon
220 anchors.left: emergencyCallLabel.right
221 anchors.leftMargin: units.gu(1)
222 width: emergencyCallLabel.height
223 height: emergencyCallLabel.height
225 color: root.foregroundColor
229 anchors.top: emergencyCallLabel.top
230 anchors.bottom: emergencyCallLabel.bottom
231 anchors.left: emergencyCallLabel.left
232 anchors.right: emergencyCallIcon.right
233 onClicked: root.emergencyCall()
238 id: infoPopupComponent
241 objectName: "infoPopup"
242 property var dialogLoader // dummy to satisfy ShellDialog's context dependent prop
246 objectName: "infoPopupOkButton"
250 PopupUtils.close(dialog)
251 root.infoPopupConfirmed();