6 import util.misc as misc_utils
9 _moduleLogger = logging.getLogger(__name__)
12 class ContactsMixin(telepathy.server.ConnectionInterfaceContacts):
15 telepathy.CONNECTION : 'contact-id',
16 telepathy.CONNECTION_INTERFACE_SIMPLE_PRESENCE : 'presence',
17 telepathy.CONNECTION_INTERFACE_ALIASING : 'alias',
18 telepathy.CONNECTION_INTERFACE_CAPABILITIES : 'caps',
22 telepathy.server.ConnectionInterfaceContacts.__init__(self)
24 dbus_interface = telepathy.CONNECTION_INTERFACE_CONTACTS
25 self._implement_property_get(
27 {'ContactAttributeInterfaces' : self.get_contact_attribute_interfaces}
30 def HoldHandles(self, *args):
34 raise NotImplementedError("Abstract function called")
36 # Overwrite the dbus attribute to get the sender argument
37 @misc_utils.log_exception(_moduleLogger)
38 @dbus.service.method(telepathy.CONNECTION_INTERFACE_CONTACTS, in_signature='auasb',
39 out_signature='a{ua{sv}}', sender_keyword='sender')
40 def GetContactAttributes(self, handles, interfaces, hold, sender):
41 #InspectHandle already checks we're connected, the handles and handle type.
42 supportedInterfaces = set()
43 for interface in interfaces:
44 if interface in self.ATTRIBUTES:
45 supportedInterfaces.add(interface)
47 _moduleLogger.debug("Ignoring unsupported interface %s" % interface)
49 handle_type = telepathy.HANDLE_TYPE_CONTACT
50 ret = dbus.Dictionary(signature='ua{sv}')
51 for handle in handles:
52 ret[handle] = dbus.Dictionary(signature='sv')
56 lambda x: zip(x, self.InspectHandles(handle_type, x)),
57 telepathy.CONNECTION_INTERFACE_SIMPLE_PRESENCE:
58 lambda x: self.GetPresences(x).items(),
59 telepathy.CONNECTION_INTERFACE_ALIASING:
60 lambda x: self.GetAliases(x).items(),
61 telepathy.CONNECTION_INTERFACE_CAPABILITIES:
62 lambda x: self.GetCapabilities(x).items(),
65 #Hold handles if needed
67 self.HoldHandles(handle_type, handles, sender)
69 # Attributes from the interface org.freedesktop.Telepathy.Connection
70 # are always returned, and need not be requested explicitly.
71 supportedInterfaces.add(telepathy.CONNECTION)
73 for interface in supportedInterfaces:
74 interface_attribute = interface + '/' + self.ATTRIBUTES[interface]
75 results = functions[interface](handles)
76 for handle, value in results:
77 ret[int(handle)][interface_attribute] = value
80 def get_contact_attribute_interfaces(self):
81 return self.ATTRIBUTES.keys()