Add method to generate map links

This commit is contained in:
Philipp Hörist 2019-04-27 12:27:32 +02:00
parent dd7496d7a7
commit 423cfb9fdc
2 changed files with 10 additions and 6 deletions

View File

@ -44,6 +44,7 @@ from gajim.common import i18n
from gajim.common.i18n import _
from gajim.common.helpers import AdditionalDataDict
from gajim.common.helpers import open_uri
from gajim.common.helpers import geo_provider_from_location
from gajim.common.contacts import GC_Contact
from gajim.common.const import AvatarSize
from gajim.common.const import KindConstant
@ -648,10 +649,9 @@ class ChatControl(ChatControlBase):
def on_location_eventbox_button_release_event(self, widget, event):
if 'geoloc' in self.contact.pep:
location = self.contact.pep['geoloc'].data
if ('lat' in location) and ('lon' in location):
uri = 'https://www.openstreetmap.org/?' + \
'mlat=%(lat)s&mlon=%(lon)s&zoom=16' % {'lat': location['lat'],
'lon': location['lon']}
if 'lat' in location and 'lon' in location:
uri = geo_provider_from_location(location['lat'],
location['lon'])
open_uri(uri)
def on_location_eventbox_leave_notify_event(self, widget, event):

View File

@ -1506,8 +1506,7 @@ def parse_uri(uri):
if not lon:
return URI(type=URIType.UNKNOWN, data=uri)
uri = ('https://www.openstreetmap.org/?'
'mlat=%s&mlon=%s&zoom=16') % (lat, lon)
uri = geo_provider_from_location(lat, lon)
return URI(type=URIType.GEO, data=uri)
if uri.startswith('file://'):
@ -1565,3 +1564,8 @@ def open_uri_with_custom(config_app, uri):
exec_command(command)
except Exception:
pass
def geo_provider_from_location(lat, lon):
return ('https://www.openstreetmap.org/?'
'mlat=%s&mlon=%s&zoom=16') % (lat, lon)