gps support implemented in qml
authorFlorian Schweikert <kelvan@logic.at>
Tue, 10 Jan 2012 20:18:04 +0000 (21:18 +0100)
committerFlorian Schweikert <kelvan@logic.at>
Tue, 10 Jan 2012 20:18:04 +0000 (21:18 +0100)
qml/MainPage.qml
qml/ResultRealtime.qml
qml/StationSheet.qml
qml/main.qml

index e2e7259..3f23ba2 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'
@@ -45,23 +75,16 @@ Page {
 
         model: ListModel {
             id: stationSelectorModel
-
-            Component.onCompleted: {
-                var stations = itip.get_nearby_stations(positionSource.position.coordinate.latitude, positionSource.position.coordinate.longitude)
-
-                for (var idx in stations) {
-                    stationSelectorModel.append({'name': stations[idx]})
-                }
-            }
         }
 
-        // 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
-
         onAccepted: {
-            console.log('accepted: ' + lineSelectorModel.get(selectedIndex).name)
-            //gline.text = lineSelectorModel.get(selectedIndex).name
+            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)
         }
     }
 
@@ -83,12 +106,12 @@ Page {
             // set selectedIndex in lineSelector to the right item
             gstation.text = ''
 
-            if (lineSelector.selectedIndex == -1) {
+            if (lineSelector.selectedIndex === -1) {
                 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
             }
         }
@@ -153,7 +176,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'
index c21dea5..bf8e695 100644 (file)
@@ -13,16 +13,27 @@ Item {
 
     property string sourceUrl: ''
     property bool busy: true
+    property bool isStation: false
 
     function refresh() {
         busy = true
-        itip.load_departures(sourceUrl)
         console.log('refreshing')
+
+        if (isStation) {
+            console.log('station based')
+            itip.load_station_departures(gstation)
+        } else {
+            console.log('one line')
+            itip.load_departures(sourceUrl)
+        }
+    }
+
+    function isCorrectInput () {
+        return resultRealtime.sourceUrl != '' || (resultRealtime.isStation && resultRealtime.gstation != '')
     }
 
-    onSourceUrlChanged: {
+    onGstationChanged: {
         refresh()
-        console.log('source url changed: ' + sourceUrl)
     }
 
     Connections {
@@ -35,7 +46,7 @@ Item {
             var departures = itip.get_departures()
 
             for (var d in departures) {
-                //console.log('time: ' + departures[d].time)
+                console.log('time: ' + departures[d].time)
                 var row = {'line': departures[d].line, 'station': departures[d].station, 'destination': departures[d].direction, 'departure': departures[d].time, 'lowfloor': departures[d].lowfloor}
                 departuresModel.append(row)
             }
@@ -159,7 +170,7 @@ Item {
         }
         delegate: departureDelegate
 
-        visible: !resultRealtime.busy && resultRealtime.sourceUrl != ''
+        visible: !resultRealtime.busy && isCorrectInput()
     }
 
     ScrollDecorator {
@@ -170,7 +181,7 @@ Item {
 
     BusyIndicator {
         id: busyIndicator
-        visible: resultRealtime.busy && resultRealtime.sourceUrl != ''
+        visible: resultRealtime.busy && isCorrectInput()
         running: visible
         platformStyle: BusyIndicatorStyle { size: 'large' }
         anchors.centerIn: parent
index 49c22f8..6e58e76 100644 (file)
@@ -138,6 +138,7 @@ Sheet {
         realtimeResult.gline = stationSheet.currentLine
         realtimeResult.gstation = stationSheet.currentStation
         realtimeResult.gdirection = stationSheet.currentDirection
+        realtimeResult.isStation = false
 
         realtimeResult.sourceUrl = itip.get_directions_url(stationSheet.currentLine, stationSheet.currentDirection, stationSheet.currentStation)
         console.log('url to get: ' + realtimeResult.sourceUrl)
index 11965e3..36c80a2 100644 (file)
@@ -55,7 +55,8 @@ PageStackWindow {
                 onClicked: {
                     //console.debug(itip.get_nearby_stations(positionSource.position.coordinate.latitude, positionSource.position.coordinate.longitude))
                     //debugText.text = itip.get_nearby_stations(positionSource.position.coordinate.latitude, positionSource.position.coordinate.longitude)
-                    itip.load_nearby_departures(positionSource.position.coordinate.latitude, positionSource.position.coordinate.longitude)
+                    //itip.load_nearby_departures(positionSource.position.coordinate.latitude, positionSource.position.coordinate.longitude)
+                    mainPage.showNearby()
                 }
             }
         }