8 import util.coroutines as coroutines
11 _moduleLogger = logging.getLogger('capabilities')
14 class CapabilitiesMixin(tp.ConnectionInterfaceCapabilities):
17 tp.ConnectionInterfaceCapabilities.__init__(self)
18 self._caps[telepathy.CHANNEL_TYPE_STREAMED_MEDIA] = self._get_capabilities(
19 None, telepathy.CHANNEL_TYPE_STREAMED_MEDIA
21 self._callback = coroutines.func_sink(
22 coroutines.expand_positional(
23 self._on_contacts_refreshed
26 self.session.addressbook.updateSignalHandler.register_sink(
35 raise NotImplementedError("Abstract property called")
41 raise NotImplementedError("Abstract function called")
43 def get_handle_by_name(self, handleType, handleName):
47 raise NotImplementedError("Abstract function called")
49 @gtk_toolbox.log_exception(_moduleLogger)
50 def _on_contacts_refreshed(self, addressbook, added, removed, changed):
51 capabilityDifferences = []
52 for isAdded, phoneNumber in itertools.chain(
53 itertools.izip(itertools.repeat(True), added),
54 itertools.izip(itertools.repeat(False), removed),
56 handle = self.get_handle_by_name(telepathy.HANDLE_TYPE_CONTACT, phoneNumber)
57 ctype = telepathy.CHANNEL_TYPE_STREAMED_MEDIA
60 new_gen, new_spec = self._get_capabilities(handle, ctype)
62 new_gen, new_spec = 0, 0
63 old_gen, old_spec = self._get_old_capabilities(handle, ctype)
65 if old_gen == new_gen and old_spec == new_spec:
68 diff = (int(handle), ctype, old_gen, new_gen, old_spec, new_spec)
69 capabilityDifferences.append(diff)
70 self.CapabilitiesChanged(capabilityDifferences)
72 def _get_old_capabilities(self, handle, ctype):
73 if handle in self._caps:
74 old_gen, old_spec = self._caps[handle][ctype]
78 return old_gen, old_spec
80 def _get_capabilities(self, handle, ctype):
84 gen_caps |= telepathy.CONNECTION_CAPABILITY_FLAG_CREATE
85 gen_caps |= telepathy.CONNECTION_CAPABILITY_FLAG_INVITE
86 spec_caps |= telepathy.CHANNEL_MEDIA_CAPABILITY_AUDIO
88 return gen_caps, spec_caps