[telepathy-butterfly/master] Add Initiator{ID, Handle} as immutable properties on media channels.
Jonny Lamb
jonny.lamb at collabora.co.uk
Mon Sep 28 10:33:38 PDT 2009
Signed-off-by: Jonny Lamb <jonny.lamb at collabora.co.uk>
---
butterfly/channel/media.py | 23 +++++++++++++++++++++++
butterfly/connection.py | 17 ++++++++++++-----
2 files changed, 35 insertions(+), 5 deletions(-)
diff --git a/butterfly/channel/media.py b/butterfly/channel/media.py
index 713029a..3a90309 100644
--- a/butterfly/channel/media.py
+++ b/butterfly/channel/media.py
@@ -28,6 +28,8 @@ from butterfly.util.decorator import async
from butterfly.handle import ButterflyHandleFactory
from butterfly.media import ButterflySessionHandler
+from telepathy.interfaces import CHANNEL_INTERFACE
+
__all__ = ['ButterflyMediaChannel']
logger = logging.getLogger('Butterfly.MediaChannel')
@@ -54,6 +56,27 @@ class ButterflyMediaChannel(
self._call = call
self._handle = handle
+ self._implement_property_get(CHANNEL_INTERFACE, {
+ 'InitiatorHandle': lambda: self._initiator.id,
+ 'InitiatorID': lambda: self._initiator.name
+ })
+
+
+ self._add_immutables({
+ 'InitiatorHandle': CHANNEL_INTERFACE,
+ 'InitiatorID': CHANNEL_INTERFACE,
+ })
+
+ if CHANNEL_INTERFACE + '.InitiatorHandle' in props:
+ self._initiator = conn.handle(telepathy.HANDLE_TYPE_CONTACT,
+ props[CHANNEL_INTERFACE + '.InitiatorHandle'])
+ elif CHANNEL_INTERFACE + '.InitiatorID' in props:
+ self._initiator = ButterflyHandleFactory(conn, 'contact',
+ id=props[CHANNEL_INTERFACE + '.InitiatorHandle'])
+ else:
+ logger.warning('InitiatorID or InitiatorHandle not set on new channel')
+ self._initiator = None
+
self._session_handler = ButterflySessionHandler(self._conn, self, call.media_session)
self.NewSessionHandler(self._session_handler, self._session_handler.subtype)
diff --git a/butterfly/connection.py b/butterfly/connection.py
index 415f4ea..ea3d183 100644
--- a/butterfly/connection.py
+++ b/butterfly/connection.py
@@ -173,14 +173,20 @@ class ButterflyConnection(telepathy.server.Connection,
self.add_client_handle(handle, sender)
return handles
- def _generate_props(self, channel_type, handle, suppress_handler):
- return {
+ def _generate_props(self, channel_type, handle, suppress_handler, initiator_handle=None):
+ props = {
telepathy.CHANNEL_INTERFACE + '.ChannelType': channel_type,
telepathy.CHANNEL_INTERFACE + '.TargetHandle': 0 if handle is None else handle.get_id(),
telepathy.CHANNEL_INTERFACE + '.TargetHandleType': telepathy.HANDLE_TYPE_NONE if handle is None else handle.get_type(),
telepathy.CHANNEL_INTERFACE + '.Requested': suppress_handler
}
+ if initiator_handle is not None:
+ props[telepathy.CHANNEL_INTERFACE + '.InitiatorHandle'] = initiator_handle.id
+
+ return props
+
+
@dbus.service.method(telepathy.CONNECTION, in_signature='suub',
out_signature='o', async_callbacks=('_success', '_error'))
def RequestChannel(self, type, handle_type, handle_id, suppress_handler,
@@ -283,7 +289,7 @@ class ButterflyConnection(telepathy.server.Connection,
participant.account, participant.network_id)
props = self._generate_props(telepathy.CHANNEL_TYPE_TEXT,
- handle, False)
+ handle, False, initiator_handle=handle)
channel = self._channel_manager.channel_for_props(props,
signal=True, conversation=conversation)
@@ -294,7 +300,8 @@ class ButterflyConnection(telepathy.server.Connection,
call.peer.network_id)
props = self._generate_props(telepathy.CHANNEL_TYPE_STREAMED_MEDIA,
- handle, False)
+ handle, False, initiator_handle=handle)
+
channel = self._channel_manager.channel_for_props(props,
signal=True, call=call)
@@ -306,7 +313,7 @@ class ButterflyConnection(telepathy.server.Connection,
handle = ButterflyHandleFactory(self, 'contact', session.peer.account,
session.peer.network_id)
props = self._generate_props(telepathy.CHANNEL_TYPE_STREAMED_MEDIA,
- handle, False)
+ handle, False, initiator_handle=handle)
channel = self._channel_manager.channel_for_props(props, signal=True,
call=session)
--
1.5.6.5
More information about the telepathy-commits
mailing list