Unity 8
GreeterContent.qml
1 /*
2  * Copyright (C) 2013 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.0
18 import AccountsService 0.1
19 import Ubuntu.Components 0.1
20 import LightDM 0.1 as LightDM
21 import "../Components"
22 
23 Item {
24  id: root
25  anchors.fill: parent
26 
27  property var inputMethod
28 
29  property bool ready: background.source == "" || background.status == Image.Ready || background.status == Image.Error
30 
31  signal selected(int uid)
32  signal unlocked(int uid)
33 
34  function tryToUnlock() {
35  if (loginLoader.item) {
36  loginLoader.item.tryToUnlock()
37  }
38  }
39 
40  function reset() {
41  if (loginLoader.item) {
42  loginLoader.item.reset()
43  }
44  }
45 
46  Rectangle {
47  // In case background fails to load
48  id: backgroundBackup
49  anchors.fill: parent
50  color: "black"
51  }
52 
53  CrossFadeImage {
54  id: background
55  objectName: "greeterBackground"
56  anchors {
57  fill: parent
58  topMargin: backgroundTopMargin
59  }
60  fillMode: Image.PreserveAspectCrop
61  // Limit how much memory we'll reserve for this image
62  sourceSize.height: height
63  sourceSize.width: width
64  source: greeter.background
65  }
66 
67  Rectangle {
68  anchors.fill: parent
69  color: "black"
70  opacity: 0.4
71  }
72 
73  Loader {
74  id: loginLoader
75  objectName: "loginLoader"
76  anchors {
77  left: parent.left
78  leftMargin: Math.min(parent.width * 0.16, units.gu(20))
79  top: parent.top
80  }
81  width: units.gu(29)
82  height: inputMethod && inputMethod.visible ? parent.height - inputMethod.keyboardRectangle.height
83  : parent.height
84  Behavior on height { UbuntuNumberAnimation {} }
85 
86  // TODO: Once we have a system API for determining which mode we are
87  // in, tablet/phone/desktop, that should be used instead of narrowMode.
88  source: greeter.narrowMode ? "" : "LoginList.qml"
89 
90  onLoaded: {
91  item.currentIndex = greeterContentLoader.currentIndex;
92  }
93 
94  Binding {
95  target: loginLoader.item
96  property: "model"
97  value: greeterContentLoader.model
98  }
99 
100  Connections {
101  target: loginLoader.item
102 
103  onSelected: {
104  root.selected(uid);
105  }
106 
107  onUnlocked: {
108  root.unlocked(uid);
109  }
110 
111  onCurrentIndexChanged: {
112  if (greeterContentLoader.currentIndex !== loginLoader.item.currentIndex) {
113  greeterContentLoader.currentIndex = loginLoader.item.currentIndex;
114  }
115  }
116  }
117  }
118 
119  Infographics {
120  id: infographics
121  objectName: "infographics"
122  height: narrowMode ? parent.height : 0.75 * parent.height
123  model: greeterContentLoader.infographicModel
124  clip: true // clip large data bubbles
125 
126  property string selectedUser
127  property string infographicUser: AccountsService.statsWelcomeScreen ? selectedUser : ""
128  onInfographicUserChanged: greeterContentLoader.infographicModel.username = infographicUser
129 
130  Component.onCompleted: {
131  selectedUser = greeterContentLoader.model.data(greeterContentLoader.currentIndex, LightDM.UserRoles.NameRole)
132  greeterContentLoader.infographicModel.username = infographicUser
133  greeterContentLoader.infographicModel.readyForDataChange()
134  }
135 
136  Connections {
137  target: root
138  onSelected: infographics.selectedUser = greeterContentLoader.model.data(uid, LightDM.UserRoles.NameRole)
139  }
140 
141  Connections {
142  target: i18n
143  onLanguageChanged: greeterContentLoader.infographicModel.readyForDataChange()
144  }
145 
146  anchors {
147  verticalCenter: parent.verticalCenter
148  left: narrowMode ? root.left : loginLoader.right
149  right: root.right
150  }
151  }
152 
153  Clock {
154  id: clock
155  visible: narrowMode
156 
157  anchors {
158  top: parent.top
159  topMargin: units.gu(2)
160  horizontalCenter: parent.horizontalCenter
161  }
162  }
163 }