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
property string initiallySelectedSession
28
signal sessionSelected(string sessionKey)
29
signal showLoginList()
31
onInitiallySelectedSessionChanged: {
32
sessionsList.currentIndex = getSelectedIndex();
33
sessionsList.positionViewAtIndex(sessionsList.currentIndex, ListView.Contain);
36
function getSelectedIndex() {
37
for (var i = 0; i < sessionsList.model.count; i++) {
38
var key = sessionsList.model.get(i).key
39
if (key === initiallySelectedSession) {
45
function currentKey() {
46
var session = LightDMService.sessions.data(
47
sessionsList.currentIndex, LightDMService.sessionRoles.KeyRole)
51
Keys.onEnterPressed: {
52
showLoginList(); // Session is already selected
53
event.accepted = true;
56
Keys.onEscapePressed: {
58
event.accepted = true;
61
Keys.onReturnPressed: {
63
event.accepted = true;
67
if (sessionsList.currentIndex < sessionsList.model.count - 1)
68
sessionsList.currentIndex++;
69
sessionSelected(currentKey());
70
event.accepted = true;
74
if (sessionsList.currentIndex > 0)
75
sessionsList.currentIndex--;
76
sessionSelected(currentKey());
77
event.accepted = true;
81
readonly property real margins: sessionsList.anchors.margins
82
readonly property real prefferedHeight: {
83
if (sessionsList.currentItem) {
84
return (sessionsList.currentItem.height *
85
(1 + sessionsList.model.count)) + 2 * margins
87
return sessionsList.headerItem.height + 2 * margins
91
height: prefferedHeight < parent.height ? prefferedHeight : parent.height - units.gu(4)
97
verticalCenter: parent.verticalCenter
110
height: parent.height - headerItem.height
112
boundsBehavior: Flickable.StopAtBounds
114
model: LightDMService.sessions
115
header: ListItemLayout {
118
padding.leading: 0 // handled by parent's margins
120
title.color: theme.palette.normal.raisedText
121
title.font.pixelSize: units.gu(2.1)
122
title.text: i18n.tr("Select desktop environment")
127
SlotsLayout.position: SlotsLayout.Leading
132
onClicked: showLoginList()
137
headerPositioning: ListView.OverlayHeader
138
highlightFollowsCurrentItem: false
142
objectName: "sessionDelegate" + index
144
divider.visible: false
146
visible: y > sessionsList.headerItem.y
147
+ sessionsList.headerItem.height
148
- sessionsList.anchors.margins
153
sessionsList.currentIndex = index
160
height: parent.height
164
color: theme.palette.normal.focus
168
visible: index === sessionsList.currentIndex
177
SlotsLayout.position: SlotsLayout.Leading
178
color: theme.palette.normal.raisedSecondaryText
182
title.color: theme.palette.normal.raisedText