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 0.1
19 import "../Components"
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 
30  // In case the Lockscreen can show a greeter message, this is the username
31  property string username: ""
32 
33  // Set this to a value greater 0 to enable auto-confirm behavior for the lockscreen.
34  // This is ignored by the alphaNumeric lockscreen as that one is confirmed with pressing enter on the OSK.
35  property int pinLength: -1
36 
37  property url background: ""
38 
39  signal entered(string passphrase)
40  signal cancel()
41  signal emergencyCall()
42 
43  onRequiredChanged: {
44  if (required && pinPadLoader.item) {
45  pinPadLoader.item.clear(false);
46  }
47  }
48 
49  function reset() {
50  // This causes the loader below to destry and recreate the source
51  pinPadLoader.resetting = true;
52  pinPadLoader.resetting = false;
53  }
54 
55  function clear(showAnimation) {
56  pinPadLoader.item.clear(showAnimation);
57  }
58 
59  Rectangle {
60  // In case background fails to load or is undefined
61  id: backgroundBackup
62  anchors.fill: parent
63  color: "black"
64  }
65 
66  Image {
67  id: backgroundImage
68  objectName: "lockscreenBackground"
69  anchors {
70  fill: parent
71  topMargin: backgroundTopMargin
72  }
73  source: root.required ? root.background : ""
74  fillMode: Image.PreserveAspectCrop
75  }
76 
77  MouseArea {
78  anchors.fill: root
79  }
80 
81  Loader {
82  id: pinPadLoader
83  objectName: "pinPadLoader"
84  anchors {
85  left: parent.left
86  right: parent.right
87  verticalCenter: parent.verticalCenter
88  verticalCenterOffset: root.alphaNumeric ? -units.gu(10) : -units.gu(4)
89  }
90  property bool resetting: false
91 
92  source: (!resetting && root.required) ? (root.alphaNumeric ? "PassphraseLockscreen.qml" : "PinLockscreen.qml") : ""
93 
94  Connections {
95  target: pinPadLoader.item
96 
97  onEntered: {
98  root.entered(passphrase);
99  }
100 
101  onCancel: {
102  root.cancel()
103  }
104  }
105 
106  Binding {
107  target: pinPadLoader.item
108  property: "pinLength"
109  value: root.pinLength
110  }
111  Binding {
112  target: pinPadLoader.item
113  property: "placeholderText"
114  value: root.placeholderText
115  }
116  Binding {
117  target: pinPadLoader.item
118  property: "username"
119  value: root.username
120  }
121  }
122 
123  Column {
124  anchors {
125  left: parent.left
126  bottom: parent.bottom
127  bottomMargin: units.gu(4)
128  right: parent.right
129  }
130  height: childrenRect.height
131  spacing: units.gu(1)
132 
133  Icon {
134  objectName: "emergencyCallIcon"
135  height: units.gu(3)
136  width: height
137  anchors.horizontalCenter: parent.horizontalCenter
138  name: "phone-app-call-symbolic"
139  color: "#f3f3e7"
140  opacity: 0.6
141 
142  MouseArea {
143  anchors.fill: parent
144  onClicked: root.emergencyCall()
145  }
146  }
147 
148  Label {
149  text: i18n.tr("Emergency Call")
150  color: "#f3f3e7"
151  opacity: 0.6
152  fontSize: "medium"
153  anchors.horizontalCenter: parent.horizontalCenter
154  }
155  }
156 }