From 51bbfd2bd83242120260dd145d5a2fdc0bcdcd8c Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Wed, 19 Sep 2012 12:06:00 +0100 Subject: [PATCH 05/15] tp_message_dup_part: add --- docs/reference/telepathy-glib-sections.txt | 1 + telepathy-glib/message.c | 24 ++++++++++++++++++++++++ telepathy-glib/message.h | 2 ++ tests/dbus/cm-message.c | 12 ++++++++++++ 4 files changed, 39 insertions(+) diff --git a/docs/reference/telepathy-glib-sections.txt b/docs/reference/telepathy-glib-sections.txt index 2e0397e..5892239 100644 --- a/docs/reference/telepathy-glib-sections.txt +++ b/docs/reference/telepathy-glib-sections.txt @@ -2744,6 +2744,7 @@ TpMessageMixinPrivate TpMessage TpMessage tp_message_count_parts +tp_message_dup_part tp_message_peek tp_message_to_text tp_message_get_message_type diff --git a/telepathy-glib/message.c b/telepathy-glib/message.c index 2cc79a6..508e86e 100644 --- a/telepathy-glib/message.c +++ b/telepathy-glib/message.c @@ -39,6 +39,7 @@ #include #include #include +#include #define DEBUG_FLAG TP_DEBUG_MISC #include "telepathy-glib/debug-internal.h" @@ -199,6 +200,29 @@ tp_message_peek (TpMessage *self, return g_ptr_array_index (self->parts, part); } +/** + * tp_message_dup_part: + * @self: a message + * @part: a part number + * + * + * + * Returns: (transfer full): + * the current contents of the given part, or %NULL if the part number is + * out of range + * + * Since: 0.UNRELEASED + */ +GVariant * +tp_message_dup_part (TpMessage *self, + guint part) +{ + if (part >= self->parts->len) + return NULL; + + return _tp_asv_to_vardict (g_ptr_array_index (self->parts, part)); +} + /** * tp_message_append_part: diff --git a/telepathy-glib/message.h b/telepathy-glib/message.h index 5f2ddf8..e4f7c28 100644 --- a/telepathy-glib/message.h +++ b/telepathy-glib/message.h @@ -46,6 +46,8 @@ GType tp_message_get_type (void); void tp_message_destroy (TpMessage *self); guint tp_message_count_parts (TpMessage *self); const GHashTable *tp_message_peek (TpMessage *self, guint part); +_TP_AVAILABLE_IN_UNRELEASED +GVariant *tp_message_dup_part (TpMessage *self, guint part); guint tp_message_append_part (TpMessage *self); void tp_message_delete_part (TpMessage *self, guint part); diff --git a/tests/dbus/cm-message.c b/tests/dbus/cm-message.c index 39ad3de..0fea5d1 100644 --- a/tests/dbus/cm-message.c +++ b/tests/dbus/cm-message.c @@ -50,7 +50,9 @@ test_new_from_parts (Test *test, TpHandle sender; TpMessage *msg; const GHashTable *part; + GVariant *part_vardict; gboolean valid; + const gchar *s; parts = g_ptr_array_new_full (2, (GDestroyNotify) g_hash_table_unref); @@ -93,6 +95,16 @@ test_new_from_parts (Test *test, g_assert_cmpstr (tp_asv_get_string (part, "content"), ==, "Badger"); + part_vardict = tp_message_dup_part (msg, 1); + g_assert_cmpstr (g_variant_get_type_string (part_vardict), ==, "a{sv}"); + valid = g_variant_lookup (part_vardict, "content-type", "s", &s); + g_assert (valid); + g_assert_cmpstr (s, ==, "text/plain"); + valid = g_variant_lookup (part_vardict, "content", "s", &s); + g_assert (valid); + g_assert_cmpstr (s, ==, "Badger"); + g_variant_unref (part_vardict); + g_assert_cmpuint (tp_message_get_message_type (msg), ==, TP_CHANNEL_TEXT_MESSAGE_TYPE_NOTICE); g_assert_cmpuint (tp_cm_message_get_sender (msg), ==, sender); -- 1.7.10.4