]> git.0d.be Git - empathy.git/commitdiff
roster-view: allow to store more than one widget per Individual
authorGuillaume Desmottes <guillaume.desmottes@collabora.co.uk>
Fri, 25 May 2012 13:21:46 +0000 (15:21 +0200)
committerGuillaume Desmottes <guillaume.desmottes@collabora.co.uk>
Thu, 14 Jun 2012 07:21:48 +0000 (09:21 +0200)
With groups we may have more than once the same individual in the list.

libempathy-gtk/empathy-roster-view.c

index 09d59517f8846d64f7ae9b6079a6bb50a5249658..eff7fbdbb6af4b633de50ebae157e3ec636a9bfc 100644 (file)
@@ -28,7 +28,8 @@ struct _EmpathyRosterViewPriv
 {
   EmpathyIndividualManager *manager;
 
-  /* FolksIndividual (borrowed) -> EmpathyRosterContact (borrowed) */
+  /* FolksIndividual (borrowed) -> GHashTable (used as a set) of
+   * EmpathyRosterContact (borrowed) */
   GHashTable *roster_contacts;
 
   gboolean show_offline;
@@ -121,27 +122,39 @@ individual_added (EmpathyRosterView *self,
     FolksIndividual *individual)
 {
   GtkWidget *contact;
+  GHashTable *contacts;
 
-  contact = g_hash_table_lookup (self->priv->roster_contacts, individual);
-  if (contact != NULL)
+  contacts = g_hash_table_lookup (self->priv->roster_contacts, individual);
+  if (contacts != NULL)
     return;
 
+  contacts = g_hash_table_new (NULL, NULL);
+
   contact = add_roster_contact (self, individual);
+  g_hash_table_add (contacts, contact);
 
-  g_hash_table_insert (self->priv->roster_contacts, individual, contact);
+  g_hash_table_insert (self->priv->roster_contacts, individual, contacts);
 }
 
 static void
 individual_removed (EmpathyRosterView *self,
     FolksIndividual *individual)
 {
-  GtkWidget *contact;
+  GHashTable *contacts;
+  GHashTableIter iter;
+  gpointer key;
 
-  contact = g_hash_table_lookup (self->priv->roster_contacts, individual);
-  if (contact == NULL)
+  contacts = g_hash_table_lookup (self->priv->roster_contacts, individual);
+  if (contacts == NULL)
     return;
 
-  gtk_container_remove (GTK_CONTAINER (self), contact);
+  g_hash_table_iter_init (&iter, contacts);
+  while (g_hash_table_iter_next (&iter, &key, NULL))
+    {
+      GtkWidget *contact = key;
+
+      gtk_container_remove (GTK_CONTAINER (self), contact);
+    }
 
   g_hash_table_remove (self->priv->roster_contacts, individual);
 }
@@ -329,7 +342,8 @@ empathy_roster_view_init (EmpathyRosterView *self)
   self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self,
       EMPATHY_TYPE_ROSTER_VIEW, EmpathyRosterViewPriv);
 
-  self->priv->roster_contacts = g_hash_table_new (NULL, NULL);
+  self->priv->roster_contacts = g_hash_table_new_full (NULL, NULL,
+      NULL, (GDestroyNotify) g_hash_table_unref);
 }
 
 GtkWidget *