aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGuillaume Desmottes <guillaume.desmottes@collabora.co.uk>2012-06-12 20:26:29 +0800
committerGuillaume Desmottes <guillaume.desmottes@collabora.co.uk>2012-06-14 15:21:50 +0800
commit674890e965f49fe00b3cc7365ce6d860583d0c88 (patch)
tree3156cbb24cced99eddc9647b000b0ff310f66f6c
parentb6912edc8b09d2478065ff95c1b55561a41ff4c5 (diff)
downloadgsoc2013-empathy-674890e965f49fe00b3cc7365ce6d860583d0c88.tar
gsoc2013-empathy-674890e965f49fe00b3cc7365ce6d860583d0c88.tar.gz
gsoc2013-empathy-674890e965f49fe00b3cc7365ce6d860583d0c88.tar.bz2
gsoc2013-empathy-674890e965f49fe00b3cc7365ce6d860583d0c88.tar.lz
gsoc2013-empathy-674890e965f49fe00b3cc7365ce6d860583d0c88.tar.xz
gsoc2013-empathy-674890e965f49fe00b3cc7365ce6d860583d0c88.tar.zst
gsoc2013-empathy-674890e965f49fe00b3cc7365ce6d860583d0c88.zip
roster-view: store all the children in EmpathyRosterGroup, not only the displayed one
When checking if a contact is already in the 'top' list, we don't care if it's actually displayed or not. This makes the whole code more logic as only storing the displayed widgets in EmpathyRosterGroup was a bit weird.
-rw-r--r--libempathy-gtk/empathy-roster-view.c101
1 files changed, 69 insertions, 32 deletions
diff --git a/libempathy-gtk/empathy-roster-view.c b/libempathy-gtk/empathy-roster-view.c
index 4f89e4e6d..4b59316df 100644
--- a/libempathy-gtk/empathy-roster-view.c
+++ b/libempathy-gtk/empathy-roster-view.c
@@ -211,7 +211,7 @@ lookup_roster_group (EmpathyRosterView *self,
return g_hash_table_lookup (self->priv->roster_groups, group);
}
-static void
+static EmpathyRosterGroup *
ensure_roster_group (EmpathyRosterView *self,
const gchar *group)
{
@@ -219,7 +219,7 @@ ensure_roster_group (EmpathyRosterView *self,
roster_group = (GtkWidget *) lookup_roster_group (self, group);
if (roster_group != NULL)
- return;
+ return EMPATHY_ROSTER_GROUP (roster_group);
roster_group = empathy_roster_group_new (group);
@@ -231,6 +231,27 @@ ensure_roster_group (EmpathyRosterView *self,
g_hash_table_insert (self->priv->roster_groups, g_strdup (group),
roster_group);
+
+ return EMPATHY_ROSTER_GROUP (roster_group);
+}
+
+static void
+update_group_widgets (EmpathyRosterView *self,
+ EmpathyRosterGroup *group,
+ EmpathyRosterContact *contact,
+ gboolean add)
+{
+ guint old_count, count;
+
+ old_count = empathy_roster_group_get_widgets_count (group);
+
+ if (add)
+ count = empathy_roster_group_add_widget (group, GTK_WIDGET (contact));
+ else
+ count = empathy_roster_group_remove_widget (group, GTK_WIDGET (contact));
+
+ if (count != old_count)
+ egg_list_box_child_changed (EGG_LIST_BOX (self), GTK_WIDGET (group));
}
static void
@@ -240,16 +261,23 @@ add_to_group (EmpathyRosterView *self,
{
GtkWidget *contact;
GHashTable *contacts;
+ EmpathyRosterGroup *roster_group = NULL;
contacts = g_hash_table_lookup (self->priv->roster_contacts, individual);
if (contacts == NULL)
return;
if (tp_strdiff (group, NO_GROUP))
- ensure_roster_group (self, group);
+ roster_group = ensure_roster_group (self, group);
contact = add_roster_contact (self, individual, group);
g_hash_table_insert (contacts, g_strdup (group), contact);
+
+ if (roster_group != NULL)
+ {
+ update_group_widgets (self, roster_group,
+ EMPATHY_ROSTER_CONTACT (contact), TRUE);
+ }
}
static void
@@ -301,30 +329,6 @@ individual_added (EmpathyRosterView *self,
}
static void
-update_group_widgets_count (EmpathyRosterView *self,
- EmpathyRosterGroup *group,
- EmpathyRosterContact *contact,
- gboolean displayed)
-{
- if (displayed)
- {
- if (empathy_roster_group_add_widget (group, GTK_WIDGET (contact)) == 1)
- {
- egg_list_box_child_changed (EGG_LIST_BOX (self),
- GTK_WIDGET (group));
- }
- }
- else
- {
- if (empathy_roster_group_remove_widget (group, GTK_WIDGET (contact)) == 0)
- {
- egg_list_box_child_changed (EGG_LIST_BOX (self),
- GTK_WIDGET (group));
- }
- }
-}
-
-static void
set_event_icon_on_individual (EmpathyRosterView *self,
FolksIndividual *individual,
const gchar *icon)
@@ -457,7 +461,7 @@ individual_removed (EmpathyRosterView *self,
group = lookup_roster_group (self, group_name);
if (group != NULL)
{
- update_group_widgets_count (self, group,
+ update_group_widgets (self, group,
EMPATHY_ROSTER_CONTACT (contact), FALSE);
}
@@ -689,8 +693,31 @@ static void
add_to_displayed (EmpathyRosterView *self,
EmpathyRosterContact *contact)
{
+ FolksIndividual *individual;
+ GHashTable *contacts;
+ GHashTableIter iter;
+ gpointer v;
+
+ if (g_hash_table_lookup (self->priv->displayed_contacts, contact) != NULL)
+ return;
+
g_hash_table_add (self->priv->displayed_contacts, contact);
update_empty (self, FALSE);
+
+ /* Groups of this contact may now be displayed if we just displays the first
+ * child in this group. */
+ individual = empathy_roster_contact_get_individual (contact);
+ contacts = g_hash_table_lookup (self->priv->roster_contacts, individual);
+ if (contacts == NULL)
+ return;
+
+ g_hash_table_iter_init (&iter, contacts);
+ while (g_hash_table_iter_next (&iter, NULL, &v))
+ {
+ GtkWidget *group = GTK_WIDGET (v);
+
+ egg_list_box_child_changed (EGG_LIST_BOX (self), group);
+ }
}
static void
@@ -752,8 +779,6 @@ filter_contact (EmpathyRosterView *self,
if (group != NULL)
{
- update_group_widgets_count (self, group, contact, displayed);
-
/* When searching, always display even if the group is closed */
if (!is_searching (self) &&
!gtk_expander_get_expanded (GTK_EXPANDER (group)))
@@ -777,7 +802,19 @@ static gboolean
filter_group (EmpathyRosterView *self,
EmpathyRosterGroup *group)
{
- return empathy_roster_group_get_widgets_count (group);
+ GList *widgets, *l;
+
+ /* Display the group if it contains at least one displayed contact */
+ widgets = empathy_roster_group_get_widgets (group);
+ for (l = widgets; l != NULL; l = g_list_next (l))
+ {
+ EmpathyRosterContact *contact = l->data;
+
+ if (contact_should_be_displayed (self, contact))
+ return TRUE;
+ }
+
+ return FALSE;
}
static gboolean
@@ -860,7 +897,7 @@ remove_from_group (EmpathyRosterView *self,
if (roster_group != NULL)
{
- update_group_widgets_count (self, roster_group,
+ update_group_widgets (self, roster_group,
EMPATHY_ROSTER_CONTACT (contact), FALSE);
}