diff options
author | Will Thompson <will.thompson@collabora.co.uk> | 2011-03-28 23:32:25 +0100 |
---|---|---|
committer | Will Thompson <will.thompson@collabora.co.uk> | 2011-04-16 14:17:55 +0100 |
commit | f4df23f20c4a0737f7ed98786aeef543b62f22ed (patch) | |
tree | 6ceea0b82ee289256522b4ca2b08e7c7e1c3aaf9 | |
parent | 6fccb59746e9432e4eaface983f9f04e600f745d (diff) | |
download | telepathy-glib-f4df23f20c4a0737f7ed98786aeef543b62f22ed.tar.gz |
Add tp_handle_set_to_identifier_map()
This is primarily useful for implementing the signals on ContactList and
ContactBlocking which use Handle_Identifier_Maps; I'm sure there are
other places where this will be useful too.
-rw-r--r-- | docs/reference/telepathy-glib-sections.txt | 1 | ||||
-rw-r--r-- | telepathy-glib/handle-repo.h | 2 | ||||
-rw-r--r-- | telepathy-glib/handle-set.c | 44 |
3 files changed, 47 insertions, 0 deletions
diff --git a/docs/reference/telepathy-glib-sections.txt b/docs/reference/telepathy-glib-sections.txt index 1e48f46d5..8767fb165 100644 --- a/docs/reference/telepathy-glib-sections.txt +++ b/docs/reference/telepathy-glib-sections.txt @@ -258,6 +258,7 @@ tp_handle_set_foreach tp_handle_set_is_empty tp_handle_set_size tp_handle_set_to_array +tp_handle_set_to_identifier_map tp_handle_set_update tp_handle_set_difference_update tp_handle_set_dump diff --git a/telepathy-glib/handle-repo.h b/telepathy-glib/handle-repo.h index 4458b1af7..622d6bc85 100644 --- a/telepathy-glib/handle-repo.h +++ b/telepathy-glib/handle-repo.h @@ -136,6 +136,8 @@ gboolean tp_handle_set_is_empty (const TpHandleSet *set); int tp_handle_set_size (const TpHandleSet *set); GArray *tp_handle_set_to_array (const TpHandleSet *set) G_GNUC_WARN_UNUSED_RESULT; +GHashTable *tp_handle_set_to_identifier_map (TpHandleSet *self) + G_GNUC_WARN_UNUSED_RESULT; TpHandleSet *tp_handle_set_new_from_array (TpHandleRepoIface *repo, const GArray *array) G_GNUC_WARN_UNUSED_RESULT; diff --git a/telepathy-glib/handle-set.c b/telepathy-glib/handle-set.c index 4858fe891..5f2f50641 100644 --- a/telepathy-glib/handle-set.c +++ b/telepathy-glib/handle-set.c @@ -28,6 +28,8 @@ #include <glib.h> #include <telepathy-glib/intset.h> +#define DEBUG_FLAG TP_DEBUG_HANDLES +#include "debug-internal.h" /** * TpHandleSet: @@ -316,6 +318,48 @@ tp_handle_set_to_array (const TpHandleSet *set) return tp_intset_to_array (set->intset); } +/** + * tp_handle_set_to_identifier_map: + * @self: a handle set + * + * Returns a dictionary mapping each handle in @self to the corresponding + * identifier, as if retrieved by calling tp_handle_inspect() on each handle. + * The type of the returned value is described as + * <code>Handle_Identifier_Map</code> in the Telepathy specification. + * + * Returns: (transfer full) (element-type TpHandle utf8): a map from the + * handles in @self to the corresponding identifier. + */ +GHashTable * +tp_handle_set_to_identifier_map ( + TpHandleSet *self) +{ + /* We don't bother dupping the strings: they remain valid as long as the + * connection's alive and hence the repo exists. + */ + GHashTable *map = g_hash_table_new (NULL, NULL); + TpIntsetFastIter iter; + TpHandle handle; + + g_return_val_if_fail (self != NULL, map); + + tp_intset_fast_iter_init (&iter, self->intset); + while (tp_intset_fast_iter_next (&iter, &handle)) + { + if (handle == 0 || !tp_handle_is_valid (self->repo, handle, NULL)) + { + WARNING ("handle set %p contains invalid handle #%u", self, handle); + } + else + { + g_hash_table_insert (map, GUINT_TO_POINTER (handle), + (gchar *) tp_handle_inspect (self->repo, handle)); + } + } + + return map; +} + static void ref_one (guint handle, gpointer data) { |