From: Xavier Claessens Date: Thu, 17 Jun 2010 09:16:16 +0000 (+0200) Subject: Fix the visibility of group when live search is active X-Git-Url: https://git.0d.be/?p=empathy.git;a=commitdiff_plain;h=fdaa85ff7081f8e3c23984872cb72d585ee1d76b Fix the visibility of group when live search is active --- diff --git a/libempathy-gtk/empathy-contact-list-view.c b/libempathy-gtk/empathy-contact-list-view.c index 208306c3..309e1481 100644 --- a/libempathy-gtk/empathy-contact-list-view.c +++ b/libempathy-gtk/empathy-contact-list-view.c @@ -1368,6 +1368,52 @@ contact_list_view_row_has_child_toggled_cb (GtkTreeModel *model, g_free (name); } +static void +contact_list_view_verify_group_visibility (EmpathyContactListView *view, + GtkTreePath *path) +{ + EmpathyContactListViewPriv *priv = GET_PRIV (view); + GtkTreeModel *model; + GtkTreePath *parent_path; + GtkTreeIter parent_iter; + + if (gtk_tree_path_get_depth (path) < 2) + return; + + /* A group row is visible if and only if at least one if its child is + * visible. So when a row is inserted/deleted/changed in the base model, + * that could modify the visibility of its parent in the filter model. + */ + + model = GTK_TREE_MODEL (priv->store); + parent_path = gtk_tree_path_copy (path); + gtk_tree_path_up (parent_path); + if (gtk_tree_model_get_iter (model, &parent_iter, parent_path)) { + /* This tells the filter to verify the visibility of that row, + * and show/hide it if necessary */ + gtk_tree_model_row_changed (GTK_TREE_MODEL (priv->store), + parent_path, &parent_iter); + } + gtk_tree_path_free (parent_path); +} + +static void +contact_list_view_store_row_changed_cb (GtkTreeModel *model, + GtkTreePath *path, + GtkTreeIter *iter, + EmpathyContactListView *view) +{ + contact_list_view_verify_group_visibility (view, path); +} + +static void +contact_list_view_store_row_deleted_cb (GtkTreeModel *model, + GtkTreePath *path, + EmpathyContactListView *view) +{ + contact_list_view_verify_group_visibility (view, path); +} + static void contact_list_view_constructed (GObject *object) { @@ -1394,6 +1440,16 @@ contact_list_view_constructed (GObject *object) gtk_tree_view_set_model (GTK_TREE_VIEW (view), GTK_TREE_MODEL (priv->filter)); + tp_g_signal_connect_object (priv->store, "row-changed", + G_CALLBACK (contact_list_view_store_row_changed_cb), + view, 0); + tp_g_signal_connect_object (priv->store, "row-inserted", + G_CALLBACK (contact_list_view_store_row_changed_cb), + view, 0); + tp_g_signal_connect_object (priv->store, "row-deleted", + G_CALLBACK (contact_list_view_store_row_deleted_cb), + view, 0); + /* Setup view */ /* Setting reorderable is a hack that gets us row previews as drag icons for free. We override all the drag handlers. It's tricky to get the