Simplify sharing code using new PS API (import the patch attached to #5079)

This commit is contained in:
Guillaume Desmottes 2008-05-14 15:07:48 +02:00
parent eb839c2ef9
commit 5c40a70e5e

View File

@ -271,78 +271,70 @@ class Activity(gobject.GObject):
def set_up_tubes(self, reply_handler, error_handler): def set_up_tubes(self, reply_handler, error_handler):
cpaths = [] chans = []
def tubes_chan_ready(chan): def tubes_ready():
_logger.debug('%r: Tubes channel %r is ready', self, chan) if self.telepathy_text_chan is None or \
self.telepathy_tubes_chan = chan self.telepathy_tubes_chan is None:
return
_logger.debug('%r: finished setting up tubes', self) _logger.debug('%r: finished setting up tubes', self)
reply_handler() reply_handler()
def got_tubes_chan(path): def tubes_chan_ready(chan):
_logger.debug('%r: got Tubes channel at %s', self, path) _logger.debug('%r: Tubes channel %r is ready', self, chan)
telepathy.client.Channel(self.telepathy_conn.service_name, self.telepathy_tubes_chan = chan
path, ready_handler=tubes_chan_ready, tubes_ready()
error_handler=error_handler)
def text_chan_ready(chan): def text_chan_ready(chan):
_logger.debug('%r: Text channel %r is ready', self, chan) _logger.debug('%r: Text channel %r is ready', self, chan)
self.telepathy_text_chan = chan self.telepathy_text_chan = chan
tubes_ready()
self.telepathy_conn.RequestChannel(telepathy.CHANNEL_TYPE_TUBES,
telepathy.HANDLE_TYPE_ROOM,
self._telepathy_room_handle,
True,
reply_handler=got_tubes_chan,
error_handler=error_handler)
def got_text_chan(path):
_logger.debug('%r: got Text channel at %s', self, path)
telepathy.client.Channel(self.telepathy_conn.service_name,
path, ready_handler=text_chan_ready,
error_handler=error_handler)
def conn_ready(conn): def conn_ready(conn):
_logger.debug('%r: Connection %r is ready', self, conn) _logger.debug('%r: Connection %r is ready', self, conn)
self.telepathy_conn = conn self.telepathy_conn = conn
found_text_channel = False
found_tubes_channel = False
# For the moment we'll do this synchronously. for chan_path, chan_iface, handle_type, handle in chans:
# If the PS gained a GetRoom method, we could if handle_type != telepathy.HANDLE_TYPE_ROOM:
# do this async too return
for channel_path in cpaths: if chan_iface == telepathy.CHANNEL_TYPE_TEXT:
channel = telepathy.client.Channel(conn.service_name, telepathy.client.Channel(
channel_path) conn.service_name, chan_path,
handle_type, handle = channel.GetHandle() ready_handler=text_chan_ready,
if handle_type == telepathy.HANDLE_TYPE_ROOM: error_handler=error_handler)
room = handle found_text_channel = True
break
if room is None: elif chan_iface == telepathy.CHANNEL_TYPE_TUBES:
telepathy.client.Channel(
conn.service_name, chan_path,
ready_handler=tubes_chan_ready,
error_handler=error_handler)
found_tubes_channel = True
if not found_text_channel:
error_handler(AssertionError("Presence Service didn't create " error_handler(AssertionError("Presence Service didn't create "
"a chatroom")) "a chatroom"))
else: elif not found_tubes_channel:
self._telepathy_room_handle = room error_handler(AssertionError("Presence Service didn't create "
"tubes channel"))
conn.RequestChannel(telepathy.CHANNEL_TYPE_TEXT, def channels_listed(bus_name, conn_path, channels):
telepathy.HANDLE_TYPE_ROOM, _logger.debug('%r: Connection on %s at %s, channels: %r',
room, True, self, bus_name, conn_path, channels)
reply_handler=got_text_chan,
error_handler=error_handler)
def got_channels(bus_name, conn_path, channel_paths):
_logger.debug('%r: Connection on %s at %s, channel paths: %r',
self, bus_name, conn_path, channel_paths)
# can't use assignment for this due to Python scoping # can't use assignment for this due to Python scoping
cpaths.extend(channel_paths) chans.extend(channels)
telepathy.client.Connection(bus_name, conn_path, telepathy.client.Connection(bus_name, conn_path,
ready_handler=conn_ready, ready_handler=conn_ready,
error_handler=error_handler) error_handler=error_handler)
self._activity.GetChannels(reply_handler=got_channels,
self._activity.ListChannels(reply_handler=channels_listed,
error_handler=error_handler) error_handler=error_handler)
def _join_cb(self): def _join_cb(self):