X-Git-Url: http://git.maemo.org/git/?p=theonering;a=blobdiff_plain;f=src%2Fsimple_presence.py;h=fa306bd651486d99cf60b949f9b82871fce69133;hp=5449344eb3732f5bd4ac76979a45b51c2303bc04;hb=3b3276f2953b0d13b04767cd3a4434071cf4821d;hpb=424b364f3c325321af6ae352e7f8ad8fcd6df8c2 diff --git a/src/simple_presence.py b/src/simple_presence.py index 5449344..fa306bd 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,12 +21,15 @@ 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), } + def __init__(self, ignoreDND): + self.__ignoreDND = ignoreDND + @property def session(self): """ @@ -53,7 +57,7 @@ class TheOneRingPresence(object): for handleId in contactIds: h = self.get_handle_by_id(telepathy.HANDLE_TYPE_CONTACT, handleId) if isinstance(h, handle.ConnectionHandle): - isDnd = self.session.is_dnd() + isDnd = self.session.is_dnd() if not self.__ignoreDND else False if isDnd: presence = TheOneRingPresence.HIDDEN else: @@ -74,12 +78,14 @@ class TheOneRingPresence(object): def set_presence(self, status): if status == self.ONLINE: - self.session.set_dnd(False) + if not self.__ignoreDND: + 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.set_dnd(True) + if not self.__ignoreDND: + self.session.set_dnd(True) elif status == self.OFFLINE: self.Disconnect() else: @@ -87,34 +93,38 @@ class TheOneRingPresence(object): _moduleLogger.info("Setting Presence to '%s'" % status) -class SimplePresenceMixin(tp.ConnectionInterfaceSimplePresence, TheOneRingPresence): +class SimplePresenceMixin(tp.ConnectionInterfaceSimplePresence): - def __init__(self): + def __init__(self, torPresence): tp.ConnectionInterfaceSimplePresence.__init__(self) - TheOneRingPresence.__init__(self) + self.__torPresence = torPresence self._implement_property_get( tp.CONNECTION_INTERFACE_SIMPLE_PRESENCE, {'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.__torPresence.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") - self.set_presence(status) + self.__torPresence.set_presence(status) def _get_statuses(self): """ @@ -124,5 +134,5 @@ class SimplePresenceMixin(tp.ConnectionInterfaceSimplePresence, TheOneRingPresen """ return dict( (localType, (telepathyType, True, False)) - for (localType, telepathyType) in self.TO_PRESENCE_TYPE.iteritems() + for (localType, telepathyType) in self.__torPresence.TO_PRESENCE_TYPE.iteritems() )