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")
27 def handle(self, handleType, handleId):
31 raise NotImplementedError("Abstract function called")
33 def GetSelfHandle(self):
37 raise NotImplementedError("Abstract function called")
39 @gtk_toolbox.log_exception(_moduleLogger)
40 def GetCapabilities(self, handleIds):
42 @todo HACK Remove this once we are building against a fixed version of python-telepathy
45 for handleId in handleIds:
46 h = self.handle(telepathy.HANDLE_TYPE_CONTACT, handleId)
47 if handleId != 0 and (telepathy.HANDLE_TYPE_CONTACT, handleId) not in self._handles:
48 raise telepathy.errors.InvalidHandle
52 for ctype, specs in types.iteritems():
53 ret.append([handleId, type, specs[0], specs[1]])
55 # No caps, so just default to the connection's caps
56 types = self._caps[self.GetSelfHandle()]
58 for ctype, specs in types.iteritems():
59 ret.append([handleId, type, specs[0], specs[1]])
62 @gtk_toolbox.log_exception(_moduleLogger)
63 def AdvertiseCapabilities(self, add, remove):
65 @todo HACK Remove this once we are building against a fixed version of python-telepathy
67 my_caps = self._caps.setdefault(self.GetSelfHandle(), {})
70 for ctype, spec_caps in add:
71 changed[ctype] = spec_caps
76 for ctype, spec_caps in changed.iteritems():
77 gen_old, spec_old = my_caps.get(ctype, (0, 0))
79 # channel type no longer supported (provider has gone away)
80 gen_new, spec_new = 0, 0
82 # channel type supports new capabilities
83 gen_new, spec_new = gen_old, spec_old | spec_caps
84 if spec_old != spec_new or gen_old != gen_new:
85 caps.append((self.GetSelfHandle(), ctype, gen_old, gen_new,
88 self.CapabilitiesChanged(caps)
89 _moduleLogger.info("CapsChanged %r" % self._caps)
91 # return all my capabilities
92 ret = [(ctype, caps[1]) for ctype, caps in my_caps.iteritems()]