diff options
author | Marco Barisione <marco@barisione.org> | 2011-09-16 16:39:02 +0100 |
---|---|---|
committer | Marco Barisione <marco@barisione.org> | 2011-09-16 16:39:02 +0100 |
commit | d4cfda9cd64923c81d87b8f875b5f20658023a17 (patch) | |
tree | b25acacac0d5c8b94c13316914914edb39ac6711 | |
parent | bc40410024314a700ef70702502f868630e02e8b (diff) |
conn-aliasing: add a plural version of the nickname-update signal handler
-rw-r--r-- | src/conn-aliasing.c | 96 | ||||
-rw-r--r-- | src/conn-aliasing.h | 3 |
2 files changed, 64 insertions, 35 deletions
diff --git a/src/conn-aliasing.c b/src/conn-aliasing.c index 8b77a8fd..bfc3b3ac 100644 --- a/src/conn-aliasing.c +++ b/src/conn-aliasing.c @@ -794,17 +794,32 @@ gabble_conn_aliasing_pep_nick_reply_handler (GabbleConnection *conn, } } - void gabble_conn_aliasing_nickname_updated (GObject *object, TpHandle handle, gpointer user_data) { + GArray *handles; + + handles = g_array_sized_new (FALSE, FALSE, sizeof (TpHandle), 1); + g_array_append_val (handles, handle); + + gabble_conn_aliasing_nicknames_updated (object, handles, user_data); + + g_array_free (handles, TRUE); +} + +void +gabble_conn_aliasing_nicknames_updated (GObject *object, + GArray *handles, + gpointer user_data) +{ GabbleConnection *conn = GABBLE_CONNECTION (user_data); - GabbleConnectionAliasSource signal_source, current_source; - gchar *alias = NULL; + GabbleConnectionAliasSource signal_source; GPtrArray *aliases; - GValue entry = { 0, }; + guint i; + + g_return_if_fail (handles->len > 0); if (object == user_data) { @@ -829,47 +844,58 @@ gabble_conn_aliasing_nickname_updated (GObject *object, return; } - current_source = _gabble_connection_get_cached_alias (conn, handle, &alias); - - g_assert (current_source != GABBLE_CONNECTION_ALIAS_NONE); + aliases = g_ptr_array_sized_new (handles->len); - /* if the active alias for this handle is already known and from - * a higher priority, this signal is not interesting so we do - * nothing */ - if (signal_source < current_source) + for (i = 0; i < handles->len; i++) { - DEBUG ("ignoring boring alias change for handle %u, signal from %u " - "but source %u has alias \"%s\"", handle, signal_source, - current_source, alias); - goto OUT; - } + TpHandle handle = g_array_index (handles, TpHandle, i); + GabbleConnectionAliasSource current_source; + gchar *alias = NULL; + GValue entry = { 0, }; + + current_source = _gabble_connection_get_cached_alias (conn, handle, + &alias); + g_assert (current_source != GABBLE_CONNECTION_ALIAS_NONE); + + /* if the active alias for this handle is already known and from + * a higher priority, this signal is not interesting so we do + * nothing */ + if (signal_source < current_source) + { + DEBUG ("ignoring boring alias change for handle %u, signal from %u " + "but source %u has alias \"%s\"", handle, signal_source, + current_source, alias); + g_free (alias); + continue; + } - g_value_init (&entry, TP_STRUCT_TYPE_ALIAS_PAIR); - g_value_take_boxed (&entry, dbus_g_type_specialized_construct - (TP_STRUCT_TYPE_ALIAS_PAIR)); + g_value_init (&entry, TP_STRUCT_TYPE_ALIAS_PAIR); + g_value_take_boxed (&entry, + dbus_g_type_specialized_construct (TP_STRUCT_TYPE_ALIAS_PAIR)); - dbus_g_type_struct_set (&entry, - 0, handle, - 1, alias, - G_MAXUINT); + dbus_g_type_struct_set (&entry, + 0, handle, + 1, alias, + G_MAXUINT); - aliases = g_ptr_array_sized_new (1); - g_ptr_array_add (aliases, g_value_get_boxed (&entry)); + g_ptr_array_add (aliases, g_value_get_boxed (&entry)); + /* Check whether the roster has an entry for the handle and if so, set + * the roster alias so the vCard isn't fetched on every connect. */ + if (signal_source < GABBLE_CONNECTION_ALIAS_FROM_ROSTER && + gabble_roster_handle_has_entry (conn->roster, handle)) + gabble_roster_handle_set_name (conn->roster, handle, alias, NULL); - tp_svc_connection_interface_aliasing_emit_aliases_changed (conn, aliases); + g_free (alias); + } - g_value_unset (&entry); - g_ptr_array_free (aliases, TRUE); + if (aliases->len > 0) + tp_svc_connection_interface_aliasing_emit_aliases_changed (conn, aliases); - /* Check whether the roster has an entry for the handle and if so, set the - * roster alias so the vCard isn't fetched on every connect. */ - if (signal_source < GABBLE_CONNECTION_ALIAS_FROM_ROSTER && - gabble_roster_handle_has_entry (conn->roster, handle)) - gabble_roster_handle_set_name (conn->roster, handle, alias, NULL); + for (i = 0; i < aliases->len; i++) + g_boxed_free (TP_STRUCT_TYPE_ALIAS_PAIR, g_ptr_array_index (aliases, i)); -OUT: - g_free (alias); + g_ptr_array_free (aliases, TRUE); } static void diff --git a/src/conn-aliasing.h b/src/conn-aliasing.h index 8716bb78..353e3238 100644 --- a/src/conn-aliasing.h +++ b/src/conn-aliasing.h @@ -33,6 +33,9 @@ void conn_aliasing_iface_init (gpointer g_iface, gpointer iface_data); void gabble_conn_aliasing_nickname_updated (GObject *object, TpHandle handle, gpointer user_data); +void gabble_conn_aliasing_nicknames_updated (GObject *object, + GArray *handles, gpointer user_data); + GabbleConnectionAliasSource _gabble_connection_get_cached_alias ( GabbleConnection *, TpHandle, gchar **); |