X-Git-Url: http://git.maemo.org/git/?p=theonering;a=blobdiff_plain;f=src%2Fsimple_presence.py;h=5449344eb3732f5bd4ac76979a45b51c2303bc04;hp=dc44399d5cc0f2701871e323f3668c96d997367d;hb=de1dda08c8fe63bcf42966ae832bdd2285b14768;hpb=68d1653679bdce47f008d9167a263dbb2259e91d diff --git a/src/simple_presence.py b/src/simple_presence.py index dc44399..5449344 100644 --- a/src/simple_presence.py +++ b/src/simple_presence.py @@ -3,6 +3,7 @@ import logging import telepathy import gtk_toolbox +import tp import handle import gvoice.state_machine as state_machine @@ -25,17 +26,6 @@ class TheOneRingPresence(object): OFFLINE: telepathy.constants.CONNECTION_PRESENCE_TYPE_OFFLINE, } - -class SimplePresenceMixin(telepathy.server.ConnectionInterfaceSimplePresence): - - def __init__(self): - telepathy.server.ConnectionInterfaceSimplePresence.__init__(self) - - self._implement_property_get( - telepathy.server.CONNECTION_INTERFACE_SIMPLE_PRESENCE, - {'Statuses' : self._get_statuses} - ) - @property def session(self): """ @@ -43,68 +33,89 @@ class SimplePresenceMixin(telepathy.server.ConnectionInterfaceSimplePresence): """ raise NotImplementedError() - @property - def handle(self): + def Disconnect(self): """ @abstract """ - raise NotImplementedError("Abstract property called") + raise NotImplementedError("Abstract function called") - def Disconnect(self): + def get_handle_by_id(self, handleType, handleId): """ @abstract """ raise NotImplementedError("Abstract function called") - @gtk_toolbox.log_exception(_moduleLogger) - def GetPresences(self, contacts): + def get_presences(self, contactIds): """ @return {ContactHandle: (Status, Presence Type, Message)} """ presences = {} - for handleId in contacts: - h = self.handle(telepathy.HANDLE_TYPE_CONTACT, handleId) + for handleId in contactIds: + h = self.get_handle_by_id(telepathy.HANDLE_TYPE_CONTACT, handleId) if isinstance(h, handle.ConnectionHandle): - isDnd = self.session.backend.is_dnd() + isDnd = self.session.is_dnd() if isDnd: presence = TheOneRingPresence.HIDDEN else: - state = self.session.stateMachine.get_state() + state = self.session.stateMachine.state if state == state_machine.StateMachine.STATE_ACTIVE: presence = TheOneRingPresence.ONLINE elif state == state_machine.StateMachine.STATE_IDLE: presence = TheOneRingPresence.AWAY else: raise telepathy.errors.InvalidArgument("Unsupported state on the state machine: %s" % state) - personalMessage = u"" presenceType = TheOneRingPresence.TO_PRESENCE_TYPE[presence] else: - presence = TheOneRingPresence.ONLINE - personalMessage = u"" + presence = TheOneRingPresence.AWAY presenceType = TheOneRingPresence.TO_PRESENCE_TYPE[presence] - presences[h] = (presenceType, presence, personalMessage) + presences[h] = (presenceType, presence) return presences - @gtk_toolbox.log_exception(_moduleLogger) - def SetPresence(self, status, message): - if message: - raise telepathy.errors.InvalidArgument("Messages aren't supported") - - if status == TheOneRingPresence.ONLINE: - self.session.backend.set_dnd(False) + def set_presence(self, status): + if status == self.ONLINE: + self.session.set_dnd(False) self.session.stateMachine.set_state(state_machine.StateMachine.STATE_ACTIVE) - elif status == TheOneRingPresence.AWAY: + elif status == self.AWAY: self.session.stateMachine.set_state(state_machine.StateMachine.STATE_IDLE) - elif status == TheOneRingPresence.HIDDEN: - self.session.backend.set_dnd(True) - elif status == TheOneRingPresence.OFFLINE: + elif status == self.HIDDEN: + self.session.set_dnd(True) + elif status == self.OFFLINE: self.Disconnect() else: raise telepathy.errors.InvalidArgument("Unsupported status: %r" % status) _moduleLogger.info("Setting Presence to '%s'" % status) +class SimplePresenceMixin(tp.ConnectionInterfaceSimplePresence, TheOneRingPresence): + + def __init__(self): + tp.ConnectionInterfaceSimplePresence.__init__(self) + TheOneRingPresence.__init__(self) + + self._implement_property_get( + tp.CONNECTION_INTERFACE_SIMPLE_PRESENCE, + {'Statuses' : self._get_statuses} + ) + + @gtk_toolbox.log_exception(_moduleLogger) + def GetPresences(self, contacts): + """ + @return {ContactHandle: (Status, Presence Type, Message)} + """ + personalMessage = u"" + return dict( + (h, (presenceType, presence, personalMessage)) + for (h, (presenceType, presence)) in self.get_presences(contacts).iteritems() + ) + + @gtk_toolbox.log_exception(_moduleLogger) + def SetPresence(self, status, message): + if message: + raise telepathy.errors.InvalidArgument("Messages aren't supported") + + self.set_presence(status) + def _get_statuses(self): """ Property mapping presence statuses available to the corresponding presence types @@ -113,5 +124,5 @@ class SimplePresenceMixin(telepathy.server.ConnectionInterfaceSimplePresence): """ return dict( (localType, (telepathyType, True, False)) - for (localType, telepathyType) in TheOneRingPresence.TO_PRESENCE_TYPE.iteritems() + for (localType, telepathyType) in self.TO_PRESENCE_TYPE.iteritems() )