Starting some tp_utils
[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_CONTACT_LIST
21                 }
22                 self._implement_channel_class(
23                         telepathy.CHANNEL_TYPE_CONTACT_LIST,
24                         self._get_list_channel,
25                         fixed,
26                         []
27                 )
28
29                 fixed = {
30                         telepathy.CHANNEL_INTERFACE + '.ChannelType': telepathy.CHANNEL_TYPE_TEXT,
31                         telepathy.CHANNEL_INTERFACE + '.TargetHandleType': dbus.UInt32(telepathy.HANDLE_TYPE_CONTACT)
32                 }
33                 self._implement_channel_class(
34                         telepathy.CHANNEL_TYPE_TEXT,
35                         self._get_text_channel,
36                         fixed,
37                         []
38                 )
39
40                 fixed = {
41                         telepathy.CHANNEL_INTERFACE + '.ChannelType': telepathy.CHANNEL_TYPE_FILE_TRANSFER,
42                         telepathy.CHANNEL_INTERFACE + '.TargetHandleType': dbus.UInt32(telepathy.HANDLE_TYPE_CONTACT)
43                 }
44                 self._implement_channel_class(
45                         telepathy.CHANNEL_TYPE_FILE_TRANSFER,
46                         self._get_file_transfer_channel,
47                         fixed,
48                         []
49                 )
50
51                 fixed = {
52                         telepathy.CHANNEL_INTERFACE + '.ChannelType': telepathy.CHANNEL_TYPE_STREAMED_MEDIA,
53                         telepathy.CHANNEL_INTERFACE + '.TargetHandleType': dbus.UInt32(telepathy.HANDLE_TYPE_CONTACT)
54                 }
55                 self._implement_channel_class(
56                         telepathy.CHANNEL_TYPE_STREAMED_MEDIA,
57                         self._get_media_channel,
58                         fixed,
59                         [telepathy.CHANNEL_INTERFACE + '.TargetHandle']
60                 )
61
62         def _get_list_channel(self, props):
63                 _, surpress_handler, h = self._get_type_requested_handle(props)
64
65                 _moduleLogger.debug('New contact list channel')
66                 chan = channel.contact_list.create_contact_list_channel(self._conn, self, props, h)
67                 return chan
68
69         def _get_text_channel(self, props):
70                 _, surpress_handler, h = self._get_type_requested_handle(props)
71
72                 accountNumber = util_misc.normalize_number(self._conn.session.backend.get_account_number())
73                 if h.phoneNumber == accountNumber:
74                         _moduleLogger.debug('New Debug channel')
75                         chan = channel.debug_prompt.DebugPromptChannel(self._conn, self, props, h)
76                 else:
77                         _moduleLogger.debug('New text channel')
78                         chan = channel.text.TextChannel(self._conn, self, props, h)
79                 return chan
80
81         def _get_file_transfer_channel(self, props):
82                 _, surpress_handler, h = self._get_type_requested_handle(props)
83
84                 _moduleLogger.debug('New file transfer channel')
85                 chan = channel.debug_log.DebugLogChannel(self._conn, self, props, h)
86                 return chan
87
88         def _get_media_channel(self, props):
89                 _, surpress_handler, h = self._get_type_requested_handle(props)
90
91                 _moduleLogger.debug('New media channel')
92                 chan = channel.call.CallChannel(self._conn, self, props, h)
93                 return chan