6 import util.misc as misc_utils
9 _moduleLogger = logging.getLogger('contacts')
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 for interface in interfaces:
43 if interface not in self.ATTRIBUTES:
44 raise telepathy.errors.InvalidArgument(
45 'Interface %s is not supported by GetContactAttributes' % (interface)
48 handle_type = telepathy.HANDLE_TYPE_CONTACT
50 for handle in handles:
55 lambda x: zip(x, self.InspectHandles(handle_type, x)),
56 telepathy.CONNECTION_INTERFACE_SIMPLE_PRESENCE:
57 lambda x: self.GetPresences(x).items(),
58 telepathy.CONNECTION_INTERFACE_ALIASING:
59 lambda x: self.GetAliases(x).items(),
60 telepathy.CONNECTION_INTERFACE_CAPABILITIES:
61 lambda x: self.GetCapabilities(x).items(),
64 #Hold handles if needed
66 self.HoldHandles(handle_type, handles, sender)
68 # Attributes from the interface org.freedesktop.Telepathy.Connection
69 # are always returned, and need not be requested explicitly.
70 interfaces = set(interfaces + [telepathy.CONNECTION])
71 for interface in interfaces:
72 interface_attribute = interface + '/' + self.ATTRIBUTES[interface]
73 results = functions[interface](handles)
74 for handle, value in results:
75 ret[int(handle)][interface_attribute] = value
78 def get_contact_attribute_interfaces(self):
79 return self.ATTRIBUTES.keys()