fixing routing.py bug, if time is 24:00
[pywienerlinien] / qml / MainPage.qml
1 import QtQuick 1.1
2 import com.nokia.meego 1.0
3 import QtMobility.location 1.1
4
5 import "UIConstants.js" as UIConstants
6 import "ExtrasConstants.js" as ExtrasConstants
7
8 Page {
9     tools: commonTools
10     orientationLock: PageOrientation.LockPortrait
11
12     property bool canRefresh: realtimeResult.sourceUrl != '' || (realtimeResult.isStation && realtimeResult.gstation != '')
13     //property alias stationSelect: stationSelector
14     property variant nearbyStations
15
16     function showFavorites() {
17         favSelector.model.clear();
18         for (var i=0; i<favManager.getCount(); i++) {
19             var data = eval('(' + favManager.getItem(i) + ')');
20             favSelector.model.append(data);
21         }
22         favSelector.model.sync();
23         favSelector.open();
24     }
25
26     function search() {
27         lineSearchButton.clicked()
28     }
29
30     function refresh() {
31         realtimeResult.refresh()
32     }
33
34     function fillNearbyStations(lat, lon) {
35         nearbyStations = itip.get_nearby_stations(lat, lon)
36     }
37
38     function showNearby() {
39         console.log("show nearby")
40
41         var stations = nearbyStations;
42         stationSelectorModel.clear();
43         for (var idx in stations) {
44             stationSelectorModel.append({'name': stations[idx]});
45         }
46
47         stationSelector.open();
48     }
49
50     Text {
51         visible: !parent.canRefresh
52         anchors.centerIn: parent
53         font.pixelSize: 30
54         text: '<p><strong>Welcome, traveller!<br></strong></p><p>Press <img src="image://theme/icon-m-toolbar-search"> to search for<br>departure information.</p><p>Press <img src="image://theme/icon-m-toolbar-view-menu"> for nearby stations.<br></p><p><strong>Have a safe journey.</strong></p>'
55     }
56
57     Rectangle {
58         id: header
59         anchors {
60             top: parent.top
61             left: parent.left
62             right: parent.right
63             margins: -1
64         }
65         border {
66             color: 'black'
67             width: 1
68         }
69
70         gradient: Gradient {
71             GradientStop { position: 0; color: '#777' }
72             GradientStop { position: 1; color: '#aaa' }
73         }
74
75         height: 80
76         color: 'white'
77
78         Image {
79             id: logo
80             source: 'logo.png'
81
82             anchors {
83                 verticalCenter: parent.verticalCenter
84                 left: parent.left
85                 leftMargin: 10
86             }
87         }
88
89
90         ToolIcon {
91             property int increaseMeGently: 0
92             anchors {
93                 verticalCenter: parent.verticalCenter
94                 right: parent.right
95                 rightMargin: 10
96             }
97             platformIconId: {
98                 if (favManager.isFavorite(realtimeResult.gline, realtimeResult.gdirection, realtimeResult.gstation, realtimeResult.sourceUrl, realtimeResult.isStation, increaseMeGently)) {
99                     'icon-m-toolbar-favorite-mark'
100                 } else {
101                     'icon-m-toolbar-favorite-unmark'
102                 }
103             }
104             onClicked: {
105                 favManager.toggleFavorite(realtimeResult.gline, realtimeResult.gdirection, realtimeResult.gstation, realtimeResult.sourceUrl, realtimeResult.isStation);
106                 increaseMeGently = increaseMeGently + 1;
107             }
108         }
109     }
110
111     PositionSource {
112         id: positionSource
113         updateInterval: 10000
114
115         active: true
116
117         onPositionChanged: {
118             fillNearbyStations(positionSource.position.coordinate.latitude, positionSource.position.coordinate.longitude)
119         }
120     }
121
122     SelectionDialog {
123         id: stationSelector
124         titleText: 'Select nearby station'
125
126         model: ListModel {
127             id: stationSelectorModel
128         }
129
130         onAccepted: {
131             realtimeResult.isStation = true
132             realtimeResult.gline = ''
133             realtimeResult.sourceUrl = ''
134             gline.text = ''
135             gstation.text = stationSelectorModel.get(selectedIndex).name
136             realtimeResult.gstation = stationSelectorModel.get(selectedIndex).name
137             console.log('station to get: ' + realtimeResult.gstation)
138         }
139     }
140
141     TextField {
142         visible: false
143         placeholderText: 'Line'
144
145         id: gline
146         anchors {
147             top: parent.top
148             left: parent.left
149             topMargin: 20
150             leftMargin: 10
151             rightMargin: 10
152             right: lineSearchButton.left
153         }
154
155         onTextChanged: {
156             gstation.text = ''
157         }
158
159          MouseArea {
160              anchors.fill: parent
161              drag.target: gline
162              drag.axis: Drag.YAxis
163              drag.minimumY: 0
164              drag.maximumY: parent.height
165          }
166     }
167
168     LineSheet {
169         id: lineSheet
170         onAccepted: {
171             gline.text = currentLine
172
173             /* We usually want to select a station after selecting a line */
174             stationPickerButton.clicked()
175         }
176     }
177
178     Button {
179         id: lineSearchButton
180         visible: false
181
182         anchors {
183             top: gline.top
184             bottom: gline.bottom
185             right: parent.right
186             rightMargin: 10
187         }
188
189         width: 60
190         iconSource: 'image://theme/icon-m-common-search'
191
192         onClicked: {
193             lineSheet.currentLine = ''
194             lineSheet.open()
195         }
196     }
197
198     TextField {
199         placeholderText: 'Station'
200         id: gstation
201         visible: false
202
203         anchors {
204             top: gline.bottom
205             left: parent.left
206             right: stationPickerButton.left
207             topMargin: 10
208             leftMargin: 10
209             rightMargin: 10*stationPickerButton.opacity
210         }
211     }
212
213     StationSheet {
214         id: stationSheet
215         onAccepted: {
216             gstation.text = stationSheet.currentStation
217
218             realtimeResult.gline = stationSheet.currentLine
219             realtimeResult.gdirection = stationSheet.currentDirection
220             realtimeResult.isStation = false
221             realtimeResult.sourceUrl = itip.get_directions_url(stationSheet.currentLine, stationSheet.currentDirection, stationSheet.currentStation)
222             realtimeResult.gstation = stationSheet.currentStation
223             
224             console.debug('url to get: ' + realtimeResult.sourceUrl)
225             realtimeResult.refresh()
226         }
227     }
228
229     Button {
230         id: stationPickerButton
231
232         anchors {
233             top: gstation.top
234             bottom: gstation.bottom
235             right: parent.right
236             rightMargin: 10
237         }
238
239         visible: false
240
241         width: lineSearchButton.width * opacity
242         //iconSource: 'image://theme/icon-m-common-location-picker'
243         iconSource: 'image://theme/icon-m-toolbar-list'
244
245         onClicked: {
246             stationSheet.open()
247             stationSheet.loadData(gline.text)
248         }
249     }
250
251     ResultRealtime {
252         id: realtimeResult
253
254         anchors {
255             margins: 10
256             top: header.bottom
257             left: parent.left
258             bottom: parent.bottom
259             right: parent.right
260         }
261
262         clip: true
263
264         gline: stationSheet.currentLine
265         gstation: stationSheet.currentStation
266         gdirection: stationSheet.currentDirection
267
268         sourceUrl: stationSheet.currentUrl
269     }
270
271     SelectionDialog {
272         id: favSelector
273         titleText: 'Your favorites'
274
275         model: ListModel {}
276
277         onAccepted: {
278             realtimeResult.isStation = model.get(selectedIndex).isstation
279             realtimeResult.gline = model.get(selectedIndex).gline
280             realtimeResult.gdirection = model.get(selectedIndex).gdirection
281             realtimeResult.sourceUrl = model.get(selectedIndex).sourceurl
282             realtimeResult.gstation = model.get(selectedIndex).gstation
283             realtimeResult.refresh()
284         }
285     }
286 }
287