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 QtQuick.Window 2.2
19 import Ubuntu.Components 1.3
20 import Ubuntu.Telephony 0.1 as Telephony
21 import "../Components"
22 
23 FocusScope {
24  id: root
25 
26  property alias dragHandleLeftMargin: coverPage.dragHandleLeftMargin
27  property alias launcherOffset: coverPage.launcherOffset
28  property alias currentIndex: loginList.currentIndex
29  property alias delayMinutes: delayedLockscreen.delayMinutes
30  property alias backgroundTopMargin: coverPage.backgroundTopMargin
31  property url background
32  property bool hasCustomBackground
33  property bool locked
34  property alias alphanumeric: loginList.alphanumeric
35  property alias userModel: loginList.model
36  property alias infographicModel: coverPage.infographicModel
37  property string sessionToStart
38  property bool waiting
39  readonly property bool fullyShown: coverPage.showProgress === 1 || lockscreen.shown
40  readonly property bool required: coverPage.required || lockscreen.required
41  readonly property bool animating: coverPage.showAnimation.running || coverPage.hideAnimation.running
42 
43  // so that it can be replaced in tests with a mock object
44  property var inputMethod: Qt.inputMethod
45 
46  signal selected(int index)
47  signal responded(string response)
48  signal tease()
49  signal emergencyCall()
50 
51  function hide() {
52  lockscreen.hide();
53  coverPage.hide();
54  }
55 
56  function showFakePassword() {
57  loginList.showFakePassword();
58  }
59 
60  function notifyAuthenticationFailed() {
61  loginList.showError();
62  }
63 
64  function showErrorMessage(msg) {
65  coverPage.showErrorMessage(msg);
66  }
67 
68  function forceShow() {
69  coverPage.show();
70  }
71 
72  function tryToUnlock(toTheRight) {
73  var coverChanged = coverPage.shown;
74  lockscreen.maybeShow();
75  if (toTheRight) {
76  coverPage.hideRight();
77  } else {
78  coverPage.hide();
79  }
80  return coverChanged;
81  }
82 
83  onLockedChanged: {
84  if (locked) {
85  lockscreen.maybeShow();
86  } else {
87  lockscreen.hide();
88  }
89  }
90 
91  Showable {
92  id: lockscreen
93  objectName: "lockscreen"
94  anchors.fill: parent
95  shown: false
96  opacity: 0
97 
98  showAnimation: StandardAnimation { property: "opacity"; to: 1 }
99  hideAnimation: StandardAnimation { property: "opacity"; to: 0 }
100 
101  Wallpaper {
102  id: lockscreenBackground
103  objectName: "lockscreenBackground"
104  anchors {
105  fill: parent
106  topMargin: root.backgroundTopMargin
107  }
108  source: root.background
109  }
110 
111  // Darken background to match CoverPage
112  Rectangle {
113  objectName: "lockscreenShade"
114  anchors.fill: parent
115  color: "black"
116  opacity: root.hasCustomBackground ? 0.4 : 0
117  }
118 
119  LoginList {
120  id: loginList
121  objectName: "loginList"
122 
123  anchors {
124  horizontalCenter: parent.horizontalCenter
125  top: parent.top
126  bottom: parent.bottom
127  }
128  width: units.gu(40)
129  boxVerticalOffset: units.gu(14)
130  enabled: !coverPage.shown && visible
131  visible: !delayedLockscreen.visible
132 
133  locked: root.locked
134 
135  onSelected: if (enabled) root.selected(index)
136  onResponded: root.responded(response)
137  }
138 
139  DelayedLockscreen {
140  id: delayedLockscreen
141  objectName: "delayedLockscreen"
142  anchors.fill: parent
143  visible: delayMinutes > 0
144  alphaNumeric: loginList.alphanumeric
145  }
146 
147  function maybeShow() {
148  if (root.locked && !shown) {
149  showNow();
150  }
151  }
152  }
153 
154  Rectangle {
155  anchors.fill: parent
156  color: "black"
157  opacity: coverPage.showProgress * 0.8
158  }
159 
160  CoverPage {
161  id: coverPage
162  objectName: "coverPage"
163  height: parent.height
164  width: parent.width
165  background: root.background
166  hasCustomBackground: root.hasCustomBackground
167  draggable: !root.waiting
168  onTease: root.tease()
169  onClicked: hide()
170 
171  onShowProgressChanged: {
172  if (showProgress === 0) {
173  if (lockscreen.shown) {
174  loginList.tryToUnlock();
175  } else {
176  root.responded("");
177  }
178  }
179  }
180 
181  Clock {
182  anchors {
183  top: parent.top
184  topMargin: units.gu(2)
185  horizontalCenter: parent.horizontalCenter
186  }
187  }
188  }
189 
190  StyledItem {
191  id: bottomBar
192  visible: lockscreen.shown
193  height: units.gu(4)
194 
195  anchors.left: parent.left
196  anchors.right: parent.right
197  anchors.top: parent.bottom
198  anchors.topMargin: - height * (1 - coverPage.showProgress)
199  - (inputMethod && inputMethod.visible ?
200  inputMethod.keyboardRectangle.height : 0)
201 
202  Rectangle {
203  color: UbuntuColors.porcelain // matches OSK background
204  anchors.fill: parent
205  }
206 
207  Label {
208  text: i18n.tr("Cancel")
209  anchors.left: parent.left
210  anchors.leftMargin: units.gu(2)
211  anchors.top: parent.top
212  anchors.bottom: parent.bottom
213  verticalAlignment: Text.AlignVCenter
214  font.weight: Font.Light
215  fontSize: "small"
216  color: UbuntuColors.slate
217 
218  AbstractButton {
219  anchors.fill: parent
220  anchors.leftMargin: -units.gu(2)
221  anchors.rightMargin: -units.gu(2)
222  onClicked: coverPage.show()
223  }
224  }
225 
226  Label {
227  objectName: "emergencyCallLabel"
228  text: callManager.hasCalls ? i18n.tr("Return to Call") : i18n.tr("Emergency")
229  anchors.right: parent.right
230  anchors.rightMargin: units.gu(2)
231  anchors.top: parent.top
232  anchors.bottom: parent.bottom
233  verticalAlignment: Text.AlignVCenter
234  font.weight: Font.Light
235  fontSize: "small"
236  color: UbuntuColors.slate
237  // TODO: uncomment once bug 1616538 is fixed
238  // visible: telepathyHelper.ready && telepathyHelper.emergencyCallsAvailable
239  enabled: visible
240 
241  AbstractButton {
242  anchors.fill: parent
243  anchors.leftMargin: -units.gu(2)
244  anchors.rightMargin: -units.gu(2)
245  onClicked: root.emergencyCall()
246  }
247  }
248  }
249 
250  // FIXME: It's difficult to keep something tied closely to the OSK (bug
251  // 1616163). But as a hack to avoid the background peeking out,
252  // we add an extra Rectangle that just serves to hide the background
253  // during OSK animations.
254  Rectangle {
255  visible: bottomBar.visible
256  height: inputMethod && inputMethod.visible ?
257  inputMethod.keyboardRectangle.height : 0
258  anchors.bottom: parent.bottom
259  anchors.left: parent.left
260  anchors.right: parent.right
261  color: UbuntuColors.porcelain
262  }
263 }