X-Git-Url: http://git.maemo.org/git/?p=theonering;a=blobdiff_plain;f=src%2Flocation.py;h=32b582340723edabe8c811469952b7c66a136f72;hp=24e73a0cad537a6b484560446af5468469ddd168;hb=afa4cdb64e451070cf87cc02f257c582fa057f53;hpb=9b5e20f30ede6b5d4bc2c224510ab30cb9138c69 diff --git a/src/location.py b/src/location.py index 24e73a0..32b5823 100644 --- a/src/location.py +++ b/src/location.py @@ -1,32 +1,70 @@ +import logging + import telepathy +import util.misc as misc_utils +import handle + + +_moduleLogger = logging.getLogger(__name__) + -class LocationMixin(telepathy.server.ConnectionInterfaceLocation): +#class LocationMixin(tp.ConnectionInterfaceLocation): +class LocationMixin(object): def __init__(self): - telepathy.server.ConnectionInterfaceLocation.__init__(self) + #tp.ConnectionInterfaceLocation.__init__(self) + pass @property def session(self): """ @abstract """ - raise NotImplementedError() + raise NotImplementedError("Abstract property called") + @misc_utils.log_exception(_moduleLogger) def GetLocations(self, contacts): """ @returns {Contact: {Location Type: Location}} """ - raise NotImplementedError() + contactLocation = ( + (contact, self._get_location(contact)) + for contact in contacts + ) + return dict( + (contact, location) + for (contact, location) in contactLocation + if location + ) + @misc_utils.log_exception(_moduleLogger) def RequestLocation(self, contact): """ @returns {Location Type: Location} """ - raise NotImplementedError() + return self._get_location(contact) + @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"], + }