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 // Informational text. (e.g. some text to tell which domain this is pin is entered for)
28 property string infoText: ""
30 // Retries text (e.g. 3 retries left)
31 property string retryText: ""
33 // The text to be displayed in case the login failed
34 property string errorText: ""
36 // In case the Lockscreen can show a greeter message, this is the username
37 property string username: ""
39 // Set those to a value greater 0 to restrict the pin length.
40 // If both are unset, the Lockscreen will show a confirm button and allow typing any length of pin before
41 // confirming. If minPinLength is set to a value > 0, the confirm button will only become active when the
42 // entered pin is at least that long. If maxPinLength is set, the lockscreen won't allow entering any
43 // more numbers than that. If both are set to the same value, the lockscreen will enter auto confirming
44 // behavior, hiding the confirmation button and triggering that automatically when the entered pin reached
45 // that length. This is ignored by the alphaNumeric lockscreen as that one is always confirmed by pressing
47 property int minPinLength: -1
48 property int maxPinLength: -1
50 property url background: ""
52 signal entered(string passphrase)
54 signal emergencyCall()
55 signal infoPopupConfirmed()
58 if (required && pinPadLoader.item) {
63 function forceDelay(delay) {
64 forcedDelayTimer.interval = delay
65 forcedDelayTimer.start()
69 // This causes the loader below to destry and recreate the source
70 pinPadLoader.resetting = true;
71 pinPadLoader.resetting = false;
74 function clear(showAnimation) {
75 if (pinPadLoader.item) {
76 pinPadLoader.item.clear(showAnimation);
78 pinPadLoader.showWrongText = showAnimation
79 pinPadLoader.waiting = false
82 function showInfoPopup(title, text) {
83 PopupUtils.open(infoPopupComponent, root, {title: title, text: text})
88 onTriggered: pinPadLoader.showWrongText = false
92 // In case background fails to load or is undefined
100 objectName: "lockscreenBackground"
104 source: root.required ? root.background : ""
105 fillMode: Image.PreserveAspectCrop
114 objectName: "pinPadLoader"
118 verticalCenter: parent.verticalCenter
119 verticalCenterOffset: root.alphaNumeric ? -units.gu(10) : 0
121 property bool resetting: false
122 property bool waiting: false
123 property bool showWrongText: false
125 source: (!resetting && root.required) ? (root.alphaNumeric ? "PassphraseLockscreen.qml" : "PinLockscreen.qml") : ""
128 showWrongText = false
131 if (forcedDelayTimer.running) {
132 pinPadLoader.item.clear(true)
137 target: pinPadLoader.item
140 pinPadLoader.waiting = true
141 root.entered(passphrase);
150 target: pinPadLoader.item
151 property: "minPinLength"
152 value: root.minPinLength
155 target: pinPadLoader.item
156 property: "maxPinLength"
157 value: root.maxPinLength
160 target: pinPadLoader.item
165 target: pinPadLoader.item
166 property: "retryText"
167 value: forcedDelayTimer.running ? i18n.tr("Please wait") : root.retryText
170 target: pinPadLoader.item
171 property: "errorText"
172 value: forcedDelayTimer.running ? i18n.tr("Too many incorrect attempts") :
173 (pinPadLoader.showWrongText ? root.errorText : "")
176 target: pinPadLoader.item
181 target: pinPadLoader.item
182 property: "entryEnabled"
183 value: !pinPadLoader.waiting && !forcedDelayTimer.running
188 id: emergencyCallLabel
189 objectName: "emergencyCallLabel"
191 // FIXME: We *should* show emergency dialer if there is a SIM present,
192 // regardless of whether the side stage is enabled. But right now,
193 // the assumption is that narrow screens are phones which have SIMs
194 // and wider screens are tablets which don't. When we do allow this
195 // on devices with a side stage and a SIM, work should be done to
196 // ensure that the main stage is disabled while the dialer is present
197 // in the side stage.
198 visible: !shell.sideStageEnabled
201 bottom: parent.bottom
202 bottomMargin: units.gu(4)
203 horizontalCenter: parent.horizontalCenter
206 text: i18n.tr("Emergency Call")
212 anchors.fill: emergencyCallLabel
213 onClicked: root.emergencyCall()
214 enabled: emergencyCallLabel.visible
218 id: infoPopupComponent
221 objectName: "infoPopup"
225 objectName: "infoPopupOkButton"
228 PopupUtils.close(dialog)
229 root.infoPopupConfirmed();