~unity-team/unity8/dash-only

« back to all changes in this revision

Viewing changes to qml/Greeter/SessionsList.qml

  • Committer: Kevin Gunn
  • Date: 2016-10-24 19:51:33 UTC
  • Revision ID: kevin.gunn@canonical.com-20161024195133-61lwdzzdwsnue1mn
shave some more

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * Copyright (C) 2015 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.4
18
 
import Ubuntu.Components 1.3
19
 
import Ubuntu.Components.ListItems 1.3
20
 
import "." 0.1
21
 
import "../Components"
22
 
 
23
 
Item {
24
 
    id: root
25
 
    objectName: "sessionsList"
26
 
 
27
 
    property string initiallySelectedSession
28
 
    signal sessionSelected(string sessionKey)
29
 
    signal showLoginList()
30
 
 
31
 
    onInitiallySelectedSessionChanged: {
32
 
        sessionsList.currentIndex = getSelectedIndex();
33
 
        sessionsList.positionViewAtIndex(sessionsList.currentIndex, ListView.Contain);
34
 
    }
35
 
 
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) {
40
 
                return i;
41
 
            }
42
 
        }
43
 
    }
44
 
 
45
 
    function currentKey() {
46
 
        var session = LightDMService.sessions.data(
47
 
            sessionsList.currentIndex, LightDMService.sessionRoles.KeyRole)
48
 
        return session;
49
 
    }
50
 
 
51
 
    Keys.onEnterPressed: {
52
 
        showLoginList(); // Session is already selected
53
 
        event.accepted = true;
54
 
    }
55
 
 
56
 
    Keys.onEscapePressed: {
57
 
        showLoginList();
58
 
        event.accepted = true;
59
 
    }
60
 
 
61
 
    Keys.onReturnPressed: {
62
 
        showLoginList();
63
 
        event.accepted = true;
64
 
    }
65
 
 
66
 
    Keys.onDownPressed: {
67
 
        if (sessionsList.currentIndex < sessionsList.model.count - 1)
68
 
            sessionsList.currentIndex++;
69
 
        sessionSelected(currentKey());
70
 
        event.accepted = true;
71
 
    }
72
 
 
73
 
    Keys.onUpPressed: {
74
 
        if (sessionsList.currentIndex > 0)
75
 
            sessionsList.currentIndex--;
76
 
        sessionSelected(currentKey());
77
 
        event.accepted = true;
78
 
    }
79
 
 
80
 
    LoginAreaContainer {
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
86
 
            } else {
87
 
                return sessionsList.headerItem.height + 2 * margins
88
 
            }
89
 
        }
90
 
 
91
 
        height: prefferedHeight < parent.height ? prefferedHeight : parent.height - units.gu(4)
92
 
        width: parent.width
93
 
 
94
 
        anchors {
95
 
            left: parent.left
96
 
            right: parent.right
97
 
            verticalCenter: parent.verticalCenter
98
 
        }
99
 
 
100
 
        UbuntuListView {
101
 
            id: sessionsList
102
 
 
103
 
            anchors {
104
 
                top: parent.top
105
 
                left: parent.left
106
 
                right: parent.right
107
 
                margins: units.gu(2)
108
 
            }
109
 
 
110
 
            height: parent.height - headerItem.height
111
 
 
112
 
            boundsBehavior: Flickable.StopAtBounds
113
 
 
114
 
            model: LightDMService.sessions
115
 
            header: ListItemLayout {
116
 
                id: header
117
 
 
118
 
                padding.leading: 0 // handled by parent's margins
119
 
 
120
 
                title.color: theme.palette.normal.raisedText
121
 
                title.font.pixelSize: units.gu(2.1)
122
 
                title.text: i18n.tr("Select desktop environment")
123
 
 
124
 
                Icon {
125
 
                    id: icon
126
 
                    width: units.gu(3)
127
 
                    SlotsLayout.position: SlotsLayout.Leading
128
 
                    name: "go-previous"
129
 
 
130
 
                    MouseArea {
131
 
                        anchors.fill: parent
132
 
                        onClicked: showLoginList()
133
 
                    }
134
 
                }
135
 
            }
136
 
 
137
 
            headerPositioning: ListView.OverlayHeader
138
 
            highlightFollowsCurrentItem: false
139
 
 
140
 
            delegate: ListItem {
141
 
                id: delegate
142
 
                objectName: "sessionDelegate" + index
143
 
 
144
 
                divider.visible: false
145
 
 
146
 
                visible: y > sessionsList.headerItem.y
147
 
                + sessionsList.headerItem.height
148
 
                - sessionsList.anchors.margins
149
 
 
150
 
               MouseArea {
151
 
                    anchors.fill: parent
152
 
                    onClicked: {
153
 
                        sessionsList.currentIndex = index
154
 
                        sessionSelected(key)
155
 
                        showLoginList()
156
 
                    }
157
 
                }
158
 
 
159
 
                Rectangle {
160
 
                    height: parent.height
161
 
                    width: parent.width
162
 
                    color: "transparent"
163
 
                    border {
164
 
                        color: theme.palette.normal.focus
165
 
                        width: units.gu(0.2)
166
 
                    }
167
 
 
168
 
                    visible: index === sessionsList.currentIndex
169
 
                }
170
 
 
171
 
                ListItemLayout {
172
 
                    id: layout
173
 
 
174
 
                    SessionIcon {
175
 
                        id: sessionIcon
176
 
                        source: icon_url
177
 
                        SlotsLayout.position: SlotsLayout.Leading
178
 
                        color: theme.palette.normal.raisedSecondaryText
179
 
                    }
180
 
 
181
 
                    title.text: display
182
 
                    title.color: theme.palette.normal.raisedText
183
 
                }
184
 
            }
185
 
        }
186
 
    }
187
 
}