From 5c35b2273ab5f2185b953f9fa22dad874d0e7901 Mon Sep 17 00:00:00 2001
From: Simon McVittie <simon.mcvittie@collabora.co.uk>
Date: Thu, 8 Mar 2012 11:24:54 +0000
Subject: [PATCH 10/10] Add a Python example which lists and inspects
 protocols with g-i

I could get used to this "rapid prototyping in Python" thing.

Bug: https://bugs.freedesktop.org/show_bug.cgi?id=46358
Signed-off-by: Simon McVittie <simon.mcvittie@collabora.co.uk>
---
 examples/client/python/Makefile.am   |    1 +
 examples/client/python/inspect-cm.py |   60 ++++++++++++++++++++++++++++++++++
 2 files changed, 61 insertions(+), 0 deletions(-)
 create mode 100644 examples/client/python/inspect-cm.py

diff --git a/examples/client/python/Makefile.am b/examples/client/python/Makefile.am
index 5eacd52..9405455 100644
--- a/examples/client/python/Makefile.am
+++ b/examples/client/python/Makefile.am
@@ -1,6 +1,7 @@
 EXTRA_DIST = \
   contact-list.py \
   ensure-channel.py \
+  inspect-cm.py \
   text-handler.py \
   file-transfer.py \
   ft-handler.py
diff --git a/examples/client/python/inspect-cm.py b/examples/client/python/inspect-cm.py
new file mode 100644
index 0000000..c653cf7
--- /dev/null
+++ b/examples/client/python/inspect-cm.py
@@ -0,0 +1,60 @@
+#!/usr/bin/env python
+
+import sys
+from gi.repository import GObject
+from gi.repository import TelepathyGLib as Tp
+
+def describe(cm):
+    print("Connection manager: %s" % cm.get_name())
+    print("")
+
+    for protocol in cm.dup_protocols():
+        print("Protocol: %s" % protocol.get_name())
+        print("\tEnglish name: %s" % protocol.get_english_name())
+        print("\tvCard field: %s" % protocol.get_vcard_field())
+
+        for param in protocol.dup_params():
+            print("\tParameter: %s" % param.get_name())
+
+            if param.is_required():
+                print("\t\tIs required")
+
+            if param.is_secret():
+                print("\t\tIs a password or equivalent")
+
+            if param.flags & Tp.ConnMgrParamFlags.HAS_DEFAULT:
+                print("\t\tDefault value: %s" % param.default_value)
+            else:
+                print("\t\tNo default")
+
+def manager_prepared_cb(cm, result, loop):
+    cm.prepare_finish(result)
+    describe(cm)
+    loop.quit()
+
+def inspect(name):
+    cm = Tp.ConnectionManager(
+            dbus_daemon=Tp.DBusDaemon.dup(),
+            bus_name=Tp.CM_BUS_NAME_BASE + name,
+            object_path=Tp.CM_OBJECT_PATH_BASE + name,
+            )
+    cm.prepare_async(None, cm, loop)
+
+def cms_cb(source, result, loop):
+    cms = Tp.list_connection_managers_finish(result)
+
+    for cm in cms:
+        describe(cm)
+        print("")
+
+    loop.quit()
+
+if __name__ == '__main__':
+    loop = GObject.MainLoop()
+
+    if len(sys.argv) >= 2:
+        inspect(sys.argv[1])
+    else:
+        Tp.list_connection_managers_async(Tp.DBusDaemon.dup(), cms_cb, loop)
+
+    loop.run()
-- 
1.7.9.1