To show the state of presence/collaboration in Sugar, here's a first
step: signalling telepathy connection manager (PS plugin) connections
and disconnections.

What would be a good place in the sugar shell to track the state of
which CM is connected? That would be useful to show, if not in the UI,
then in the control panel where http://dev.laptop.org/ticket/6248
suggests we could have a place to control which telepathy connection
managers are used in a persistent way.

Regards
Morgan
diff --git a/src/presenceservice.py b/src/presenceservice.py
index e68bded..6748e2d 100644
--- a/src/presenceservice.py
+++ b/src/presenceservice.py
@@ -146,6 +146,7 @@ class PresenceService(ExportedGObject):
         _logger.debug("Disconnected from session bus!!!")
 
     def _tp_status_cb(self, plugin, status, reason):
+        conn_name = plugin.conn_name()
         if status == CONNECTION_STATUS_CONNECTED:
             self._tp_connected(plugin)
             if (plugin == self._server_plugin and self._ll_plugin) or \
@@ -155,6 +156,7 @@ class PresenceService(ExportedGObject):
                 # corner cases where laptops on mesh can't talk to ones on APs
                 _logger.debug("Gabble takes precedence, disconnect Salut")
                 self._ll_plugin.cleanup()
+            self.ConnectionManagerConnected(conn_name)
         else:
             self._tp_disconnected(plugin)
             if plugin == self._server_plugin and self._ll_plugin and \
@@ -163,6 +165,7 @@ class PresenceService(ExportedGObject):
                 # corner cases where laptops on mesh can't talk to ones on APs
                 if self._ll_plugin.status == CONNECTION_STATUS_DISCONNECTED:
                     self._ll_plugin.start()
+            self.ConnectionManagerDisconnected(conn_name)
 
     def _tp_connected(self, tp):
         self._connected_plugins.add(tp)
@@ -610,6 +613,14 @@ class PresenceService(ExportedGObject):
     def PrivateInvitation(self, bus_name, connection, channel, chan_type):
         pass
 
+    @dbus.service.signal(PRESENCE_INTERFACE, signature="s")
+    def ConnectionManagerConnected(self, conn_name):
+        pass
+
+    @dbus.service.signal(PRESENCE_INTERFACE, signature="s")
+    def ConnectionManagerDisconnected(self, conn_name):
+        pass
+
     @dbus.service.method(PRESENCE_INTERFACE, in_signature='',
                          out_signature="ao")
     def GetActivities(self):
diff --git a/src/telepathy_plugin.py b/src/telepathy_plugin.py
index 982f7cc..09025c1 100644
--- a/src/telepathy_plugin.py
+++ b/src/telepathy_plugin.py
@@ -599,3 +599,10 @@ class TelepathyPlugin(gobject.GObject):
         _logger.debug("::: IP4 address now %s", address)
 
         self._reconnect_timeout = self._RECONNECT_INITIAL_TIMEOUT
+
+    def conn_name(self):
+        """Identify the connection manager running.
+
+        Returns 'gabble' or 'salut'.
+        """
+        return self._TP_CONN_MANAGER
diff --git a/src/sugar/presence/presenceservice.py b/src/sugar/presence/presenceservice.py
index e2398a8..718da2b 100644
--- a/src/sugar/presence/presenceservice.py
+++ b/src/sugar/presence/presenceservice.py
@@ -62,7 +62,11 @@ class PresenceService(gobject.GObject):
                         ([gobject.TYPE_PYOBJECT])),
         'activity-shared': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE,
                         ([gobject.TYPE_PYOBJECT, gobject.TYPE_PYOBJECT,
-                          gobject.TYPE_PYOBJECT]))
+                          gobject.TYPE_PYOBJECT])),
+        'tp-connected': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE,
+                         ([gobject.TYPE_STRING])),
+        'tp-disconnected': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE,
+                         ([gobject.TYPE_STRING]))
     }
 
     _PS_BUDDY_OP = DBUS_PATH + "/Buddies/"
@@ -147,6 +151,10 @@ class PresenceService(gobject.GObject):
                                      self._activity_invitation_cb)
                 ps.connect_to_signal('PrivateInvitation',
                                      self._private_invitation_cb)
+                ps.connect_to_signal('ConnectionManagerConnected',
+                                     self._tp_connected_cb)
+                ps.connect_to_signal('ConnectionManagerDisconnected',
+                                     self._tp_disconnected_cb)
         return self._ps_
         
     _ps = property(
@@ -255,6 +263,28 @@ class PresenceService(gobject.GObject):
         gobject.idle_add(self._emit_private_invitation_signal, bus_name,
                 connection, channel, chan_type)
 
+    def _emit_tp_connected_signal(self, conn_name):
+        """Emit GObject event with name of Telepathy CM connected.
+        
+        Possible values for conn_name include 'gabble' and 'salut'.
+        """
+        self.emit('tp-connected', conn_name)
+
+    def _tp_connected_cb(self, conn_name):
+        """Callback for dbus event (forwards to method to emit GObject event)"""
+        gobject.idle_add(self._emit_tp_connected_signal, conn_name)
+
+    def _emit_tp_disconnected_signal(self, conn_name):
+        """Emit GObject event with name of Telepathy CM disconnected.
+        
+        Possible values for conn_name include 'gabble' and 'salut'.
+        """
+        self.emit('tp-disconnected', conn_name)
+
+    def _tp_disconnected_cb(self, conn_name):
+        """Callback for dbus event (forwards to method to emit GObject event)"""
+        gobject.idle_add(self._emit_tp_disconnected_signal, conn_name)
+
     def _emit_activity_appeared_signal(self, object_path):
         """Emit GObject event with presence.activity.Activity object"""
         self.emit('activity-appeared', self._new_object(object_path))
_______________________________________________
Sugar mailing list
[email protected]
http://lists.laptop.org/listinfo/sugar

Reply via email to