Merge github.com:kelvan/gotoVienna into experimental
[pywienerlinien] / qml / MainPage.qml
index 5c91374..8a6c4cc 100644 (file)
@@ -1,5 +1,6 @@
 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
@@ -7,12 +8,41 @@ import "ExtrasConstants.js" as ExtrasConstants
 Page {
     tools: commonTools
 
-    property bool canRefresh: realtimeResult.sourceUrl != ''
+    property bool canRefresh: realtimeResult.sourceUrl != '' || (realtimeResult.isStation && realtimeResult.gstation != '')
+    //property alias stationSelect: stationSelector
+    property variant nearbyStations
 
     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]})
+        }
+
+        stationSelector.open()
+    }
+
+    PositionSource {
+        id: positionSource
+        updateInterval: 10000
+
+        active: true
+
+        onPositionChanged: {
+            fillNearbyStations(positionSource.position.coordinate.latitude, positionSource.position.coordinate.longitude)
+        }
+    }
+
     SelectionDialog {
         id: lineSelector
         titleText: 'Select line'
@@ -39,6 +69,25 @@ Page {
         }
     }
 
+    SelectionDialog {
+        id: stationSelector
+        titleText: 'Select nearby station'
+
+        model: ListModel {
+            id: stationSelectorModel
+        }
+
+        onAccepted: {
+            realtimeResult.isStation = true
+            realtimeResult.gstation = stationSelectorModel.get(selectedIndex).name
+            realtimeResult.gline = ''
+            realtimeResult.sourceUrl = ''
+            gline.text = ''
+            gstation.text = stationSelectorModel.get(selectedIndex).name
+            console.log('station to get: ' + realtimeResult.gstation)
+        }
+    }
+
     TextField {
         placeholderText: 'Line'
 
@@ -57,14 +106,13 @@ Page {
             // set selectedIndex in lineSelector to the right item
             gstation.text = ''
 
-            text = text.toUpperCase()
-
-            if (lineSelector.selectedIndex == -1) {
+            if (lineSelector.selectedIndex === -1) {
+                text = text.toUpperCase()
                 return
             }
 
             // Disable selection in line selector if user changes the text
-            if (lineSelectorModel.get(lineSelector.selectedIndex).name != text) {
+            if (lineSelectorModel.get(lineSelector.selectedIndex).name !== text) {
                 lineSelector.selectedIndex = -1
             }
         }
@@ -129,7 +177,7 @@ Page {
 
         Behavior on opacity { PropertyAnimation { } }
 
-        opacity: gline.text != '' // XXX: Check if the line is valid
+        opacity: gline.text !== '' // XXX: Check if the line is valid
 
         width: lineSearchButton.width * opacity
         //iconSource: 'image://theme/icon-m-common-location-picker'