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/>.
20import Lomiri.Components 1.3
21import Lomiri.Components.Popups 1.3
22import Lomiri.Telephony 0.1 as Telephony
27 // Determine if a numeric or alphanumeric pad is used.
28 property bool alphaNumeric: false
30 // Whether to show an emergency call button
31 property bool showEmergencyCallButton: true
33 // Whether to show a cancel button (not all lockscreen types normally do anyway)
34 property bool showCancelButton: true
36 // Informational text. (e.g. some text to tell which domain this is pin is entered for)
37 property string infoText: ""
39 // Retries text (e.g. 3 retries left)
40 // (This is not currently used, but will be necessary for SIM unlock screen)
41 property string retryText: ""
43 // The text to be displayed in case the login failed
44 property string errorText: ""
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: ""
58 property alias backgroundSourceSize: backgroundImage.sourceSize
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 source: root.required ? root.background : ""
112 // a) align it with the greeter and
113 // b) keep the white fonts readable on bright backgrounds
117 opacity: root.darkenBackground
122 objectName: "pinPadLoader"
124 property bool resetting: false
125 property bool waiting: false
126 property bool showWrongText: false
130 if (resetting || !root.required) {
132 } else if (root.alphaNumeric) {
133 return "PassphraseLockscreen.qml"
135 return "PinLockscreen.qml"
140 showWrongText = false
144 target: pinPadLoader.item
146 function onEntered() {
147 pinPadLoader.waiting = true
148 root.entered(passphrase);
151 function onCancel() {
157 target: pinPadLoader.item
158 property: "minPinLength"
159 value: root.minPinLength
160 restoreMode: Binding.RestoreBinding
163 target: pinPadLoader.item
164 property: "maxPinLength"
165 value: root.maxPinLength
166 restoreMode: Binding.RestoreBinding
169 target: pinPadLoader.item
172 restoreMode: Binding.RestoreBinding
175 target: pinPadLoader.item
176 property: "retryText"
177 value: root.retryText
178 restoreMode: Binding.RestoreBinding
181 target: pinPadLoader.item
182 property: "errorText"
183 value: pinPadLoader.showWrongText ? root.errorText : ""
184 restoreMode: Binding.RestoreBinding
187 target: pinPadLoader.item
188 property: "entryEnabled"
189 value: !pinPadLoader.waiting
190 restoreMode: Binding.RestoreBinding
193 target: pinPadLoader.item
194 property: "showCancelButton"
195 value: root.showCancelButton
196 restoreMode: Binding.RestoreBinding
199 target: pinPadLoader.item
200 property: "foregroundColor"
201 value: root.foregroundColor
202 restoreMode: Binding.RestoreBinding
209 visible: showEmergencyCallButton
212 bottom: parent.bottom
213 bottomMargin: units.gu(7) + (Qt.inputMethod.visible ? Qt.inputMethod.keyboardRectangle.height : 0)
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: root.foregroundColor
228 id: emergencyCallIcon
229 anchors.left: emergencyCallLabel.right
230 anchors.leftMargin: units.gu(1)
231 width: emergencyCallLabel.height
232 height: emergencyCallLabel.height
234 color: root.foregroundColor
238 anchors.top: emergencyCallLabel.top
239 anchors.bottom: emergencyCallLabel.bottom
240 anchors.left: emergencyCallLabel.left
241 anchors.right: emergencyCallIcon.right
242 onClicked: root.emergencyCall()
247 id: infoPopupComponent
250 objectName: "infoPopup"
251 property var dialogLoader // dummy to satisfy ShellDialog's context dependent prop
255 objectName: "infoPopupOkButton"
259 PopupUtils.close(dialog)
260 root.infoPopupConfirmed();