- for chan in self._listChannels.values():
- chan.Close()
- 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):
- try:
- chan = self._listChannels[handle]
- except KeyError, e:
- if handle.get_type() != telepathy.HANDLE_TYPE_LIST:
- raise telepathy.errors.NotImplemented("Only server lists are allowed")
- _moduleLogger.debug("Requesting new contact list channel")
-
- chan = channel.contact_list.create_contact_list_channel(self._connRef(), handle)
- self._listChannels[handle] = chan
- self._connRef().add_channel(chan, handle, suppress_handler)
+ for channel_type in self._requestable_channel_classes:
+ for chan in self._channels[channel_type].values():
+ try:
+ _moduleLogger.debug("Closing %s %s" % (channel_type, chan._object_path))
+ chan.Close()
+ except Exception:
+ _moduleLogger.exception("Shutting down %r" % (chan, ))
+
+ def remove_channel(self, chan):
+ for channel_type in self._requestable_channel_classes:
+ for handle, ichan in self._channels[channel_type].items():
+ if chan == ichan:
+ del self._channels[channel_type][handle]
+
+ def _get_type_requested_handle(self, props):
+ type = props[telepathy.interfaces.CHANNEL_INTERFACE + '.ChannelType']
+ requested = props[telepathy.interfaces.CHANNEL_INTERFACE + '.Requested']
+ target_handle = props[telepathy.interfaces.CHANNEL_INTERFACE + '.TargetHandle']
+ target_handle_type = props[telepathy.interfaces.CHANNEL_INTERFACE + '.TargetHandleType']
+
+ handle = self._conn._handles[target_handle_type, target_handle]
+
+ return (type, requested, handle)
+
+ def channel_exists(self, props):
+ type, _, handle = self._get_type_requested_handle(props)
+
+ if type in self._channels:
+ if handle in self._channels[type]:
+ return True
+
+ return False
+
+ def channel_for_props(self, props, signal=True, **args):
+ type, suppress_handler, handle = self._get_type_requested_handle(props)
+
+ if type not in self._requestable_channel_classes:
+ raise NotImplemented('Unknown channel type "%s"' % type)
+
+ if self.channel_exists(props):
+ return self._channels[type][handle]
+
+ chan = self._requestable_channel_classes[type](props, **args)
+
+ if hasattr(self._conn, "add_channels"):
+ # HACK Newer python-telepathy
+ self._conn.add_channels([chan], signal=signal)
+ elif hasattr(self._conn, "add_channel"):
+ # HACK Older python-telepathy
+ self._conn.NewChannels([(chan._object_path, chan.get_props())])
+ self._conn.add_channel(chan, handle, suppress_handler)
+ else:
+ raise RuntimeError("Uhh, what just happened with the connection")
+ self._channels[type][handle] = chan
+