6e58e76a912208110ec13051483c47bc85e5c541
[pywienerlinien] / qml / StationSheet.qml
1 import QtQuick 1.1
2 import com.nokia.meego 1.0
3 import "UIConstants.js" as UIConstants
4 import "ExtrasConstants.js" as ExtrasConstants
5
6 Sheet {
7     id: stationSheet
8     property string currentLine: ''
9     property string currentDirection: ''
10     property string currentStation: ''
11     property string currentUrl: ''
12
13     acceptButtonText: 'Select'
14     rejectButtonText: 'Cancel'
15
16     function loadData(lineName) {
17         stationSheet.currentLine = lineName
18
19         directionChooser.direction1 = ''
20         directionChooser.direction2 = ''
21
22         directionChooserBusyIndicator.running = true
23         itip.load_directions(stationSheet.currentLine)
24
25         firstDirection.clicked()
26         directionChooser.checkedButton = firstDirection
27     }
28
29     Connections {
30         target: itip
31
32         onDirectionsLoaded: {
33             directionChooserBusyIndicator.running = false
34
35             directionChooser.direction1 = itip.get_direction(0)
36             directionChooser.direction2 = itip.get_direction(1)
37
38             firstDirection.clicked()
39             directionChooser.checkedButton = firstDirection
40         }
41     }
42
43     content: Item {
44         anchors.fill: parent
45
46         ButtonColumn {
47             id: directionChooser
48             property string direction1
49             property string direction2
50
51             visible: !directionChooserBusyIndicator.running
52
53             function chosen(idx) {
54                 console.log('direction chosen: '+ idx)
55
56                 stationSelectorListView.selectedIndex = -1
57
58                 if (idx == 1) {
59                     stationSheet.currentDirection = directionChooser.direction1
60                 } else {
61                     stationSheet.currentDirection = directionChooser.direction2
62                 }
63
64                 directionChooserModel.clear()
65                 var stations = itip.get_stations(stationSheet.currentLine, stationSheet.currentDirection)
66
67                 for (var s in stations) {
68                     directionChooserModel.append({'station': stations[s]})
69                 }
70             }
71
72             anchors {
73                 margins: 10
74                 top: parent.top
75                 left: parent.left
76                 right: parent.right
77             }
78
79             Button {
80                 id: firstDirection
81                 text: 'Richtung ' + directionChooser.direction1
82                 onClicked: directionChooser.chosen(1)
83             }
84
85             Button {
86                 id: secondDirection
87                 text: 'Richtung ' + directionChooser.direction2
88                 onClicked: directionChooser.chosen(2)
89             }
90         }
91
92         ListView {
93             id: stationSelectorListView
94             visible: !directionChooserBusyIndicator.running
95
96             property int selectedIndex: -1
97             onSelectedIndexChanged: {
98                 console.log('current index: ' + selectedIndex)
99                 if (selectedIndex != -1) {
100                     stationSheet.currentStation = directionChooserModel.get(selectedIndex).station
101                 } else {
102                     stationSheet.currentStation = ''
103                 }
104             }
105
106             anchors {
107                 margins: 10
108                 top: directionChooser.bottom
109                 left: parent.left
110                 right: parent.right
111                 bottom: parent.bottom
112             }
113
114             clip: true
115
116             model: ListModel {
117                 id: directionChooserModel
118             }
119
120             delegate: SheetListItem { selector: stationSelectorListView }
121         }
122
123         ScrollDecorator {
124             flickableItem: stationSelectorListView
125         }
126
127         BusyIndicator {
128             id: directionChooserBusyIndicator
129             anchors.centerIn: parent
130             visible: running
131             platformStyle: BusyIndicatorStyle { size: 'large' }
132         }
133     }
134
135     onAccepted: {
136         gstation.text = stationSheet.currentStation
137
138         realtimeResult.gline = stationSheet.currentLine
139         realtimeResult.gstation = stationSheet.currentStation
140         realtimeResult.gdirection = stationSheet.currentDirection
141         realtimeResult.isStation = false
142
143         realtimeResult.sourceUrl = itip.get_directions_url(stationSheet.currentLine, stationSheet.currentDirection, stationSheet.currentStation)
144         console.log('url to get: ' + realtimeResult.sourceUrl)
145
146     }
147 }