Unity 8
 All Classes Functions Properties
Lockscreen.qml
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  */
16 
17 import QtQuick 2.0
18 import Ubuntu.Components 1.0
19 import Ubuntu.Components.Popups 1.0
20 
21 Showable {
22  id: root
23 
24  // Determine if a numeric or alphanumeric pad is used.
25  property bool alphaNumeric: false
26 
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: ""
33 
34  // Informational text. (e.g. some text to tell which domain this is pin is entered for.
35  property string infoText: ""
36 
37  // In case the Lockscreen can show a greeter message, this is the username
38  property string username: ""
39 
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
50 
51  property url background: ""
52 
53  signal entered(string passphrase)
54  signal cancel()
55  signal emergencyCall()
56  signal infoPopupConfirmed()
57 
58  onRequiredChanged: {
59  if (required && pinPadLoader.item) {
60  pinPadLoader.item.clear(false);
61  }
62  }
63 
64  function reset() {
65  // This causes the loader below to destry and recreate the source
66  pinPadLoader.resetting = true;
67  pinPadLoader.resetting = false;
68  }
69 
70  function clear(showAnimation) {
71  pinPadLoader.item.clear(showAnimation);
72  }
73 
74  function showInfoPopup(title, text) {
75  PopupUtils.open(infoPopupComponent, root, {title: title, text: text})
76  }
77 
78  Rectangle {
79  // In case background fails to load or is undefined
80  id: backgroundBackup
81  anchors.fill: parent
82  color: "black"
83  }
84 
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  }
94 
95  MouseArea {
96  anchors.fill: root
97  }
98 
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  }
133 
134 
135 
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
146 
147  source: (!resetting && root.required) ? (root.alphaNumeric ? "PassphraseLockscreen.qml" : "PinLockscreen.qml") : ""
148 
149  Connections {
150  target: pinPadLoader.item
151 
152  onEntered: {
153  root.entered(passphrase);
154  }
155 
156  onCancel: {
157  root.cancel()
158  }
159  }
160 
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  }
187 
188  Column {
189  id: emergencyCallColumn
190 
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
199 
200  anchors {
201  left: parent.left
202  bottom: parent.bottom
203  bottomMargin: units.gu(4)
204  right: parent.right
205  }
206  height: childrenRect.height
207  spacing: units.gu(1)
208 
209  Icon {
210  objectName: "emergencyCallIcon"
211  height: units.gu(3)
212  width: height
213  anchors.horizontalCenter: parent.horizontalCenter
214  name: "phone-app-call-symbolic"
215  color: "#f3f3e7"
216  opacity: 0.6
217  }
218 
219  Label {
220  text: i18n.tr("Emergency Call")
221  color: "#f3f3e7"
222  opacity: 0.6
223  fontSize: "medium"
224  anchors.horizontalCenter: parent.horizontalCenter
225  }
226  }
227 
228  MouseArea {
229  anchors.fill: emergencyCallColumn
230  onClicked: root.emergencyCall()
231  enabled: emergencyCallColumn.visible
232  }
233 
234  Component {
235  id: infoPopupComponent
236  Dialog {
237  id: dialog
238  objectName: "infoPopup"
239  modal: true
240 
241  Button {
242  objectName: "infoPopupOkButton"
243  text: i18n.tr("OK")
244  onClicked: {
245  PopupUtils.close(dialog)
246  root.infoPopupConfirmed();
247  }
248  }
249  }
250  }
251 }