Bumping to -10 and adding two new interfaces that are now required
authorEd Page <eopage@byu.net>
Thu, 7 Jan 2010 04:16:20 +0000 (22:16 -0600)
committerEd Page <eopage@byu.net>
Thu, 7 Jan 2010 04:16:20 +0000 (22:16 -0600)
src/connection.py
src/constants.py
src/contacts.py [new file with mode: 0644]

index 22f0905..e5673a6 100644 (file)
@@ -16,12 +16,16 @@ import constants
 import util.go_utils as gobject_utils
 import util.coroutines as coroutines
 import gtk_toolbox
+
 import gvoice
 import handle
+
+import contacts
 import aliasing
 import simple_presence
 import presence
 import capabilities
+
 import channel_manager
 
 
@@ -30,6 +34,8 @@ _moduleLogger = logging.getLogger("connection")
 
 class TheOneRingConnection(
        telepathy.server.Connection,
+       telepathy.server.ConnectionInterfaceRequests, # already a mixin
+       contacts.ContactsMixin,
        aliasing.AliasingMixin,
        simple_presence.SimplePresenceMixin,
        presence.PresenceMixin,
@@ -66,6 +72,8 @@ class TheOneRingConnection(
                        account,
                        constants._telepathy_implementation_name_
                )
+               telepathy.server.ConnectionInterfaceRequests.__init__(self)
+               contacts.ContactsMixin.__init__(self)
                aliasing.AliasingMixin.__init__(self)
                simple_presence.SimplePresenceMixin.__init__(self)
                presence.PresenceMixin.__init__(self)
index d575dcc..c2c7be7 100644 (file)
@@ -3,7 +3,7 @@ import os
 __pretty_app_name__ = "Telepathy-TheOneRing"
 __app_name__ = "telepathy-theonering"
 __version__ = "0.1.0"
-__build__ = 9
+__build__ = 10
 __app_magic__ = 0xdeadbeef
 _data_path_ = os.path.join(os.path.expanduser("~"), ".telepathy-theonering")
 _user_settings_ = "%s/settings.ini" % _data_path_
diff --git a/src/contacts.py b/src/contacts.py
new file mode 100644 (file)
index 0000000..8a7d16b
--- /dev/null
@@ -0,0 +1,76 @@
+import logging
+
+import dbus
+import telepathy
+
+
+_moduleLogger = logging.getLogger('contacts')
+
+
+class ContactsMixin(telepathy.server.ConnectionInterfaceContacts):
+
+       ATTRIBUTES = {
+               telepathy.CONNECTION : 'contact-id',
+               telepathy.CONNECTION_INTERFACE_SIMPLE_PRESENCE : 'presence',
+               telepathy.CONNECTION_INTERFACE_ALIASING : 'alias',
+               telepathy.CONNECTION_INTERFACE_CAPABILITIES : 'caps',
+       }
+
+       def __init__(self):
+               telepathy.server.ConnectionInterfaceContacts.__init__(self)
+
+               dbus_interface = telepathy.CONNECTION_INTERFACE_CONTACTS
+               self._implement_property_get(
+                       dbus_interface,
+                       {'ContactAttributeInterfaces' : self.get_contact_attribute_interfaces}
+               )
+
+       def HoldHandles(self, *args):
+               """
+               @abstract
+               """
+               raise NotImplementedError("Abstract function called")
+
+       # Overwrite the dbus attribute to get the sender argument
+       @dbus.service.method(telepathy.CONNECTION_INTERFACE_CONTACTS, in_signature='auasb',
+                                                       out_signature='a{ua{sv}}', sender_keyword='sender')
+       def GetContactAttributes(self, handles, interfaces, hold, sender):
+               #InspectHandle already checks we're connected, the handles and handle type.
+               for interface in interfaces:
+                       if interface not in self.ATTRIBUTES:
+                               raise telepathy.errors.InvalidArgument(
+                                       'Interface %s is not supported by GetContactAttributes' % (interface)
+                               )
+
+               handle_type = telepathy.HANDLE_TYPE_CONTACT
+               ret = {}
+               for handle in handles:
+                       ret[handle] = {}
+
+               functions = {
+                       telepathy.CONNECTION:
+                               lambda x: zip(x, self.InspectHandles(handle_type, x)),
+                       telepathy.CONNECTION_INTERFACE_SIMPLE_PRESENCE:
+                               lambda x: self.GetPresences(x).items(),
+                       telepathy.CONNECTION_INTERFACE_ALIASING:
+                               lambda x: self.GetAliases(x).items(),
+                       telepathy.CONNECTION_INTERFACE_CAPABILITIES:
+                               lambda x: self.GetCapabilities(x).items(),
+               }
+
+               #Hold handles if needed
+               if hold:
+                       self.HoldHandles(handle_type, handles, sender)
+
+               # Attributes from the interface org.freedesktop.Telepathy.Connection
+               # are always returned, and need not be requested explicitly.
+               interfaces = set(interfaces + [telepathy.CONNECTION])
+               for interface in interfaces:
+                       interface_attribute = interface + '/' + self.ATTRIBUTES[interface]
+                       results = functions[interface](handles)
+                       for handle, value in results:
+                               ret[int(handle)][interface_attribute] = value
+               return ret
+
+       def get_contact_attribute_interfaces(self):
+               return self.ATTRIBUTES.keys()