Fixing some errorhandling bugs
[pywienerlinien] / qml / LineSheet.qml
1 import QtQuick 1.1
2 import com.nokia.meego 1.0
3 import com.nokia.extras 1.0
4
5 import "UIConstants.js" as UIConstants
6 import "ExtrasConstants.js" as ExtrasConstants
7
8 Sheet {
9     id: lineSheet
10     property string currentSection: ''
11     property string currentLine: ''
12
13     acceptButtonText: 'Select'
14     rejectButtonText: 'Cancel'
15
16     function loadData() {
17         var lines = itip.get_lines()
18
19         for (var i in lines) {
20             lineSelectorModel.append({'name': lines[i]})
21         }
22         lineSheet.currentSection = sectionName
23
24         sectionChooserBusyIndicator.running = true
25
26         underground.clicked()
27         sectionChooser.checkedButton = underground
28     }
29
30     Connections {
31         target: itip
32
33         onLinesLoaded: {
34             sectionChooserBusyIndicator.running = false
35
36             underground.clicked()
37             sectionChooser.checkedButton = underground
38         }
39     }
40
41     content: Item {
42         anchors.fill: parent
43
44         ButtonRow {
45             id: sectionChooser
46             property string section1
47             property string section2
48             property string section3
49             property string section4
50
51             visible: !sectionChooserBusyIndicator.running
52
53             function chosen(idx) {
54                 console.log('section chosen: '+ idx)
55
56                 lineSelectorListView.selectedIndex = -1
57
58                 if (idx == 1) {
59                     lineSheet.currentSection = sectionChooser.section1
60                 } else if (idx == 2) {
61                     lineSheet.currentSection = sectionChooser.section2
62                 } else if (idx == 2) {
63                     lineSheet.currentSection = sectionChooser.section3
64                 } else {
65                     lineSheet.currentSection = sectionChooser.section4
66                 }
67                 console.log(lineSheet.currentSection)
68
69                 sectionChooserModel.clear()
70                 var lines = itip.get_lines()
71
72                 for (var i in lines) {
73                     lineSelectorModel.append({'name': lines[i]})
74                 }
75             }
76
77             anchors {
78                 margins: 10
79                 top: parent.top
80                 left: parent.left
81                 right: parent.right
82             }
83
84                 Button {
85                     id: underground
86                     text: 'U-Bahn'
87                     onClicked: sectionChooser.chosen(1)
88                 }
89
90                 Button {
91                     id: tram
92                     text: 'Straßenbahn'
93                     onClicked: sectionChooser.chosen(2)
94                 }
95
96                 Button {
97                     id: bus
98                     text: 'Autobus'
99                     onClicked: sectionChooser.chosen(3)
100                 }
101
102                 Button {
103                     id: nightline
104                     text: 'Nightline'
105                     onClicked: sectionChooser.chosen(4)
106                 }
107
108         }
109
110         ListView {
111             id: lineSelectorListView
112             visible: !sectionChooserBusyIndicator.running
113
114             property int selectedIndex: -1
115             onSelectedIndexChanged: {
116                 console.log('current index: ' + selectedIndex)
117                 if (selectedIndex != -1) {
118                     lineSheet.currentLine = sectionChooserModel.get(selectedIndex).station
119                 } else {
120                     lineSheet.currentLine = ''
121                 }
122             }
123
124             anchors {
125                 margins: 10
126                 top: sectionChooserModel.bottom
127                 left: parent.left
128                 right: parent.right
129                 bottom: parent.bottom
130             }
131
132             clip: true
133
134             model: ListModel {
135                 id: sectionChooserModel
136             }
137
138             delegate: SheetListItem { selector: lineSelectorListView }
139         }
140
141         ScrollDecorator {
142             flickableItem: lineSelectorListView
143         }
144
145         BusyIndicator {
146             id: sectionChooserBusyIndicator
147             anchors.centerIn: parent
148             visible: running
149             platformStyle: BusyIndicatorStyle { size: 'large' }
150         }
151     }
152
153     onAccepted: {
154         gstation.text = stationSheet.currentStation
155
156         realtimeResult.gline = stationSheet.currentLine
157
158         realtimeResult.sourceUrl = itip.get_directions_url(lineSheet.currentLine, lineSheet.currentSection, lineSheet.currentStation)
159     }
160 }