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):
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)
# 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')
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/'
MouseArea {
anchors {
fill: parent
- margins: -(inputLine.height - height)/2
+ margins: -30
}
onClicked: {
buttonFeedback.start()
//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()
}
}
}
+
+ 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 {
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()
+ }
+ }
}
+++ /dev/null
-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")
- }
-
- }
-}
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
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: {
anchors.left: parent.left
}
+ SettingsHeader {
+ text: 'Location'
+ }
+
Row {
anchors.left: parent.left
anchors.right: parent.right
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()
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();
}
}
--- /dev/null
+
+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
+ }
+ }
+}
+
text: 'Nearby stations'
onClicked: mainPage.showNearby()
}
+ MenuItem {
+ text: 'Favorites'
+ onClicked: mainPage.showFavorites()
+ }
//MenuItem {
// text: 'Map'
// onClicked: pageStack.push(map)