[telepathy-butterfly/master] Implemented Capabilities interface

Louis-Francis Ratté-Boulianne louis-francis.ratte-boulianne at collabora.co.uk
Thu Sep 10 06:48:10 PDT 2009


---
 butterfly/capabilities.py |   95 +++++++++++++++++++++++++++++++++++++++++++++
 butterfly/connection.py   |    3 +
 butterfly/contacts.py     |    7 ++-
 3 files changed, 103 insertions(+), 2 deletions(-)
 create mode 100644 butterfly/capabilities.py

diff --git a/butterfly/capabilities.py b/butterfly/capabilities.py
new file mode 100644
index 0000000..3a63045
--- /dev/null
+++ b/butterfly/capabilities.py
@@ -0,0 +1,95 @@
+# telepathy-butterfly - an MSN connection manager for Telepathy
+#
+# Copyright (C) 2009 Youness Alaoui <youness.alaoui at collabora.co.uk>
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+
+import logging
+import dbus
+
+import telepathy
+import papyon
+import papyon.event
+
+from butterfly.handle import ButterflyHandleFactory
+
+__all__ = ['ButterflyCapabilities']
+
+logger = logging.getLogger('Butterfly.Capabilities')
+
+class ButterflyCapabilities(
+        telepathy.server.ConnectionInterfaceCapabilities,
+        papyon.event.ContactEventInterface):
+
+    def __init__(self):
+        telepathy.server.ConnectionInterfaceCapabilities.__init__(self)
+        papyon.event.ContactEventInterface.__init__(self, self.msn_client)
+        dbus_interface = telepathy.CONNECTION_INTERFACE_CAPABILITIES
+
+    @dbus.service.method('org.freedesktop.Telepathy.Connection.Interface.Capabilities', in_signature='a(su)as', out_signature='a(su)')
+    def AdvertiseCapabilities(self, Add, Remove):
+        print "*******AdvertiseCapabilities ****** %r ***** %r" % (Add, Remove)
+        for caps, specs in Add:
+            if caps == telepathy.CHANNEL_TYPE_STREAMED_MEDIA:
+                self._self_handle.profile.client_id.has_webcam = True
+        for caps in Remove:
+            if caps == telepathy.CHANNEL_TYPE_STREAMED_MEDIA:
+                self._self_handle.profile.client_id.has_webcam = False
+
+        return telepathy.server.ConnectionInterfaceCapabilities.\
+            AdvertiseCapabilities(self, Add, Remove)
+
+    # papyon.event.ContactEventInterface
+    def on_contact_client_capabilities_changed(self, contact):
+        self._update_capabilities(contact)
+
+    def _update_capabilities(self, contact):
+        handle = ButterflyHandleFactory(self, 'contact',
+                contact.account, contact.network_id)
+        ctype = telepathy.CHANNEL_TYPE_STREAMED_MEDIA
+
+        new_gen, new_spec = self._get_capabilities(contact)
+        if handle in self._caps:
+            old_gen, old_spec = self._caps[handle][ctype]
+        else:
+            old_gen = 0
+            old_spec = 0
+
+        if old_gen == new_gen and old_spec == new_spec:
+            return
+
+        diff = (int(handle), ctype, old_gen, new_gen, old_spec, new_spec)
+        print diff
+        self.CapabilitiesChanged([diff])
+
+    def _get_capabilities(self, contact):
+        gen_caps = 0
+        spec_caps = 0
+
+        caps = contact.client_capabilities
+        if caps.supports_sip_invite:
+            gen_caps |= telepathy.CONNECTION_CAPABILITY_FLAG_CREATE
+            gen_caps |= telepathy.CONNECTION_CAPABILITY_FLAG_INVITE
+            spec_caps |= telepathy.CHANNEL_MEDIA_CAPABILITY_AUDIO
+            spec_caps |= telepathy.CHANNEL_MEDIA_CAPABILITY_NAT_TRAVERSAL_STUN
+            print "%s supports audio" % contact.account
+
+            if caps.has_webcam:
+                spec_caps |= telepathy.CHANNEL_MEDIA_CAPABILITY_VIDEO
+                print "%s supports video" % contact.account
+            else:
+                print "%s doesn't support video" % contact.account
+
+        return gen_caps, spec_caps
diff --git a/butterfly/connection.py b/butterfly/connection.py
index fe82400..94dd8fa 100644
--- a/butterfly/connection.py
+++ b/butterfly/connection.py
@@ -29,6 +29,7 @@ from butterfly.presence import ButterflyPresence
 from butterfly.aliasing import ButterflyAliasing
 from butterfly.avatars import ButterflyAvatars
 from butterfly.handle import ButterflyHandleFactory
+from butterfly.capabilities import ButterflyCapabilities
 from butterfly.contacts import ButterflyContacts
 from butterfly.channel_manager import ButterflyChannelManager
 
@@ -42,6 +43,7 @@ class ButterflyConnection(telepathy.server.Connection,
         ButterflyPresence,
         ButterflyAliasing,
         ButterflyAvatars,
+        ButterflyCapabilities,
         ButterflyContacts,
         papyon.event.ClientEventInterface,
         papyon.event.InviteEventInterface):
@@ -95,6 +97,7 @@ class ButterflyConnection(telepathy.server.Connection,
             ButterflyPresence.__init__(self)
             ButterflyAliasing.__init__(self)
             ButterflyAvatars.__init__(self)
+            ButterflyCapabilities.__init__(self)
             ButterflyContacts.__init__(self)
             papyon.event.ClientEventInterface.__init__(self, self._msn_client)
             papyon.event.InviteEventInterface.__init__(self, self._msn_client)
diff --git a/butterfly/contacts.py b/butterfly/contacts.py
index 26700ba..62696cb 100644
--- a/butterfly/contacts.py
+++ b/butterfly/contacts.py
@@ -38,7 +38,8 @@ class ButterflyContacts(
         telepathy.CONNECTION : 'contact-id',
         telepathy.CONNECTION_INTERFACE_SIMPLE_PRESENCE : 'presence',
         telepathy.CONNECTION_INTERFACE_ALIASING : 'alias',
-        telepathy.CONNECTION_INTERFACE_AVATARS : 'token'
+        telepathy.CONNECTION_INTERFACE_AVATARS : 'token',
+        telepathy.CONNECTION_INTERFACE_CAPABILITIES : 'caps'
         }
 
     def __init__(self):
@@ -74,7 +75,9 @@ class ButterflyContacts(
             telepathy.CONNECTION_INTERFACE_ALIASING :
                 lambda x: self.GetAliases(x).items(),
             telepathy.CONNECTION_INTERFACE_AVATARS :
-                lambda x: self.GetKnownAvatarTokens(x).items()
+                lambda x: self.GetKnownAvatarTokens(x).items(),
+            telepathy.CONNECTION_INTERFACE_CAPABILITIES :
+                lambda x: self.GetCapabilities(x).items()
             }
 
         #Hold handles if needed
-- 
1.5.6.5




More information about the telepathy-commits mailing list