Skip to content

Commit

Permalink
fix a bug and add choice for sharing position, fixes #56
Browse files Browse the repository at this point in the history
  • Loading branch information
rinigus committed Sep 16, 2018
1 parent 871e73b commit 3b3ae64
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 8 deletions.
2 changes: 2 additions & 0 deletions poor/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@
"poi_list_show_bookmarked": False,
"reroute": True,
"router": "stadiamaps",
"share_osm": True,
"share_googlemaps": False,
"show_narrative": True,
"show_navigation_sign": True,
# "always", "exceeding", "never"
Expand Down
23 changes: 15 additions & 8 deletions poor/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,18 +244,25 @@ def format_distance_and_bearing(meters, bearing, n=2, short=True):
if bearing == 360: return f(_("{distance} north"))
raise ValueError("Unexpected bearing: {}".format(repr(bearing)))

def format_location_message(x, y, html=False):
def format_location_message(x, y, html=False, osm=True, gmaps=False):
"""Format coordinates of a point into a location message."""
osm_url = short_osm(y,x)
if osm: osm_url = short_osm(y,x)
if gmaps: gm = 'http://maps.google.com/?q={y:.5f},{x:.5f}'.format(x=x, y=y)
if html:
return ('<a href="geo:{y:.5f},{x:.5f}">geo:{y:.5f},{x:.5f}</a><br>'
'<a href="{osm}">'
'{osm}</a>'
.format(x=x, y=y, osm=osm_url))
r = ('<a href="geo:{y:.5f},{x:.5f}">geo:{y:.5f},{x:.5f}</a>'
.format(x=x, y=y))
if osm: r += ('<br><a href="{osm}">{osm}</a>'
.format(osm=osm_url))
if gmaps: r += ('<br><a href="{gm}">{gm}</a>'
.format(gm=gm))
else:
return ('geo:{y:.5f},{x:.5f} '
'{osm}'
r = ('geo:{y:.5f},{x:.5f}'
.format(x=x, y=y))
if osm: r += (' {osm}'
.format(osm=osm_url))
if gmaps: r += (' {gm}'
.format(gm=gm))
return r

def format_time(seconds):
"""Format `seconds` to format ``# h # min``."""
Expand Down
24 changes: 24 additions & 0 deletions qml/SharePage.qml
Original file line number Diff line number Diff line change
Expand Up @@ -100,11 +100,35 @@ Page {
horizontalAlignment: Text.AlignHCenter
}

TextSwitch {
id: shareOsmSwitch
anchors.top: infoLabel.bottom
anchors.topMargin: 2 * Theme.paddingLarge
checked: app.conf.get("share_osm")
text: app.tr("Add link to OpenStreetMaps")
onCheckedChanged: {
app.conf.set("share_osm", shareOsmSwitch.checked);
}
}

TextSwitch {
id: shareGoogleSwitch
anchors.top: shareOsmSwitch.bottom
anchors.topMargin: Theme.paddingMedium
checked: app.conf.get("share_googlemaps")
text: app.tr("Add link to Google Maps")
onCheckedChanged: {
app.conf.set("share_googlemaps", shareGoogleSwitch.checked);
}
}

function formatMessage(html) {
return py.call_sync("poor.util.format_location_message", [
page.coordinate.longitude,
page.coordinate.latitude,
html,
shareOsmSwitch.checked,
shareGoogleSwitch.checked,
]);
}

Expand Down

0 comments on commit 3b3ae64

Please sign in to comment.