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 PopupUtils.open(infoPopupComponent, root, {title: title, text: text})
85 // In case background fails to load
89 visible: root.background.toString() !== ""
94 objectName: "lockscreenBackground"
98 source: root.required ? root.background : ""
99 fillMode: Image.PreserveAspectCrop
105 if (pinPadLoader.item)
106 pinPadLoader.item.forceActiveFocus()
116 objectName: "pinPadLoader"
118 property bool resetting: false
119 property bool waiting: false
120 property bool showWrongText: false
123 if (resetting || !root.required) {
125 } else if (root.delayMinutes > 0) {
126 return "DelayedLockscreen.qml"
127 } else if (root.alphaNumeric) {
128 return "PassphraseLockscreen.qml"
130 return "PinLockscreen.qml"
135 showWrongText = false
136 if (loaderScope.activeFocus && pinPadLoader.item)
137 pinPadLoader.item.forceActiveFocus()
141 target: pinPadLoader.item
144 pinPadLoader.waiting = true
145 root.entered(passphrase);
154 target: pinPadLoader.item
155 property: "minPinLength"
156 value: root.minPinLength
159 target: pinPadLoader.item
160 property: "maxPinLength"
161 value: root.maxPinLength
164 target: pinPadLoader.item
169 target: pinPadLoader.item
170 property: "retryText"
171 value: root.retryText
174 target: pinPadLoader.item
175 property: "errorText"
176 value: pinPadLoader.showWrongText ? root.errorText : ""
179 target: pinPadLoader.item
180 property: "entryEnabled"
181 value: !pinPadLoader.waiting
184 target: pinPadLoader.item
185 property: "alphaNumeric"
186 value: root.alphaNumeric
189 target: pinPadLoader.item
190 property: "delayMinutes"
191 value: root.delayMinutes
195 target: pinPadLoader.item
196 property: "showCancelButton"
197 value: root.showCancelButton
204 visible: showEmergencyCallButton
207 bottom: parent.bottom
208 bottomMargin: units.gu(7) + (Qt.inputMethod.visible ? Qt.inputMethod.keyboardRectangle.height : 0)
214 id: emergencyCallLabel
215 objectName: "emergencyCallLabel"
216 anchors.horizontalCenter: parent.horizontalCenter
218 text: i18n.tr("Emergency Call")
223 id: emergencyCallIcon
224 anchors.left: emergencyCallLabel.right
225 anchors.leftMargin: units.gu(1)
226 width: emergencyCallLabel.height
227 height: emergencyCallLabel.height
233 anchors.top: emergencyCallLabel.top
234 anchors.bottom: emergencyCallLabel.bottom
235 anchors.left: emergencyCallLabel.left
236 anchors.right: emergencyCallIcon.right
237 onClicked: root.emergencyCall()
242 id: infoPopupComponent
245 objectName: "infoPopup"
249 objectName: "infoPopupOkButton"
252 PopupUtils.close(dialog)
253 root.infoPopupConfirmed();