on 2e48ade help sign in
unity8/Greeter/Lockscreen.qml
156 lines 4.2 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 0.1
19import "../Components"
20import LightDM 0.1 as LightDM
22Showable {
23 id: root
25 // Determine if a numeric or alphanumeric pad is used.
26 property bool alphaNumeric: false
28 // Placeholder text
29 property string placeholderText: ""
31 // In case the Lockscreen can show a greeter message, this is the username
32 property string username: ""
34 // As the numeric PIN pad doesn't have a OK button by design, we need to auto-confirm on a certain length.
35 // This is ignored by the alphaNumeric lockscreen as that one is confirmed with pressing enter on the OSK.
36 property int pinLength: 4
38 property url background: ""
40 signal unlocked()
41 signal cancel()
42 signal emergencyCall()
44 onRequiredChanged: {
45 if (required && pinPadLoader.item) {
46 pinPadLoader.item.clear(false);
47 }
48 }
50 function reset() {
51 // This causes the loader below to destry and recreate the source
52 pinPadLoader.resetting = true;
53 pinPadLoader.resetting = false;
54 }
56 Image {
57 anchors.fill: parent
58 source: root.required ? root.background : ""
59 fillMode: Image.PreserveAspectCrop
60 }
62 MouseArea {
63 anchors.fill: root
64 }
66 Loader {
67 id: pinPadLoader
68 objectName: "pinPadLoader"
69 anchors {
70 left: parent.left
71 right: parent.right
72 verticalCenter: parent.verticalCenter
73 verticalCenterOffset: root.alphaNumeric ? -units.gu(10) : -units.gu(4)
74 }
75 property bool resetting: false
77 source: (!resetting && root.required) ? (root.alphaNumeric ? "PassphraseLockscreen.qml" : "PinLockscreen.qml") : ""
79 Connections {
80 target: pinPadLoader.item
82 onEntered: {
83 LightDM.Greeter.respond(passphrase);
84 }
86 onCancel: {
87 root.cancel()
88 }
89 }
91 Binding {
92 target: pinPadLoader.item
93 property: "pinLength"
94 value: root.pinLength
95 }
96 Binding {
97 target: pinPadLoader.item
98 property: "placeholderText"
99 value: root.placeholderText
100 }
101 Binding {
102 target: pinPadLoader.item
103 property: "username"
104 value: root.username
105 }
106 }
108 Column {
109 anchors {
110 left: parent.left
111 bottom: parent.bottom
112 bottomMargin: units.gu(4)
113 right: parent.right
114 }
115 height: childrenRect.height
116 spacing: units.gu(1)
118 Icon {
119 objectName: "emergencyCallIcon"
120 height: units.gu(3)
121 width: height
122 anchors.horizontalCenter: parent.horizontalCenter
123 name: "phone-app-call-symbolic"
124 color: "#f3f3e7"
125 opacity: 0.6
127 MouseArea {
128 anchors.fill: parent
129 onClicked: root.emergencyCall()
130 }
131 }
133 Label {
134 text: i18n.tr("Emergency Call")
135 color: "#f3f3e7"
136 opacity: 0.6
137 fontSize: "medium"
138 anchors.horizontalCenter: parent.horizontalCenter
139 }
140 }
142 Connections {
143 target: LightDM.Greeter
145 onAuthenticationComplete: {
146 if (LightDM.Greeter.promptless) {
147 return;
148 }
149 if (LightDM.Greeter.authenticated) {
150 root.unlocked();
151 } else {
152 pinPadLoader.item.clear(true);
153 }
154 }
155 }