From c9f8bb22f691b10c34503ec7a6802050b36c623e Mon Sep 17 00:00:00 2001 From: Georges Basile Stavracas Neto Date: Fri, 8 Jul 2022 15:34:17 -0300 Subject: [PATCH] restrict-applications-selector: Adapt to AdwActionRow This greatly reduces the code size. GtkBin is no more, and AdwActionRow has specific API to add suffix widgets. --- .../restrict-applications-selector.c | 18 ++++-------------- 1 file changed, 4 insertions(+), 14 deletions(-) diff --git a/libmalcontent-ui/restrict-applications-selector.c b/libmalcontent-ui/restrict-applications-selector.c index ced1ed9..c444f2b 100644 --- a/libmalcontent-ui/restrict-applications-selector.c +++ b/libmalcontent-ui/restrict-applications-selector.c @@ -356,12 +356,13 @@ create_row_for_app_cb (gpointer item, gtk_style_context_add_provider (context, GTK_STYLE_PROVIDER (self->css_provider), GTK_STYLE_PROVIDER_PRIORITY_APPLICATION - 1); - gtk_container_add (GTK_CONTAINER (row), w); + adw_action_row_add_suffix (ADW_ACTION_ROW (row), w); adw_action_row_set_activatable_widget (ADW_ACTION_ROW (row), w); gtk_widget_show_all (row); /* Fetch status from AccountService */ + g_object_set_data (G_OBJECT (row), "GtkSwitch", w); g_object_set_data_full (G_OBJECT (w), "GAppInfo", g_object_ref (app), g_object_unref); update_listbox_row_switch (self, GTK_SWITCH (w)); g_signal_connect (w, "notify::active", G_CALLBACK (on_switch_active_changed_cb), self); @@ -782,24 +783,13 @@ mct_restrict_applications_selector_set_app_filter (MctRestrictApplicationsSelect for (guint i = 0; i < n_apps; i++) { GtkListBoxRow *row; - GtkWidget *box, *w; - g_autoptr(GList) children = NULL; /* (element-type GtkWidget) */ + GtkWidget *w; /* Navigate the widget hierarchy set up in create_row_for_app_cb(). */ row = gtk_list_box_get_row_at_index (self->listbox, i); g_assert (row != NULL && GTK_IS_LIST_BOX_ROW (row)); - box = gtk_bin_get_child (GTK_BIN (row)); - g_assert (box != NULL && GTK_IS_BOX (box)); - - children = gtk_container_get_children (GTK_CONTAINER (box)); - g_assert (children != NULL); - - w = g_list_nth_data (children, 3); - g_assert (w != NULL && GTK_IS_BOX (w)); - children = gtk_container_get_children (GTK_CONTAINER (w)); - - w = g_list_nth_data (children, 0); + w = g_object_get_data (G_OBJECT (row), "GtkSwitch"); g_assert (w != NULL && GTK_IS_SWITCH (w)); update_listbox_row_switch (self, GTK_SWITCH (w));