[telepathy-python/master] Don't listen to NewChannels but take the channel returned from CreateChannel.

Jonny Lamb jonny.lamb at collabora.co.uk
Wed Jul 15 04:35:15 PDT 2009


Signed-off-by: Jonny Lamb <jonny.lamb at collabora.co.uk>
---
 examples/message.py |   48 ++++++++++++++++++++----------------------------
 1 files changed, 20 insertions(+), 28 deletions(-)

diff --git a/examples/message.py b/examples/message.py
index 66464a9..dac5983 100644
--- a/examples/message.py
+++ b/examples/message.py
@@ -35,21 +35,38 @@ class Message:
 
     def ready_cb(self, conn):
         print "connected"
-        conn[CONNECTION_INTERFACE_REQUESTS].connect_to_signal('NewChannels',
-            self.new_channels_cb)
 
         handle = self.conn[CONN_INTERFACE].RequestHandles(
             CONNECTION_HANDLE_TYPE_CONTACT, [self.contact])[0]
 
         print 'got handle %d for %s' % (handle, self.contact)
 
-        self.conn[CONNECTION_INTERFACE_REQUESTS].CreateChannel(dbus.Dictionary(
+        object_path, props = self.conn[CONNECTION_INTERFACE_REQUESTS].CreateChannel(dbus.Dictionary(
             {
                 CHANNEL_INTERFACE + '.ChannelType': CHANNEL_TYPE_TEXT,
                 CHANNEL_INTERFACE + '.TargetHandleType': CONNECTION_HANDLE_TYPE_CONTACT,
                 CHANNEL_INTERFACE + '.TargetHandle': handle
             }, signature='sv'))
 
+        handle_type = props[CHANNEL_INTERFACE + '.TargetHandleType']
+        handle = props[CHANNEL_INTERFACE + '.TargetHandle']
+
+        print 'got text channel with handle (%d,%d)' % (handle_type, handle)
+        channel = Channel(self.conn.service_name, object_path)
+
+        channel[CHANNEL_TYPE_TEXT].connect_to_signal('Sent', self.sent_cb)
+        channel[CHANNEL_TYPE_TEXT].connect_to_signal('Received', self.recvd_cb)
+        channel[CHANNEL_TYPE_TEXT].connect_to_signal('SendError',
+            self.send_error_cb)
+
+        if self.message is not None:
+            channel[CHANNEL_TYPE_TEXT].Send(
+                CHANNEL_TEXT_MESSAGE_TYPE_NORMAL, self.message)
+        else:
+            for message in channel[CHANNEL_TYPE_TEXT].ListPendingMessages(True):
+                self.recvd_cb(*message)
+
+
     def run(self):
         print "main loop running"
         self.loop = gobject.MainLoop()
@@ -64,31 +81,6 @@ class Message:
             self.loop.quit()
             self.loop = None
 
-    def new_channels_cb(self, channels):
-        for object_path, props in channels:
-            channel_type = props[CHANNEL_INTERFACE + '.ChannelType']
-
-            if channel_type != CHANNEL_TYPE_TEXT:
-                return
-
-            handle_type = props[CHANNEL_INTERFACE + '.TargetHandleType']
-            handle = props[CHANNEL_INTERFACE + '.TargetHandle']
-
-            print 'got text channel with handle (%d,%d)' % (handle_type, handle)
-            channel = Channel(self.conn.service_name, object_path)
-
-            channel[CHANNEL_TYPE_TEXT].connect_to_signal('Sent', self.sent_cb)
-            channel[CHANNEL_TYPE_TEXT].connect_to_signal('Received', self.recvd_cb)
-            channel[CHANNEL_TYPE_TEXT].connect_to_signal('SendError',
-                self.send_error_cb)
-
-            if self.message is not None:
-                channel[CHANNEL_TYPE_TEXT].Send(
-                    CHANNEL_TEXT_MESSAGE_TYPE_NORMAL, self.message)
-            else:
-                for message in channel[CHANNEL_TYPE_TEXT].ListPendingMessages(True):
-                    self.recvd_cb(*message)
-
     def recvd_cb(self, *args):
         print args
         id, timestamp, sender, type, flags, text = args
-- 
1.5.6.5




More information about the telepathy-commits mailing list