What I said was 0.8.15 was really 0.8.16
[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 misc_utils
9
10
11 _moduleLogger = logging.getLogger(__name__)
12
13
14 class ChannelManager(tp.ChannelManager):
15
16         def __init__(self, connection):
17                 tp.ChannelManager.__init__(self, connection)
18
19                 classes = [
20                         (
21                                 {
22                                         telepathy.CHANNEL_INTERFACE + '.ChannelType': telepathy.CHANNEL_TYPE_CONTACT_LIST,
23                                         telepathy.CHANNEL_INTERFACE + '.TargetHandleType': dbus.UInt32(telepathy.HANDLE_TYPE_LIST),
24                                 },
25                                 [
26                                         telepathy.CHANNEL_INTERFACE + '.TargetHandle',
27                                         telepathy.CHANNEL_INTERFACE + '.TargetID',
28                                 ],
29                         ),
30                 ]
31                 self.implement_channel_classes(
32                         telepathy.CHANNEL_TYPE_CONTACT_LIST,
33                         self._get_list_channel,
34                         classes,
35                 )
36
37                 classes = [
38                         (
39                                 {
40                                         telepathy.CHANNEL_INTERFACE + '.ChannelType': telepathy.CHANNEL_TYPE_TEXT,
41                                         telepathy.CHANNEL_INTERFACE + '.TargetHandleType': dbus.UInt32(telepathy.HANDLE_TYPE_CONTACT)
42                                 },
43                                 [
44                                         telepathy.CHANNEL_INTERFACE + '.TargetHandle',
45                                         telepathy.CHANNEL_INTERFACE + '.TargetID',
46                                 ],
47                         ),
48                 ]
49                 self.implement_channel_classes(
50                         telepathy.CHANNEL_TYPE_TEXT,
51                         self._get_text_channel,
52                         classes,
53                 )
54
55                 classes = [
56                         (
57                                 {
58                                         telepathy.CHANNEL_INTERFACE + '.ChannelType': telepathy.CHANNEL_TYPE_FILE_TRANSFER,
59                                         telepathy.CHANNEL_INTERFACE + '.TargetHandleType': dbus.UInt32(telepathy.HANDLE_TYPE_CONTACT)
60                                 },
61                                 [
62                                         telepathy.CHANNEL_INTERFACE + '.TargetHandle',
63                                         telepathy.CHANNEL_INTERFACE + '.TargetID',
64                                 ],
65                         ),
66                 ]
67                 self.implement_channel_classes(
68                         telepathy.CHANNEL_TYPE_FILE_TRANSFER,
69                         self._get_file_transfer_channel,
70                         classes,
71                 )
72
73                 classes = [
74                         (
75                                 {
76                                         telepathy.CHANNEL_INTERFACE + '.ChannelType': telepathy.CHANNEL_TYPE_STREAMED_MEDIA,
77                                         telepathy.CHANNEL_INTERFACE + '.TargetHandleType': dbus.UInt32(telepathy.HANDLE_TYPE_CONTACT)
78                                 },
79                                 [
80                                         telepathy.CHANNEL_INTERFACE + '.TargetHandle',
81                                         telepathy.CHANNEL_INTERFACE + '.TargetID',
82                                         telepathy.CHANNEL_TYPE_STREAMED_MEDIA + '.InitialAudio',
83                                         telepathy.CHANNEL_TYPE_STREAMED_MEDIA + '.InitialVideo',
84                                 ],
85                         ),
86                 ]
87                 self.implement_channel_classes(
88                         telepathy.CHANNEL_TYPE_STREAMED_MEDIA,
89                         self._get_media_channel,
90                         classes,
91                 )
92
93         def _get_list_channel(self, props):
94                 _, surpress_handler, h = self._get_type_requested_handle(props)
95
96                 _moduleLogger.debug('New contact list channel')
97                 chan = channel.contact_list.create_contact_list_channel(self._conn, self, props, h)
98                 return chan
99
100         def _get_text_channel(self, props):
101                 _, surpress_handler, h = self._get_type_requested_handle(props)
102
103                 accountNumber = misc_utils.normalize_number(self._conn.session.backend.get_account_number())
104                 if h.phoneNumber == accountNumber:
105                         _moduleLogger.debug('New Debug channel')
106                         chan = channel.debug_prompt.DebugPromptChannel(self._conn, self, props, h)
107                 else:
108                         _moduleLogger.debug('New text channel')
109                         chan = channel.text.TextChannel(self._conn, self, props, h)
110                 return chan
111
112         def _get_file_transfer_channel(self, props):
113                 _, surpress_handler, h = self._get_type_requested_handle(props)
114
115                 _moduleLogger.debug('New file transfer channel')
116                 chan = channel.debug_log.DebugLogChannel(self._conn, self, props, h)
117                 return chan
118
119         def _get_media_channel(self, props):
120                 _, surpress_handler, h = self._get_type_requested_handle(props)
121
122                 _moduleLogger.debug('New media channel')
123                 chan = channel.call.CallChannel(self._conn, self, props, h)
124                 return chan