Implemented DnD in the backend and in the presence code
[theonering] / src / simple_presence.py
index b95c2ea..8a615b4 100644 (file)
@@ -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)