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_AVATARS : 'token',
19 telepathy.CONNECTION_INTERFACE_CAPABILITIES : 'caps',
20 telepathy.CONNECTION_INTERFACE_CONTACT_CAPABILITIES : 'capabilities'
24 telepathy.server.ConnectionInterfaceContacts.__init__(self)
26 dbus_interface = telepathy.CONNECTION_INTERFACE_CONTACTS
27 self._implement_property_get(
29 {'ContactAttributeInterfaces' : self.get_contact_attribute_interfaces}
32 def HoldHandles(self, *args):
36 raise NotImplementedError("Abstract function called")
38 # Overwrite the dbus attribute to get the sender argument
39 @misc_utils.log_exception(_moduleLogger)
40 @dbus.service.method(telepathy.CONNECTION_INTERFACE_CONTACTS, in_signature='auasb',
41 out_signature='a{ua{sv}}', sender_keyword='sender')
42 def GetContactAttributes(self, handles, interfaces, hold, sender):
43 #InspectHandle already checks we're connected, the handles and handle type.
44 supportedInterfaces = set()
45 for interface in interfaces:
46 if interface in self.ATTRIBUTES:
47 supportedInterfaces.add(interface)
49 _moduleLogger.debug("Ignoring unsupported interface %s" % interface)
51 handle_type = telepathy.HANDLE_TYPE_CONTACT
52 ret = dbus.Dictionary(signature='ua{sv}')
53 for handle in handles:
54 ret[handle] = dbus.Dictionary(signature='sv')
58 lambda x: zip(x, self.InspectHandles(handle_type, x)),
59 telepathy.CONNECTION_INTERFACE_SIMPLE_PRESENCE:
60 lambda x: self.GetPresences(x).items(),
61 telepathy.CONNECTION_INTERFACE_ALIASING:
62 lambda x: self.GetAliases(x).items(),
63 telepathy.CONNECTION_INTERFACE_AVATARS :
64 lambda x: self.GetKnownAvatarTokens(x).items(),
65 telepathy.CONNECTION_INTERFACE_CAPABILITIES:
66 lambda x: self.GetCapabilities(x).items(),
67 telepathy.CONNECTION_INTERFACE_CONTACT_CAPABILITIES :
68 lambda x: self.GetContactCapabilities(x).items()
71 #Hold handles if needed
73 self.HoldHandles(handle_type, handles, sender)
75 # Attributes from the interface org.freedesktop.Telepathy.Connection
76 # are always returned, and need not be requested explicitly.
77 supportedInterfaces.add(telepathy.CONNECTION)
79 for interface in supportedInterfaces:
80 interface_attribute = interface + '/' + self.ATTRIBUTES[interface]
81 results = functions[interface](handles)
82 for handle, value in results:
83 ret[int(handle)][interface_attribute] = value
86 def get_contact_attribute_interfaces(self):
87 return self.ATTRIBUTES.keys()