8ba29e476fcd63d460602d70054acf396e3cd4be
[quandoparte] / application / resources / harmattan / qml / StationPage.qml
1 import QtQuick 1.1
2 import com.nokia.meego 1.0
3 import net.cirulla.quandoparte 1.0
4 import "uiconstants.js" as UiConstants
5
6 Page {
7     property alias name: schedule.name
8     property alias code: schedule.code
9
10     tools: ToolBarLayout {
11         id: toolBar
12         ToolIcon { iconId: "icon-m-toolbar-back"; onClicked: pageStack.pop() }
13         ToolIcon { iconId: "icon-m-toolbar-refresh"; onClicked: updateStation() }
14         ToolIcon { iconId: "icon-m-toolbar-view-menu"; onClicked: menu.open() }
15     }
16     PageHeader {
17         id: header
18         anchors.top: parent.top
19         selectedIndex: schedule.type
20         options: [
21             qsTr("Departures"),
22             qsTr("Arrivals")
23         ]
24     }
25     InfoBar {
26         id: infoBar
27         anchors.top: header.bottom
28         text: parent.name
29     }
30     Binding {
31         target: schedule
32         property: "type"
33         value: header.selectedIndex
34     }
35     LabelStyle {
36         id: labelStyle
37     }
38     Item {
39         id: view
40         anchors {
41             top: infoBar.bottom
42             bottom: parent.bottom
43             left: parent.left
44             right: parent.right
45         }
46         DroppedShadow {
47             id: shadow
48             anchors.top: view.top
49         }
50         ListView {
51             id: stationScheduleView
52             clip: true
53             visible: false
54             width: parent.width
55             cacheBuffer: 10
56             anchors {
57                 top: shadow.top
58                 bottom: parent.bottom
59             }
60             model: schedule
61             delegate: StationScheduleDelegate {
62                 width: stationScheduleView.width
63                 type: schedule.type
64                 arrivalTime: model.arrivalTime
65                 departureTime: model.departureTime
66                 train: model.train
67                 arrivalStation: model.arrivalStation
68                 departureStation: model.departureStation
69                 delay: model.delay
70                 actualPlatform: model.actualPlatform
71                 expectedPlatfrom: model.expectedPlatform
72             }
73         }
74         ScrollDecorator {
75             id: decorator
76             flickableItem: stationScheduleView
77         }
78         BusyIndicator {
79             id: busyIndicator
80             platformStyle: BusyIndicatorStyle {
81                 size: "large"
82             }
83             anchors.centerIn: parent
84             running: visible
85         }
86         Item {
87             id: errorDisplay
88             anchors.centerIn: parent
89             Column {
90                 anchors.centerIn: parent
91                 spacing: UiConstants.DefaultMargin
92                 Text {
93                     text: qsTr("Error")
94                     font.pixelSize: UiConstants.HeaderFontPixelSize
95                     font.bold: UiConstants.HeaderFontBoldness
96                     horizontalAlignment: Text.AlignHCenter
97                 }
98                 Text {
99                     text: schedule.error
100                     font.pixelSize: UiConstants.DefaultFontBoldness
101                     font.bold: UiConstants.DefaultFontBoldness
102                     horizontalAlignment: Text.AlignHCenter
103                 }
104             }
105         }
106         states: [
107             State {
108                 name: "loading"
109                 when: !completed
110                 PropertyChanges {
111                     target: stationScheduleView
112                     visible: false
113                 }
114                 PropertyChanges {
115                     target: errorDisplay
116                     visible: false
117                 }
118                 PropertyChanges {
119                     target: busyIndicator
120                     visible: true
121                 }
122             },
123             State {
124                 name: "ready"
125                 PropertyChanges {
126                     target: stationScheduleView
127                     visible: true
128                 }
129                 PropertyChanges {
130                     target: errorDisplay
131                     visible: false
132                 }
133                 PropertyChanges {
134                     target: busyIndicator
135                     visible: false
136                 }
137             },
138             State {
139                 name: "error"
140                 when: schedule.error
141                 PropertyChanges {
142                     target: stationScheduleView
143                     visible: true
144                 }
145                 PropertyChanges {
146                     target: errorDisplay
147                     visible: false
148                 }
149                 PropertyChanges {
150                     target: busyIndicator
151                     visible: false
152                 }
153             }
154         ]
155     }
156     StationScheduleModel {
157         id: schedule
158         onNameChanged: updateStation()
159         onLayoutChanged: if (error) view.state = "error"
160                          else view.state = "ready"
161     }
162     Component.onCompleted: {
163         updateTimer.timeout.connect(updateStation)
164         view.state = "loading"
165     }
166     function updateStation() {
167         view.state = "loading"
168         console.log("Updating station with " + schedule.name + ", " + schedule.code)
169         schedule.fetch(schedule.name, schedule.code)
170     }
171 }