Unity 8
WideView.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 "." 0.1
20 
21 FocusScope {
22  id: root
23  focus: true
24 
25  property alias background: coverPage.background
26  property alias backgroundTopMargin: coverPage.backgroundTopMargin
27  property alias hasCustomBackground: coverPage.hasCustomBackground
28  property alias dragHandleLeftMargin: coverPage.dragHandleLeftMargin
29  property alias infographicModel: coverPage.infographicModel
30  property alias launcherOffset: coverPage.launcherOffset
31  property alias currentIndex: loginList.currentIndex
32  property int delayMinutes // TODO
33  property alias alphanumeric: loginList.alphanumeric
34  property alias locked: loginList.locked
35  property alias sessionToStart: loginList.currentSession
36  property alias waiting: loginList.waiting
37  property var userModel // Set from outside
38 
39  readonly property bool animating: coverPage.showAnimation.running || coverPage.hideAnimation.running
40  readonly property bool fullyShown: coverPage.showProgress === 1
41  readonly property bool required: coverPage.required
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() // unused
50 
51  function notifyAuthenticationFailed() {
52  loginList.showError();
53  }
54 
55  function reset(forceShow) {
56  loginList.reset();
57  }
58 
59  function showMessage(html) {
60  loginList.showMessage(html);
61  }
62 
63  function showPrompt(text, isSecret, isDefaultPrompt) {
64  loginList.showPrompt(text, isSecret, isDefaultPrompt);
65  }
66 
67  function tryToUnlock(toTheRight) {
68  if (root.locked) {
69  coverPage.show();
70  loginList.tryToUnlock();
71  return false;
72  } else {
73  var coverChanged = coverPage.shown;
74  if (toTheRight) {
75  coverPage.hideRight();
76  } else {
77  coverPage.hide();
78  }
79  return coverChanged;
80  }
81  }
82 
83  function hide() {
84  coverPage.hide();
85  }
86 
87  function notifyAuthenticationSucceeded(showFakePassword) {
88  if (showFakePassword) {
89  loginList.showFakePassword();
90  }
91  }
92 
93  function showLastChance() {
94  // TODO
95  }
96 
97  Rectangle {
98  anchors.fill: parent
99  color: "black"
100  opacity: coverPage.showProgress * 0.8
101  }
102 
103  CoverPage {
104  id: coverPage
105  objectName: "coverPage"
106  height: parent.height
107  width: parent.width
108  draggable: !root.locked && !root.waiting
109  state: "LoginList"
110 
111  infographics {
112  height: 0.75 * parent.height
113  anchors.leftMargin: loginList.x + loginList.width
114  }
115 
116  onTease: root.tease()
117 
118  onShowProgressChanged: {
119  if (showProgress === 0 && !root.locked) {
120  root.responded("");
121  }
122  }
123 
124  LoginList {
125  id: loginList
126  objectName: "loginList"
127 
128  property int selectedUserIndex: 0
129 
130  width: units.gu(40)
131  anchors {
132  left: parent.left
133  leftMargin: Math.min(parent.width * 0.16, units.gu(20))
134  top: parent.top
135  bottom: parent.bottom
136  }
137 
138  boxVerticalOffset: (height - highlightedHeight -
139  (inputMethod && inputMethod.visible ?
140  inputMethod.keyboardRectangle.height : 0)) / 2
141  Behavior on boxVerticalOffset { UbuntuNumberAnimation {} }
142 
143  model: root.userModel
144  currentSession: LightDMService.users.data(selectedUserIndex, LightDMService.userRoles.SessionRole);
145  onResponded: root.responded(response)
146  onSelected: {
147  root.selected(index)
148  loginList.selectedUserIndex = index;
149  }
150  onSessionChooserButtonClicked: parent.state = "SessionsList"
151 
152  Keys.forwardTo: [sessionChooserLoader.item]
153  }
154 
155  Loader {
156  id: sessionChooserLoader
157 
158  height: loginList.height
159  width: loginList.width
160  anchors {
161  left: parent.left
162  leftMargin: Math.min(parent.width * 0.16, units.gu(20))
163  top: parent.top
164  }
165 
166  active: false
167 
168  onLoaded: sessionChooserLoader.item.forceActiveFocus();
169  Binding {
170  target: sessionChooserLoader.item
171  property: "initiallySelectedSession"
172  value: loginList.currentSession
173  }
174 
175  Connections {
176  target: sessionChooserLoader.item
177  onSessionSelected: loginList.currentSession = sessionKey
178  onShowLoginList: {
179  coverPage.state = "LoginList"
180  loginList.passwordInput.forceActiveFocus();
181  }
182  ignoreUnknownSignals: true
183  }
184  }
185 
186  states: [
187  State {
188  name: "SessionsList"
189  PropertyChanges { target: loginList; opacity: 0 }
190  PropertyChanges { target: sessionChooserLoader;
191  active: true;
192  opacity: 1
193  source: "SessionsList.qml"
194  }
195  },
196 
197  State {
198  name: "LoginList"
199  PropertyChanges { target: loginList; opacity: 1 }
200  PropertyChanges { target: sessionChooserLoader;
201  active: false;
202  opacity: 0
203  source: "";
204  }
205  }
206  ]
207 
208  transitions: [
209  Transition {
210  from: "*"
211  to: "*"
212  UbuntuNumberAnimation {
213  property: "opacity";
214  }
215  }
216  ]
217  }
218 }