diff options
author | Alexander Larsson <alexl@redhat.com> | 2013-06-13 12:21:18 +0200 |
---|---|---|
committer | Thomas Wood <thomas.wood@intel.com> | 2013-07-02 16:19:09 +0100 |
commit | a46a652093f2860a07bda056f569122c3165c7ac (patch) | |
tree | 3ce8bc22a8a8b2cca6521fec9de371188456fb36 | |
parent | 1db26b435aef98037232ed1899b4387457e1214f (diff) | |
download | gnome-control-center-a46a652093f2860a07bda056f569122c3165c7ac.tar.gz |
search: Convert to GtkListBox
https://bugzilla.gnome.org/show_bug.cgi?id=702164
-rw-r--r-- | panels/search/cc-search-locations-dialog.c | 89 | ||||
-rw-r--r-- | panels/search/cc-search-panel.c | 67 |
2 files changed, 78 insertions, 78 deletions
diff --git a/panels/search/cc-search-locations-dialog.c b/panels/search/cc-search-locations-dialog.c index c408486e5..ad9698918 100644 --- a/panels/search/cc-search-locations-dialog.c +++ b/panels/search/cc-search-locations-dialog.c @@ -21,7 +21,6 @@ #include "cc-search-locations-dialog.h" -#include <egg-list-box/egg-list-box.h> #include <glib/gi18n.h> #define TRACKER_SCHEMA "org.freedesktop.Tracker.Miner.Files" @@ -418,7 +417,7 @@ place_query_info_ready (GObject *source, GAsyncResult *res, gpointer user_data) { - GtkWidget *child, *w; + GtkWidget *row, *box, *w; Place *place; GFileInfo *info; const gchar *desktop_path; @@ -428,10 +427,12 @@ place_query_info_ready (GObject *source, if (!info) return; - child = user_data; - place = g_object_get_data (G_OBJECT (child), "place"); + row = user_data; + place = g_object_get_data (G_OBJECT (row), "place"); g_clear_object (&place->cancellable); + box = gtk_bin_get_child (GTK_BIN (row)); + /* FIXME: GLib is currently buggy and returns a non-existent icon name * when asked for the desktop symbolic icon. */ @@ -451,13 +452,13 @@ place_query_info_ready (GObject *source, g_free (path); w = gtk_image_new_from_gicon (place->icon, GTK_ICON_SIZE_MENU); - gtk_container_add (GTK_CONTAINER (child), w); + gtk_container_add (GTK_CONTAINER (box), w); w = gtk_label_new (place->display_name); - gtk_container_add (GTK_CONTAINER (child), w); + gtk_container_add (GTK_CONTAINER (box), w); w = gtk_switch_new (); - gtk_box_pack_end (GTK_BOX (child), w, FALSE, FALSE, 0); + gtk_box_pack_end (GTK_BOX (box), w, FALSE, FALSE, 0); g_settings_bind_with_mapping (tracker_preferences, place->settings_key, w, "active", G_SETTINGS_BIND_DEFAULT, @@ -465,7 +466,7 @@ place_query_info_ready (GObject *source, switch_tracker_set_mapping, place, NULL); - gtk_widget_show_all (child); + gtk_widget_show_all (row); g_object_unref (info); } @@ -484,18 +485,18 @@ get_heading_name (PlaceType place) } static void -place_separator_func (GtkWidget **separator, - GtkWidget *child, - GtkWidget *before, - gpointer user_data) +place_header_func (GtkListBoxRow *row, + GtkListBoxRow *before, + gpointer user_data) { gboolean need_separator; + GtkWidget *current; Place *place, *place_before; gchar *text; GtkWidget *w; need_separator = FALSE; - place = g_object_get_data (G_OBJECT (child), "place"); + place = g_object_get_data (G_OBJECT (row), "place"); if (before != NULL) { @@ -510,7 +511,8 @@ place_separator_func (GtkWidget **separator, need_separator = TRUE; } - if (need_separator && *separator == NULL) + current = gtk_list_box_row_get_header (row); + if (need_separator && current == NULL) { text = g_strdup_printf ("<b>%s</b>", get_heading_name (place->place_type)); w = gtk_label_new (NULL); @@ -524,14 +526,13 @@ place_separator_func (GtkWidget **separator, gtk_widget_set_halign (w, GTK_ALIGN_START); gtk_style_context_add_class (gtk_widget_get_style_context (w), "dim-label"); - g_object_ref_sink (w); - *separator = w; + gtk_list_box_row_set_header (row, w); g_free (text); } - else if (!need_separator && *separator != NULL) + else if (!need_separator && current != NULL) { - gtk_widget_destroy (*separator); + gtk_list_box_row_set_header (row, NULL); } } @@ -571,51 +572,53 @@ place_compare_func (gconstpointer a, } static GtkWidget * -create_child_for_place (Place *place) +create_row_for_place (Place *place) { - GtkWidget *child; + GtkWidget *child, *row; + row = gtk_list_box_row_new (); child = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6); - g_object_set (child, "margin-left", 16, "margin-right", 16, NULL); - g_object_set_data_full (G_OBJECT (child), "place", place, (GDestroyNotify) place_free); + gtk_container_add (GTK_CONTAINER (row), child); + g_object_set (row, "margin-left", 16, "margin-right", 16, NULL); + g_object_set_data_full (G_OBJECT (row), "place", place, (GDestroyNotify) place_free); place->cancellable = g_cancellable_new (); g_file_query_info_async (place->location, "standard::symbolic-icon", G_FILE_QUERY_INFO_NONE, G_PRIORITY_DEFAULT, - place->cancellable, place_query_info_ready, child); + place->cancellable, place_query_info_ready, row); - return child; + return row; } static void populate_list_box (GtkWidget *list_box) { GList *places, *l; - GtkWidget *child; + GtkWidget *row; places = get_places_list (); for (l = places; l != NULL; l = l->next) { /* assumes ownership of place */ - child = create_child_for_place (l->data); - gtk_container_add (GTK_CONTAINER (list_box), child); + row = create_row_for_place (l->data); + gtk_container_add (GTK_CONTAINER (list_box), row); } g_list_free (places); } static void -list_box_child_selected (EggListBox *list_box, - GtkWidget *child, - gpointer user_data) +list_box_row_selected (GtkListBox *list_box, + GtkListBoxRow *row, + gpointer user_data) { GtkWidget *remove_button = user_data; Place *place; gboolean sensitive = FALSE; - if (child != NULL) + if (row != NULL) { - place = g_object_get_data (G_OBJECT (child), "place"); + place = g_object_get_data (G_OBJECT (row), "place"); sensitive = (place->place_type == PLACE_OTHER); } @@ -627,12 +630,12 @@ remove_button_clicked (GtkWidget *widget, gpointer user_data) { GtkWidget *list_box = user_data; - GtkWidget *child; + GtkListBoxRow *row; Place *place; GPtrArray *new_values; - child = egg_list_box_get_selected_child (EGG_LIST_BOX (list_box)); - place = g_object_get_data (G_OBJECT (child), "place"); + row = gtk_list_box_get_selected_row (GTK_LIST_BOX (list_box)); + place = g_object_get_data (G_OBJECT (row), "place"); new_values = place_get_new_settings_values (place, TRUE); g_settings_set_strv (tracker_preferences, place->settings_key, (const gchar **) new_values->pdata); @@ -721,18 +724,18 @@ cc_search_locations_dialog_new (CcSearchPanel *self) locations_dialog = GTK_WIDGET (gtk_builder_get_object (dialog_builder, "locations_dialog")); widget = GTK_WIDGET (gtk_builder_get_object (dialog_builder, "locations_scrolledwindow")); - list_box = GTK_WIDGET (egg_list_box_new ()); - egg_list_box_add_to_scrolled (EGG_LIST_BOX (list_box), GTK_SCROLLED_WINDOW (widget)); - egg_list_box_set_sort_func (EGG_LIST_BOX (list_box), - place_compare_func, NULL, NULL); - egg_list_box_set_separator_funcs (EGG_LIST_BOX (list_box), - place_separator_func, NULL, NULL); + list_box = GTK_WIDGET (gtk_list_box_new ()); + gtk_container_add (GTK_CONTAINER (widget), list_box); + gtk_list_box_set_sort_func (GTK_LIST_BOX (list_box), + (GtkListBoxSortFunc)place_compare_func, NULL, NULL); + gtk_list_box_set_header_func (GTK_LIST_BOX (list_box), + place_header_func, NULL, NULL); gtk_widget_show (list_box); widget = GTK_WIDGET (gtk_builder_get_object (dialog_builder, "locations_remove")); gtk_widget_set_sensitive (widget, FALSE); - g_signal_connect (list_box, "child-selected", - G_CALLBACK (list_box_child_selected), widget); + g_signal_connect (list_box, "row-selected", + G_CALLBACK (list_box_row_selected), widget); g_signal_connect (widget, "clicked", G_CALLBACK (remove_button_clicked), list_box); g_signal_connect_swapped (tracker_preferences, "changed::" TRACKER_KEY_RECURSIVE_DIRECTORIES, diff --git a/panels/search/cc-search-panel.c b/panels/search/cc-search-panel.c index b70184fd8..2c2336c2f 100644 --- a/panels/search/cc-search-panel.c +++ b/panels/search/cc-search-panel.c @@ -23,7 +23,6 @@ #include "cc-search-locations-dialog.h" #include "cc-search-resources.h" -#include <egg-list-box/egg-list-box.h> #include <gio/gdesktopappinfo.h> #include <glib/gi18n.h> @@ -52,17 +51,13 @@ list_sort_func (gconstpointer a, gpointer user_data) { CcSearchPanel *self = user_data; - GtkWidget *widget_a, *widget_b; GAppInfo *app_a, *app_b; const gchar *id_a, *id_b; gint idx_a, idx_b; gpointer lookup; - widget_a = GTK_WIDGET (a); - widget_b = GTK_WIDGET (b); - - app_a = g_object_get_data (G_OBJECT (widget_a), "app-info"); - app_b = g_object_get_data (G_OBJECT (widget_b), "app-info"); + app_a = g_object_get_data (G_OBJECT (a), "app-info"); + app_b = g_object_get_data (G_OBJECT (b), "app-info"); id_a = g_app_info_get_id (app_a); id_b = g_app_info_get_id (app_b); @@ -100,16 +95,16 @@ search_panel_invalidate_button_state (CcSearchPanel *self) { GList *children; gboolean is_first, is_last; - GtkWidget *child; + GtkListBoxRow *row; - child = egg_list_box_get_selected_child (EGG_LIST_BOX (self->priv->list_box)); + row = gtk_list_box_get_selected_row (GTK_LIST_BOX (self->priv->list_box)); children = gtk_container_get_children (GTK_CONTAINER (self->priv->list_box)); - if (!child || !children) + if (!row || !children) return; - is_first = (child == g_list_first (children)->data); - is_last = (child == g_list_last (children)->data); + is_first = (row == g_list_first (children)->data); + is_last = (row == g_list_last (children)->data); gtk_widget_set_sensitive (self->priv->up_button, !is_first); gtk_widget_set_sensitive (self->priv->down_button, !is_last); @@ -129,7 +124,7 @@ search_panel_invalidate_sort_order (CcSearchPanel *self) for (idx = 0; sort_order[idx] != NULL; idx++) g_hash_table_insert (self->priv->sort_order, g_strdup (sort_order[idx]), GINT_TO_POINTER (idx + 1)); - egg_list_box_resort (EGG_LIST_BOX (self->priv->list_box)); + gtk_list_box_invalidate_sort (GTK_LIST_BOX (self->priv->list_box)); g_strfreev (sort_order); search_panel_invalidate_button_state (self); @@ -189,7 +184,7 @@ static void search_panel_move_selected (CcSearchPanel *self, gboolean down) { - GtkWidget *box, *other_box; + GtkListBoxRow *row, *other_row; GAppInfo *app_info, *other_app_info; const gchar *app_id, *other_app_id; const gchar *last_good_app, *target_app; @@ -198,8 +193,8 @@ search_panel_move_selected (CcSearchPanel *self, gboolean found; GList *children, *l, *other; - box = egg_list_box_get_selected_child (EGG_LIST_BOX (self->priv->list_box)); - app_info = g_object_get_data (G_OBJECT (box), "app-info"); + row = gtk_list_box_get_selected_row (GTK_LIST_BOX (self->priv->list_box)); + app_info = g_object_get_data (G_OBJECT (row), "app-info"); app_id = g_app_info_get_id (app_info); children = gtk_container_get_children (GTK_CONTAINER (self->priv->list_box)); @@ -207,14 +202,14 @@ search_panel_move_selected (CcSearchPanel *self, /* The assertions are valid only as long as we don't move the first or the last item. */ - l = g_list_find (children, box); + l = g_list_find (children, row); g_assert (l != NULL); other = down ? g_list_next(l) : g_list_previous(l); g_assert (other != NULL); - other_box = other->data; - other_app_info = g_object_get_data (G_OBJECT (other_box), "app-info"); + other_row = other->data; + other_app_info = g_object_get_data (G_OBJECT (other_row), "app-info"); other_app_id = g_app_info_get_id (other_app_info); g_assert (other_app_id != NULL); @@ -329,9 +324,9 @@ switch_settings_mapping_set (const GValue *value, const GVariantType *expected_type, gpointer user_data) { - GtkWidget *box = user_data; - CcSearchPanel *self = g_object_get_data (G_OBJECT (box), "self"); - GAppInfo *app_info = g_object_get_data (G_OBJECT (box), "app-info"); + GtkWidget *row = user_data; + CcSearchPanel *self = g_object_get_data (G_OBJECT (row), "self"); + GAppInfo *app_info = g_object_get_data (G_OBJECT (row), "app-info"); gchar **disabled; GPtrArray *new_disabled; gint idx; @@ -373,8 +368,8 @@ switch_settings_mapping_get (GValue *value, GVariant *variant, gpointer user_data) { - GtkWidget *box = user_data; - GAppInfo *app_info = g_object_get_data (G_OBJECT (box), "app-info"); + GtkWidget *row = user_data; + GAppInfo *app_info = g_object_get_data (G_OBJECT (row), "app-info"); const gchar **disabled; gint idx; gboolean found; @@ -400,7 +395,7 @@ static void search_panel_add_one_app_info (CcSearchPanel *self, GAppInfo *app_info) { - GtkWidget *box, *w; + GtkWidget *row, *box, *w; GIcon *icon; /* gnome-control-center is special cased in the shell, @@ -412,13 +407,15 @@ search_panel_add_one_app_info (CcSearchPanel *self, /* reset valignment of the list box */ gtk_widget_set_valign (self->priv->list_box, GTK_ALIGN_FILL); + row = gtk_list_box_row_new (); box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6); + gtk_container_add (GTK_CONTAINER (row), box); gtk_widget_set_hexpand (box, TRUE); gtk_container_set_border_width (GTK_CONTAINER (box), 6); - g_object_set_data_full (G_OBJECT (box), "app-info", + g_object_set_data_full (G_OBJECT (row), "app-info", g_object_ref (app_info), g_object_unref); - g_object_set_data (G_OBJECT (box), "self", self); - gtk_container_add (GTK_CONTAINER (self->priv->list_box), box); + g_object_set_data (G_OBJECT (row), "self", self); + gtk_container_add (GTK_CONTAINER (self->priv->list_box), row); icon = g_app_info_get_icon (app_info); if (icon == NULL) @@ -442,9 +439,9 @@ search_panel_add_one_app_info (CcSearchPanel *self, G_SETTINGS_BIND_DEFAULT, switch_settings_mapping_get, switch_settings_mapping_set, - box, NULL); + row, NULL); - gtk_widget_show_all (box); + gtk_widget_show_all (row); } static void @@ -658,14 +655,14 @@ cc_search_panel_init (CcSearchPanel *self) } scrolled_window = WID ("scrolled_window"); - widget = GTK_WIDGET (egg_list_box_new ()); - egg_list_box_set_sort_func (EGG_LIST_BOX (widget), - list_sort_func, self, NULL); - egg_list_box_add_to_scrolled (EGG_LIST_BOX (widget), GTK_SCROLLED_WINDOW (scrolled_window)); + widget = GTK_WIDGET (gtk_list_box_new ()); + gtk_list_box_set_sort_func (GTK_LIST_BOX (widget), + (GtkListBoxSortFunc)list_sort_func, self, NULL); + gtk_container_add (GTK_CONTAINER (scrolled_window), widget); self->priv->list_box = widget; gtk_widget_show (widget); - g_signal_connect_swapped (widget, "child-selected", + g_signal_connect_swapped (widget, "row-selected", G_CALLBACK (search_panel_invalidate_button_state), self); self->priv->up_button = WID ("up_button"); |