on 239fdcc help sign in
unity8/qml/Greeter/NarrowView.qml
184 lines 5.7 kB history raw
1/*
2 * Copyright (C) 2015-2016 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.4
18import Ubuntu.Components 1.3
19import "../Components"
21FocusScope {
22 id: root
24 property alias dragHandleLeftMargin: coverPage.dragHandleLeftMargin
25 property alias launcherOffset: coverPage.launcherOffset
26 property int currentIndex // unused
27 property alias delayMinutes: lockscreen.delayMinutes
28 property alias backgroundTopMargin: coverPage.backgroundTopMargin
29 property url background
30 property bool locked
31 property bool alphanumeric
32 property var userModel // unused
33 property alias infographicModel: coverPage.infographicModel
34 readonly property bool fullyShown: coverPage.showProgress === 1 || lockscreen.shown
35 readonly property bool required: coverPage.required || lockscreen.required
36 readonly property bool animating: coverPage.showAnimation.running || coverPage.hideAnimation.running
38 signal selected(int index) // unused
39 signal responded(string response)
40 signal tease()
41 signal emergencyCall()
43 function showMessage(html) {
44 // TODO
45 }
47 function showPrompt(text, isSecret, isDefaultPrompt) {
48 lockscreen.promptText = isDefaultPrompt ? "" : text.toLowerCase();
49 lockscreen.maybeShow();
50 }
52 function showLastChance() {
53 var title = lockscreen.alphaNumeric ?
54 i18n.tr("Sorry, incorrect passphrase.") :
55 i18n.tr("Sorry, incorrect passcode.");
56 var text = i18n.tr("This will be your last attempt.") + " " +
57 (lockscreen.alphaNumeric ?
58 i18n.tr("If passphrase is entered incorrectly, your phone will conduct a factory reset and all personal data will be deleted.") :
59 i18n.tr("If passcode is entered incorrectly, your phone will conduct a factory reset and all personal data will be deleted."));
60 lockscreen.showInfoPopup(title, text);
61 }
63 function hide() {
64 lockscreen.hide();
65 coverPage.hide();
66 }
68 function notifyAuthenticationSucceeded() {
69 lockscreen.hide();
70 }
72 function notifyAuthenticationFailed() {
73 lockscreen.clear(true);
74 }
76 function reset() {
77 coverPage.show();
78 }
80 function tryToUnlock(toTheRight) {
81 var coverChanged = coverPage.shown;
82 lockscreen.maybeShow();
83 if (toTheRight) {
84 coverPage.hideRight();
85 } else {
86 coverPage.hide();
87 }
88 return coverChanged;
89 }
91 onLockedChanged: {
92 if (locked) {
93 lockscreen.maybeShow();
94 } else {
95 lockscreen.hide();
96 }
97 }
99 Lockscreen {
100 id: lockscreen
101 objectName: "lockscreen"
103 shown: false
104 showAnimation: StandardAnimation { property: "opacity"; to: 1 }
105 hideAnimation: StandardAnimation { property: "opacity"; to: 0 }
106 anchors.fill: parent
107 visible: required
108 enabled: !coverPage.shown
109 background: root.background
110 darkenBackground: 0.4
111 alphaNumeric: root.alphanumeric
112 minPinLength: 4
113 maxPinLength: 4
115 property string promptText
116 infoText: promptText !== "" ? i18n.tr("Enter %1").arg(promptText) :
117 alphaNumeric ? i18n.tr("Enter passphrase") :
118 i18n.tr("Enter passcode")
119 errorText: promptText !== "" ? i18n.tr("Sorry, incorrect %1").arg(promptText) :
120 alphaNumeric ? i18n.tr("Sorry, incorrect passphrase") + "\n" +
121 i18n.ctr("passphrase", "Please re-enter") :
122 i18n.tr("Sorry, incorrect passcode")
124 onEntered: root.responded(passphrase)
125 onCancel: coverPage.show()
126 onEmergencyCall: root.emergencyCall()
128 onEnabledChanged: {
129 if (enabled) {
130 lockscreen.forceActiveFocus();
131 }
132 }
134 onVisibleChanged: {
135 if (visible) {
136 lockscreen.forceActiveFocus();
137 }
138 }
140 function maybeShow() {
141 if (root.locked && !shown) {
142 showNow();
143 }
144 }
145 }
147 Rectangle {
148 anchors.fill: parent
149 color: "black"
150 opacity: coverPage.showProgress * 0.8
151 }
153 CoverPage {
154 id: coverPage
155 objectName: "coverPage"
156 height: parent.height
157 width: parent.width
158 background: root.background
159 onTease: root.tease()
160 onClicked: hide()
162 onShowProgressChanged: {
163 if (showProgress === 1) {
164 lockscreen.reset();
165 }
167 if (showProgress === 0) {
168 if (root.locked) {
169 lockscreen.clear(false); // to reset focus if necessary
170 } else {
171 root.responded("");
172 }
173 }
174 }
176 Clock {
177 anchors {
178 top: parent.top
179 topMargin: units.gu(2)
180 horizontalCenter: parent.horizontalCenter
181 }
182 }
183 }