8 _moduleLogger = logging.getLogger('capabilities')
11 class CapabilitiesMixin(telepathy.server.ConnectionInterfaceCapabilities):
14 telepathy.server.ConnectionInterfaceCapabilities.__init__(self)
15 self._implement_property_get(
16 telepathy.interfaces.CONN_INTERFACE_CAPABILITIES,
17 {"caps": self.GetCapabilities},
25 raise NotImplementedError("Abstract property called")
32 raise NotImplementedError("Abstract property called")
34 @gtk_toolbox.log_exception(_moduleLogger)
35 def GetCapabilities(self, handles):
37 @todo HACK Remove this once we are building against a fixed version of python-telepathy
40 for handle in handles:
41 if handle != 0 and (telepathy.HANDLE_TYPE_CONTACT, handle) not in self._handles:
42 raise telepathy.errors.InvalidHandle
43 elif handle in self._caps:
44 theirs = self._caps[handle]
46 ret.append([handle, type, theirs[0], theirs[1]])
47 _moduleLogger.info("GetCaps %r" % ret)
50 @gtk_toolbox.log_exception(_moduleLogger)
51 def AdvertiseCapabilities(self, add, remove):
53 @todo HACK Remove this once we are building against a fixed version of python-telepathy
55 my_caps = self._caps.setdefault(self._self_handle, {})
58 for ctype, spec_caps in add:
59 changed[ctype] = spec_caps
64 for ctype, spec_caps in changed.iteritems():
65 gen_old, spec_old = my_caps.get(ctype, (0, 0))
67 # channel type no longer supported (provider has gone away)
68 gen_new, spec_new = 0, 0
70 # channel type supports new capabilities
71 gen_new, spec_new = gen_old, spec_old | spec_caps
72 if spec_old != spec_new or gen_old != gen_new:
73 caps.append((self._self_handle, ctype, gen_old, gen_new,
76 _moduleLogger.info("CapsChanged %r" % caps)
77 self.CapabilitiesChanged(caps)
79 # return all my capabilities
80 ret = [(ctype, caps[1]) for ctype, caps in my_caps.iteritems()]
81 _moduleLogger.info("Adv %r" % ret)