From 6c6d28e8fa3de810f129336e28d34ffa42d53c68 Mon Sep 17 00:00:00 2001 From: Travis Reitter Date: Wed, 29 Jun 2011 16:19:58 -0700 Subject: [PATCH] Add Vala example for the new contact list API. --- .gitignore | 3 ++ configure.ac | 1 + examples/client/Makefile.am | 6 +++ examples/client/vala/Makefile.am | 25 +++++++++++++ examples/client/vala/contact-list.vala | 62 ++++++++++++++++++++++++++++++++ 5 files changed, 97 insertions(+), 0 deletions(-) create mode 100644 examples/client/vala/Makefile.am create mode 100644 examples/client/vala/contact-list.vala diff --git a/.gitignore b/.gitignore index 2cee639..eaa3d98 100644 --- a/.gitignore +++ b/.gitignore @@ -56,6 +56,9 @@ examples/extensions/extensions.html /examples/future/*/telepathy-example-* examples/client/stream-tubes/accepter examples/client/stream-tubes/offerer +/examples/client/vala/contact-list +/examples/client/vala/contact-list.c +/examples/client/vala/*_vala.stamp /extensions/extensions.html gtk-doc.make install-sh diff --git a/configure.ac b/configure.ac index b1dd273..4ff028b 100644 --- a/configure.ac +++ b/configure.ac @@ -299,6 +299,7 @@ AC_OUTPUT( Makefile \ examples/client/Makefile \ examples/client/python/Makefile \ examples/client/stream-tubes/Makefile \ + examples/client/vala/Makefile \ examples/cm/Makefile \ examples/cm/callable/Makefile \ examples/cm/channelspecific/Makefile \ diff --git a/examples/client/Makefile.am b/examples/client/Makefile.am index c452599..6ff8232 100644 --- a/examples/client/Makefile.am +++ b/examples/client/Makefile.am @@ -1,5 +1,11 @@ SUBDIRS = stream-tubes python +if HAVE_INTROSPECTION +if HAVE_VALA +SUBDIRS += vala +endif +endif + EXAMPLES = EXAMPLES += telepathy-example-inspect-channel diff --git a/examples/client/vala/Makefile.am b/examples/client/vala/Makefile.am new file mode 100644 index 0000000..f223cc6 --- /dev/null +++ b/examples/client/vala/Makefile.am @@ -0,0 +1,25 @@ +VALAFLAGS = \ + --vapidir=$(top_srcdir)/vala \ + --pkg=gobject-2.0 \ + --pkg=dbus-glib-1 \ + --pkg=telepathy-glib \ + $(NULL) + +bin_PROGRAMS = contact-list + +contact_list_SOURCES = contact-list.vala +contact_list_LDADD = \ + $(GLIB_LIBS) \ + $(DBUS_LIBS) \ + $(top_builddir)/telepathy-glib/libtelepathy-glib.la \ + $(NULL) +contact_list_CFLAGS = \ + -I$(top_srcdir) -I$(top_builddir) \ + $(GLIB_CFLAGS) \ + $(DBUS_CFLAGS) \ + $(NULL) + +GITIGNOREFILES = \ + contact_list_vala.stamp \ + $(contact_list_SOURCES:.vala=.c) \ + $(NULL) diff --git a/examples/client/vala/contact-list.vala b/examples/client/vala/contact-list.vala new file mode 100644 index 0000000..97c5228 --- /dev/null +++ b/examples/client/vala/contact-list.vala @@ -0,0 +1,62 @@ +using GLib; +using TelepathyGLib; + +public static int main (string[] argv) +{ + var main_loop = new MainLoop (); + TelepathyGLib.DBusDaemon bus; + try + { + bus = TelepathyGLib.DBusDaemon.dup (); + } + catch (GLib.Error e) + { + error (e.message); + } + var factory = new SimpleClientFactory (bus); + factory.add_account_features ({Account.get_feature_quark_connection ()}); + factory.add_connection_features ( + {Connection.get_feature_quark_contact_list ()}); + factory.add_contact_features ( + {ContactFeature.CONTACT_GROUPS, ContactFeature.PRESENCE}); + + var manager = factory.dup_account_manager (); + manager.prepare_async.begin ( + {TelepathyGLib.AccountManager.get_feature_quark_account()}, + (obj, result) => + { + try + { + manager.prepare_async.end (result); + } + catch (GLib.Error e) + { + error ("Error preparing account manager: %s", e.message); + } + + var accounts = manager.get_valid_accounts (); + foreach (var account in accounts) + { + var connection = account.get_connection (); + if (connection != null) + { + var contacts = connection.get_contact_list (); + foreach (var contact in contacts) + { + GLib.print ("%s\n\tPresence: %s; %s\n\tGroups: %s\n", + contact.get_identifier (), + contact.get_presence_status (), + contact.get_presence_message (), + string.joinv (", ", contact.get_contact_groups ())); + } + } + } + + main_loop.quit (); + } + ); + + main_loop.run (); + + return 0; +} -- 1.7.5.4