Lomiri
Loading...
Searching...
No Matches
Lockscreen.qml
1/*
2 * Copyright (C) 2013-2017 Canonical Ltd.
3 * Copyright (C) 2021 UBports Foundation
4 *
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.
8 *
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.
13 *
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/>.
16 */
17
18import QtQuick 2.15
19import QtQml 2.15
20import Lomiri.Components 1.3
21import Lomiri.Components.Popups 1.3
22import Lomiri.Telephony 0.1 as Telephony
23
24Showable {
25 id: root
26
27 // Determine if a numeric or alphanumeric pad is used.
28 property bool alphaNumeric: false
29
30 // Whether to show an emergency call button
31 property bool showEmergencyCallButton: true
32
33 // Whether to show a cancel button (not all lockscreen types normally do anyway)
34 property bool showCancelButton: true
35
36 // Informational text. (e.g. some text to tell which domain this is pin is entered for)
37 property string infoText: ""
38
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: ""
42
43 // The text to be displayed in case the login failed
44 property string errorText: ""
45
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
53 // enter on the OSK.
54 property int minPinLength: -1
55 property int maxPinLength: -1
56
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
62
63 property color foregroundColor: "#f3f3e7"
64
65 readonly property string passphrase: (pinPadLoader.item && pinPadLoader.item.passphrase) ? pinPadLoader.item.passphrase : ""
66
67 signal entered(string passphrase)
68 signal cancel()
69 signal emergencyCall()
70 signal infoPopupConfirmed()
71
72 onActiveFocusChanged: if (activeFocus && pinPadLoader.item) pinPadLoader.item.forceActiveFocus()
73
74 function reset() {
75 // This causes the loader below to destry and recreate the source
76 pinPadLoader.resetting = true;
77 pinPadLoader.resetting = false;
78 }
79
80 function clear(showAnimation) {
81 if (pinPadLoader.item) {
82 pinPadLoader.item.clear(showAnimation);
83 }
84 pinPadLoader.showWrongText = showAnimation
85 pinPadLoader.waiting = false
86 }
87
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
92 }
93
94 Rectangle {
95 // In case background fails to load
96 id: backgroundBackup
97 anchors.fill: parent
98 color: "black"
99 visible: root.background.toString() !== ""
100 }
101
102 Wallpaper {
103 id: backgroundImage
104 objectName: "lockscreenBackground"
105 anchors {
106 fill: parent
107 }
108 source: root.required ? root.background : ""
109 }
110
111 // This is to
112 // a) align it with the greeter and
113 // b) keep the white fonts readable on bright backgrounds
114 Rectangle {
115 anchors.fill: parent
116 color: "black"
117 opacity: root.darkenBackground
118 }
119
120 Loader {
121 id: pinPadLoader
122 objectName: "pinPadLoader"
123 anchors.fill: parent
124 property bool resetting: false
125 property bool waiting: false
126 property bool showWrongText: false
127 focus: true
128
129 source: {
130 if (resetting || !root.required) {
131 return ""
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 }
142
143 Connections {
144 target: pinPadLoader.item
145
146 function onEntered() {
147 pinPadLoader.waiting = true
148 root.entered(passphrase);
149 }
150
151 function onCancel() {
152 root.cancel()
153 }
154 }
155
156 Binding {
157 target: pinPadLoader.item
158 property: "minPinLength"
159 value: root.minPinLength
160 restoreMode: Binding.RestoreBinding
161 }
162 Binding {
163 target: pinPadLoader.item
164 property: "maxPinLength"
165 value: root.maxPinLength
166 restoreMode: Binding.RestoreBinding
167 }
168 Binding {
169 target: pinPadLoader.item
170 property: "infoText"
171 value: root.infoText
172 restoreMode: Binding.RestoreBinding
173 }
174 Binding {
175 target: pinPadLoader.item
176 property: "retryText"
177 value: root.retryText
178 restoreMode: Binding.RestoreBinding
179 }
180 Binding {
181 target: pinPadLoader.item
182 property: "errorText"
183 value: pinPadLoader.showWrongText ? root.errorText : ""
184 restoreMode: Binding.RestoreBinding
185 }
186 Binding {
187 target: pinPadLoader.item
188 property: "entryEnabled"
189 value: !pinPadLoader.waiting
190 restoreMode: Binding.RestoreBinding
191 }
192 Binding {
193 target: pinPadLoader.item
194 property: "showCancelButton"
195 value: root.showCancelButton
196 restoreMode: Binding.RestoreBinding
197 }
198 Binding {
199 target: pinPadLoader.item
200 property: "foregroundColor"
201 value: root.foregroundColor
202 restoreMode: Binding.RestoreBinding
203 }
204 }
205
206 Item {
207 id: emergencyCallRow
208
209 visible: showEmergencyCallButton
210
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 }
217
218 Label {
219 id: emergencyCallLabel
220 objectName: "emergencyCallLabel"
221 anchors.horizontalCenter: parent.horizontalCenter
222
223 text: callManager.hasCalls ? i18n.tr("Return to Call") : i18n.tr("Emergency Call")
224 color: root.foregroundColor
225 }
226
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: root.foregroundColor
235 }
236
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 }
245
246 Component {
247 id: infoPopupComponent
248 ShellDialog {
249 id: dialog
250 objectName: "infoPopup"
251 property var dialogLoader // dummy to satisfy ShellDialog's context dependent prop
252
253 Button {
254 width: parent.width
255 objectName: "infoPopupOkButton"
256 text: i18n.tr("OK")
257 focus: true
258 onClicked: {
259 PopupUtils.close(dialog)
260 root.infoPopupConfirmed();
261 }
262 }
263 }
264 }
265}