show restart notification after db update
[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     property bool isStation: false
17
18     function refresh() {
19         busy = true
20         console.log('refreshing')
21
22         if (isStation) {
23             console.log('station based')
24             itip.load_station_departures(gstation)
25         } else {
26             console.log('one line')
27             itip.load_departures(sourceUrl)
28         }
29     }
30
31     function isCorrectInput () {
32         return resultRealtime.sourceUrl != '' || (resultRealtime.isStation && resultRealtime.gstation != '')
33     }
34
35     onGstationChanged: {
36         refresh()
37     }
38
39     Connections {
40         target: itip
41
42         onDeparturesLoaded: {
43             busy = false
44             departuresModel.clear()
45
46             var departures = itip.get_departures()
47
48             for (var d in departures) {
49                 console.log('time: ' + departures[d].time)
50                 var row = {'line': departures[d].line, 'station': departures[d].station, 'destination': departures[d].direction, 'departure': departures[d].time, 'lowfloor': departures[d].lowfloor}
51                 departuresModel.append(row)
52             }
53         }
54     }
55
56     Component {
57         id: departureDelegate
58
59         Item {
60             width: parent.width
61             height: 80
62
63             BorderImage {
64                 anchors.fill: parent
65                 visible: mouseArea.pressed
66                 source: theme.inverted ? 'image://theme/meegotouch-list-inverted-background-pressed-vertical-center': 'image://theme/meegotouch-list-background-pressed-vertical-center'
67             }
68
69             Item {
70                 anchors.fill: parent
71                 anchors.margins: UIConstants.DEFAULT_MARGIN
72
73                 Row {
74                     spacing: 10
75                     Text {
76                         id: l
77                         text: line // <----
78                         anchors.verticalCenter: parent.verticalCenter
79                         //width: 70
80                         font.pixelSize: UIConstants.FONT_XLARGE
81                         font.bold: true
82                         font.family: ExtrasConstants.FONT_FAMILY_LIGHT
83                         color: !theme.inverted ? UIConstants.COLOR_FOREGROUND : UIConstants.COLOR_INVERTED_FOREGROUND
84                     }
85
86                     Column {
87                         anchors.verticalCenter: parent.verticalCenter
88
89                         Text {
90                             id: s
91                             text: station // <----
92                             width: parent.parent.parent.width - l.width - dep.width - 15
93                             elide: Text.ElideRight
94                             font.pixelSize: UIConstants.FONT_LARGE
95                             font.family: ExtrasConstants.FONT_FAMILY_LIGHT
96                             color: !theme.inverted ? UIConstants.COLOR_FOREGROUND : UIConstants.COLOR_INVERTED_FOREGROUND
97                         }
98
99                         Text {
100                             id: d
101                             text: destination // <----
102                             width: parent.parent.parent.width - l.width - dep.width - 15
103                             elide: Text.ElideRight
104                             color: !theme.inverted ? UIConstants.COLOR_SECONDARY_FOREGROUND : UIConstants.COLOR_INVERTED_SECONDARY_FOREGROUND
105                             font.family: ExtrasConstants.FONT_FAMILY_LIGHT
106                             font.pixelSize: UIConstants.FONT_LSMALL
107                         }
108                     }
109                 }
110             }
111
112             Column {
113                 anchors.right: parent.right
114                 anchors.verticalCenter: parent.verticalCenter
115                 Text {
116                     id: dep
117                     // FIXME strange int float transformation appears
118                     text: departure
119                     anchors.right: parent.right
120                     anchors.rightMargin: UIConstants.DEFAULT_MARGIN
121                     font.italic: lowfloor == 1
122                     font.bold: true
123                     font.pixelSize: UIConstants.FONT_XLARGE
124                     font.family: ExtrasConstants.FONT_FAMILY_LIGHT
125                     color: !theme.inverted ? UIConstants.COLOR_FOREGROUND : UIConstants.COLOR_INVERTED_FOREGROUND
126                 }
127             }
128
129             MouseArea {
130                 id: mouseArea
131                 anchors.fill: parent
132                 onClicked: {
133                     console.debug("clicked: " + l.text)
134                 }
135             }
136         }
137     }
138
139     ListView {
140         id: list
141         width: parent.width; height: parent.height
142
143         header: Rectangle {
144             width: parent.width
145             height: childrenRect.height + 2*UIConstants.DEFAULT_MARGIN
146             color: "lightsteelblue"
147             radius: 5.0
148             smooth: true
149
150             Text {
151                 id: header
152
153                 anchors {
154                     top: parent.top
155                     left: parent.left
156                     right: parent.right
157                     margins: UIConstants.DEFAULT_MARGIN
158                 }
159
160                 text: 'Richtung ' + gdirection
161                 elide: Text.ElideRight
162                 font.bold: true
163                 font.family: ExtrasConstants.FONT_FAMILY_LIGHT
164                 font.pixelSize: UIConstants.FONT_LSMALL
165             }
166         }
167
168         model: ListModel {
169             id: departuresModel
170         }
171         delegate: departureDelegate
172
173         visible: !resultRealtime.busy && isCorrectInput()
174     }
175
176     ScrollDecorator {
177         id: scrolldecorator
178         flickableItem: list
179         platformStyle: ScrollDecoratorStyle {}
180     }
181
182     BusyIndicator {
183         id: busyIndicator
184         visible: resultRealtime.busy && isCorrectInput()
185         running: visible
186         platformStyle: BusyIndicatorStyle { size: 'large' }
187         anchors.centerIn: parent
188     }
189 }