diff options
author | Guillaume Desmottes <guillaume.desmottes@collabora.co.uk> | 2011-11-29 16:48:11 +0100 |
---|---|---|
committer | Guillaume Desmottes <guillaume.desmottes@collabora.co.uk> | 2011-11-29 16:48:11 +0100 |
commit | f1a9c6deaa7f706df73cb4e1195647a2a27177c6 (patch) | |
tree | 8718faead1a6ef9feed652fca4d946e14dec82cc /libempathy | |
parent | b5764db7cf39aeaaabc261ece49c57776540a0be (diff) | |
download | empathy-f1a9c6deaa7f706df73cb4e1195647a2a27177c6.tar.gz |
WIP
Diffstat (limited to 'libempathy')
-rw-r--r-- | libempathy/empathy-connection-aggregator.c | 72 | ||||
-rw-r--r-- | libempathy/empathy-connection-aggregator.h | 3 |
2 files changed, 75 insertions, 0 deletions
diff --git a/libempathy/empathy-connection-aggregator.c b/libempathy/empathy-connection-aggregator.c index 7074e5186..88f789548 100644 --- a/libempathy/empathy-connection-aggregator.c +++ b/libempathy/empathy-connection-aggregator.c @@ -34,6 +34,13 @@ G_DEFINE_TYPE (EmpathyConnectionAggregator, empathy_connection_aggregator, G_TYPE_OBJECT); +enum { + EVENT_CONTACT_LIST_CHANGED, + LAST_SIGNAL +}; + +static guint signals[LAST_SIGNAL]; + struct _EmpathyConnectionAggregatorPriv { TpAccountManager *mgr; @@ -62,10 +69,30 @@ empathy_connection_aggregator_class_init ( oclass->dispose = empathy_connection_aggregator_dispose; + signals[EVENT_CONTACT_LIST_CHANGED] = + g_signal_new ("contact-list-changed", + G_TYPE_FROM_CLASS (klass), + G_SIGNAL_RUN_LAST, + 0, + NULL, NULL, + g_cclosure_marshal_generic, + G_TYPE_NONE, + 3, TP_TYPE_CONNECTION, G_TYPE_PTR_ARRAY, G_TYPE_PTR_ARRAY); + g_type_class_add_private (klass, sizeof (EmpathyConnectionAggregatorPriv)); } static void +contact_list_changed_cb (TpConnection *conn, + GPtrArray *added, + GPtrArray *removed, + EmpathyConnectionAggregator *self) +{ + g_signal_emit (self, signals[EVENT_CONTACT_LIST_CHANGED], 0, conn, + added, removed); +} + +static void conn_invalidated_cb (TpConnection *conn, guint domain, gint code, @@ -81,12 +108,28 @@ static void check_connection (EmpathyConnectionAggregator *self, TpConnection *conn) { + GPtrArray *contacts; + if (g_list_find (self->priv->conns, conn) != NULL) return; self->priv->conns = g_list_prepend (self->priv->conns, g_object_ref (conn)); + tp_g_signal_connect_object (conn, "contact-list-changed", + G_CALLBACK (contact_list_changed_cb), self, 0); + + contacts = tp_connection_dup_contact_list (conn); + if (contacts != NULL) + { + GPtrArray *empty; + + empty = g_ptr_array_new (); + + contact_list_changed_cb (conn, contacts, empty, self); + g_ptr_array_unref (empty); + } + tp_g_signal_connect_object (conn, "invalidated", G_CALLBACK (conn_invalidated_cb), self, 0); } @@ -216,3 +259,32 @@ empathy_connection_aggregator_get_all_groups (EmpathyConnectionAggregator *self) return keys; } + +GPtrArray * +empathy_connection_aggregator_dup_all_contacts ( + EmpathyConnectionAggregator *self) +{ + GPtrArray *result; + GList *l; + + result = g_ptr_array_new_with_free_func (g_object_unref); + + for (l = self->priv->conns; l != NULL; l = g_list_next (l)) + { + TpConnection *conn = l->data; + GPtrArray *contacts; + + contacts = tp_connection_dup_contact_list (conn); + if (contacts == NULL) + continue; + + tp_g_ptr_array_extend (result, contacts); + + /* tp_g_ptr_array_extend() doesn't give us an extra ref */ + g_ptr_array_foreach (contacts, (GFunc) g_object_ref, NULL); + + g_ptr_array_unref (contacts); + } + + return result; +} diff --git a/libempathy/empathy-connection-aggregator.h b/libempathy/empathy-connection-aggregator.h index 6a7fb656e..c21c04dec 100644 --- a/libempathy/empathy-connection-aggregator.h +++ b/libempathy/empathy-connection-aggregator.h @@ -64,6 +64,9 @@ EmpathyConnectionAggregator * empathy_connection_aggregator_dup_singleton (void) GList * empathy_connection_aggregator_get_all_groups ( EmpathyConnectionAggregator *self); +GPtrArray * empathy_connection_aggregator_dup_all_contacts ( + EmpathyConnectionAggregator *self); + G_END_DECLS #endif /* #ifndef __EMPATHY_CONNECTION_AGGREGATOR_H__*/ |