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