Unity 8
NarrowView.qml
1 /*
2  * Copyright (C) 2015 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.3
18 import Ubuntu.Components 1.1
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  readonly property bool fullyShown: coverPage.showProgress === 1 || lockscreen.shown
35  readonly property bool required: coverPage.required || lockscreen.required
36 
37  signal selected(int index) // unused
38  signal responded(string response)
39  signal tease()
40  signal emergencyCall()
41 
42  function showMessage(html) {
43  // TODO
44  }
45 
46  function showPrompt(text, isSecret, isDefaultPrompt) {
47  lockscreen.promptText = isDefaultPrompt ? "" : text.toLowerCase();
48  lockscreen.maybeShow();
49  }
50 
51  function showLastChance() {
52  var title = lockscreen.alphaNumeric ?
53  i18n.tr("Sorry, incorrect passphrase.") :
54  i18n.tr("Sorry, incorrect passcode.");
55  var text = i18n.tr("This will be your last attempt.") + " " +
56  (lockscreen.alphaNumeric ?
57  i18n.tr("If passphrase is entered incorrectly, your phone will conduct a factory reset and all personal data will be deleted.") :
58  i18n.tr("If passcode is entered incorrectly, your phone will conduct a factory reset and all personal data will be deleted."));
59  lockscreen.showInfoPopup(title, text);
60  }
61 
62  function hide() {
63  lockscreen.hide();
64  coverPage.hide();
65  }
66 
67  function notifyAuthenticationSucceeded() {
68  lockscreen.hide();
69  }
70 
71  function notifyAuthenticationFailed() {
72  lockscreen.clear(true);
73  }
74 
75  function reset() {
76  coverPage.show();
77  }
78 
79  function tryToUnlock(toTheRight) {
80  var coverChanged = coverPage.shown;
81  lockscreen.maybeShow();
82  if (toTheRight) {
83  coverPage.hideRight();
84  } else {
85  coverPage.hide();
86  }
87  return coverChanged;
88  }
89 
90  onLockedChanged: {
91  if (locked) {
92  lockscreen.maybeShow();
93  } else {
94  lockscreen.hide();
95  }
96  }
97 
98  Lockscreen {
99  id: lockscreen
100  objectName: "lockscreen"
101 
102  shown: false
103  showAnimation: StandardAnimation { property: "opacity"; to: 1 }
104  hideAnimation: StandardAnimation { property: "opacity"; to: 0 }
105  anchors.fill: parent
106  visible: required
107  enabled: !coverPage.shown
108  background: root.background
109  darkenBackground: 0.4
110  alphaNumeric: root.alphanumeric
111  minPinLength: 4
112  maxPinLength: 4
113 
114  property string promptText
115  infoText: promptText !== "" ? i18n.tr("Enter %1").arg(promptText) :
116  alphaNumeric ? i18n.tr("Enter passphrase") :
117  i18n.tr("Enter passcode")
118  errorText: promptText !== "" ? i18n.tr("Sorry, incorrect %1").arg(promptText) :
119  alphaNumeric ? i18n.tr("Sorry, incorrect passphrase") + "\n" +
120  i18n.tr("Please re-enter") :
121  i18n.tr("Sorry, incorrect passcode")
122 
123  onEntered: root.responded(passphrase)
124  onCancel: coverPage.show()
125  onEmergencyCall: root.emergencyCall()
126 
127  function maybeShow() {
128  if (root.locked && !shown) {
129  showNow();
130  }
131  }
132  }
133 
134  Rectangle {
135  anchors.fill: parent
136  color: "black"
137  opacity: coverPage.showProgress * 0.8
138  }
139 
140  CoverPage {
141  id: coverPage
142  objectName: "coverPage"
143  height: parent.height
144  width: parent.width
145  background: root.background
146  onTease: root.tease()
147 
148  onShowProgressChanged: {
149  if (showProgress === 1) {
150  lockscreen.reset();
151  }
152 
153  if (showProgress === 0) {
154  if (root.locked) {
155  lockscreen.clear(false); // to reset focus if necessary
156  } else {
157  root.responded("");
158  }
159  }
160  }
161 
162  Clock {
163  anchors {
164  top: parent.top
165  topMargin: units.gu(2)
166  horizontalCenter: parent.horizontalCenter
167  }
168  }
169  }
170 }