Merge branch 'master' of github.com:kelvan/gotoVienna
authorFlorian Schweikert <kelvan@logic.at>
Wed, 14 Mar 2012 22:39:37 +0000 (23:39 +0100)
committerFlorian Schweikert <kelvan@logic.at>
Wed, 14 Mar 2012 22:39:37 +0000 (23:39 +0100)
Conflicts:
gotovienna-qml

gotovienna-qml
gotovienna/defaults.py
qml/LinePad.qml
qml/MainPage.qml
qml/MapView.qml [deleted file]
qml/ResultRealtime.qml
qml/Settings.qml
qml/SettingsHeader.qml [new file with mode: 0644]
qml/main.qml

index 033f537..190018c 100755 (executable)
@@ -19,10 +19,13 @@ from gotovienna.gps import *
 from gotovienna.update import *
 from gotovienna.config import config as conf
 
+from gotovienna import defaults
+
 import urllib2
 import os
 import sys
 import threading
+import json
 from datetime import time
 
 class Config(QObject):
@@ -122,6 +125,57 @@ class DepartureModel(QAbstractListModel):
         self._data = dep
         self.endResetModel()
 
+class FavoriteManager(QObject):
+    def __init__(self):
+        QObject.__init__(self)
+        self._faves = []
+        if os.path.exists(defaults.favorites_file):
+            try:
+                self._faves = json.load(open(defaults.favorites_file, 'r'))
+                self._faves = map(tuple, self._faves)
+                print 'faves loaded:', self._faves
+            except Exception, e:
+                print 'faves load error:', e
+
+    @Slot(result=int)
+    def getCount(self):
+        result = len(self._faves)
+        print 'getCount->', result
+        return result
+
+    @Slot(int, result=unicode)
+    def getItem(self, index):
+        keys = ['gline', 'gdirection', 'gstation', 'sourceurl', 'isstation']
+        result = dict(zip(keys, self._faves[index]))
+        result['name'] = u'%(gline)s -> %(gdirection)s @ %(gstation)s' % result
+        result = json.dumps(result)
+        print 'getItem:', index, result
+        return result
+
+    def _persist(self):
+        print 'persist:', self._faves, '->', defaults.favorites_file
+        try:
+            fp = open(defaults.favorites_file, 'w')
+            json.dump(self._faves, fp)
+            fp.close()
+        except Exception, e:
+            print 'faves save error:', e
+
+    @Slot(unicode, unicode, unicode, unicode, bool, int, result=bool)
+    def isFavorite(self, gline, gdirection, gstation, sourceurl, isstation, x):
+        k = (gline, gdirection, gstation, sourceurl, isstation)
+        return (k in self._faves)
+
+    @Slot(unicode, unicode, unicode, unicode, bool)
+    def toggleFavorite(self, gline, gdirection, gstation, sourceurl, isstation):
+        k = (gline, gdirection, gstation, sourceurl, isstation)
+        if k in self._faves:
+            self._faves.remove(k)
+        else:
+            self._faves.append(k)
+
+        self._persist()
+
 class Gui(QObject):
     def __init__(self, depModel):
         QObject.__init__(self)
@@ -266,13 +320,16 @@ if __name__ == '__main__':
     # instantiate the Python object
     itip = Gui(departureModel)
 
+    favManager = FavoriteManager()
+
     # expose the object to QML
     context = view.rootContext()
     context.setContextProperty('itip', itip)
     context.setContextProperty('aboutInfo', aboutInfo)
     context.setContextProperty('config', config)
     context.setContextProperty('resultModel', departureModel)
-    
+    context.setContextProperty('favManager', favManager)
+
     if os.path.abspath(__file__).startswith('/usr/bin/'):
         # Assume system-wide installation, QML from /usr/share/
         view.setSource('/usr/share/gotovienna/qml/main.qml')
index 9f5df69..051030c 100644 (file)
@@ -19,6 +19,9 @@ cache_stations = path.join(cache_folder, 'stations.json')
 sql_gps_query = 'SELECT name FROM stations WHERE lat > ? and lat < ? and lon > ? and lon < ?'
 sql_file = path.expanduser('~/.gotovienna/stations.db')
 
+# Favorites store
+favorites_file = path.expanduser('~/.gotovienna/favorites.json')
+
 # iTip
 
 line_overview = 'http://www.wienerlinien.at/itip/linienwahl/'
index bead39c..ba1cf44 100644 (file)
@@ -90,7 +90,7 @@ Rectangle {
             MouseArea {
                 anchors {
                     fill: parent
-                    margins: -(inputLine.height - height)/2
+                    margins: -30
                 }
                 onClicked: {
                     buttonFeedback.start()
index c6deee0..b3582c7 100644 (file)
@@ -13,6 +13,16 @@ Page {
     //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()
     }
@@ -76,6 +86,26 @@ Page {
             }
         }
 
+
+        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 {
@@ -237,5 +267,21 @@ Page {
 
         sourceUrl: stationSheet.currentUrl
     }
+
+    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()
+        }
+    }
 }
 
diff --git a/qml/MapView.qml b/qml/MapView.qml
deleted file mode 100644 (file)
index ad52fdf..0000000
+++ /dev/null
@@ -1,35 +0,0 @@
-import QtQuick 1.1
-import Qt 4.7
-import QtMobility.location 1.2
-import com.nokia.meego 1.0
-
-Page {
-    tools: mapTools
-
-    ToolBarLayout {
-        id: mapTools
-        x: 0
-        y: 0
-        ToolIcon { iconId: "toolbar-back"; onClicked: { menu.close(); pageStack.pop(null,false); } }
-    }
-
-    Map {
-        id: map
-        plugin : Plugin {
-            name : "nokia"
-        }
-
-        anchors.fill: parent
-        size.width: parent.width
-        size.height: parent.height
-        zoomLevel: 7
-        //center: positionSource.position.coordinate
-        //objects: t_data.mapObjectsList
-
-
-        onZoomLevelChanged: {
-            console.log("Zoom changed")
-        }
-
-    }
-}
index c5a1c4f..9a49eba 100644 (file)
@@ -90,7 +90,7 @@ Item {
 
                         Text {
                             id: d
-                            text: model.direction // <----
+                            text: model.direction // <---   -
                             width: parent.parent.parent.width - l.width - dep.width - 15
                             elide: Text.ElideRight
                             color: !theme.inverted ? UIConstants.COLOR_SECONDARY_FOREGROUND : UIConstants.COLOR_INVERTED_SECONDARY_FOREGROUND
index 87f7f4f..dc6f93c 100644 (file)
@@ -18,7 +18,7 @@ Page {
         anchors.fill: parent
         anchors.margins: UIConstants.DEFAULT_MARGIN
 
-        contentHeight: content_column.height + 2 * UIConstants.DEFAULT_MARGIN
+        //contentHeight: content_column.height + 2 * UIConstants.DEFAULT_MARGIN
         flickableDirection: Flickable.VerticalFlick
 
         Component.onCompleted: {
@@ -40,6 +40,10 @@ Page {
                 anchors.left: parent.left
             }
 
+            SettingsHeader {
+                text: 'Location'
+            }
+
             Row {
                 anchors.left: parent.left
                 anchors.right: parent.right
@@ -50,7 +54,7 @@ Page {
                     color: !theme.inverted ? UIConstants.COLOR_FOREGROUND : UIConstants.COLOR_INVERTED_FOREGROUND
                     anchors.verticalCenter: parent.verticalCenter
                 }
-                CheckBox {
+                Switch {
                     id: gpsEnable
                     anchors.right: parent.right
                     checked: config.getGpsEnabled()
@@ -77,44 +81,36 @@ Page {
                 id:updateDialog
             }
 
-            Row {
-                anchors.left: parent.left
-                anchors.right: parent.right
-                Text {
-                    text: "Update stations"
-                    anchors.left: parent.left
-                    font.pixelSize: UIConstants.FONT_LARGE
-                    color: !theme.inverted ? UIConstants.COLOR_FOREGROUND : UIConstants.COLOR_INVERTED_FOREGROUND
-                    anchors.verticalCenter: parent.verticalCenter
-                }
+            SettingsHeader {
+                text: 'Station List'
+            }
 
-                Button {
-                    id: btnUpdate
-                    anchors.right: parent.right
-                    text: "Update"
-                    width: 100
+            Button {
+                id: btnUpdate
+                anchors.horizontalCenter: parent.horizontalCenter
+                text: "Update stations"
+                width: parent.width * .7
 
-                    Component.onCompleted: {
-                        if (config.checkStationsUpdate()) {
-                            btnUpdate.color = "green"
-                        }
+                Component.onCompleted: {
+                    if (config.checkStationsUpdate()) {
+                        btnUpdate.color = "green"
                     }
+                }
 
-                    onClicked: {
-                        var updateAvailable = config.checkStationsUpdate();
-                        if (updateAvailable) {
-                            var updated = config.updateStations();
-                            if (updated !== '') {
-                                updateDialog.text = "Stations updated\nPlease restart app"
-                                txtLastUpdate.text = updated
-                            } else {
-                                updateDialog.text = "[UpdateError]:\nTry again later or send me an email:\n<gotovienna@logic.at>"
-                            }
+                onClicked: {
+                    var updateAvailable = config.checkStationsUpdate();
+                    if (updateAvailable) {
+                        var updated = config.updateStations();
+                        if (updated !== '') {
+                            updateDialog.text = "Stations updated\nPlease restart app"
+                            txtLastUpdate.text = updated
                         } else {
-                            updateDialog.text = "No updates available";
+                            updateDialog.text = "[UpdateError]:\nTry again later or send me an email:\n<gotovienna@logic.at>"
                         }
-                        updateDialog.open();
+                    } else {
+                        updateDialog.text = "No updates available";
                     }
+                    updateDialog.open();
                 }
             }
 
diff --git a/qml/SettingsHeader.qml b/qml/SettingsHeader.qml
new file mode 100644 (file)
index 0000000..ef98e91
--- /dev/null
@@ -0,0 +1,39 @@
+
+import QtQuick 1.0
+
+Item {
+    id: settingsHeader
+    property alias text: headerCaption.text
+    property color color: headerCaption.visible?'#666':'#fff'
+
+    width: parent.width
+    height: headerCaption.visible?60*.7:10
+
+    Rectangle {
+        id: horizontalLine
+
+        anchors {
+            left: parent.left
+            right: headerCaption.left
+            rightMargin: headerCaption.visible?16:0
+            verticalCenter: headerCaption.verticalCenter
+        }
+
+        height: 1
+        color: settingsHeader.color
+    }
+
+    Text {
+        id: headerCaption
+        text: ''
+        visible: text !== ''
+        color: settingsHeader.color
+        font.pixelSize: 17
+
+        anchors {
+            right: parent.right
+            bottom: parent.bottom
+        }
+    }
+}
+
index 5a2a01f..01d0010 100644 (file)
@@ -77,6 +77,10 @@ PageStackWindow {
                 text: 'Nearby stations'
                 onClicked: mainPage.showNearby()
             }
+            MenuItem {
+                text: 'Favorites'
+                onClicked: mainPage.showFavorites()
+            }
             //MenuItem {
             //    text: 'Map'
             //    onClicked: pageStack.push(map)