on 43bbdfb help sign in
unity8/qml/Components/Lockscreen.qml
239 lines 6.9 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 // Placeholder text
28 property string placeholderText: ""
29 // Placeholder text while shaking (e.g. Incorrect passprase)
30 property string wrongPlaceholderText: ""
31 // Retries text (e.g. 3 retries left)
32 property string retryText: ""
34 // Informational text. (e.g. some text to tell which domain this is pin is entered for.
35 property string infoText: ""
37 // In case the Lockscreen can show a greeter message, this is the username
38 property string username: ""
40 // Set those to a value greater 0 to restrict the pin length.
41 // If both are unset, the Lockscreen will show a confirm button and allow typing any length of pin before
42 // confirming. If minPinLength is set to a value > 0, the confirm button will only become active when the
43 // entered pin is at least that long. If maxPinLength is set, the lockscreen won't allow entering any
44 // more numbers than that. If both are set to the same value, the lockscreen will enter auto confirming
45 // behavior, hiding the confirmation button and triggering that automatically when the entered pin reached
46 // that length. This is ignored by the alphaNumeric lockscreen as that one is always confirmed by pressing
47 // enter on the OSK.
48 property int minPinLength: -1
49 property int maxPinLength: -1
51 property url background: ""
53 signal entered(string passphrase)
54 signal cancel()
55 signal emergencyCall()
56 signal infoPopupConfirmed()
58 onRequiredChanged: {
59 if (required && pinPadLoader.item) {
60 pinPadLoader.item.clear(false);
61 }
62 }
64 function reset() {
65 // This causes the loader below to destry and recreate the source
66 pinPadLoader.resetting = true;
67 pinPadLoader.resetting = false;
68 }
70 function clear(showAnimation) {
71 pinPadLoader.item.clear(showAnimation);
72 }
74 function showInfoPopup(title, text) {
75 PopupUtils.open(infoPopupComponent, root, {title: title, text: text})
76 }
78 Rectangle {
79 // In case background fails to load or is undefined
80 id: backgroundBackup
81 anchors.fill: parent
82 color: "black"
83 }
85 Image {
86 id: backgroundImage
87 objectName: "lockscreenBackground"
88 anchors {
89 fill: parent
90 }
91 source: root.required ? root.background : ""
92 fillMode: Image.PreserveAspectCrop
93 }
95 MouseArea {
96 anchors.fill: root
97 }
99 Column {
100 spacing: units.gu(2)
101 anchors {
102 left: parent.left
103 right: parent.right
104 bottom: pinPadLoader.top
105 bottomMargin: units.gu(2)
106 }
107 Label {
108 objectName: "retryCountLabel"
109 anchors {
110 left: parent.left
111 right: parent.right
112 }
113 text: root.retryText
114 horizontalAlignment: Text.AlignHCenter
115 color: "#f3f3e7"
116 opacity: 0.6
117 visible: root.retryText.length > 0
118 }
119 Label {
120 id: infoTextLabel
121 objectName: "infoTextLabel"
122 anchors {
123 left: parent.left
124 right: parent.right
125 }
126 text: root.infoText
127 horizontalAlignment: Text.AlignHCenter
128 color: "#f3f3e7"
129 opacity: 0.6
130 visible: root.infoText.length > 0
131 }
132 }
136 Loader {
137 id: pinPadLoader
138 objectName: "pinPadLoader"
139 anchors {
140 left: parent.left
141 right: parent.right
142 verticalCenter: parent.verticalCenter
143 verticalCenterOffset: root.alphaNumeric ? -units.gu(10) : -units.gu(4)
144 }
145 property bool resetting: false
147 source: (!resetting && root.required) ? (root.alphaNumeric ? "PassphraseLockscreen.qml" : "PinLockscreen.qml") : ""
149 Connections {
150 target: pinPadLoader.item
152 onEntered: {
153 root.entered(passphrase);
154 }
156 onCancel: {
157 root.cancel()
158 }
159 }
161 Binding {
162 target: pinPadLoader.item
163 property: "minPinLength"
164 value: root.minPinLength
165 }
166 Binding {
167 target: pinPadLoader.item
168 property: "maxPinLength"
169 value: root.maxPinLength
170 }
171 Binding {
172 target: pinPadLoader.item
173 property: "placeholderText"
174 value: root.placeholderText
175 }
176 Binding {
177 target: pinPadLoader.item
178 property: "wrongPlaceholderText"
179 value: root.wrongPlaceholderText
180 }
181 Binding {
182 target: pinPadLoader.item
183 property: "username"
184 value: root.username
185 }
186 }
188 Column {
189 anchors {
190 left: parent.left
191 bottom: parent.bottom
192 bottomMargin: units.gu(4)
193 right: parent.right
194 }
195 height: childrenRect.height
196 spacing: units.gu(1)
198 Icon {
199 objectName: "emergencyCallIcon"
200 height: units.gu(3)
201 width: height
202 anchors.horizontalCenter: parent.horizontalCenter
203 name: "phone-app-call-symbolic"
204 color: "#f3f3e7"
205 opacity: 0.6
207 MouseArea {
208 anchors.fill: parent
209 onClicked: root.emergencyCall()
210 }
211 }
213 Label {
214 text: i18n.tr("Emergency Call")
215 color: "#f3f3e7"
216 opacity: 0.6
217 fontSize: "medium"
218 anchors.horizontalCenter: parent.horizontalCenter
219 }
220 }
222 Component {
223 id: infoPopupComponent
224 Dialog {
225 id: dialog
226 objectName: "infoPopup"
227 modal: true
229 Button {
230 objectName: "infoPopupOkButton"
231 text: i18n.tr("OK")
232 onClicked: {
233 PopupUtils.close(dialog)
234 root.infoPopupConfirmed();
235 }
236 }
237 }
238 }