X-Git-Url: http://git.maemo.org/git/?p=theonering;a=blobdiff_plain;f=src%2Fsimple_presence.py;h=c71a5c249fb65c401c44f2eed81a9250267f2330;hp=8958368337f7e62f16a3552b780bc9e9e5329e75;hb=b14494d3d36e55d4a6c2cbd2e467e1686cbb8f7e;hpb=3ae1df25c091b2bfb6b88b1d4023b868e63ce92f diff --git a/src/simple_presence.py b/src/simple_presence.py index 8958368..c71a5c2 100644 --- a/src/simple_presence.py +++ b/src/simple_presence.py @@ -1,14 +1,15 @@ import logging +import dbus import telepathy -import gtk_toolbox +import util.misc as misc_utils import tp import handle import gvoice.state_machine as state_machine -_moduleLogger = logging.getLogger("simple_presence") +_moduleLogger = logging.getLogger(__name__) class TheOneRingPresence(object): @@ -20,10 +21,10 @@ class TheOneRingPresence(object): OFFLINE = 'offline' TO_PRESENCE_TYPE = { - ONLINE: telepathy.constants.CONNECTION_PRESENCE_TYPE_AVAILABLE, - AWAY: telepathy.constants.CONNECTION_PRESENCE_TYPE_AWAY, - HIDDEN: telepathy.constants.CONNECTION_PRESENCE_TYPE_HIDDEN, - OFFLINE: telepathy.constants.CONNECTION_PRESENCE_TYPE_OFFLINE, + ONLINE: dbus.UInt32(telepathy.constants.CONNECTION_PRESENCE_TYPE_AVAILABLE), + AWAY: dbus.UInt32(telepathy.constants.CONNECTION_PRESENCE_TYPE_AWAY), + HIDDEN: dbus.UInt32(telepathy.constants.CONNECTION_PRESENCE_TYPE_HIDDEN), + OFFLINE: dbus.UInt32(telepathy.constants.CONNECTION_PRESENCE_TYPE_OFFLINE), } @property @@ -39,7 +40,7 @@ class TheOneRingPresence(object): """ raise NotImplementedError("Abstract function called") - def handle(self, handleType, handleId): + def get_handle_by_id(self, handleType, handleId): """ @abstract """ @@ -47,15 +48,13 @@ class TheOneRingPresence(object): def get_presences(self, contactIds): """ - @bug On Maemo 5, the connection handle is being passed in a lot, forcing lots of downloads is the webpage for dnd - @return {ContactHandle: (Status, Presence Type, Message)} """ presences = {} 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: @@ -68,7 +67,7 @@ class TheOneRingPresence(object): raise telepathy.errors.InvalidArgument("Unsupported state on the state machine: %s" % state) presenceType = TheOneRingPresence.TO_PRESENCE_TYPE[presence] else: - presence = TheOneRingPresence.ONLINE + presence = TheOneRingPresence.AWAY presenceType = TheOneRingPresence.TO_PRESENCE_TYPE[presence] presences[h] = (presenceType, presence) @@ -76,12 +75,12 @@ class TheOneRingPresence(object): def set_presence(self, status): if status == self.ONLINE: - self.session.backend.set_dnd(False) + self.session.set_dnd(False) self.session.stateMachine.set_state(state_machine.StateMachine.STATE_ACTIVE) elif status == self.AWAY: self.session.stateMachine.set_state(state_machine.StateMachine.STATE_IDLE) elif status == self.HIDDEN: - self.session.backend.set_dnd(True) + self.session.set_dnd(True) elif status == self.OFFLINE: self.Disconnect() else: @@ -100,18 +99,21 @@ class SimplePresenceMixin(tp.ConnectionInterfaceSimplePresence, TheOneRingPresen {'Statuses' : self._get_statuses} ) - @gtk_toolbox.log_exception(_moduleLogger) + @misc_utils.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() + return dbus.Dictionary( + ( + (h, dbus.Struct((presenceType, presence, personalMessage), signature="uss")) + for (h, (presenceType, presence)) in self.get_presences(contacts).iteritems() + ), + signature="u(uss)" ) - @gtk_toolbox.log_exception(_moduleLogger) + @misc_utils.log_exception(_moduleLogger) def SetPresence(self, status, message): if message: raise telepathy.errors.InvalidArgument("Messages aren't supported")