Tweaked layout
[quandoparte] / application / resources / sailfish / qml / pages / StationPage.qml
1 import QtQuick 2.0
2 import Sailfish.Silica 1.0
3 import net.cirulla.quandoparte 1.0
4 import "components"
5
6 Page {
7     property alias name: schedule.name
8     property alias code: schedule.code
9
10     SilicaFlickable {
11         id: view
12         anchors.fill: parent
13         PullDownMenu {
14             MenuItem {
15                 text: qsTr("Update Schedule")
16                 onClicked: updateStation()
17             }
18             MenuItem {
19                 text: qsTr("Departures")
20                 onClicked: schedule.type = StationScheduleModel.DepartureSchedule
21             }
22             MenuItem {
23                 text: qsTr("Arrivals")
24                 onClicked: schedule.type = StationScheduleModel.ArrivalSchedule
25             }
26         }
27         SilicaListView {
28             id: stationScheduleView
29             anchors.fill: parent
30             clip: true
31             visible: false
32             width: parent.width
33             cacheBuffer: 40
34             header: PageHeader {
35                     id: header
36                     title: (schedule.type === StationScheduleModel.DepartureSchedule ? qsTr("Departures from ") : qsTr("Arrivals to ")) + name
37                 }
38             model: schedule
39             delegate: StationScheduleDelegate {
40                 width: stationScheduleView.width
41                 type: schedule.type
42                 arrivalTime: model.arrivalTime
43                 departureTime: model.departureTime
44                 train: model.train
45                 arrivalStation: model.arrivalStation
46                 departureStation: model.departureStation
47                 delay: model.delay
48                 actualPlatform: model.actualPlatform
49                 expectedPlatfrom: model.expectedPlatform
50             }
51         }
52         BusyIndicator {
53             id: busyIndicator
54             anchors.centerIn: parent
55             running: visible
56             size: BusyIndicatorSize.Large
57         }
58         Item {
59             id: errorDisplay
60             anchors.centerIn: parent
61             Column {
62                 anchors.centerIn: parent
63                 spacing: Theme.paddingLarge
64                 Label {
65                     text: qsTr("Error!")
66                     width: parent.width
67                     font.pixelSize: Theme.fontSizeHuge
68                     horizontalAlignment: Text.AlignHCenter
69                 }
70                 Label {
71                     text: schedule.error
72                     width: parent.width
73                     font.pixelSize: Theme.fontSizeHuge
74                     horizontalAlignment: Text.AlignHCenter
75                 }
76             }
77         }
78         states: [
79             State {
80                 name: "loading"
81                 when: !completed
82                 PropertyChanges {
83                     target: stationScheduleView
84                     visible: false
85                 }
86                 PropertyChanges {
87                     target: errorDisplay
88                     visible: false
89                 }
90                 PropertyChanges {
91                     target: busyIndicator
92                     visible: true
93                 }
94             },
95             State {
96                 name: "ready"
97                 PropertyChanges {
98                     target: stationScheduleView
99                     visible: true
100                 }
101                 PropertyChanges {
102                     target: errorDisplay
103                     visible: false
104                 }
105                 PropertyChanges {
106                     target: busyIndicator
107                     visible: false
108                 }
109             },
110             State {
111                 name: "error"
112                 when: schedule.error
113                 PropertyChanges {
114                     target: stationScheduleView
115                     visible: false
116                 }
117                 PropertyChanges {
118                     target: errorDisplay
119                     visible: true
120                 }
121                 PropertyChanges {
122                     target: busyIndicator
123                     visible: false
124                 }
125             }
126         ]
127
128         function updateStation() {
129             view.state = "loading"
130             console.log("Updating station with " + schedule.name + ", " + schedule.code)
131             schedule.fetch(schedule.name, schedule.code)
132         }
133         StationScheduleModel {
134             id: schedule
135             onNameChanged: view.updateStation()
136             onLayoutChanged: if (error) view.state = "error"
137                              else view.state = "ready"
138         }
139
140         Component.onCompleted: {
141             updateTimer.triggered.connect(view.updateStation)
142             view.state = "loading"
143         }
144     }
145 }