on 8f21147 help sign in
unity8/qml/Components/Lockscreen.qml
220 lines 6.5 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 signal entered(string passphrase)
52 signal cancel()
53 signal emergencyCall()
54 signal infoPopupConfirmed()
56 onRequiredChanged: {
57 if (required && pinPadLoader.item) {
58 pinPadLoader.item.clear(false);
59 }
60 }
62 function reset() {
63 // This causes the loader below to destry and recreate the source
64 pinPadLoader.resetting = true;
65 pinPadLoader.resetting = false;
66 }
68 function clear(showAnimation) {
69 pinPadLoader.item.clear(showAnimation);
70 }
72 function showInfoPopup(title, text) {
73 PopupUtils.open(infoPopupComponent, root, {title: title, text: text})
74 }
76 MouseArea {
77 anchors.fill: root
78 }
80 Column {
81 spacing: units.gu(2)
82 anchors {
83 left: parent.left
84 right: parent.right
85 bottom: pinPadLoader.top
86 bottomMargin: units.gu(2)
87 }
88 Label {
89 objectName: "retryCountLabel"
90 anchors {
91 left: parent.left
92 right: parent.right
93 }
94 text: root.retryText
95 horizontalAlignment: Text.AlignHCenter
96 color: "#f3f3e7"
97 opacity: 0.6
98 visible: root.retryText.length > 0
99 }
100 Label {
101 id: infoTextLabel
102 objectName: "infoTextLabel"
103 anchors {
104 left: parent.left
105 right: parent.right
106 }
107 text: root.infoText
108 horizontalAlignment: Text.AlignHCenter
109 color: "#f3f3e7"
110 opacity: 0.6
111 visible: root.infoText.length > 0
112 }
113 }
117 Loader {
118 id: pinPadLoader
119 objectName: "pinPadLoader"
120 anchors {
121 left: parent.left
122 right: parent.right
123 verticalCenter: parent.verticalCenter
124 verticalCenterOffset: root.alphaNumeric ? -units.gu(10) : -units.gu(4)
125 }
126 property bool resetting: false
128 source: (!resetting && root.required) ? (root.alphaNumeric ? "PassphraseLockscreen.qml" : "PinLockscreen.qml") : ""
130 Connections {
131 target: pinPadLoader.item
133 onEntered: {
134 root.entered(passphrase);
135 }
137 onCancel: {
138 root.cancel()
139 }
140 }
142 Binding {
143 target: pinPadLoader.item
144 property: "minPinLength"
145 value: root.minPinLength
146 }
147 Binding {
148 target: pinPadLoader.item
149 property: "maxPinLength"
150 value: root.maxPinLength
151 }
152 Binding {
153 target: pinPadLoader.item
154 property: "placeholderText"
155 value: root.placeholderText
156 }
157 Binding {
158 target: pinPadLoader.item
159 property: "wrongPlaceholderText"
160 value: root.wrongPlaceholderText
161 }
162 Binding {
163 target: pinPadLoader.item
164 property: "username"
165 value: root.username
166 }
167 }
169 Column {
170 anchors {
171 left: parent.left
172 bottom: parent.bottom
173 bottomMargin: units.gu(4)
174 right: parent.right
175 }
176 height: childrenRect.height
177 spacing: units.gu(1)
179 Icon {
180 objectName: "emergencyCallIcon"
181 height: units.gu(3)
182 width: height
183 anchors.horizontalCenter: parent.horizontalCenter
184 name: "phone-app-call-symbolic"
185 color: "#f3f3e7"
186 opacity: 0.6
188 MouseArea {
189 anchors.fill: parent
190 onClicked: root.emergencyCall()
191 }
192 }
194 Label {
195 text: i18n.tr("Emergency Call")
196 color: "#f3f3e7"
197 opacity: 0.6
198 fontSize: "medium"
199 anchors.horizontalCenter: parent.horizontalCenter
200 }
201 }
203 Component {
204 id: infoPopupComponent
205 Dialog {
206 id: dialog
207 objectName: "infoPopup"
208 modal: true
210 Button {
211 objectName: "infoPopupOkButton"
212 text: i18n.tr("OK")
213 onClicked: {
214 PopupUtils.close(dialog)
215 root.infoPopupConfirmed();
216 }
217 }
218 }
219 }