2 * Copyright (C) 2015 Canonical, Ltd.
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.
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.
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/>.
18 import Ubuntu.Components 1.3
19 import Ubuntu.Components.ListItems 1.3
21 import "../Components"
25 objectName: "sessionsList"
27 signal sessionSelected(string sessionKey)
28 signal showLoginList()
30 // Sets the position of the background highlight
31 function updateHighlight(session) {
32 sessionsList.currentIndex = getIndexOfSession(session);
33 sessionsList.currentItem.initialSession = session;
36 function getIndexOfSession(session) {
37 for (var i = 0; i < sessionsList.model.count; i++) {
38 var key = sessionsList.model.get(i).key;
39 if (key === session) {
44 return 0; // Just choose the first session
47 function currentKey() {
48 var session = LightDMService.sessions.data(
49 sessionsList.currentIndex, LightDMService.sessionRoles.KeyRole)
53 Keys.onEnterPressed: {
54 sessionSelected(currentKey());
56 event.accepted = true;
59 Keys.onEscapePressed: {
61 event.accepted = true;
64 Keys.onReturnPressed: {
65 sessionSelected(currentKey());
67 event.accepted = true;
71 if (sessionsList.currentIndex < sessionsList.model.count - 1)
72 sessionsList.currentIndex++;
73 event.accepted = true;
77 if (sessionsList.currentIndex > 0)
78 sessionsList.currentIndex--;
79 event.accepted = true;
83 readonly property real margins: sessionsList.anchors.margins
84 readonly property real preferredHeight: {
85 if (sessionsList.currentItem) {
86 return (sessionsList.currentItem.height *
87 (1 + sessionsList.model.count)) + 2 * margins
89 return sessionsList.headerItem.height + 2 * margins
93 height: preferredHeight < parent.height ? preferredHeight : parent.height - units.gu(4)
99 verticalCenter: parent.verticalCenter
113 height: parent.height - units.gu(2.5)
114 boundsBehavior: Flickable.StopAtBounds
116 model: LightDMService.sessions
117 header: ListItemLayout {
120 padding.leading: 0 // handled by parent's margins
122 title.color: theme.palette.normal.raisedText
123 title.font.pixelSize: units.gu(2.1)
124 title.text: i18n.tr("Select desktop environment")
129 SlotsLayout.position: SlotsLayout.Leading
134 onClicked: showLoginList()
139 headerPositioning: ListView.OverlayHeader
141 // The highlighting is all self-managed, so account for that
142 highlightFollowsCurrentItem: false
143 highlight: QtObject {}
147 objectName: "sessionDelegate" + index
149 property string initialSession: ""
151 divider.visible: false
152 visible: y > sessionsList.headerItem.y
153 + sessionsList.headerItem.height
154 - sessionsList.anchors.margins
159 sessionsList.currentIndex = index
166 id: backgroundHighlight
168 height: sessionsList.currentItem.height
169 width: sessionsList.currentItem.width
170 color: theme.palette.normal.selection
172 visible: initialSession === key && !!key
176 height: parent.height
180 color: theme.palette.normal.focus
184 visible: index === sessionsList.currentIndex
190 readonly property color itemColor: theme.palette.normal.raisedText
194 SlotsLayout.position: SlotsLayout.Leading
195 color: parent.itemColor
199 title.color: itemColor