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  Rectangle {
33  // In case background fails to load
34  id: backgroundBackup
35  anchors.fill: parent
36  color: "black"
37  }
38 
39  property url backgroundValue: AccountsService.backgroundFile != undefined && AccountsService.backgroundFile.length > 0 ? AccountsService.backgroundFile : greeter.defaultBackground
40  onBackgroundValueChanged: background.source = backgroundValue
41 
42  CrossFadeImage {
43  id: background
44  objectName: "greeterBackground"
45  anchors {
46  fill: parent
47  topMargin: backgroundTopMargin
48  }
49  fillMode: Image.PreserveAspectCrop
50  // Limit how much memory we'll reserve for this image
51  sourceSize.height: height
52  sourceSize.width: width
53  }
54 
55  // See Shell.qml's backgroundSettings treatment for why we need a separate
56  // Image, but it boils down to avoiding binding loop detection.
57  Image {
58  source: background.source
59  height: 0
60  width: 0
61  sourceSize.height: 0
62  sourceSize.width: 0
63  onStatusChanged: {
64  if (status == Image.Error && source != greeter.defaultBackground) {
65  background.source = greeter.defaultBackground
66  }
67  }
68  }
69 
70  Rectangle {
71  anchors.fill: parent
72  color: "black"
73  opacity: 0.4
74  }
75 
76  Loader {
77  id: loginLoader
78  objectName: "loginLoader"
79  anchors {
80  left: parent.left
81  leftMargin: Math.min(parent.width * 0.16, units.gu(20))
82  verticalCenter: parent.verticalCenter
83  }
84  width: units.gu(29)
85  height: parent.height
86 
87  // TODO: Once we have a system API for determining which mode we are
88  // in, tablet/phone/desktop, that should be used instead of narrowMode.
89  source: greeter.narrowMode ? "" : "LoginList.qml"
90 
91  onLoaded: {
92  item.currentIndex = greeterContentLoader.currentIndex;
93  }
94 
95  Binding {
96  target: loginLoader.item
97  property: "model"
98  value: greeterContentLoader.model
99  }
100 
101  Connections {
102  target: loginLoader.item
103 
104  onSelected: {
105  root.selected(uid);
106  }
107 
108  onUnlocked: {
109  root.unlocked(uid);
110  }
111 
112  onCurrentIndexChanged: {
113  if (greeterContentLoader.currentIndex !== loginLoader.item.currentIndex) {
114  greeterContentLoader.currentIndex = loginLoader.item.currentIndex;
115  }
116  }
117  }
118  }
119 
120  Infographics {
121  id: infographics
122  objectName: "infographics"
123  height: narrowMode ? parent.height : 0.75 * parent.height
124  model: greeterContentLoader.infographicModel
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  anchors {
142  verticalCenter: parent.verticalCenter
143  left: narrowMode ? root.left : loginLoader.right
144  right: root.right
145  }
146  }
147 
148  Clock {
149  id: clock
150  visible: narrowMode
151 
152  anchors {
153  top: parent.top
154  topMargin: units.gu(2)
155  horizontalCenter: parent.horizontalCenter
156  }
157  }
158 }