Cleaned up presence and cleaned up the exceptions
[theonering] / src / simple_presence.py
index cd36856..29deb88 100644 (file)
@@ -2,6 +2,11 @@ import logging
 
 import telepathy
 
+import gtk_toolbox
+
+
+_moduleLogger = logging.getLogger("simple_presence")
+
 
 class TheOneRingPresence(object):
        ONLINE = 'available'
@@ -13,7 +18,7 @@ class TheOneRingPresence(object):
        }
 
 
-class TheOneRingSimplePresence(telepathy.server.ConnectionInterfaceSimplePresence):
+class SimplePresenceMixin(telepathy.server.ConnectionInterfaceSimplePresence):
 
        def __init__(self):
                telepathy.server.ConnectionInterfaceSimplePresence.__init__(self)
@@ -22,6 +27,21 @@ class TheOneRingSimplePresence(telepathy.server.ConnectionInterfaceSimplePresenc
 
                self._implement_property_get(dbus_interface, {'Statuses' : self._get_statuses})
 
+       @property
+       def session(self):
+               """
+               @abstract
+               """
+               raise NotImplementedError()
+
+       @property
+       def handle(self):
+               """
+               @abstract
+               """
+               raise NotImplementedError("Abstract property called")
+
+       @gtk_toolbox.log_exception(_moduleLogger)
        def GetPresences(self, contacts):
                """
                @todo Figure out how to know when its self and get whether busy or not
@@ -39,17 +59,19 @@ class TheOneRingSimplePresence(telepathy.server.ConnectionInterfaceSimplePresenc
                        presences[handle] = (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._conn.mark_dnd(True)
+                       self.gvoice_backend.mark_dnd(True)
                elif status == TheOneRingPresence.BUSY:
-                       self._conn.mark_dnd(False)
+                       raise telepathy.errors.NotAvailable("DnD support not yet added to TheOneRing")
+                       self.gvoice_backend.mark_dnd(False)
                else:
-                       raise telepathy.errors.InvalidArgument
-               logging.info("Setting Presence to '%s'" % status)
+                       raise telepathy.errors.InvalidArgument("Unsupported status: %r" % status)
+               _moduleLogger.info("Setting Presence to '%s'" % status)
 
 
        def _get_statuses(self):