Bumping to 0.7.3 and releasing the .deb
[theonering] / src / contacts.py
1 import logging
2
3 import dbus
4 import telepathy
5
6
7 _moduleLogger = logging.getLogger('contacts')
8
9
10 class ContactsMixin(telepathy.server.ConnectionInterfaceContacts):
11
12         ATTRIBUTES = {
13                 telepathy.CONNECTION : 'contact-id',
14                 telepathy.CONNECTION_INTERFACE_SIMPLE_PRESENCE : 'presence',
15                 telepathy.CONNECTION_INTERFACE_ALIASING : 'alias',
16                 telepathy.CONNECTION_INTERFACE_CAPABILITIES : 'caps',
17         }
18
19         def __init__(self):
20                 telepathy.server.ConnectionInterfaceContacts.__init__(self)
21
22                 dbus_interface = telepathy.CONNECTION_INTERFACE_CONTACTS
23                 self._implement_property_get(
24                         dbus_interface,
25                         {'ContactAttributeInterfaces' : self.get_contact_attribute_interfaces}
26                 )
27
28         def HoldHandles(self, *args):
29                 """
30                 @abstract
31                 """
32                 raise NotImplementedError("Abstract function called")
33
34         # Overwrite the dbus attribute to get the sender argument
35         @dbus.service.method(telepathy.CONNECTION_INTERFACE_CONTACTS, in_signature='auasb',
36                                                         out_signature='a{ua{sv}}', sender_keyword='sender')
37         def GetContactAttributes(self, handles, interfaces, hold, sender):
38                 #InspectHandle already checks we're connected, the handles and handle type.
39                 for interface in interfaces:
40                         if interface not in self.ATTRIBUTES:
41                                 raise telepathy.errors.InvalidArgument(
42                                         'Interface %s is not supported by GetContactAttributes' % (interface)
43                                 )
44
45                 handle_type = telepathy.HANDLE_TYPE_CONTACT
46                 ret = {}
47                 for handle in handles:
48                         ret[handle] = {}
49
50                 functions = {
51                         telepathy.CONNECTION:
52                                 lambda x: zip(x, self.InspectHandles(handle_type, x)),
53                         telepathy.CONNECTION_INTERFACE_SIMPLE_PRESENCE:
54                                 lambda x: self.GetPresences(x).items(),
55                         telepathy.CONNECTION_INTERFACE_ALIASING:
56                                 lambda x: self.GetAliases(x).items(),
57                         telepathy.CONNECTION_INTERFACE_CAPABILITIES:
58                                 lambda x: self.GetCapabilities(x).items(),
59                 }
60
61                 #Hold handles if needed
62                 if hold:
63                         self.HoldHandles(handle_type, handles, sender)
64
65                 # Attributes from the interface org.freedesktop.Telepathy.Connection
66                 # are always returned, and need not be requested explicitly.
67                 interfaces = set(interfaces + [telepathy.CONNECTION])
68                 for interface in interfaces:
69                         interface_attribute = interface + '/' + self.ATTRIBUTES[interface]
70                         results = functions[interface](handles)
71                         for handle, value in results:
72                                 ret[int(handle)][interface_attribute] = value
73                 return ret
74
75         def get_contact_attribute_interfaces(self):
76                 return self.ATTRIBUTES.keys()