9 _moduleLogger = logging.getLogger('capabilities')
12 class CapabilitiesMixin(tp.ConnectionInterfaceCapabilities):
15 tp.ConnectionInterfaceCapabilities.__init__(self)
16 self._implement_property_get(
17 telepathy.interfaces.CONN_INTERFACE_CAPABILITIES,
18 {"caps": self.GetCapabilities},
26 raise NotImplementedError("Abstract property called")
28 def get_handle_by_id(self, handleType, handleId):
32 raise NotImplementedError("Abstract function called")
34 def GetSelfHandle(self):
38 raise NotImplementedError("Abstract function called")
40 @gtk_toolbox.log_exception(_moduleLogger)
41 def GetCapabilities(self, handleIds):
43 @todo HACK Remove this once we are building against a fixed version of python-telepathy
46 for handleId in handleIds:
47 h = self.get_handle_by_id(telepathy.HANDLE_TYPE_CONTACT, handleId)
48 if handleId != 0 and (telepathy.HANDLE_TYPE_CONTACT, handleId) not in self._handles:
49 raise telepathy.errors.InvalidHandle
53 for ctype, specs in types.iteritems():
54 ret.append([handleId, type, specs[0], specs[1]])
56 # No caps, so just default to the connection's caps
57 types = self._caps[self.GetSelfHandle()]
59 for ctype, specs in types.iteritems():
60 ret.append([handleId, type, specs[0], specs[1]])
63 @gtk_toolbox.log_exception(_moduleLogger)
64 def AdvertiseCapabilities(self, add, remove):
66 @todo HACK Remove this once we are building against a fixed version of python-telepathy
68 my_caps = self._caps.setdefault(self.GetSelfHandle(), {})
71 for ctype, spec_caps in add:
72 changed[ctype] = spec_caps
77 for ctype, spec_caps in changed.iteritems():
78 gen_old, spec_old = my_caps.get(ctype, (0, 0))
80 # channel type no longer supported (provider has gone away)
81 gen_new, spec_new = 0, 0
83 # channel type supports new capabilities
84 gen_new, spec_new = gen_old, spec_old | spec_caps
85 if spec_old != spec_new or gen_old != gen_new:
86 caps.append((self.GetSelfHandle(), ctype, gen_old, gen_new,
89 self.CapabilitiesChanged(caps)
90 _moduleLogger.info("CapsChanged %r" % self._caps)
92 # return all my capabilities
93 ret = [(ctype, caps[1]) for ctype, caps in my_caps.iteritems()]