on a8aed54 help sign in
unity8/qml/Greeter/GreeterContent.qml
170 lines 5.1 kB history raw
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 */
17import QtQuick 2.0
18import AccountsService 0.1
19import Ubuntu.Components 0.1
20import LightDM 0.1 as LightDM
21import "../Components"
23Item {
24 id: root
25 anchors.fill: parent
27 property bool ready: background.source == "" || background.status == Image.Ready || background.status == Image.Error
29 signal selected(int uid)
30 signal unlocked(int uid)
32 function tryToUnlock() {
33 if (loginLoader.item) {
34 loginLoader.item.tryToUnlock()
35 }
36 }
38 function reset() {
39 if (loginLoader.item) {
40 loginLoader.item.reset()
41 }
42 }
44 Rectangle {
45 // In case background fails to load
46 id: backgroundBackup
47 anchors.fill: parent
48 color: "black"
49 }
51 property url backgroundValue: AccountsService.backgroundFile != undefined && AccountsService.backgroundFile.length > 0 ? AccountsService.backgroundFile : greeter.defaultBackground
52 onBackgroundValueChanged: background.source = backgroundValue
54 CrossFadeImage {
55 id: background
56 objectName: "greeterBackground"
57 anchors {
58 fill: parent
59 topMargin: backgroundTopMargin
60 }
61 fillMode: Image.PreserveAspectCrop
62 // Limit how much memory we'll reserve for this image
63 sourceSize.height: height
64 sourceSize.width: width
65 }
67 // See Shell.qml's backgroundSettings treatment for why we need a separate
68 // Image, but it boils down to avoiding binding loop detection.
69 Image {
70 source: background.source
71 height: 0
72 width: 0
73 sourceSize.height: 0
74 sourceSize.width: 0
75 onStatusChanged: {
76 if (status == Image.Error && source != greeter.defaultBackground) {
77 background.source = greeter.defaultBackground
78 }
79 }
80 }
82 Rectangle {
83 anchors.fill: parent
84 color: "black"
85 opacity: 0.4
86 }
88 Loader {
89 id: loginLoader
90 objectName: "loginLoader"
91 anchors {
92 left: parent.left
93 leftMargin: Math.min(parent.width * 0.16, units.gu(20))
94 verticalCenter: parent.verticalCenter
95 }
96 width: units.gu(29)
97 height: parent.height
99 // TODO: Once we have a system API for determining which mode we are
100 // in, tablet/phone/desktop, that should be used instead of narrowMode.
101 source: greeter.narrowMode ? "" : "LoginList.qml"
103 onLoaded: {
104 item.currentIndex = greeterContentLoader.currentIndex;
105 }
107 Binding {
108 target: loginLoader.item
109 property: "model"
110 value: greeterContentLoader.model
111 }
113 Connections {
114 target: loginLoader.item
116 onSelected: {
117 root.selected(uid);
118 }
120 onUnlocked: {
121 root.unlocked(uid);
122 }
124 onCurrentIndexChanged: {
125 if (greeterContentLoader.currentIndex !== loginLoader.item.currentIndex) {
126 greeterContentLoader.currentIndex = loginLoader.item.currentIndex;
127 }
128 }
129 }
130 }
132 Infographics {
133 id: infographics
134 objectName: "infographics"
135 height: narrowMode ? parent.height : 0.75 * parent.height
136 model: greeterContentLoader.infographicModel
138 property string selectedUser
139 property string infographicUser: AccountsService.statsWelcomeScreen ? selectedUser : ""
140 onInfographicUserChanged: greeterContentLoader.infographicModel.username = infographicUser
142 Component.onCompleted: {
143 selectedUser = greeterContentLoader.model.data(greeterContentLoader.currentIndex, LightDM.UserRoles.NameRole)
144 greeterContentLoader.infographicModel.username = infographicUser
145 greeterContentLoader.infographicModel.readyForDataChange()
146 }
148 Connections {
149 target: root
150 onSelected: infographics.selectedUser = greeterContentLoader.model.data(uid, LightDM.UserRoles.NameRole)
151 }
153 anchors {
154 verticalCenter: parent.verticalCenter
155 left: narrowMode ? root.left : loginLoader.right
156 right: root.right
157 }
158 }
160 Clock {
161 id: clock
162 visible: narrowMode
164 anchors {
165 top: parent.top
166 topMargin: units.gu(2)
167 horizontalCenter: parent.horizontalCenter
168 }
169 }