Unity 8
NarrowView.qml
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  */
16 
17 import QtQuick 2.4
18 import Ubuntu.Components 1.3
19 import "../Components"
20 
21 FocusScope {
22  id: root
23 
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  property bool waiting
35  readonly property bool fullyShown: coverPage.showProgress === 1 || lockscreen.shown
36  readonly property bool required: coverPage.required || lockscreen.required
37  readonly property bool animating: coverPage.showAnimation.running || coverPage.hideAnimation.running
38 
39  signal selected(int index) // unused
40  signal responded(string response)
41  signal tease()
42  signal emergencyCall()
43 
44  function showMessage(html) {
45  // TODO
46  }
47 
48  function showPrompt(text, isSecret, isDefaultPrompt) {
49  lockscreen.promptText = isDefaultPrompt ? "" : text.toLowerCase();
50  lockscreen.maybeShow();
51  }
52 
53  function showLastChance() {
54  var title = lockscreen.alphaNumeric ?
55  i18n.tr("Sorry, incorrect passphrase.") :
56  i18n.tr("Sorry, incorrect passcode.");
57  var text = i18n.tr("This will be your last attempt.") + " " +
58  (lockscreen.alphaNumeric ?
59  i18n.tr("If passphrase is entered incorrectly, your phone will conduct a factory reset and all personal data will be deleted.") :
60  i18n.tr("If passcode is entered incorrectly, your phone will conduct a factory reset and all personal data will be deleted."));
61  lockscreen.showInfoPopup(title, text);
62  }
63 
64  function hide() {
65  lockscreen.hide();
66  coverPage.hide();
67  }
68 
69  function notifyAuthenticationSucceeded(showFakePassword) {
70  // When using an alternate log in mechanism like fingerprints, the
71  // design is it looks like the user entered a passcode.
72  if (!alphanumeric && showFakePassword) {
73  lockscreen.showText("...."); // actual text doesn't matter, we show bullets
74  }
75  }
76 
77  function notifyAuthenticationFailed() {
78  lockscreen.customError = "";
79  lockscreen.clear(true);
80  }
81 
82  function showErrorMessage(msg) {
83  coverPage.showErrorMessage(msg);
84  lockscreen.customError = msg ? msg : " "; // avoid default message
85  lockscreen.clear(true);
86  }
87 
88  function reset() {
89  lockscreen.customError = "";
90  coverPage.show();
91  }
92 
93  function tryToUnlock(toTheRight) {
94  var coverChanged = coverPage.shown;
95  lockscreen.maybeShow();
96  if (toTheRight) {
97  coverPage.hideRight();
98  } else {
99  coverPage.hide();
100  }
101  return coverChanged;
102  }
103 
104  onLockedChanged: {
105  if (locked) {
106  lockscreen.maybeShow();
107  } else {
108  lockscreen.hide();
109  }
110  }
111 
112  Lockscreen {
113  id: lockscreen
114  objectName: "lockscreen"
115 
116  shown: false
117  showAnimation: StandardAnimation { property: "opacity"; to: 1 }
118  hideAnimation: StandardAnimation { property: "opacity"; to: 0 }
119  anchors.fill: parent
120  visible: required
121  enabled: !coverPage.shown
122  background: root.background
123  darkenBackground: 0.4
124  alphaNumeric: root.alphanumeric
125  minPinLength: 4
126  maxPinLength: 4
127 
128  property string promptText
129  infoText: promptText !== "" ? i18n.tr("Enter %1").arg(promptText) :
130  alphaNumeric ? i18n.tr("Enter passphrase") :
131  i18n.tr("Enter passcode")
132 
133  property string customError
134  errorText: customError !== "" ? customError :
135  promptText !== "" ? i18n.tr("Sorry, incorrect %1").arg(promptText) :
136  alphaNumeric ? i18n.tr("Sorry, incorrect passphrase") + "\n" +
137  i18n.ctr("passphrase", "Please re-enter") :
138  i18n.tr("Sorry, incorrect passcode")
139 
140  onEntered: root.responded(passphrase)
141  onCancel: coverPage.show()
142  onEmergencyCall: root.emergencyCall()
143 
144  onEnabledChanged: {
145  if (enabled) {
146  lockscreen.forceActiveFocus();
147  }
148  }
149 
150  onVisibleChanged: {
151  if (visible) {
152  lockscreen.forceActiveFocus();
153  }
154  }
155 
156  function maybeShow() {
157  if (root.locked && !shown) {
158  showNow();
159  }
160  }
161  }
162 
163  Rectangle {
164  anchors.fill: parent
165  color: "black"
166  opacity: coverPage.showProgress * 0.8
167  }
168 
169  CoverPage {
170  id: coverPage
171  objectName: "coverPage"
172  height: parent.height
173  width: parent.width
174  background: root.background
175  draggable: !root.waiting
176  onTease: root.tease()
177  onClicked: hide()
178 
179  onShowProgressChanged: {
180  if (showProgress === 1) {
181  lockscreen.reset();
182  }
183 
184  if (showProgress === 0) {
185  if (root.locked) {
186  lockscreen.clear(false); // to reset focus if necessary
187  } else {
188  root.responded("");
189  }
190  }
191  }
192 
193  Clock {
194  anchors {
195  top: parent.top
196  topMargin: units.gu(2)
197  horizontalCenter: parent.horizontalCenter
198  }
199  }
200  }
201 }