Explaining the hack I put in
[theonering] / src / channel_manager.py
1 import logging
2
3 import dbus
4 import telepathy
5
6 import tp
7 import channel
8 import util.misc as util_misc
9
10
11 _moduleLogger = logging.getLogger("channel_manager")
12
13
14 class ChannelManager(tp.ChannelManager):
15
16         def __init__(self, connection):
17                 tp.ChannelManager.__init__(self, connection)
18
19                 fixed = {
20                         telepathy.CHANNEL_INTERFACE + '.ChannelType': telepathy.CHANNEL_TYPE_TEXT,
21                         telepathy.CHANNEL_INTERFACE + '.TargetHandleType': dbus.UInt32(telepathy.HANDLE_TYPE_CONTACT)
22                 }
23                 self._implement_channel_class(
24                         telepathy.CHANNEL_TYPE_TEXT,
25                         self._get_text_channel,
26                         fixed,
27                         []
28                 )
29
30                 fixed = {
31                         telepathy.CHANNEL_INTERFACE + '.ChannelType': telepathy.CHANNEL_TYPE_CONTACT_LIST
32                 }
33                 self._implement_channel_class(
34                         telepathy.CHANNEL_TYPE_CONTACT_LIST,
35                         self._get_list_channel,
36                         fixed,
37                         []
38                 )
39
40                 fixed = {
41                         telepathy.CHANNEL_INTERFACE + '.ChannelType': telepathy.CHANNEL_TYPE_STREAMED_MEDIA,
42                         telepathy.CHANNEL_INTERFACE + '.TargetHandleType': dbus.UInt32(telepathy.HANDLE_TYPE_CONTACT)
43                 }
44                 self._implement_channel_class(
45                         telepathy.CHANNEL_TYPE_STREAMED_MEDIA,
46                         self._get_media_channel,
47                         fixed,
48                         [telepathy.CHANNEL_INTERFACE + '.TargetHandle']
49                 )
50
51         def _get_list_channel(self, props):
52                 _, surpress_handler, h = self._get_type_requested_handle(props)
53
54                 _moduleLogger.debug('New contact list channel')
55                 chan = channel.contact_list.create_contact_list_channel(self._conn, self, props, h)
56                 return chan
57
58         def _get_text_channel(self, props):
59                 _, surpress_handler, h = self._get_type_requested_handle(props)
60
61                 accountNumber = util_misc.normalize_number(self._conn.session.backend.get_account_number())
62                 if h.phoneNumber == accountNumber:
63                         _moduleLogger.debug('New Debug channel')
64                         chan = channel.debug_prompt.DebugPromptChannel(self._conn, self, props, h)
65                 else:
66                         _moduleLogger.debug('New text channel')
67                         chan = channel.text.TextChannel(self._conn, self, props, h)
68                 return chan
69
70         def _get_media_channel(self, props):
71                 _, surpress_handler, h = self._get_type_requested_handle(props)
72
73                 _moduleLogger.debug('New media channel')
74                 chan = channel.call.CallChannel(self._conn, self, props, h)
75                 return chan