X-Git-Url: http://git.maemo.org/git/?p=theonering;a=blobdiff_plain;f=src%2Fchannel_manager.py;h=bce767ba9a8bf75521918479fc6180de18e6e87e;hp=979481f6af474a92a513cbab2fcaf1392d7abae1;hb=b3994c75e30db01e5c8995981adfb6949a184092;hpb=7912b2aa8daf492f3933d975fab97e59937981e1 diff --git a/src/channel_manager.py b/src/channel_manager.py index 979481f..bce767b 100644 --- a/src/channel_manager.py +++ b/src/channel_manager.py @@ -1,64 +1,75 @@ -import weakref import logging +import dbus import telepathy +import tp import channel +import util.misc as util_misc _moduleLogger = logging.getLogger("channel_manager") -class ChannelManager(object): +class ChannelManager(tp.ChannelManager): def __init__(self, connection): - self._connRef = weakref.ref(connection) - self._listChannels = weakref.WeakValueDictionary() - self._textChannels = weakref.WeakValueDictionary() - self._callChannels = 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() - for chan in self._callChannels.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.contact_list.GroupChannel(self._connRef(), handle) - elif handle.get_type() == telepathy.HANDLE_TYPE_CONTACT: - chan = channel.contact_list.creat_contact_list_channel(self._connRef(), handle) - else: - _moduleLogger.warn("Unknown channel type %r" % handle.get_type()) - self._listChannels[handle] = chan - self._connRef().add_channel(chan, handle, suppress_handler) - return chan + tp.ChannelManager.__init__(self, connection) - def channel_for_text(self, handle, suppress_handler=False): - if handle in self._textChannels: - chan = self._textChannels[handle] - else: - _moduleLogger.debug("Requesting new text channel") - contact = handle.contact + fixed = { + telepathy.CHANNEL_INTERFACE + '.ChannelType': telepathy.CHANNEL_TYPE_TEXT, + telepathy.CHANNEL_INTERFACE + '.TargetHandleType': dbus.UInt32(telepathy.HANDLE_TYPE_CONTACT) + } + self._implement_channel_class( + telepathy.CHANNEL_TYPE_TEXT, + self._get_text_channel, + fixed, + [] + ) + + fixed = { + telepathy.CHANNEL_INTERFACE + '.ChannelType': telepathy.CHANNEL_TYPE_CONTACT_LIST + } + self._implement_channel_class( + telepathy.CHANNEL_TYPE_CONTACT_LIST, + self._get_list_channel, + fixed, + [] + ) + + fixed = { + telepathy.CHANNEL_INTERFACE + '.ChannelType': telepathy.CHANNEL_TYPE_STREAMED_MEDIA, + telepathy.CHANNEL_INTERFACE + '.TargetHandleType': dbus.UInt32(telepathy.HANDLE_TYPE_CONTACT) + } + self._implement_channel_class( + telepathy.CHANNEL_TYPE_STREAMED_MEDIA, + self._get_media_channel, + fixed, + [telepathy.CHANNEL_INTERFACE + '.TargetHandle'] + ) - chan = channel.text.TextChannel(self._connRef()) - self._textChannels[handle] = chan - self._connRef().add_channel(chan, handle, suppress_handler) + 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_call(self, handle, suppress_handler=False): - if handle in self._callChannels: - chan = self._callChannels[handle] + def _get_text_channel(self, props): + _, surpress_handler, h = self._get_type_requested_handle(props) + + accountNumber = util_misc.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: - _moduleLogger.debug("Requesting new call channel") - contact = handle.contact + _moduleLogger.debug('New text channel') + chan = channel.text.TextChannel(self._conn, self, props, h) + return chan + + def _get_media_channel(self, props): + _, surpress_handler, h = self._get_type_requested_handle(props) - chan = channel.call.CallChannel(self._connRef()) - self._callChannels[handle] = chan - self._connRef().add_channel(chan, handle, suppress_handler) + _moduleLogger.debug('New media channel') + chan = channel.call.CallChannel(self._conn, self, props, h) return chan