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