X-Git-Url: http://git.maemo.org/git/?p=theonering;a=blobdiff_plain;f=src%2Fchannel_manager.py;h=1f732e177b8efe76010300c189276e2ed60b27fc;hp=ba069573cf8c829c3706a6b9fe304b2931fb25ec;hb=afa4cdb64e451070cf87cc02f257c582fa057f53;hpb=ab4da214c520d763bbbddeb828c8e7c838374fe3;ds=sidebyside diff --git a/src/channel_manager.py b/src/channel_manager.py index ba06957..1f732e1 100644 --- a/src/channel_manager.py +++ b/src/channel_manager.py @@ -1,49 +1,124 @@ -import weakref import logging +import dbus import telepathy +import tp import channel +import util.misc as misc_utils -class ChannelManager(object): +_moduleLogger = logging.getLogger(__name__) + + +class ChannelManager(tp.ChannelManager): def __init__(self, connection): - self._connRef = weakref.ref(connection) - self._listChannels = weakref.WeakValueDictionary() - self._textChannels = weakref.WeakValueDictionary() - - def close(self): - for chan in self._listChannels.values(): - chan.remove_from_connection()# so that dbus lets it die. - for chan in self._textChannels.values(): - chan.Close() - - def channel_for_list(self, handle, suppress_handler=False): - if handle in self._listChannels: - chan = self._listChannels[handle] - else: - if handle.get_type() == telepathy.HANDLE_TYPE_GROUP: - chan = channel.group.GroupChannel(self._connRef(), handle) - elif handle.get_type() == telepathy.HANDLE_TYPE_CONTACT: - chan = channel.contact_list.creat_contact_list_channel(self._connRef(), handle) - else: - logging.warn("Unknown channel type %r" % handle.get_type()) - self._listChannels[handle] = chan - self._connRef().add_channel(chan, handle, suppress_handler) + tp.ChannelManager.__init__(self, connection) + + classes = [ + ( + { + telepathy.CHANNEL_INTERFACE + '.ChannelType': telepathy.CHANNEL_TYPE_CONTACT_LIST, + telepathy.CHANNEL_INTERFACE + '.TargetHandleType': dbus.UInt32(telepathy.HANDLE_TYPE_LIST), + }, + [ + telepathy.CHANNEL_INTERFACE + '.TargetHandle', + telepathy.CHANNEL_INTERFACE + '.TargetID', + ], + ), + ] + self.implement_channel_classes( + telepathy.CHANNEL_TYPE_CONTACT_LIST, + self._get_list_channel, + classes, + ) + + classes = [ + ( + { + telepathy.CHANNEL_INTERFACE + '.ChannelType': telepathy.CHANNEL_TYPE_TEXT, + telepathy.CHANNEL_INTERFACE + '.TargetHandleType': dbus.UInt32(telepathy.HANDLE_TYPE_CONTACT) + }, + [ + telepathy.CHANNEL_INTERFACE + '.TargetHandle', + telepathy.CHANNEL_INTERFACE + '.TargetID', + ], + ), + ] + self.implement_channel_classes( + telepathy.CHANNEL_TYPE_TEXT, + self._get_text_channel, + classes, + ) + + classes = [ + ( + { + telepathy.CHANNEL_INTERFACE + '.ChannelType': telepathy.CHANNEL_TYPE_FILE_TRANSFER, + telepathy.CHANNEL_INTERFACE + '.TargetHandleType': dbus.UInt32(telepathy.HANDLE_TYPE_CONTACT) + }, + [ + telepathy.CHANNEL_INTERFACE + '.TargetHandle', + telepathy.CHANNEL_INTERFACE + '.TargetID', + ], + ), + ] + self.implement_channel_classes( + telepathy.CHANNEL_TYPE_FILE_TRANSFER, + self._get_file_transfer_channel, + classes, + ) + + classes = [ + ( + { + telepathy.CHANNEL_INTERFACE + '.ChannelType': telepathy.CHANNEL_TYPE_STREAMED_MEDIA, + telepathy.CHANNEL_INTERFACE + '.TargetHandleType': dbus.UInt32(telepathy.HANDLE_TYPE_CONTACT) + }, + [ + telepathy.CHANNEL_INTERFACE + '.TargetHandle', + telepathy.CHANNEL_INTERFACE + '.TargetID', + telepathy.CHANNEL_TYPE_STREAMED_MEDIA + '.InitialAudio', + telepathy.CHANNEL_TYPE_STREAMED_MEDIA + '.InitialVideo', + ], + ), + ] + self.implement_channel_classes( + telepathy.CHANNEL_TYPE_STREAMED_MEDIA, + self._get_media_channel, + classes, + ) + + def _get_list_channel(self, props): + _, surpress_handler, h = self._get_type_requested_handle(props) + + _moduleLogger.debug('New contact list channel') + chan = channel.contact_list.create_contact_list_channel(self._conn, self, props, h) return chan - def channel_for_text(self, handle, conversation=None, suppress_handler=False): - if handle in self._textChannels: - chan = self._textChannels[handle] + def _get_text_channel(self, props): + _, surpress_handler, h = self._get_type_requested_handle(props) + + accountNumber = misc_utils.normalize_number(self._conn.session.backend.get_account_number()) + if h.phoneNumber == accountNumber: + _moduleLogger.debug('New Debug channel') + chan = channel.debug_prompt.DebugPromptChannel(self._conn, self, props, h) else: - logging.debug("Requesting new text channel") - contact = handle.contact - - if conversation is None: - client = self._connRef().msn_client - conversation = None - chan = channel.text.TextChannel(self._connRef(), conversation) - self._textChannels[handle] = chan - self._connRef().add_channel(chan, handle, suppress_handler) + _moduleLogger.debug('New text channel') + chan = channel.text.TextChannel(self._conn, self, props, h) + return chan + + def _get_file_transfer_channel(self, props): + _, surpress_handler, h = self._get_type_requested_handle(props) + + _moduleLogger.debug('New file transfer channel') + chan = channel.debug_log.DebugLogChannel(self._conn, self, props, h) + return chan + + def _get_media_channel(self, props): + _, surpress_handler, h = self._get_type_requested_handle(props) + + _moduleLogger.debug('New media channel') + chan = channel.call.CallChannel(self._conn, self, props, h) return chan