X-Git-Url: http://git.maemo.org/git/?p=theonering;a=blobdiff_plain;f=src%2Fsimple_presence.py;h=8a615b477fe8296c25940036e8f2114e2e5e2b93;hp=b95c2ea6ec289ba29bb521d81ddbd86824cfcb7e;hb=78b9596221268a59856b410c4360e3da6d2bd60a;hpb=9b5e20f30ede6b5d4bc2c224510ab30cb9138c69 diff --git a/src/simple_presence.py b/src/simple_presence.py index b95c2ea..8a615b4 100644 --- a/src/simple_presence.py +++ b/src/simple_presence.py @@ -2,6 +2,9 @@ import logging import telepathy +import gtk_toolbox +import handle + _moduleLogger = logging.getLogger("simple_presence") @@ -32,33 +35,46 @@ class SimplePresenceMixin(telepathy.server.ConnectionInterfaceSimplePresence): """ raise NotImplementedError() - def GetPresences(self, contacts): + @property + def handle(self): + """ + @abstract """ - @todo Figure out how to know when its self and get whether busy or not + raise NotImplementedError("Abstract property called") + @gtk_toolbox.log_exception(_moduleLogger) + def GetPresences(self, contacts): + """ @return {ContactHandle: (Status, Presence Type, Message)} """ presences = {} for handleId in contacts: - handle = self.handle(telepathy.HANDLE_TYPE_CONTACT, handleId) - - presence = TheOneRingPresence.BUSY - personalMessage = u"" - presenceType = TheOneRingPresence.TO_PRESENCE_TYPE[presence] - - presences[handle] = (presenceType, presence, personalMessage) + h = self.handle(telepathy.HANDLE_TYPE_CONTACT, handleId) + if isinstance(h, handle.ConnectionHandle): + isDnd = self.session.backend.is_dnd() + presence = TheOneRingPresence.BUSY if isDnd else TheOneRingPresence.ONLINE + personalMessage = u"" + presenceType = TheOneRingPresence.TO_PRESENCE_TYPE[presence] + else: + presence = TheOneRingPresence.ONLINE + personalMessage = u"" + presenceType = TheOneRingPresence.TO_PRESENCE_TYPE[presence] + + presences[h] = (presenceType, presence, personalMessage) return presences + @gtk_toolbox.log_exception(_moduleLogger) def SetPresence(self, status, message): if message: - raise telepathy.errors.InvalidArgument + raise telepathy.errors.InvalidArgument("Messages aren't supported") + if status == TheOneRingPresence.ONLINE: - self.gvoice_backend.mark_dnd(True) + self.gvoice_backend.set_dnd(False) elif status == TheOneRingPresence.BUSY: - self.gvoice_backend.mark_dnd(False) + self.gvoice_backend.set_dnd(True) else: - raise telepathy.errors.InvalidArgument + raise telepathy.errors.InvalidArgument("Unsupported status: %r" % status) _moduleLogger.info("Setting Presence to '%s'" % status)