on f4e2441 help sign in
unity8/Greeter/Lockscreen.qml
164 lines 4.4 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 Rectangle {
57 // In case wallpaper fails to load or is undefined
58 id: wallpaperBackup
59 anchors.fill: parent
60 color: "black"
61 }
63 Image {
64 id: wallpaper
65 anchors.fill: parent
66 source: root.required ? root.background : ""
67 fillMode: Image.PreserveAspectCrop
68 }
70 MouseArea {
71 anchors.fill: root
72 }
74 Loader {
75 id: pinPadLoader
76 objectName: "pinPadLoader"
77 anchors {
78 left: parent.left
79 right: parent.right
80 verticalCenter: parent.verticalCenter
81 verticalCenterOffset: root.alphaNumeric ? -units.gu(10) : -units.gu(4)
82 }
83 property bool resetting: false
85 source: (!resetting && root.required) ? (root.alphaNumeric ? "PassphraseLockscreen.qml" : "PinLockscreen.qml") : ""
87 Connections {
88 target: pinPadLoader.item
90 onEntered: {
91 LightDM.Greeter.respond(passphrase);
92 }
94 onCancel: {
95 root.cancel()
96 }
97 }
99 Binding {
100 target: pinPadLoader.item
101 property: "pinLength"
102 value: root.pinLength
103 }
104 Binding {
105 target: pinPadLoader.item
106 property: "placeholderText"
107 value: root.placeholderText
108 }
109 Binding {
110 target: pinPadLoader.item
111 property: "username"
112 value: root.username
113 }
114 }
116 Column {
117 anchors {
118 left: parent.left
119 bottom: parent.bottom
120 bottomMargin: units.gu(4)
121 right: parent.right
122 }
123 height: childrenRect.height
124 spacing: units.gu(1)
126 Icon {
127 objectName: "emergencyCallIcon"
128 height: units.gu(3)
129 width: height
130 anchors.horizontalCenter: parent.horizontalCenter
131 name: "phone-app-call-symbolic"
132 color: "#f3f3e7"
133 opacity: 0.6
135 MouseArea {
136 anchors.fill: parent
137 onClicked: root.emergencyCall()
138 }
139 }
141 Label {
142 text: i18n.tr("Emergency Call")
143 color: "#f3f3e7"
144 opacity: 0.6
145 fontSize: "medium"
146 anchors.horizontalCenter: parent.horizontalCenter
147 }
148 }
150 Connections {
151 target: LightDM.Greeter
153 onAuthenticationComplete: {
154 if (LightDM.Greeter.promptless) {
155 return;
156 }
157 if (LightDM.Greeter.authenticated) {
158 root.unlocked();
159 } else {
160 pinPadLoader.item.clear(true);
161 }
162 }
163 }