Add support for displaying realtime results + refreshing
[pywienerlinien] / qml / ResultRealtime.qml
1 import QtQuick 1.1
2 import com.nokia.meego 1.0
3 import com.nokia.extras 1.0
4 import "UIConstants.js" as UIConstants
5 import "ExtrasConstants.js" as ExtrasConstants
6
7 Item {
8     id: resultRealtime
9
10     property string gline: ''
11     property string gstation: ''
12     property string gdirection: ''
13
14     property string sourceUrl: ''
15     property bool busy: true
16
17     function refresh() {
18         busy = true
19         itip.load_departures(sourceUrl)
20         console.log('refreshing')
21     }
22
23     onSourceUrlChanged: {
24         refresh()
25         console.log('source url changed: ' + sourceUrl)
26     }
27
28     Connections {
29         target: itip
30
31         onDeparturesLoaded: {
32             busy = false
33             departuresModel.clear()
34
35             var departures = itip.get_departures()
36
37             for (var d in departures) {
38                 console.log('departure: ' + departures[d])
39                 // XXX: destination might be wrong?!
40                 var row = {'line': resultRealtime.gline, 'station': resultRealtime.gstation, 'destination': gdirection, 'departure': departures[d]}
41                 console.log('inserting: ' + row)
42                 departuresModel.append(row)
43             }
44         }
45     }
46
47     Component {
48          id: departureDelegate
49
50          Item {
51              width: parent.width
52              height: 80
53
54              BorderImage {
55                  anchors.fill: parent
56                  visible: mouseArea.pressed
57                  source: theme.inverted ? 'image://theme/meegotouch-list-inverted-background-pressed-vertical-center': 'image://theme/meegotouch-list-background-pressed-vertical-center'
58              }
59
60              Item {
61                  anchors.fill: parent
62                  anchors.margins: UIConstants.DEFAULT_MARGIN
63
64                  Row {
65                      Text {
66                          id: l
67                          text: line // <----
68                          anchors.verticalCenter: parent.verticalCenter
69                          width: 70
70                          font.pixelSize: UIConstants.FONT_XLARGE
71                          font.bold: true
72                          font.family: ExtrasConstants.FONT_FAMILY_LIGHT
73                          color: !theme.inverted ? UIConstants.COLOR_FOREGROUND : UIConstants.COLOR_INVERTED_FOREGROUND
74                      }
75
76                      Column {
77                          anchors.verticalCenter: parent.verticalCenter
78
79                          Text {
80                              id: s
81                              text: station // <----
82                              width: 75
83                              font.pixelSize: UIConstants.FONT_LARGE
84                              font.family: ExtrasConstants.FONT_FAMILY_LIGHT
85                              color: !theme.inverted ? UIConstants.COLOR_FOREGROUND : UIConstants.COLOR_INVERTED_FOREGROUND
86                          }
87
88                          Text {
89                              id: d
90                              text: destination // <----
91                              color: !theme.inverted ? UIConstants.COLOR_SECONDARY_FOREGROUND : UIConstants.COLOR_INVERTED_SECONDARY_FOREGROUND
92                              font.family: ExtrasConstants.FONT_FAMILY_LIGHT
93                              font.pixelSize: UIConstants.FONT_LSMALL
94                          }
95                      }
96                  }
97              }
98
99              Column {
100                  anchors.right: parent.right
101                  anchors.verticalCenter: parent.verticalCenter
102                  Text {
103                      id: dep
104                      // FIXME strange int float transformation appears
105                      text: departure
106                      anchors.right: parent.right
107                      anchors.rightMargin: UIConstants.DEFAULT_MARGIN
108                      font.bold: true
109                      font.pixelSize: UIConstants.FONT_XLARGE
110                      font.family: ExtrasConstants.FONT_FAMILY_LIGHT
111                      color: !theme.inverted ? UIConstants.COLOR_FOREGROUND : UIConstants.COLOR_INVERTED_FOREGROUND
112                  }
113              }
114
115              MouseArea {
116                  id: mouseArea
117                  anchors.fill: parent
118                  onClicked: {
119                      console.debug("clicked: " + l.text)
120                  }
121              }
122          }
123      }
124
125      ListView {
126          id: list
127          width: parent.width; height: parent.height
128
129          header: Rectangle {
130              width: parent.width
131              height: childrenRect.height + 2*UIConstants.DEFAULT_MARGIN
132              color: "lightsteelblue"
133
134              Text {
135                  anchors {
136                      top: parent.top
137                      left: parent.left
138                      right: parent.right
139                      margins: UIConstants.DEFAULT_MARGIN
140                  }
141
142                  text: 'Abfahrten Richtung ' + gdirection
143                  elide: Text.ElideRight
144                  font.bold: true
145                  font.family: ExtrasConstants.FONT_FAMILY_LIGHT
146                  font.pixelSize: UIConstants.FONT_LSMALL
147              }
148          }
149
150          model: ListModel {
151              id: departuresModel
152 /*
153             ListElement {
154                 line: "N60"
155                 station: "Schottentor"
156                 destination: "Maurer Hauptplatz"
157                 departure: 5
158             }
159             ListElement {
160                 line: "N38"
161                 station: "Schottentor"
162                 destination: "Grinzing"
163                 departure: 7
164             }*/
165          }
166          delegate: departureDelegate
167
168          visible: !resultRealtime.busy && resultRealtime.sourceUrl != ''
169      }
170
171      ScrollDecorator {
172          id: scrolldecorator
173          flickableItem: list
174          platformStyle: ScrollDecoratorStyle {}
175      }
176
177      BusyIndicator {
178          id: busyIndicator
179          visible: resultRealtime.busy && resultRealtime.sourceUrl != ''
180          running: visible
181          platformStyle: BusyIndicatorStyle { size: 'large' }
182          anchors.centerIn: parent
183      }
184 }