summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorGuillaume Desmottes <guillaume.desmottes@collabora.co.uk>2011-01-11 10:17:25 +0100
committerGuillaume Desmottes <guillaume.desmottes@collabora.co.uk>2011-01-28 11:16:01 +0100
commit187aeea2b19b7b26171dbb51bfc15ab92b5611a7 (patch)
tree0fcbffd3044b5b320a6b0417234058c371466c00 /examples
parent715348339953d6efbd702496b7d35b79eaffcafb (diff)
downloadtelepathy-glib-187aeea2b19b7b26171dbb51bfc15ab92b5611a7.tar.gz
add python/text-handler.py (fdo #32524)
Diffstat (limited to 'examples')
-rw-r--r--examples/client/python/Makefile.am3
-rwxr-xr-xexamples/client/python/text-handler.py65
2 files changed, 67 insertions, 1 deletions
diff --git a/examples/client/python/Makefile.am b/examples/client/python/Makefile.am
index 1b336ac1a..f31e15236 100644
--- a/examples/client/python/Makefile.am
+++ b/examples/client/python/Makefile.am
@@ -1 +1,2 @@
-EXTRA_DIST =
+EXTRA_DIST = \
+ text-handler.py
diff --git a/examples/client/python/text-handler.py b/examples/client/python/text-handler.py
new file mode 100755
index 000000000..23bf2adb4
--- /dev/null
+++ b/examples/client/python/text-handler.py
@@ -0,0 +1,65 @@
+#!/usr/bin/env python
+
+import gobject
+gobject.threads_init()
+
+from gi.repository import TelepathyGLib
+
+def echo_message(channel, msg, pending):
+ text, flags = msg.to_text()
+
+ if pending:
+ print "pending: %s" % (text)
+ else:
+ print "received: %s" % (text)
+
+ reply = TelepathyGLib.ClientMessage.new_text(0, text.upper())
+
+ channel.send_message_async(reply, 0, lambda a, b, c: 0, None)
+
+def message_received_cb(channel, msg):
+ echo_message(channel, msg, False)
+
+ channel.ack_message_async(msg, lambda a, b, c: 0, None)
+
+def display_pending_messages(channel):
+ messages = channel.get_pending_messages()
+
+ for msg in messages:
+ echo_message(channel, msg, True)
+
+ channel.ack_messages_async(messages, lambda a, b, c: 0, None)
+
+def handle_channels_cb(handler, account, connection, channels, requests,
+ user_action_time, context, user_data):
+ for channel in channels:
+ if not isinstance(channel, TelepathyGLib.TextChannel):
+ continue
+
+ print "Handling text channel with", channel.get_identifier()
+
+ channel.connect('message-received', message_received_cb)
+
+ display_pending_messages(channel)
+
+ context.accept()
+
+if __name__ == '__main__':
+ #TelepathyGLib.debug_set_flags("all")
+
+ dbus = TelepathyGLib.DBusDaemon.dup()
+
+ handler = TelepathyGLib.SimpleHandler.new(dbus, False, False,
+ 'ExampleHandler', False, handle_channels_cb, None)
+
+ handler.add_handler_filter({
+ TelepathyGLib.PROP_CHANNEL_CHANNEL_TYPE: TelepathyGLib.IFACE_CHANNEL_TYPE_TEXT,
+ # bgo #637466
+ TelepathyGLib.PROP_CHANNEL_TARGET_HANDLE_TYPE: int(TelepathyGLib.HandleType.CONTACT),
+ TelepathyGLib.PROP_CHANNEL_REQUESTED: False,
+ })
+
+ handler.register()
+
+ main_loop = gobject.MainLoop()
+ main_loop.run()