import QtQuick 1.1
import com.nokia.meego 1.0
+import QtMobility.location 1.1
+
import "UIConstants.js" as UIConstants
import "ExtrasConstants.js" as ExtrasConstants
Page {
tools: commonTools
+ orientationLock: PageOrientation.LockPortrait
+
+ property bool canRefresh: realtimeResult.sourceUrl != '' || (realtimeResult.isStation && realtimeResult.gstation != '')
+ //property alias stationSelect: stationSelector
+ property variant nearbyStations
+
+ function showFavorites() {
+ favSelector.model.clear();
+ for (var i=0; i<favManager.getCount(); i++) {
+ var data = eval('(' + favManager.getItem(i) + ')');
+ favSelector.model.append(data);
+ }
+ favSelector.model.sync();
+ favSelector.open();
+ }
+
+ function search() {
+ lineSearchButton.clicked()
+ }
+
+ function refresh() {
+ realtimeResult.refresh()
+ }
+
+ function fillNearbyStations(lat, lon) {
+ nearbyStations = itip.get_nearby_stations(lat, lon)
+ }
+
+ function showNearby() {
+ console.log("show nearby")
+
+ var stations = nearbyStations;
+ stationSelectorModel.clear();
+ for (var idx in stations) {
+ stationSelectorModel.append({'name': stations[idx]});
+ }
- Image {
- id: logo
- source: 'logo.png'
+ stationSelector.open();
+ }
+
+ Text {
+ visible: !parent.canRefresh
+ anchors.centerIn: parent
+ font.pixelSize: 30
+ 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>'
+ }
+ Rectangle {
+ id: header
anchors {
- topMargin: 25
top: parent.top
- horizontalCenter: parent.horizontalCenter
+ left: parent.left
+ right: parent.right
+ margins: -1
+ }
+ border {
+ color: 'black'
+ width: 1
}
- }
- SelectionDialog {
- id: lineSelector
- titleText: 'Select line'
+ gradient: Gradient {
+ GradientStop { position: 0; color: '#777' }
+ GradientStop { position: 1; color: '#aaa' }
+ }
- model: ListModel {
- id: lineSelectorModel
+ height: 80
+ color: 'white'
+
+ Image {
+ id: logo
+ source: 'logo.png'
+
+ anchors {
+ verticalCenter: parent.verticalCenter
+ left: parent.left
+ leftMargin: 10
+ }
+ }
- Component.onCompleted: {
- var lines = itip.get_lines()
- for (var idx in lines) {
- lineSelectorModel.append({'name': lines[idx]})
+ ToolIcon {
+ property int increaseMeGently: 0
+ anchors {
+ verticalCenter: parent.verticalCenter
+ right: parent.right
+ rightMargin: 10
+ }
+ platformIconId: {
+ if (favManager.isFavorite(realtimeResult.gline, realtimeResult.gdirection, realtimeResult.gstation, realtimeResult.sourceUrl, realtimeResult.isStation, increaseMeGently)) {
+ 'icon-m-toolbar-favorite-mark'
+ } else {
+ 'icon-m-toolbar-favorite-unmark'
}
}
+ onClicked: {
+ favManager.toggleFavorite(realtimeResult.gline, realtimeResult.gdirection, realtimeResult.gstation, realtimeResult.sourceUrl, realtimeResult.isStation);
+ increaseMeGently = increaseMeGently + 1;
+ }
+ }
+ }
+
+ PositionSource {
+ id: positionSource
+ updateInterval: 10000
+
+ active: true
+
+ onPositionChanged: {
+ fillNearbyStations(positionSource.position.coordinate.latitude, positionSource.position.coordinate.longitude)
}
+ }
- // XXX It would be nice if we could make a delegate with
- // icons (i.e. U1, U2, ... in the right colors), but we
- // would have to "copy" the default delegate style
+ SelectionDialog {
+ id: stationSelector
+ titleText: 'Select nearby station'
+
+ model: ListModel {
+ id: stationSelectorModel
+ }
onAccepted: {
- console.log('accepted: ' + selectedIndex)
- gline.text = lineSelectorModel.get(selectedIndex).name
+ realtimeResult.isStation = true
+ realtimeResult.gline = ''
+ realtimeResult.sourceUrl = ''
+ gline.text = ''
+ gstation.text = stationSelectorModel.get(selectedIndex).name
+ realtimeResult.gstation = stationSelectorModel.get(selectedIndex).name
+ console.log('station to get: ' + realtimeResult.gstation)
}
}
TextField {
+ visible: false
placeholderText: 'Line'
id: gline
anchors {
- top: logo.bottom
+ top: parent.top
left: parent.left
topMargin: 20
leftMargin: 10
}
onTextChanged: {
- // TODO: Check if text matches an item in lineSelectorModel and
- // set selectedIndex in lineSelector to the right item
-
- if (lineSelector.selectedIndex == -1) {
- return
- }
-
- // Disable selection in line selector if user changes the text
- if (lineSelectorModel.get(lineSelector.selectedIndex).name != text) {
- lineSelector.selectedIndex = -1
- }
+ gstation.text = ''
}
MouseArea {
}
}
+ LineSheet {
+ id: lineSheet
+ onAccepted: {
+ gline.text = currentLine
+
+ /* We usually want to select a station after selecting a line */
+ stationPickerButton.clicked()
+ }
+ }
+
Button {
id: lineSearchButton
+ visible: false
anchors {
top: gline.top
width: 60
iconSource: 'image://theme/icon-m-common-search'
- onClicked: lineSelector.open()
+ onClicked: {
+ lineSheet.currentLine = ''
+ lineSheet.open()
+ }
}
TextField {
placeholderText: 'Station'
id: gstation
+ visible: false
+
anchors {
top: gline.bottom
left: parent.left
leftMargin: 10
rightMargin: 10*stationPickerButton.opacity
}
- onTextChanged: {
- directionLabel.currentDirection = ''
- }
}
- Sheet {
+ StationSheet {
id: stationSheet
- property string currentLine: ''
- property string currentDirection: ''
- property string currentStation: ''
-
- acceptButtonText: 'Select'
- rejectButtonText: 'Cancel'
-
- function loadData(lineName) {
- stationSheet.currentLine = lineName
-
- directionChooser.direction1 = ''
- directionChooser.direction2 = ''
-
- directionChooserBusyIndicator.running = true
- itip.load_directions(stationSheet.currentLine)
-
- firstDirection.clicked()
- directionChooser.checkedButton = firstDirection
- }
-
- Connections {
- target: itip
-
- onDirectionsLoaded: {
- directionChooserBusyIndicator.running = false
-
- directionChooser.direction1 = itip.get_direction(0)
- directionChooser.direction2 = itip.get_direction(1)
-
- firstDirection.clicked()
- directionChooser.checkedButton = firstDirection
- }
- }
-
- content: Item {
- anchors.fill: parent
-
- ButtonColumn {
- id: directionChooser
- property string direction1
- property string direction2
-
- visible: !directionChooserBusyIndicator.running
-
- function chosen(idx) {
- console.log('direction chosen: '+ idx)
-
- stationSelectorListView.selectedIndex = -1
-
- if (idx == 1) {
- stationSheet.currentDirection = directionChooser.direction1
- } else {
- stationSheet.currentDirection = directionChooser.direction2
- }
-
- directionChooserModel.clear()
- var stations = itip.get_stations(stationSheet.currentLine, stationSheet.currentDirection)
-
- for (var s in stations) {
- directionChooserModel.append({'station': stations[s]})
- }
- }
-
- anchors {
- margins: 10
- top: parent.top
- left: parent.left
- right: parent.right
- }
-
- Button {
- id: firstDirection
- text: 'Richtung ' + directionChooser.direction1
- onClicked: directionChooser.chosen(1)
- }
-
- Button {
- id: secondDirection
- text: 'Richtung ' + directionChooser.direction2
- onClicked: directionChooser.chosen(2)
- }
- }
-
- ListView {
- id: stationSelectorListView
- visible: !directionChooserBusyIndicator.running
-
- property int selectedIndex: -1
- onSelectedIndexChanged: {
- console.log('current index: ' + selectedIndex)
- }
-
- anchors {
- margins: 10
- top: directionChooser.bottom
- left: parent.left
- right: parent.right
- bottom: parent.bottom
- }
-
- clip: true
-
- model: ListModel {
- id: directionChooserModel
- }
-
- delegate: StationListItem { selector: stationSelectorListView }
- }
-
- ScrollDecorator {
- flickableItem: stationSelectorListView
- }
-
- BusyIndicator {
- id: directionChooserBusyIndicator
- anchors.centerIn: parent
- visible: running
- platformStyle: BusyIndicatorStyle { size: 'large' }
- }
- }
-
onAccepted: {
- if (stationSelectorListView.selectedIndex == -1) {
- gstation.text = ''
- } else {
- gstation.text = directionChooserModel.get(stationSelectorListView.selectedIndex).station
- }
-
- directionLabel.currentDirection = stationSheet.currentDirection
+ gstation.text = stationSheet.currentStation
+
+ realtimeResult.gline = stationSheet.currentLine
+ realtimeResult.gdirection = stationSheet.currentDirection
+ realtimeResult.isStation = false
+ realtimeResult.sourceUrl = itip.get_directions_url(stationSheet.currentLine, stationSheet.currentDirection, stationSheet.currentStation)
+ realtimeResult.gstation = stationSheet.currentStation
+
+ console.debug('url to get: ' + realtimeResult.sourceUrl)
+ realtimeResult.refresh()
}
}
rightMargin: 10
}
- Behavior on opacity { PropertyAnimation { } }
-
- opacity: gline.text != '' // XXX: Check if the line is valid
+ visible: false
width: lineSearchButton.width * opacity
//iconSource: 'image://theme/icon-m-common-location-picker'
}
}
- ResultRealtime { id: resu }
-
- Label {
- id: directionLabel
- property string currentDirection: ''
- text: 'Richtung ' + currentDirection
+ ResultRealtime {
+ id: realtimeResult
anchors {
+ margins: 10
+ top: header.bottom
left: parent.left
+ bottom: parent.bottom
right: parent.right
- top: gstation.bottom
- margins: 20*directionLabel.opacity
}
- font.pixelSize: UIConstants.FONT_SMALL
+ clip: true
- opacity: currentDirection != ''
- scale: opacity
+ gline: stationSheet.currentLine
+ gstation: stationSheet.currentStation
+ gdirection: stationSheet.currentDirection
- Behavior on opacity { PropertyAnimation { } }
+ sourceUrl: stationSheet.currentUrl
}
- 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
+ SelectionDialog {
+ id: favSelector
+ titleText: 'Your favorites'
+
+ model: ListModel {}
+
+ onAccepted: {
+ realtimeResult.isStation = model.get(selectedIndex).isstation
+ realtimeResult.gline = model.get(selectedIndex).gline
+ realtimeResult.gdirection = model.get(selectedIndex).gdirection
+ realtimeResult.sourceUrl = model.get(selectedIndex).sourceurl
+ realtimeResult.gstation = model.get(selectedIndex).gstation
+ realtimeResult.refresh()
}
}
}