self.current_line = ''
self.current_stations = []
+ self.current_departures = []
@Slot(int, result=str)
def get_direction(self, idx):
threading.Thread(target=load_async).start()
+ departuresLoaded = Signal()
+
+ @Slot(str)
+ def load_departures(self, url):
+ def load_async():
+ self.current_departures = [str(x) for x in
+ self.itip.get_departures(url)]
+ print self.current_departures
+ self.departuresLoaded.emit()
+
+ threading.Thread(target=load_async).start()
+
+ @Slot(str, str, str, result=str)
+ def get_directions_url(self, line, direction, station):
+ return self.itip.get_url_from_direction(line, direction, station)
+
@Slot(result='QStringList')
def get_lines(self):
return self.lines
+ @Slot(result='QStringList')
+ def get_departures(self):
+ return self.current_departures
+
@Slot(str, str)
def search(self, line, station):
line = line.upper()
return self._lines
+ def get_url_from_direction(self, line, direction, station):
+ stations = self.get_stations(line)
+
+ for stationname, url in stations.get(direction, []):
+ if stationname == station:
+ return url
+
+ return None
+
def get_departures(self, url):
""" Get list of next departures
integer if time until next departure
Page {
tools: commonTools
+ property bool canRefresh: realtimeResult.sourceUrl != ''
+
+ function refresh() {
+ realtimeResult.refresh()
+ }
+
Image {
id: logo
source: 'logo.png'
onTextChanged: {
// TODO: Check if text matches an item in lineSelectorModel and
// set selectedIndex in lineSelector to the right item
+ gstation.text = ''
if (lineSelector.selectedIndex == -1) {
return
TextField {
placeholderText: 'Station'
id: gstation
+
anchors {
top: gline.bottom
left: parent.left
leftMargin: 10
rightMargin: 10*stationPickerButton.opacity
}
- onTextChanged: {
- directionLabel.currentDirection = ''
- }
}
Sheet {
property int selectedIndex: -1
onSelectedIndexChanged: {
console.log('current index: ' + selectedIndex)
+ if (selectedIndex != -1) {
+ stationSheet.currentStation = directionChooserModel.get(selectedIndex).station
+ } else {
+ stationSheet.currentStation = ''
+ }
}
anchors {
}
onAccepted: {
- if (stationSelectorListView.selectedIndex == -1) {
- gstation.text = ''
- } else {
- gstation.text = directionChooserModel.get(stationSelectorListView.selectedIndex).station
- }
+ gstation.text = stationSheet.currentStation
+
+ realtimeResult.gline = stationSheet.currentLine
+ realtimeResult.gstation = stationSheet.currentStation
+ realtimeResult.gdirection = stationSheet.currentDirection
+
+ realtimeResult.sourceUrl = itip.get_directions_url(stationSheet.currentLine, stationSheet.currentDirection, stationSheet.currentStation)
+ console.log('url to get: ' + realtimeResult.sourceUrl)
- directionLabel.currentDirection = stationSheet.currentDirection
}
}
}
}
- ResultRealtime { id: resu }
-
- Label {
- id: directionLabel
- property string currentDirection: ''
- text: 'Richtung ' + currentDirection
+ ResultRealtime {
+ id: realtimeResult
anchors {
+ margins: 10
+ top: gstation.bottom
left: parent.left
+ bottom: parent.bottom
right: parent.right
- top: gstation.bottom
- margins: 20*directionLabel.opacity
}
- font.pixelSize: UIConstants.FONT_SMALL
-
- opacity: currentDirection != ''
- scale: opacity
+ clip: true
- Behavior on opacity { PropertyAnimation { } }
- }
+ gline: stationSheet.currentLine
+ gstation: stationSheet.currentStation
+ gdirection: stationSheet.currentDirection
- Button {
- id: btnSearch
- text: 'Search'
- anchors {
- top: directionLabel.bottom
- topMargin: 10
- horizontalCenter: parent.horizontalCenter
- }
- onClicked: {
- resu.gline = gline.text
- resu.gstation = gstation.text
- pageStack.push(resu)
- itip.search(gline.text, gstation.text)
- resu.busy = false
- }
+ sourceUrl: stationSheet.currentUrl
}
}
import "UIConstants.js" as UIConstants
import "ExtrasConstants.js" as ExtrasConstants
-Page {
- tools: commonTools
-
- property string gline : ""
- property string gstation : ""
- property bool busy : true
+Item {
+ id: resultRealtime
+
+ property string gline: ''
+ property string gstation: ''
+ property string gdirection: ''
+
+ property string sourceUrl: ''
+ property bool busy: true
+
+ function refresh() {
+ busy = true
+ itip.load_departures(sourceUrl)
+ console.log('refreshing')
+ }
+
+ onSourceUrlChanged: {
+ refresh()
+ console.log('source url changed: ' + sourceUrl)
+ }
+
+ Connections {
+ target: itip
+
+ onDeparturesLoaded: {
+ busy = false
+ departuresModel.clear()
+
+ var departures = itip.get_departures()
+
+ for (var d in departures) {
+ console.log('departure: ' + departures[d])
+ // XXX: destination might be wrong?!
+ var row = {'line': resultRealtime.gline, 'station': resultRealtime.gstation, 'destination': gdirection, 'departure': departures[d]}
+ console.log('inserting: ' + row)
+ departuresModel.append(row)
+ }
+ }
+ }
Component {
id: departureDelegate
}
}
- Component {
- id: heading
- Rectangle {
- width: parent.width
- height: childrenRect.height + 2*UIConstants.DEFAULT_MARGIN
- color: "lightsteelblue"
-
- Text {
- anchors {
- top: parent.top
- left: parent.left
- margins: UIConstants.DEFAULT_MARGIN
- }
-
- text: gstation + " [" + gline + "]"
- font.bold: true
- font.family: ExtrasConstants.FONT_FAMILY_LIGHT
- font.pixelSize: UIConstants.FONT_LSMALL
- }
- }
- }
-
ListView {
id: list
width: parent.width; height: parent.height
- header: heading
+ header: Rectangle {
+ width: parent.width
+ height: childrenRect.height + 2*UIConstants.DEFAULT_MARGIN
+ color: "lightsteelblue"
+
+ Text {
+ anchors {
+ top: parent.top
+ left: parent.left
+ right: parent.right
+ margins: UIConstants.DEFAULT_MARGIN
+ }
+
+ text: 'Abfahrten Richtung ' + gdirection
+ elide: Text.ElideRight
+ font.bold: true
+ font.family: ExtrasConstants.FONT_FAMILY_LIGHT
+ font.pixelSize: UIConstants.FONT_LSMALL
+ }
+ }
model: ListModel {
+ id: departuresModel
+/*
ListElement {
line: "N60"
station: "Schottentor"
station: "Schottentor"
destination: "Grinzing"
departure: 7
- }
- ListElement {
- line: "N25"
- station: "Schottentor"
- destination: "Großfeldsiedlung"
- departure: 8
- }
- ListElement {
- line: "N41"
- station: "Schottentor"
- destination: "Pötzleinsdorf"
- departure: 12
- }
- ListElement {
- line: "N43"
- station: "Schottentor"
- destination: "Neuwaldegg"
- departure: 12
- }
- ListElement {
- line: "N66"
- station: "Schottentor"
- destination: "Liesing S"
- departure: 20
- }
- ListElement {
- line: "N38"
- station: "Schottentor"
- destination: "Grinzing"
- departure: 22
- }
- ListElement {
- line: "N25"
- station: "Schottentor"
- destination: "Großfeldsiedlung"
- departure: 35
- }
- ListElement {
- line: "N60"
- station: "Schottentor"
- destination: "Maurer Hauptplatz"
- departure: 35
- }
- ListElement {
- line: "N38"
- station: "Schottentor"
- destination: "Grinzing"
- departure: 37
- }
- ListElement {
- line: "N41"
- station: "Schottentor"
- destination: "Pötzleinsdorf"
- departure: "03:12"
- }
- ListElement {
- line: "N43"
- station: "Schottentor"
- destination: "Neuwaldegg"
- departure: 42
- }
- ListElement {
- line: "N66"
- station: "Schottentor"
- destination: "Liesing S"
- departure: 50
- }
- ListElement {
- line: "N38"
- station: "Schottentor"
- destination: "Grinzing"
- departure: 52
- }
+ }*/
}
delegate: departureDelegate
+
+ visible: !resultRealtime.busy && resultRealtime.sourceUrl != ''
}
ScrollDecorator {
BusyIndicator {
id: busyIndicator
- visible: busy
- running: true
+ visible: resultRealtime.busy && resultRealtime.sourceUrl != ''
+ running: visible
platformStyle: BusyIndicatorStyle { size: 'large' }
anchors.centerIn: parent
}
ToolBarLayout {
id: commonTools
visible: true
- ToolIcon {
+ /*ToolIcon {
platformIconId: "toolbar-view-menu"
anchors.right: (parent === undefined) ? undefined : parent.right
onClicked: (menu.status == DialogStatus.Closed) ? menu.open() : menu.close()
- }
+ }*/
ToolIcon {
- enabled: appWindow.pageStack.depth > 1
- platformIconId: enabled ? "icon-m-toolbar-back" : "icon-m-toolbar-back-dimmed"
- anchors.left: parent.left
- onClicked: pageStack.pop()
- }
+ enabled: mainPage.canRefresh
+ platformIconId: enabled ? 'icon-m-toolbar-refresh' : 'icon-m-toolbar-refresh-dimmed'
+ anchors.right: parent.right
+ onClicked: mainPage.refresh()
+ }
}
Menu {