diff options
author | Jonny Lamb <jonny.lamb@collabora.co.uk> | 2009-07-15 12:35:15 +0100 |
---|---|---|
committer | Jonny Lamb <jonny.lamb@collabora.co.uk> | 2009-07-15 12:35:15 +0100 |
commit | f02df20a33906d40eddf6072246fd490aa9973e6 (patch) | |
tree | 8db82c1a7ad01ca0371a39ba6e31de10a289fdef /examples | |
parent | 3a833e3a13a13096066062dbb475f1c8e9d98439 (diff) |
Don't listen to NewChannels but take the channel returned from CreateChannel.
Signed-off-by: Jonny Lamb <jonny.lamb@collabora.co.uk>
Diffstat (limited to 'examples')
-rw-r--r-- | 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 |