Getting start on this here em code
[theonering] / src / channel_manager.py
1 import weakref
2 import logging
3
4 import telepathy
5
6 import channel
7
8
9 class ChannelManager(object):
10
11         def __init__(self, connection):
12                 self._connRef = weakref.ref(connection)
13                 self._listChannels = weakref.WeakValueDictionary()
14                 self._textChannels = weakref.WeakValueDictionary()
15
16         def close(self):
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():
20                         chan.Close()
21
22         def channel_for_list(self, handle, suppress_handler=False):
23                 if handle in self._listChannels:
24                         chan = self._listChannels[handle]
25                 else:
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)
30                         else:
31                                 logging.warn("Unknown channel type %r" % handle.get_type())
32                         self._listChannels[handle] = chan
33                         self._connRef().add_channel(chan, handle, suppress_handler)
34                 return chan
35
36         def channel_for_text(self, handle, conversation=None, suppress_handler=False):
37                 if handle in self._textChannels:
38                         chan = self._textChannels[handle]
39                 else:
40                         logging.debug("Requesting new text channel")
41                         contact = handle.contact
42
43                         if conversation is None:
44                                 client = self._connRef().msn_client
45                                 conversation = None
46                         chan = channel.text.TextChannel(self._connRef(), conversation)
47                         self._textChannels[handle] = chan
48                         self._connRef().add_channel(chan, handle, suppress_handler)
49                 return chan