summaryrefslogtreecommitdiff
path: root/telepathy-glib/base-contact-list.c
diff options
context:
space:
mode:
authorWill Thompson <will.thompson@collabora.co.uk>2011-03-15 09:48:37 +0000
committerWill Thompson <will.thompson@collabora.co.uk>2011-04-16 14:17:55 +0100
commit5214a5763ae982e3d72110ed61faa5bc15f830ba (patch)
tree5f7eec9951ad215fbdeed65f6c2ee753ec80e98f /telepathy-glib/base-contact-list.c
parent1eae063d507e2940d7df1e5ea042590bbc732d3f (diff)
downloadtelepathy-glib-5214a5763ae982e3d72110ed61faa5bc15f830ba.tar.gz
BaseContactList: emit BlockedContactsChanged
Just like we only emit the ContactList/ContactGroups signals if the connection the BaseContactList is attached to implements those interfaces, so here we only emit BlockedContactsChange if ContactBlocking is implemented. We do the hard work of building the hash tables anyway. I don't think this is a big cost (and we have been turning intsets into arrays and then immediately freeing them since this code was written!). The test case checks that blocking/unblocking individual contacts using the old API causes this new signal to be emitted.
Diffstat (limited to 'telepathy-glib/base-contact-list.c')
-rw-r--r--telepathy-glib/base-contact-list.c34
1 files changed, 23 insertions, 11 deletions
diff --git a/telepathy-glib/base-contact-list.c b/telepathy-glib/base-contact-list.c
index d9618a1c6..84ca416fe 100644
--- a/telepathy-glib/base-contact-list.c
+++ b/telepathy-glib/base-contact-list.c
@@ -2261,7 +2261,7 @@ tp_base_contact_list_contact_blocking_changed (TpBaseContactList *self,
{
TpHandleSet *now_blocked;
TpIntset *blocked, *unblocked;
- GArray *blocked_arr, *unblocked_arr;
+ GHashTable *blocked_contacts, *unblocked_contacts;
TpIntsetFastIter iter;
GObject *deny_chan;
TpHandle handle;
@@ -2284,18 +2284,29 @@ tp_base_contact_list_contact_blocking_changed (TpBaseContactList *self,
blocked = tp_intset_new ();
unblocked = tp_intset_new ();
+ blocked_contacts = g_hash_table_new (NULL, NULL);
+ unblocked_contacts = g_hash_table_new (NULL, NULL);
tp_intset_fast_iter_init (&iter, tp_handle_set_peek (changed));
while (tp_intset_fast_iter_next (&iter, &handle))
{
+ const char *id = tp_handle_inspect (self->priv->contact_repo, handle);
+
if (tp_handle_set_is_member (now_blocked, handle))
- tp_intset_add (blocked, handle);
+ {
+ tp_intset_add (blocked, handle);
+ g_hash_table_insert (blocked_contacts, GUINT_TO_POINTER (handle),
+ (gpointer) id);
+ }
else
- tp_intset_add (unblocked, handle);
+ {
+ tp_intset_add (unblocked, handle);
+ g_hash_table_insert (unblocked_contacts, GUINT_TO_POINTER (handle),
+ (gpointer) id);
+ }
- DEBUG ("Contact %s: blocked=%c",
- tp_handle_inspect (self->priv->contact_repo, handle),
+ DEBUG ("Contact %s: blocked=%c", id,
tp_handle_set_is_member (now_blocked, handle) ? 'Y' : 'N');
}
@@ -2304,15 +2315,16 @@ tp_base_contact_list_contact_blocking_changed (TpBaseContactList *self,
tp_base_connection_get_self_handle (self->priv->conn),
TP_CHANNEL_GROUP_CHANGE_REASON_NONE);
- blocked_arr = tp_intset_to_array (blocked);
- unblocked_arr = tp_intset_to_array (unblocked);
- /* FIXME: emit ContactBlockingChanged (blocked_arr, unblocked_arr) when the
- * new D-Bus API is available */
- g_array_unref (blocked_arr);
- g_array_unref (unblocked_arr);
+ if (self->priv->svc_contact_blocking &&
+ (g_hash_table_size (blocked_contacts) > 0 ||
+ g_hash_table_size (unblocked_contacts) > 0))
+ tp_svc_connection_interface_contact_blocking_emit_blocked_contacts_changed (
+ self->priv->conn, blocked_contacts, unblocked_contacts);
tp_intset_destroy (blocked);
tp_intset_destroy (unblocked);
+ g_hash_table_unref (blocked_contacts);
+ g_hash_table_unref (unblocked_contacts);
tp_handle_set_destroy (now_blocked);
}