diff options
author | Guillaume Desmottes <guillaume.desmottes@collabora.co.uk> | 2012-05-17 19:37:16 +0800 |
---|---|---|
committer | Guillaume Desmottes <guillaume.desmottes@collabora.co.uk> | 2012-06-14 15:21:45 +0800 |
commit | 1d5260ad9bd4a36c234878133b63d46fea173c45 (patch) | |
tree | 1296c12f10aa13f3438ebb1e78e7ca135ad5dded /libempathy-gtk | |
parent | 121fcf568ee102ca50aa5bf3ca12d6c0045f05e3 (diff) | |
download | gsoc2013-empathy-1d5260ad9bd4a36c234878133b63d46fea173c45.tar gsoc2013-empathy-1d5260ad9bd4a36c234878133b63d46fea173c45.tar.gz gsoc2013-empathy-1d5260ad9bd4a36c234878133b63d46fea173c45.tar.bz2 gsoc2013-empathy-1d5260ad9bd4a36c234878133b63d46fea173c45.tar.lz gsoc2013-empathy-1d5260ad9bd4a36c234878133b63d46fea173c45.tar.xz gsoc2013-empathy-1d5260ad9bd4a36c234878133b63d46fea173c45.tar.zst gsoc2013-empathy-1d5260ad9bd4a36c234878133b63d46fea173c45.zip |
roster-view: populate with EmpathyRosterItem
Diffstat (limited to 'libempathy-gtk')
-rw-r--r-- | libempathy-gtk/empathy-roster-view.c | 83 |
1 files changed, 82 insertions, 1 deletions
diff --git a/libempathy-gtk/empathy-roster-view.c b/libempathy-gtk/empathy-roster-view.c index 1baefe22b..76e74b356 100644 --- a/libempathy-gtk/empathy-roster-view.c +++ b/libempathy-gtk/empathy-roster-view.c @@ -3,6 +3,8 @@ #include "empathy-roster-view.h" +#include <libempathy-gtk/empathy-roster-item.h> + G_DEFINE_TYPE (EmpathyRosterView, empathy_roster_view, EGG_TYPE_LIST_BOX) enum @@ -23,6 +25,9 @@ static guint signals[LAST_SIGNAL]; struct _EmpathyRosterViewPriv { EmpathyIndividualManager *manager; + + /* FolksIndividual (borrowed) -> EmpathyRosterItem (borrowed) */ + GHashTable *items; }; static void @@ -65,16 +70,88 @@ empathy_roster_view_set_property (GObject *object, } static void +individual_added (EmpathyRosterView *self, + FolksIndividual *individual) +{ + GtkWidget *item; + + item = g_hash_table_lookup (self->priv->items, individual); + if (item != NULL) + return; + + item = empathy_roster_item_new (individual); + + gtk_widget_show (item); + gtk_container_add (GTK_CONTAINER (self), item); + + g_hash_table_insert (self->priv->items, individual, item); +} + +static void +individual_removed (EmpathyRosterView *self, + FolksIndividual *individual) +{ + GtkWidget *item; + + item = g_hash_table_lookup (self->priv->items, individual); + if (item == NULL) + return; + + gtk_container_remove (GTK_CONTAINER (self), item); + + g_hash_table_remove (self->priv->items, individual); +} + +static void +members_changed_cb (EmpathyIndividualManager *manager, + const gchar *message, + GList *added, + GList *removed, + TpChannelGroupChangeReason reason, + EmpathyRosterView *self) +{ + GList *l; + + for (l = added; l != NULL; l = g_list_next (l)) + { + FolksIndividual *individual = l->data; + + individual_added (self, individual); + } + + for (l = removed; l != NULL; l = g_list_next (l)) + { + FolksIndividual *individual = l->data; + + individual_removed (self, individual); + } +} + +static void empathy_roster_view_constructed (GObject *object) { EmpathyRosterView *self = EMPATHY_ROSTER_VIEW (object); void (*chain_up) (GObject *) = ((GObjectClass *) empathy_roster_view_parent_class)->constructed; + GList *individuals, *l; if (chain_up != NULL) chain_up (object); g_assert (EMPATHY_IS_INDIVIDUAL_MANAGER (self->priv->manager)); + + individuals = empathy_individual_manager_get_members (self->priv->manager); + for (l = individuals; l != NULL; l = g_list_next (l)) + { + FolksIndividual *individual = l->data; + + individual_added (self, individual); + } + + tp_g_signal_connect_object (self->priv->manager, "members-changed", + G_CALLBACK (members_changed_cb), self, 0); + + g_list_free (individuals); } static void @@ -93,10 +170,12 @@ empathy_roster_view_dispose (GObject *object) static void empathy_roster_view_finalize (GObject *object) { - //EmpathyRosterView *self = EMPATHY_ROSTER_VIEW (object); + EmpathyRosterView *self = EMPATHY_ROSTER_VIEW (object); void (*chain_up) (GObject *) = ((GObjectClass *) empathy_roster_view_parent_class)->finalize; + g_hash_table_unref (self->priv->items); + if (chain_up != NULL) chain_up (object); } @@ -128,6 +207,8 @@ empathy_roster_view_init (EmpathyRosterView *self) { self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self, EMPATHY_TYPE_ROSTER_VIEW, EmpathyRosterViewPriv); + + self->priv->items = g_hash_table_new (NULL, NULL); } GtkWidget * |