summaryrefslogtreecommitdiff
path: root/examples/client/python/ensure-channel.py
diff options
context:
space:
mode:
authorGuillaume Desmottes <guillaume.desmottes@collabora.co.uk>2011-01-11 11:37:26 +0100
committerGuillaume Desmottes <guillaume.desmottes@collabora.co.uk>2011-01-28 13:34:38 +0100
commit71c01964d1a87b6f2b94089ca46de3fe12d2617d (patch)
tree166c457e0fea4d4666ba43da32888c93617e7eec /examples/client/python/ensure-channel.py
parent516a065e2dc5ecbbc185423a0b32b17a38b4946b (diff)
add client/python/ensure-channel.py (#32986)
Diffstat (limited to 'examples/client/python/ensure-channel.py')
-rwxr-xr-xexamples/client/python/ensure-channel.py68
1 files changed, 68 insertions, 0 deletions
diff --git a/examples/client/python/ensure-channel.py b/examples/client/python/ensure-channel.py
new file mode 100755
index 000000000..1acce1d21
--- /dev/null
+++ b/examples/client/python/ensure-channel.py
@@ -0,0 +1,68 @@
+#!/usr/bin/env python
+import sys
+
+import gobject
+gobject.threads_init()
+
+from gi.repository import TelepathyGLib
+
+def usage():
+ print "%s ACCOUNT [text|audio|video] CONTACT" % sys.argv[0]
+ print "ACCOUNT is a Telepathy account name, use 'mc-tool list' to list all your accounts"
+ print "CONTACT is a contact id such as badger@gmail.com"
+
+ sys.exit(1)
+
+def create_request(action, contact_id):
+ if action == 'text':
+ return {
+ TelepathyGLib.PROP_CHANNEL_CHANNEL_TYPE:
+ TelepathyGLib.IFACE_CHANNEL_TYPE_TEXT,
+ TelepathyGLib.PROP_CHANNEL_TARGET_HANDLE_TYPE:
+ int(TelepathyGLib.HandleType.CONTACT),
+ TelepathyGLib.PROP_CHANNEL_TARGET_ID: contact_id}
+ elif action in ['audio', 'video']:
+ return {
+ TelepathyGLib.PROP_CHANNEL_CHANNEL_TYPE:
+ TelepathyGLib.IFACE_CHANNEL_TYPE_STREAMED_MEDIA,
+ TelepathyGLib.PROP_CHANNEL_TARGET_HANDLE_TYPE:
+ int(TelepathyGLib.HandleType.CONTACT),
+ TelepathyGLib.PROP_CHANNEL_TARGET_ID: contact_id,
+ TelepathyGLib.PROP_CHANNEL_TYPE_STREAMED_MEDIA_INITIAL_AUDIO:
+ True,
+ TelepathyGLib.PROP_CHANNEL_TYPE_STREAMED_MEDIA_INITIAL_VIDEO:
+ action == 'video'}
+ else:
+ usage()
+
+def ensure_channel_cb(req, result, main_loop):
+ req.ensure_channel_finish(result)
+
+ main_loop.quit()
+
+if __name__ == '__main__':
+ #TelepathyGLib.debug_set_flags("all")
+
+ dbus = TelepathyGLib.DBusDaemon.dup()
+
+ if len(sys.argv) != 4:
+ usage()
+
+ _, account_id, action, contact_id = sys.argv
+
+ mgr = TelepathyGLib.AccountManager.dup()
+
+ account = mgr.ensure_account("%s%s" % (TelepathyGLib.ACCOUNT_OBJECT_PATH_BASE,
+ account_id))
+
+ request = create_request(action, contact_id)
+
+ req = TelepathyGLib.AccountChannelRequest.new(account, request, 0)
+ # FIXME: for some reason TelepathyGLib.USER_ACTION_TIME_CURRENT_TIME is
+ # not defined
+
+ main_loop = gobject.MainLoop()
+
+ req.ensure_channel_async("", None, ensure_channel_cb, main_loop)
+
+ main_loop.run()