[Telepathy-commits] [telepathy-doc/master] Get a roster, use the Contacts interface to look things up
Davyd Madeley
davyd at madeley.id.au
Sun Mar 1 20:24:03 PST 2009
---
docs/examples/python_simple_presence/example.py | 78 ++++++++++++++++++++++-
1 files changed, 76 insertions(+), 2 deletions(-)
diff --git a/docs/examples/python_simple_presence/example.py b/docs/examples/python_simple_presence/example.py
index 57cfc69..7867907 100755
--- a/docs/examples/python_simple_presence/example.py
+++ b/docs/examples/python_simple_presence/example.py
@@ -10,10 +10,16 @@ import telepathy
import telepathy.client
from telepathy.interfaces import CONNECTION_MANAGER, \
CONNECTION, \
+ CONNECTION_INTERFACE_REQUESTS, \
+ CONNECTION_INTERFACE_ALIASING, \
CONNECTION_INTERFACE_SIMPLE_PRESENCE, \
- CONNECTION_INTERFACE_CONTACTS
+ CONNECTION_INTERFACE_CONTACTS, \
+ CHANNEL, \
+ CHANNEL_TYPE_CONTACT_LIST, \
+ CHANNEL_INTERFACE_GROUP
from telepathy.constants import CONNECTION_STATUS_CONNECTED, \
- CONNECTION_STATUS_DISCONNECTED
+ CONNECTION_STATUS_DISCONNECTED, \
+ CONNECTION_HANDLE_TYPE_LIST
DBUS_PROPERTIES = 'org.freedesktop.DBus.Properties'
@@ -78,11 +84,71 @@ class Example (object):
if status != CONNECTION_STATUS_CONNECTED: return
print 'Carrier Detected' # remember dialup modems?
+ print 'Ctrl-C to disconnect'
# get a list of interfaces on this connection
conn[CONNECTION].GetInterfaces(reply_handler = self.get_interfaces_cb,
error_handler = self.error_cb)
+ def request_contact_list (self, *groups):
+ conn = self.conn
+
+ class ensure_channel_cb (object):
+ def __init__ (self, parent, group):
+ self.parent = parent
+ self.group = group
+
+ def __call__ (self, yours, path, properties):
+ print "got channel for %s -> %s, yours = %s" % (
+ self.group, path, yours)
+
+ channel = telepathy.client.Channel(conn.service_name, path)
+ self.channel = channel
+
+ # request the list of members
+ channel[DBUS_PROPERTIES].Get(CHANNEL_INTERFACE_GROUP,
+ 'Members',
+ reply_handler = self.members_cb,
+ error_handler = self.parent.error_cb)
+
+ def members_cb (self, handles):
+ # request information for this list of handles using the
+ # Contacts interface
+ conn[CONNECTION_INTERFACE_CONTACTS].GetContactAttributes(
+ handles, [
+ CONNECTION,
+ CONNECTION_INTERFACE_ALIASING,
+ CONNECTION_INTERFACE_SIMPLE_PRESENCE,
+ ],
+ False,
+ reply_handler = self.get_contact_attributes_cb,
+ error_handler = self.parent.error_cb)
+
+ def get_contact_attributes_cb (self, attributes):
+ print '-' * 78
+ print self.group
+ print '-' * 78
+ for member in attributes.values():
+ for key, value in member.iteritems():
+ print '%s: %s' % (key, value)
+ print
+ print '-' * 78
+
+ def no_channel_available (error):
+ print error
+
+ # we can either use TargetID if we know a name, or TargetHandle
+ # if we already have a handle
+ for group in groups:
+ print "Ensuring channel to %s..." % group
+ conn[CONNECTION_INTERFACE_REQUESTS].EnsureChannel({
+ CHANNEL + '.ChannelType' : CHANNEL_TYPE_CONTACT_LIST,
+ CHANNEL + '.TargetHandleType': CONNECTION_HANDLE_TYPE_LIST,
+ CHANNEL + '.TargetID' : group,
+ },
+ reply_handler = ensure_channel_cb(self, group),
+ error_handler = no_channel_available)
+
def get_interfaces_cb (self, interfaces):
conn = self.conn
@@ -90,6 +156,14 @@ class Example (object):
for interface in interfaces:
print " - %s" % interface
+ if CONNECTION_INTERFACE_REQUESTS in interfaces:
+ self.request_contact_list('subscribe',
+ 'publish',
+ 'hide',
+ 'allow',
+ 'deny',
+ 'known')
+
if CONNECTION_INTERFACE_SIMPLE_PRESENCE in interfaces:
# request the statuses
print 'Requesting statuses...'
--
1.5.6.5
More information about the telepathy-commits
mailing list