From: Florian Schweikert Date: Wed, 14 Mar 2012 22:39:37 +0000 (+0100) Subject: Merge branch 'master' of github.com:kelvan/gotoVienna X-Git-Url: http://git.maemo.org/git/?p=pywienerlinien;a=commitdiff_plain;h=ec5e6afed4ebefcd4ea8a234fdd82b7d6e231a3f;hp=838be31a8f4acb994f2e141873188a0f4b959178 Merge branch 'master' of github.com:kelvan/gotoVienna Conflicts: gotovienna-qml --- diff --git a/gotovienna-qml b/gotovienna-qml index 033f537..190018c 100755 --- a/gotovienna-qml +++ b/gotovienna-qml @@ -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') diff --git a/gotovienna/defaults.py b/gotovienna/defaults.py index 9f5df69..051030c 100644 --- a/gotovienna/defaults.py +++ b/gotovienna/defaults.py @@ -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/' diff --git a/qml/LinePad.qml b/qml/LinePad.qml index bead39c..ba1cf44 100644 --- a/qml/LinePad.qml +++ b/qml/LinePad.qml @@ -90,7 +90,7 @@ Rectangle { MouseArea { anchors { fill: parent - margins: -(inputLine.height - height)/2 + margins: -30 } onClicked: { buttonFeedback.start() diff --git a/qml/MainPage.qml b/qml/MainPage.qml index c6deee0..b3582c7 100644 --- a/qml/MainPage.qml +++ b/qml/MainPage.qml @@ -13,6 +13,16 @@ Page { //property alias stationSelect: stationSelector property variant nearbyStations + function showFavorites() { + favSelector.model.clear(); + for (var i=0; i