on ee4510d help sign in
unity8/qml/Components/Lockscreen.qml
234 lines 7.2 kB history raw
1/*
2 * Copyright (C) 2013 Canonical, Ltd.
3 *
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.
7 *
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.
12 *
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/>.
15 */
17import QtQuick 2.0
18import Ubuntu.Components 1.0
19import Ubuntu.Components.Popups 1.0
21Showable {
22 id: root
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
46 // enter on the OSK.
47 property int minPinLength: -1
48 property int maxPinLength: -1
50 property url background: ""
52 signal entered(string passphrase)
53 signal cancel()
54 signal emergencyCall()
55 signal infoPopupConfirmed()
57 onRequiredChanged: {
58 if (required && pinPadLoader.item) {
59 clear(false)
60 }
61 }
63 function forceDelay(delay) {
64 forcedDelayTimer.interval = delay
65 forcedDelayTimer.start()
66 }
68 function reset() {
69 // This causes the loader below to destry and recreate the source
70 pinPadLoader.resetting = true;
71 pinPadLoader.resetting = false;
72 }
74 function clear(showAnimation) {
75 if (pinPadLoader.item) {
76 pinPadLoader.item.clear(showAnimation);
77 }
78 pinPadLoader.showWrongText = showAnimation
79 pinPadLoader.waiting = false
80 }
82 function showInfoPopup(title, text) {
83 PopupUtils.open(infoPopupComponent, root, {title: title, text: text})
84 }
86 Timer {
87 id: forcedDelayTimer
88 onTriggered: pinPadLoader.showWrongText = false
89 }
91 Rectangle {
92 // In case background fails to load or is undefined
93 id: backgroundBackup
94 anchors.fill: parent
95 color: "black"
96 }
98 Image {
99 id: backgroundImage
100 objectName: "lockscreenBackground"
101 anchors {
102 fill: parent
103 }
104 source: root.required ? root.background : ""
105 fillMode: Image.PreserveAspectCrop
106 }
108 MouseArea {
109 anchors.fill: root
110 }
112 Loader {
113 id: pinPadLoader
114 objectName: "pinPadLoader"
115 anchors {
116 left: parent.left
117 right: parent.right
118 verticalCenter: parent.verticalCenter
119 verticalCenterOffset: root.alphaNumeric ? -units.gu(10) : 0
120 }
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") : ""
126 onSourceChanged: {
127 waiting = false
128 showWrongText = false
129 }
130 onLoaded: {
131 if (forcedDelayTimer.running) {
132 pinPadLoader.item.clear(true)
133 }
134 }
136 Connections {
137 target: pinPadLoader.item
139 onEntered: {
140 pinPadLoader.waiting = true
141 root.entered(passphrase);
142 }
144 onCancel: {
145 root.cancel()
146 }
147 }
149 Binding {
150 target: pinPadLoader.item
151 property: "minPinLength"
152 value: root.minPinLength
153 }
154 Binding {
155 target: pinPadLoader.item
156 property: "maxPinLength"
157 value: root.maxPinLength
158 }
159 Binding {
160 target: pinPadLoader.item
161 property: "infoText"
162 value: root.infoText
163 }
164 Binding {
165 target: pinPadLoader.item
166 property: "retryText"
167 value: forcedDelayTimer.running ? i18n.tr("Please wait") : root.retryText
168 }
169 Binding {
170 target: pinPadLoader.item
171 property: "errorText"
172 value: forcedDelayTimer.running ? i18n.tr("Too many incorrect attempts") :
173 (pinPadLoader.showWrongText ? root.errorText : "")
174 }
175 Binding {
176 target: pinPadLoader.item
177 property: "username"
178 value: root.username
179 }
180 Binding {
181 target: pinPadLoader.item
182 property: "entryEnabled"
183 value: !pinPadLoader.waiting && !forcedDelayTimer.running
184 }
185 }
187 Label {
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
200 anchors {
201 bottom: parent.bottom
202 bottomMargin: units.gu(4)
203 horizontalCenter: parent.horizontalCenter
204 }
206 text: i18n.tr("Emergency Call")
207 color: "#f3f3e7"
208 opacity: 0.6
209 }
211 MouseArea {
212 anchors.fill: emergencyCallLabel
213 onClicked: root.emergencyCall()
214 enabled: emergencyCallLabel.visible
215 }
217 Component {
218 id: infoPopupComponent
219 Dialog {
220 id: dialog
221 objectName: "infoPopup"
222 modal: true
224 Button {
225 objectName: "infoPopupOkButton"
226 text: i18n.tr("OK")
227 onClicked: {
228 PopupUtils.close(dialog)
229 root.infoPopupConfirmed();
230 }
231 }
232 }
233 }