summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDanielle Madeley <danielle.madeley@collabora.co.uk>2010-08-20 05:28:12 (GMT)
committerDanielle Madeley <danielle.madeley@collabora.co.uk>2010-08-20 05:28:12 (GMT)
commit89d9771ebb7e9177d7701cd3fe4f1da2f81abdf0 (patch)
treebd77b039875eb14795f67a51e4e99ed82a1e36f5
parent59b64a387ecc663f817e3ddfd58d918dafdbbbf5 (diff)
downloadtelepathy-doc-89d9771ebb7e9177d7701cd3fe4f1da2f81abdf0.tar.gz
telepathy-doc-89d9771ebb7e9177d7701cd3fe4f1da2f81abdf0.tar.xz
Text channel example showing re-handled
-rw-r--r--configure.ac1
-rw-r--r--docs/examples/Makefile.am4
-rw-r--r--docs/examples/glib_text_channel/Makefile.am9
-rw-r--r--docs/examples/glib_text_channel/example.c182
4 files changed, 195 insertions, 1 deletions
diff --git a/configure.ac b/configure.ac
index 0759c6b..05b6a3f 100644
--- a/configure.ac
+++ b/configure.ac
@@ -35,6 +35,7 @@ AC_OUTPUT([
docs/examples/glib_telepathy_properties/Makefile
docs/examples/glib_dbus_tube/Makefile
docs/examples/glib_stream_tube/Makefile
+ docs/examples/glib_text_channel/Makefile
docs/examples/glib_mc5_connections/Makefile
docs/examples/glib_mc5_dbus_tube_handler/Makefile
docs/examples/glib_mc5_observer/Makefile
diff --git a/docs/examples/Makefile.am b/docs/examples/Makefile.am
index 6ce2f53..cb5d90f 100644
--- a/docs/examples/Makefile.am
+++ b/docs/examples/Makefile.am
@@ -7,6 +7,7 @@ example_dirs = \
glib_telepathy_properties \
glib_dbus_tube \
glib_stream_tube \
+ glib_text_channel \
glib_mc5_connections \
glib_mc5_dbus_tube_handler \
glib_mc5_observer \
@@ -19,7 +20,8 @@ example_dirs = \
python_irc_channel \
python_irc_roomlist \
python_mc5_clients \
- python_simple_presence
+ python_simple_presence \
+ $(NULL)
SUBDIRS = $(example_dirs)
diff --git a/docs/examples/glib_text_channel/Makefile.am b/docs/examples/glib_text_channel/Makefile.am
new file mode 100644
index 0000000..409e2b6
--- /dev/null
+++ b/docs/examples/glib_text_channel/Makefile.am
@@ -0,0 +1,9 @@
+INCLUDES = $(TELEPATHY_GLIB_CFLAGS)
+LDADD = $(TELEPATHY_GLIB_LIBS)
+
+noinst_PROGRAMS = example
+
+example_SOURCES = \
+ example.c
+
+include $(top_srcdir)/docs/rsync-dist.make
diff --git a/docs/examples/glib_text_channel/example.c b/docs/examples/glib_text_channel/example.c
new file mode 100644
index 0000000..41ab9a2
--- /dev/null
+++ b/docs/examples/glib_text_channel/example.c
@@ -0,0 +1,182 @@
+#include <unistd.h>
+
+#include <glib.h>
+
+#include <telepathy-glib/telepathy-glib.h>
+
+static GMainLoop *loop = NULL;
+
+static void
+handle_error (const GError *error)
+{
+ if (error != NULL)
+ g_error ("ERROR: %s\n", error->message);
+}
+
+
+static void
+_channel_group_ready (GObject *channel,
+ GAsyncResult *res,
+ gpointer user_data)
+{
+ TpHandleChannelsContext *context = user_data;
+ GError *error;
+
+ if (!tp_proxy_prepare_finish (channel, res, &error))
+ {
+ tp_handle_channels_context_fail (context, error);
+ handle_error (error);
+ }
+
+ tp_handle_channels_context_accept (context);
+ g_object_unref (context);
+
+ g_print ("Handled channel %s\n",
+ tp_proxy_get_object_path (channel));
+}
+
+
+static void
+_channel_invalidated (TpProxy *channel,
+ guint domain,
+ guint code,
+ const char *message,
+ gpointer user_data)
+{
+ g_print ("Channel invalidated %s\n",
+ tp_proxy_get_object_path (channel));
+
+ /* unref the request */
+ g_object_set_data (G_OBJECT (channel), "request", NULL);
+
+ /* unref the channel */
+ g_object_unref (channel);
+}
+
+
+static void
+_channel_rehandled (TpAccountChannelRequest *request,
+ TpChannel *channel,
+ gint64 user_action_time,
+ TpHandleChannelsContext *context,
+ gpointer user_data)
+{
+ g_print ("Channel rehandled %s\n",
+ tp_proxy_get_object_path (channel));
+}
+
+
+static void
+_channel_ready (GObject *request,
+ GAsyncResult *res,
+ gpointer user_data)
+{
+ TpChannel *channel;
+ TpHandleChannelsContext *context;
+ GQuark features[] = { TP_CHANNEL_FEATURE_GROUP, 0 };
+ GError *error = NULL;
+
+ channel = tp_account_channel_request_ensure_and_handle_channel_finish (
+ TP_ACCOUNT_CHANNEL_REQUEST (request), res, &context, &error);
+ if (channel == NULL)
+ handle_error (error);
+
+ /* prepare the GROUP feature on this channel */
+ tp_proxy_prepare_async (channel, features, _channel_group_ready, context);
+
+ tp_handle_channels_context_delay (context);
+
+ g_object_set_data_full (G_OBJECT (channel), "request",
+ g_object_ref (request), g_object_unref);
+
+ g_signal_connect (channel, "invalidated",
+ G_CALLBACK (_channel_invalidated), NULL);
+
+ g_signal_connect (request, "re-handled",
+ G_CALLBACK (_channel_rehandled), NULL);
+}
+
+
+static void
+_account_ready (GObject *account,
+ GAsyncResult *res,
+ gpointer user_data)
+{
+ TpAccountChannelRequest *request;
+ GHashTable *props;
+ const char *targetid = user_data;
+ GError *error = NULL;
+
+ if (!tp_proxy_prepare_finish (account, res, &error))
+ handle_error (error);
+
+ props = tp_asv_new (
+ TP_PROP_CHANNEL_CHANNEL_TYPE,
+ G_TYPE_STRING,
+ TP_IFACE_CHANNEL_TYPE_TEXT,
+
+ TP_PROP_CHANNEL_TARGET_HANDLE_TYPE,
+ G_TYPE_UINT,
+ TP_HANDLE_TYPE_ROOM,
+
+ TP_PROP_CHANNEL_TARGET_ID,
+ G_TYPE_STRING,
+ targetid,
+
+ NULL);
+
+ request = tp_account_channel_request_new (TP_ACCOUNT (account), props,
+ TP_USER_ACTION_TIME_CURRENT_TIME);
+
+ tp_account_channel_request_ensure_and_handle_channel_async (request,
+ NULL, _channel_ready, NULL);
+
+ g_object_unref (request);
+ g_hash_table_destroy (props);
+}
+
+
+int
+main (int argc,
+ char **argv)
+{
+ TpDBusDaemon *dbus;
+ TpAccount *account;
+ char *account_path;
+ GError *error = NULL;
+
+ g_type_init ();
+
+ if (argc != 3)
+ g_error ("Must provide an account and target id!");
+
+ /* create a main loop */
+ loop = g_main_loop_new (NULL, FALSE);
+
+ /* acquire a connection to the D-Bus daemon */
+ dbus = tp_dbus_daemon_dup (&error);
+ if (dbus == NULL)
+ handle_error (error);
+
+ /* get the complete path of the account */
+ account_path = g_strconcat (TP_ACCOUNT_OBJECT_PATH_BASE, argv[1], NULL);
+
+ /* get the account */
+ account = tp_account_new (dbus, account_path, &error);
+ if (account == NULL)
+ {
+ handle_error (error);
+ }
+
+ g_free (account_path);
+
+ /* prepare the account */
+ tp_proxy_prepare_async (account, NULL, _account_ready, argv[2]);
+
+ g_main_loop_run (loop);
+
+ g_object_unref (dbus);
+ g_object_unref (account);
+
+ return 0;
+}