[Telepathy-commits] [telepathy-doc/master] Use the iter, not the first item

Murray Cumming murrayc at murrayc.com
Mon Aug 18 02:45:36 PDT 2008


---
 configure.ac                                |   15 +++-
 docs/examples/Makefile.am                   |   13 ++++
 docs/examples/Makefile.am_fragment          |    4 +-
 docs/examples/contacts_list_all/Makefile.am |    7 ++
 docs/examples/contacts_list_all/main.c      |  101 +++++++++++++++++++++++++++
 5 files changed, 135 insertions(+), 5 deletions(-)

diff --git a/configure.ac b/configure.ac
index 1c243fa..609f67b 100644
--- a/configure.ac
+++ b/configure.ac
@@ -11,12 +11,21 @@ GNOME_DOC_INIT([0.9.0])
 # Get the path to perl, so we can use perl scripts without hard-coding the path.
 TELEPATHY_DOCS_CHECK_PERL([5.6.0])
 
-PKG_CHECK_MODULES(TELEPATHY, telepathy-glib >= 0.7.3)
+# We depend on GTK+ too, because that allows us to create more realistic 
+# examples that are easier to play with. But we will try to write only a small 
+# amount of UI code. 
+PKG_CHECK_MODULES(TELEPATHY_DOCS, telepathy-glib >= 0.7.3 gtk+-2.0 >= 2.12.0)
+
+# Use C:
+AC_PROG_CC()
 
 AC_OUTPUT([
   Makefile
   m4/Makefile
+
   docs/Makefile
-  docs/examples/Makefile
-  docs/book/Makefile
+    docs/examples/Makefile
+      docs/examples/contacts_list_all/Makefile
+
+    docs/book/Makefile
 ])
diff --git a/docs/examples/Makefile.am b/docs/examples/Makefile.am
index 139597f..ce86d9a 100644
--- a/docs/examples/Makefile.am
+++ b/docs/examples/Makefile.am
@@ -1,2 +1,15 @@
+include $(top_srcdir)/docs/Makefile_web.am_fragment
+
+example_dirs = contacts_list_all
+
+# container - Disabled until the new higher-level library exists.
+
+SUBDIRS = $(example_dirs)
+
+EXTRA_DIST =  Makefile.am_fragment
+
+exclude_args = --delete-excluded --exclude *.o --exclude .libs --exclude .deps --exclude core --exclude .cvsignore --exclude a.out --exclude Makefile --exclude Makefile.in --exclude example --exclude .svn
+post-html:
+	rsync $(rsync_args) -a $(exclude_args) $(example_dirs) $$USER@$(web_host):$(web_path)examples
 
 
diff --git a/docs/examples/Makefile.am_fragment b/docs/examples/Makefile.am_fragment
index 2679a54..153b7a9 100644
--- a/docs/examples/Makefile.am_fragment
+++ b/docs/examples/Makefile.am_fragment
@@ -1,6 +1,6 @@
-LIBS  = $(CLUTTER_DOC_LIBS)
+LIBS  = $(TELEPATHY_DOCS_LIBS)
 
-all_includes =  $(CLUTTER_DOC_CFLAGS) $(CLUTTER_DOC_WARNING_FLAGS)
+all_includes =  $(TELEPATHY_DOCS_CFLAGS) $(TELEPATHY_DOCS_WARNING_FLAGS)
 
 DEFS = @DEFS@
 DEFAULT_INCLUDES =
diff --git a/docs/examples/contacts_list_all/Makefile.am b/docs/examples/contacts_list_all/Makefile.am
index e69de29..d0a304f 100644
--- a/docs/examples/contacts_list_all/Makefile.am
+++ b/docs/examples/contacts_list_all/Makefile.am
@@ -0,0 +1,7 @@
+include $(top_srcdir)/docs/examples/Makefile.am_fragment
+
+#Build the executable, but don't install it.
+noinst_PROGRAMS = example
+
+example_SOURCES = main.c
+
diff --git a/docs/examples/contacts_list_all/main.c b/docs/examples/contacts_list_all/main.c
index e69de29..99dbb80 100644
--- a/docs/examples/contacts_list_all/main.c
+++ b/docs/examples/contacts_list_all/main.c
@@ -0,0 +1,101 @@
+/* Copyright 2008 Collabora Ltd
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#include <telepathy-glib/connection-manager.h>
+#include <glib/gprintf.h>
+
+GMainLoop *mainloop = NULL;
+
+static void
+on_list_connection_managers(TpConnectionManager * const *connection_manager,
+                            gsize n_cms,
+                            const GError *error,
+                            gpointer user_data,
+                            GObject *weak_object)
+{
+  if (error != NULL)
+    {
+      g_warning ("%s", error->message);
+      
+      /* Stop the mainloop so the program finishes: */
+      g_main_loop_quit (mainloop);
+      return;
+    }
+
+  g_printf ("Found %" G_GSIZE_FORMAT " connection managers:\n", n_cms);
+
+  //TODO: See http://bugs.freedesktop.org/show_bug.cgi?id=17115
+  //about the awkwardness of these pointers to pointers:
+  TpConnectionManager * const *cm_iter = connection_manager;
+  for (; *cm_iter != NULL; ++cm_iter)
+    {
+      TpConnectionManager * cm = *cm_iter;
+      //TODO: The protocols really shouldn't be const.
+      //const shouldn't be used for complex types in C because C doesn't have full const support.
+      //For instance, g_object_get() takes a non-const, so this causes a warning:
+      gchar *cm_name = NULL;
+
+      g_object_get (G_OBJECT(cm_iter),
+        "connection-manager", &cm_name,
+        NULL);
+
+      g_printf ("  Connection Manager name: %s\n", cm_name);
+
+      g_free (cm_name);
+
+      //TODO: See http://bugs.freedesktop.org/show_bug.cgi?id=17112
+      //about the lack of real API for this:
+      //Note that it's an array of pointers, not a pointer to an array
+      //(unlike the connection_manager array above.)
+      TpConnectionManagerProtocol * const *protocols;
+
+      for (protocols = (TpConnectionManagerProtocol * const *)cm->protocols;
+          protocols != NULL && *protocols != NULL; ++protocols)
+        {
+          TpConnectionManagerProtocol *protocol = *protocols;
+          if (protocol->name)
+            g_printf ("    Protocol name: %s\n", protocol->name);
+        }
+
+    }
+
+  /* Stop the mainloop so the program finishes: */
+  g_main_loop_quit (mainloop);
+}
+
+int
+main (int argc, char **argv)
+{
+  g_type_init ();
+
+  /* Create the main loop: */
+  mainloop = g_main_loop_new (NULL, FALSE);
+
+  TpDBusDaemon *bus_daemon = tp_dbus_daemon_new (tp_get_bus ());
+
+  tp_list_connection_managers (bus_daemon, &on_list_connection_managers, 
+    NULL /* user_data */, NULL /* destroy callback */, NULL);
+
+
+  /* tp_list_connection_names (bus_daemon, got_connections, &data, NULL, NULL); */
+
+  /* Start the main loop, and clean up when it finishes. */
+  g_main_loop_run (mainloop);
+  g_main_loop_unref (mainloop);
+  g_object_unref (bus_daemon);
+
+  return 0;
+}
-- 
1.5.6.3




More information about the Telepathy-commits mailing list