X-Git-Url: http://git.maemo.org/git/?a=blobdiff_plain;ds=sidebyside;f=src%2Flocation.py;h=32b582340723edabe8c811469952b7c66a136f72;hb=05f9c808abdbbdb67f339bd8346584826d45e7b3;hp=59195fd82dfb3a72ef073f0c752f82094302de70;hpb=a840b976430685dbf23bee4e590d1ee23594728c;p=theonering diff --git a/src/location.py b/src/location.py index 59195fd..32b5823 100644 --- a/src/location.py +++ b/src/location.py @@ -2,10 +2,11 @@ import logging import telepathy -import gtk_toolbox +import util.misc as misc_utils +import handle -_moduleLogger = logging.getLogger('location') +_moduleLogger = logging.getLogger(__name__) #class LocationMixin(tp.ConnectionInterfaceLocation): @@ -22,23 +23,48 @@ class LocationMixin(object): """ raise NotImplementedError("Abstract property called") - @gtk_toolbox.log_exception(_moduleLogger) + @misc_utils.log_exception(_moduleLogger) def GetLocations(self, contacts): """ @returns {Contact: {Location Type: Location}} """ - raise telepathy.errors.NotImplemented("Yet") + contactLocation = ( + (contact, self._get_location(contact)) + for contact in contacts + ) + return dict( + (contact, location) + for (contact, location) in contactLocation + if location + ) - @gtk_toolbox.log_exception(_moduleLogger) + @misc_utils.log_exception(_moduleLogger) def RequestLocation(self, contact): """ @returns {Location Type: Location} """ - raise telepathy.errors.NotImplemented("Yet") + return self._get_location(contact) - @gtk_toolbox.log_exception(_moduleLogger) + @misc_utils.log_exception(_moduleLogger) def SetLocation(self, location): """ Since presence is based off of phone numbers, not allowing the client to change it """ raise telepathy.errors.PermissionDenied() + + def _get_location(self, contact): + h = self.get_handle_by_id(telepathy.HANDLE_TYPE_CONTACT, contact) + if isinstance(h, handle.ConnectionHandle): + number = self.session.backend.get_callback_number() + else: + number = h.phoneNumber + + rawData = self.session.location.request_location(number) + if rawData is None: + return {} + + data = { + "country": rawData["country"], + "city": rawData["city"], + "region": rawData["region"], + }