on db4dbae help sign in
unity8/qml/Components/Lockscreen.qml
256 lines 8.1 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.4
18import Ubuntu.Components 1.3
19import Ubuntu.Components.Popups 1.3
20import Ubuntu.Telephony 0.1 as Telephony
22Showable {
23 id: root
25 // Determine if a numeric or alphanumeric pad is used.
26 property bool alphaNumeric: false
28 // Whether to show an emergency call button
29 property bool showEmergencyCallButton: true
31 // Whether to show a cancel button (not all lockscreen types normally do anyway)
32 property bool showCancelButton: true
34 // Informational text. (e.g. some text to tell which domain this is pin is entered for)
35 property string infoText: ""
37 // Retries text (e.g. 3 retries left)
38 // (This is not currently used, but will be necessary for SIM unlock screen)
39 property string retryText: ""
41 // The text to be displayed in case the login failed
42 property string errorText: ""
44 // Set those to a value greater 0 to restrict the pin length.
45 // If both are unset, the Lockscreen will show a confirm button and allow typing any length of pin before
46 // confirming. If minPinLength is set to a value > 0, the confirm button will only become active when the
47 // entered pin is at least that long. If maxPinLength is set, the lockscreen won't allow entering any
48 // more numbers than that. If both are set to the same value, the lockscreen will enter auto confirming
49 // behavior, hiding the confirmation button and triggering that automatically when the entered pin reached
50 // that length. This is ignored by the alphaNumeric lockscreen as that one is always confirmed by pressing
51 // enter on the OSK.
52 property int minPinLength: -1
53 property int maxPinLength: -1
55 property url background: ""
56 // Use this to put a black overlay above the background
57 // 0: normal background, 1: black background
58 property real darkenBackground: 0
60 property color foregroundColor: "#f3f3e7"
62 readonly property string passphrase: (pinPadLoader.item && pinPadLoader.item.passphrase) ? pinPadLoader.item.passphrase : ""
64 signal entered(string passphrase)
65 signal cancel()
66 signal emergencyCall()
67 signal infoPopupConfirmed()
69 onActiveFocusChanged: if (activeFocus && pinPadLoader.item) pinPadLoader.item.forceActiveFocus()
71 function reset() {
72 // This causes the loader below to destry and recreate the source
73 pinPadLoader.resetting = true;
74 pinPadLoader.resetting = false;
75 }
77 function clear(showAnimation) {
78 if (pinPadLoader.item) {
79 pinPadLoader.item.clear(showAnimation);
80 }
81 pinPadLoader.showWrongText = showAnimation
82 pinPadLoader.waiting = false
83 }
85 function showInfoPopup(title, text) {
86 var popup = PopupUtils.open(infoPopupComponent, root, {title: title, text: text})
87 // FIXME: SDK will do this internally soonish
88 popup.z = Number.MAX_VALUE
89 }
91 Rectangle {
92 // In case background fails to load
93 id: backgroundBackup
94 anchors.fill: parent
95 color: "black"
96 visible: root.background.toString() !== ""
97 }
99 Image {
100 id: backgroundImage
101 objectName: "lockscreenBackground"
102 anchors {
103 fill: parent
104 }
105 // Limit how much memory we'll reserve for this image
106 sourceSize.height: height
107 sourceSize.width: width
108 source: root.required ? root.background : ""
109 fillMode: Image.PreserveAspectCrop
110 }
112 // This is to
113 // a) align it with the greeter and
114 // b) keep the white fonts readable on bright backgrounds
115 Rectangle {
116 anchors.fill: parent
117 color: "black"
118 opacity: root.darkenBackground
119 }
121 Loader {
122 id: pinPadLoader
123 objectName: "pinPadLoader"
124 anchors.fill: parent
125 property bool resetting: false
126 property bool waiting: false
127 property bool showWrongText: false
128 focus: true
130 source: {
131 if (resetting || !root.required) {
132 return ""
133 } else if (root.alphaNumeric) {
134 return "PassphraseLockscreen.qml"
135 } else {
136 return "PinLockscreen.qml"
137 }
138 }
139 onSourceChanged: {
140 waiting = false
141 showWrongText = false
142 }
144 Connections {
145 target: pinPadLoader.item
147 onEntered: {
148 pinPadLoader.waiting = true
149 root.entered(passphrase);
150 }
152 onCancel: {
153 root.cancel()
154 }
155 }
157 Binding {
158 target: pinPadLoader.item
159 property: "minPinLength"
160 value: root.minPinLength
161 }
162 Binding {
163 target: pinPadLoader.item
164 property: "maxPinLength"
165 value: root.maxPinLength
166 }
167 Binding {
168 target: pinPadLoader.item
169 property: "infoText"
170 value: root.infoText
171 }
172 Binding {
173 target: pinPadLoader.item
174 property: "retryText"
175 value: root.retryText
176 }
177 Binding {
178 target: pinPadLoader.item
179 property: "errorText"
180 value: pinPadLoader.showWrongText ? root.errorText : ""
181 }
182 Binding {
183 target: pinPadLoader.item
184 property: "entryEnabled"
185 value: !pinPadLoader.waiting
186 }
187 Binding {
188 target: pinPadLoader.item
189 property: "showCancelButton"
190 value: root.showCancelButton
191 }
192 Binding {
193 target: pinPadLoader.item
194 property: "foregroundColor"
195 value: root.foregroundColor
196 }
197 }
199 Item {
200 id: emergencyCallRow
202 visible: showEmergencyCallButton
204 anchors {
205 bottom: parent.bottom
206 bottomMargin: units.gu(7) + (Qt.inputMethod.visible ? Qt.inputMethod.keyboardRectangle.height : 0)
207 left: parent.left
208 right: parent.right
209 }
211 Label {
212 id: emergencyCallLabel
213 objectName: "emergencyCallLabel"
214 anchors.horizontalCenter: parent.horizontalCenter
216 text: callManager.hasCalls ? i18n.tr("Return to Call") : i18n.tr("Emergency Call")
217 color: root.foregroundColor
218 }
220 Icon {
221 id: emergencyCallIcon
222 anchors.left: emergencyCallLabel.right
223 anchors.leftMargin: units.gu(1)
224 width: emergencyCallLabel.height
225 height: emergencyCallLabel.height
226 name: "call-start"
227 color: root.foregroundColor
228 }
230 MouseArea {
231 anchors.top: emergencyCallLabel.top
232 anchors.bottom: emergencyCallLabel.bottom
233 anchors.left: emergencyCallLabel.left
234 anchors.right: emergencyCallIcon.right
235 onClicked: root.emergencyCall()
236 }
237 }
239 Component {
240 id: infoPopupComponent
241 ShellDialog {
242 id: dialog
243 objectName: "infoPopup"
244 property var dialogLoader // dummy to satisfy ShellDialog's context dependent prop
246 Button {
247 objectName: "infoPopupOkButton"
248 text: i18n.tr("OK")
249 onClicked: {
250 PopupUtils.close(dialog)
251 root.infoPopupConfirmed();
252 }
253 }
254 }
255 }