aboutsummaryrefslogtreecommitdiffstats
path: root/libempathy
diff options
context:
space:
mode:
authorGuillaume Desmottes <guillaume.desmottes@collabora.co.uk>2011-11-29 23:55:51 +0800
committerGuillaume Desmottes <guillaume.desmottes@collabora.co.uk>2011-11-30 20:02:16 +0800
commit0fe601d9ae8c727a1abbd0d59c3aa7b80cb2b936 (patch)
treeead5e129baf84d804420aabf7a518489e480120a /libempathy
parentbc690f37e7b0a49258b505653dd0cb94ffa48056 (diff)
downloadgsoc2013-empathy-0fe601d9ae8c727a1abbd0d59c3aa7b80cb2b936.tar
gsoc2013-empathy-0fe601d9ae8c727a1abbd0d59c3aa7b80cb2b936.tar.gz
gsoc2013-empathy-0fe601d9ae8c727a1abbd0d59c3aa7b80cb2b936.tar.bz2
gsoc2013-empathy-0fe601d9ae8c727a1abbd0d59c3aa7b80cb2b936.tar.lz
gsoc2013-empathy-0fe601d9ae8c727a1abbd0d59c3aa7b80cb2b936.tar.xz
gsoc2013-empathy-0fe601d9ae8c727a1abbd0d59c3aa7b80cb2b936.tar.zst
gsoc2013-empathy-0fe601d9ae8c727a1abbd0d59c3aa7b80cb2b936.zip
connection-aggregator: add API to track contacts
https://bugzilla.gnome.org/show_bug.cgi?id=660547
Diffstat (limited to 'libempathy')
-rw-r--r--libempathy/empathy-connection-aggregator.c71
-rw-r--r--libempathy/empathy-connection-aggregator.h3
2 files changed, 74 insertions, 0 deletions
diff --git a/libempathy/empathy-connection-aggregator.c b/libempathy/empathy-connection-aggregator.c
index 043aa4f38..22d5ab8b2 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,29 @@ 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,
+ 2, 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, added, removed);
+}
+
+static void
conn_invalidated_cb (TpConnection *conn,
guint domain,
gint code,
@@ -81,12 +107,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 +258,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__*/