9 class ChannelManager(object):
11 def __init__(self, connection):
12 self._connRef = weakref.ref(connection)
13 self._listChannels = weakref.WeakValueDictionary()
14 self._textChannels = weakref.WeakValueDictionary()
17 for chan in self._listChannels.values():
18 chan.remove_from_connection()# so that dbus lets it die.
19 for chan in self._textChannels.values():
22 def channel_for_list(self, handle, suppress_handler=False):
23 if handle in self._listChannels:
24 chan = self._listChannels[handle]
26 if handle.get_type() == telepathy.HANDLE_TYPE_GROUP:
27 chan = channel.group.GroupChannel(self._connRef(), handle)
28 elif handle.get_type() == telepathy.HANDLE_TYPE_CONTACT:
29 chan = channel.contact_list.creat_contact_list_channel(self._connRef(), handle)
31 logging.warn("Unknown channel type %r" % handle.get_type())
32 self._listChannels[handle] = chan
33 self._connRef().add_channel(chan, handle, suppress_handler)
36 def channel_for_text(self, handle, conversation=None, suppress_handler=False):
37 if handle in self._textChannels:
38 chan = self._textChannels[handle]
40 logging.debug("Requesting new text channel")
41 contact = handle.contact
43 if conversation is None:
44 client = self._connRef().msn_client
46 chan = channel.text.TextChannel(self._connRef(), conversation)
47 self._textChannels[handle] = chan
48 self._connRef().add_channel(chan, handle, suppress_handler)