[gnome-software: 17/110] Adapt gs_container_remove_all to GTK4




commit 16ed2cf0ec1d7d96af9c5020b14025b4558c472e
Author: Georges Basile Stavracas Neto <georges stavracas gmail com>
Date:   Sat Aug 21 14:45:59 2021 -0300

    Adapt gs_container_remove_all to GTK4
    
    GTK4 doesn't have GtkContainer anymore, and all widget subclasses
    have their own specialized functions.
    
    Replace gs_container_remove_all() with gs_widget_remove_all(),
    which receives a remove function.
    
    More steps are necessary to get rid of GtkContainer in the codebase.

 src/gs-age-rating-context-dialog.c       |  2 +-
 src/gs-app-details-page.c                |  8 +-------
 src/gs-app-version-history-dialog.c      |  2 +-
 src/gs-category-page.c                   | 10 +++++-----
 src/gs-common.c                          | 18 +++++++++---------
 src/gs-common.h                          |  6 +++++-
 src/gs-details-page.c                    |  6 +++---
 src/gs-extras-page.c                     |  2 +-
 src/gs-featured-carousel.c               |  2 +-
 src/gs-hardware-support-context-dialog.c |  2 +-
 src/gs-installed-page.c                  |  8 ++++----
 src/gs-moderate-page.c                   |  2 +-
 src/gs-os-update-page.c                  |  2 +-
 src/gs-overview-page.c                   |  8 ++++----
 src/gs-repos-dialog.c                    | 10 ++++++++--
 src/gs-safety-context-dialog.c           |  2 +-
 src/gs-screenshot-carousel.c             |  2 +-
 src/gs-search-page.c                     |  2 +-
 src/gs-star-widget.c                     |  2 +-
 src/gs-storage-context-dialog.c          |  2 +-
 src/gs-update-dialog.c                   |  2 +-
 21 files changed, 52 insertions(+), 48 deletions(-)
---
diff --git a/src/gs-age-rating-context-dialog.c b/src/gs-age-rating-context-dialog.c
index 94d1be57c..c8c60f7b2 100644
--- a/src/gs-age-rating-context-dialog.c
+++ b/src/gs-age-rating-context-dialog.c
@@ -653,7 +653,7 @@ update_attributes_list (GsAgeRatingContextDialog *self)
        gboolean is_unknown;
        g_autofree gchar *title = NULL;
 
-       gs_container_remove_all (GTK_CONTAINER (self->attributes_list));
+       gs_widget_remove_all (GTK_WIDGET (self->attributes_list), (GsRemoveFunc) gtk_list_box_remove);
 
        /* UI state is undefined if app is not set. */
        if (self->app == NULL)
diff --git a/src/gs-app-details-page.c b/src/gs-app-details-page.c
index 79fe76ef0..18af0d791 100644
--- a/src/gs-app-details-page.c
+++ b/src/gs-app-details-page.c
@@ -82,16 +82,10 @@ static const struct {
   { GS_APP_PERMISSIONS_ESCAPE_SANDBOX, N_("Sandbox escape"), N_("Can escape the sandbox and circumvent any 
other restrictions") },
 };
 
-static void
-destroy_cb (GtkWidget *widget, gpointer data)
-{
-       gtk_widget_destroy (widget);
-}
-
 static void
 populate_permissions_section (GsAppDetailsPage *page, GsAppPermissions permissions)
 {
-       gtk_container_foreach (GTK_CONTAINER (page->permissions_section_content), destroy_cb, NULL);
+       gs_widget_remove_all (page->permissions_section_content, (GsRemoveFunc) gtk_box_remove);
 
        for (gsize i = 0; i < G_N_ELEMENTS (permission_display_data); i++) {
                GtkWidget *row, *image, *box, *label;
diff --git a/src/gs-app-version-history-dialog.c b/src/gs-app-version-history-dialog.c
index 8b61b7c2b..6ebb9bb52 100644
--- a/src/gs-app-version-history-dialog.c
+++ b/src/gs-app-version-history-dialog.c
@@ -31,7 +31,7 @@ populate_version_history (GsAppVersionHistoryDialog *dialog,
        g_autoptr(GPtrArray) version_history = NULL;
 
        /* remove previous */
-       gs_container_remove_all (GTK_CONTAINER (dialog->listbox));
+       gs_widget_remove_all (dialog->listbox, (GsRemoveFunc) gtk_list_box_remove);
 
        version_history = gs_app_get_version_history (app);
        if (version_history == NULL || version_history->len == 0) {
diff --git a/src/gs-category-page.c b/src/gs-category-page.c
index 833141768..d37e0dabb 100644
--- a/src/gs-category-page.c
+++ b/src/gs-category-page.c
@@ -88,7 +88,7 @@ gs_category_page_add_placeholders (GsCategoryPage *self,
                                    GtkFlowBox     *flow_box,
                                    guint           n_placeholders)
 {
-       gs_container_remove_all (GTK_CONTAINER (flow_box));
+       gs_widget_remove_all (GTK_WIDGET (flow_box), (GsRemoveFunc) gtk_flow_box_remove);
 
        for (guint i = 0; i < n_placeholders; ++i) {
                GtkWidget *tile = gs_summary_tile_new (NULL);
@@ -264,9 +264,9 @@ load_category_finish (LoadCategoryData *data)
                return;
 
        /* Remove the loading tiles. */
-       gs_container_remove_all (GTK_CONTAINER (self->featured_flow_box));
-       gs_container_remove_all (GTK_CONTAINER (self->recently_updated_flow_box));
-       gs_container_remove_all (GTK_CONTAINER (self->category_detail_box));
+       gs_widget_remove_all (self->featured_flow_box, (GsRemoveFunc) gtk_flow_box_remove);
+       gs_widget_remove_all (self->recently_updated_flow_box, (GsRemoveFunc) gtk_flow_box_remove);
+       gs_widget_remove_all (self->category_detail_box, (GsRemoveFunc) gtk_flow_box_remove);
 
        /* Last 30 days */
        recently_updated_cutoff_secs = g_get_real_time () / G_USEC_PER_SEC - 30 * 24 * 60 * 60;
@@ -344,7 +344,7 @@ gs_category_page_load_category (GsCategoryPage *self)
                 * indicator that there will be featured apps */
                gs_category_page_add_placeholders (self, GTK_FLOW_BOX (self->featured_flow_box), 4);
        } else {
-               gs_container_remove_all (GTK_CONTAINER (self->featured_flow_box));
+               gs_widget_remove_all (self->featured_flow_box, (GsRemoveFunc) gtk_flow_box_remove);
                gtk_widget_hide (self->featured_flow_box);
        }
 
diff --git a/src/gs-common.c b/src/gs-common.c
index f5339da8a..ce88f6320 100644
--- a/src/gs-common.c
+++ b/src/gs-common.c
@@ -86,17 +86,17 @@ gs_start_spinner (GtkSpinner *spinner)
                                GUINT_TO_POINTER (id), remove_source);
 }
 
-static void
-remove_all_cb (GtkWidget *widget, gpointer user_data)
-{
-       GtkContainer *container = GTK_CONTAINER (user_data);
-       gtk_container_remove (container, widget);
-}
-
 void
-gs_container_remove_all (GtkContainer *container)
+gs_widget_remove_all (GtkWidget    *container,
+                      GsRemoveFunc  remove_func)
 {
-       gtk_container_foreach (container, remove_all_cb, container);
+       GtkWidget *child;
+       while ((child = gtk_widget_get_first_child (container)) != NULL) {
+               if (remove_func)
+                       remove_func (container, child);
+               else
+                       gtk_widget_unparent (child);
+       }
 }
 
 static void
diff --git a/src/gs-common.h b/src/gs-common.h
index cc27dbcb6..0a19daab6 100644
--- a/src/gs-common.h
+++ b/src/gs-common.h
@@ -16,9 +16,13 @@
 
 G_BEGIN_DECLS
 
+typedef void (*GsRemoveFunc) (GtkWidget *container,
+                             GtkWidget *child);
+
 void    gs_start_spinner               (GtkSpinner     *spinner);
 void    gs_stop_spinner                (GtkSpinner     *spinner);
-void    gs_container_remove_all        (GtkContainer   *container);
+void    gs_widget_remove_all           (GtkWidget      *container,
+                                        GsRemoveFunc    remove_func);
 void    gs_grab_focus_when_mapped      (GtkWidget      *widget);
 
 void    gs_app_notify_installed        (GsApp          *app);
diff --git a/src/gs-details-page.c b/src/gs-details-page.c
index 550037724..aa4c2655c 100644
--- a/src/gs-details-page.c
+++ b/src/gs-details-page.c
@@ -639,7 +639,7 @@ gs_details_page_get_alternates_cb (GObject *source_object,
        gint origin_row_by_packaging_format_index = 0;
 
        self->origin_by_packaging_format = FALSE;
-       gs_container_remove_all (GTK_CONTAINER (self->origin_popover_list_box));
+       gs_widget_remove_all (self->origin_popover_list_box, (GsRemoveFunc) gtk_list_box_remove);
 
        /* Did we switch away from the page in the meantime? */
        if (!gs_page_is_active (GS_PAGE (self))) {
@@ -1202,7 +1202,7 @@ gs_details_page_refresh_addons (GsDetailsPage *self)
        GsAppList *addons;
        guint i;
 
-       gs_container_remove_all (GTK_CONTAINER (self->list_box_addons));
+       gs_widget_remove_all (self->list_box_addons, (GsRemoveFunc) gtk_list_box_remove);
 
        addons = gs_app_get_addons (self->app);
        for (i = 0; i < gs_app_list_length (addons); i++) {
@@ -1367,7 +1367,7 @@ gs_details_page_refresh_reviews (GsDetailsPage *self)
        }
 
        /* add all the reviews */
-       gs_container_remove_all (GTK_CONTAINER (self->list_box_reviews));
+       gs_widget_remove_all (self->list_box_reviews, (GsRemoveFunc) gtk_list_box_remove);
        reviews = gs_app_get_reviews (self->app);
        for (i = 0; i < reviews->len; i++) {
                AsReview *review = g_ptr_array_index (reviews, i);
diff --git a/src/gs-extras-page.c b/src/gs-extras-page.c
index c41d687ee..17549024d 100644
--- a/src/gs-extras-page.c
+++ b/src/gs-extras-page.c
@@ -702,7 +702,7 @@ gs_extras_page_load (GsExtrasPage *self, GPtrArray *array_search_data)
        self->pending_search_cnt = 0;
 
        /* remove old entries */
-       gs_container_remove_all (GTK_CONTAINER (self->list_box_results));
+       gs_widget_remove_all (self->list_box_results, (GsRemoveFunc) gtk_list_box_remove);
 
        /* set state as loading */
        self->state = GS_EXTRAS_PAGE_STATE_LOADING;
diff --git a/src/gs-featured-carousel.c b/src/gs-featured-carousel.c
index 66cadb12e..bb99587a7 100644
--- a/src/gs-featured-carousel.c
+++ b/src/gs-featured-carousel.c
@@ -425,7 +425,7 @@ gs_featured_carousel_set_apps (GsFeaturedCarousel *self,
                return;
 
        stop_rotation_timer (self);
-       gs_container_remove_all (GTK_CONTAINER (self->carousel));
+       gs_widget_remove_all (GTK_WIDGET (self->carousel), (GsRemoveFunc) adw_carousel_remove);
 
        g_set_object (&self->apps, apps);
 
diff --git a/src/gs-hardware-support-context-dialog.c b/src/gs-hardware-support-context-dialog.c
index 6361ddb17..2fcbace1d 100644
--- a/src/gs-hardware-support-context-dialog.c
+++ b/src/gs-hardware-support-context-dialog.c
@@ -515,7 +515,7 @@ update_relations_list (GsHardwareSupportContextDialog *self)
         * support based on app properties. */
        chosen_rating = GS_CONTEXT_DIALOG_ROW_IMPORTANCE_NEUTRAL;
 
-       gs_container_remove_all (GTK_CONTAINER (self->relations_list));
+       gs_widget_remove_all (GTK_WIDGET (self->relations_list), (GsRemoveFunc) gtk_list_box_remove);
 
        /* UI state is undefined if app is not set. */
        if (self->app == NULL)
diff --git a/src/gs-installed-page.c b/src/gs-installed-page.c
index 67a4b7a51..5ac7ae959 100644
--- a/src/gs-installed-page.c
+++ b/src/gs-installed-page.c
@@ -305,10 +305,10 @@ gs_installed_page_load (GsInstalledPage *self)
        self->waiting = TRUE;
 
        /* remove old entries */
-       gs_container_remove_all (GTK_CONTAINER (self->list_box_install_in_progress));
-       gs_container_remove_all (GTK_CONTAINER (self->list_box_install_apps));
-       gs_container_remove_all (GTK_CONTAINER (self->list_box_install_system_apps));
-       gs_container_remove_all (GTK_CONTAINER (self->list_box_install_addons));
+       gs_widget_remove_all (self->list_box_install_in_progress, (GsRemoveFunc) gtk_list_box_remove);
+       gs_widget_remove_all (self->list_box_install_apps, (GsRemoveFunc) gtk_list_box_remove);
+       gs_widget_remove_all (self->list_box_install_system_apps, (GsRemoveFunc) gtk_list_box_remove);
+       gs_widget_remove_all (self->list_box_install_addons, (GsRemoveFunc) gtk_list_box_remove);
 
        flags = GS_PLUGIN_REFINE_FLAGS_REQUIRE_ICON |
                GS_PLUGIN_REFINE_FLAGS_REQUIRE_HISTORY |
diff --git a/src/gs-moderate-page.c b/src/gs-moderate-page.c
index 54e184b92..69d560a44 100644
--- a/src/gs-moderate-page.c
+++ b/src/gs-moderate-page.c
@@ -233,7 +233,7 @@ gs_moderate_page_load (GsModeratePage *self)
        g_autoptr(GError) local_error = NULL;
 
        /* remove old entries */
-       gs_container_remove_all (GTK_CONTAINER (self->list_box_install));
+       gs_widget_remove_all (self->list_box_install, (GsRemoveFunc) gtk_list_box_remove);
 
        /* get unvoted reviews as apps */
        if (!gs_odrs_provider_add_unvoted_reviews (self->odrs_provider, list,
diff --git a/src/gs-os-update-page.c b/src/gs-os-update-page.c
index 4e13aead3..e74ebcab6 100644
--- a/src/gs-os-update-page.c
+++ b/src/gs-os-update-page.c
@@ -400,7 +400,7 @@ gs_os_update_page_set_app (GsOsUpdatePage *page, GsApp *app)
        for (guint i = 0; i < GS_OS_UPDATE_PAGE_SECTION_LAST; i++) {
                if (page->list_boxes[i] == NULL)
                        continue;
-               gs_container_remove_all (GTK_CONTAINER (page->list_boxes[i]));
+               gs_widget_remove_all (page->list_boxes[i], (GsRemoveFunc) gtk_list_box_remove);
        }
 
        if (app) {
diff --git a/src/gs-overview-page.c b/src/gs-overview-page.c
index 70c604e5a..938c1bb3e 100644
--- a/src/gs-overview-page.c
+++ b/src/gs-overview-page.c
@@ -150,7 +150,7 @@ gs_overview_page_get_popular_cb (GObject *source_object,
 
        gs_app_list_randomize (list);
 
-       gs_container_remove_all (GTK_CONTAINER (self->box_popular));
+       gs_widget_remove_all (self->box_popular, (GsRemoveFunc) gtk_flow_box_remove);
 
        for (i = 0; i < gs_app_list_length (list) && i < N_TILES; i++) {
                app = gs_app_list_index (list, i);
@@ -199,7 +199,7 @@ gs_overview_page_get_recent_cb (GObject *source_object, GAsyncResult *res, gpoin
 
        gs_app_list_randomize (list);
 
-       gs_container_remove_all (GTK_CONTAINER (self->box_recent));
+       gs_widget_remove_all (self->box_recent, (GsRemoveFunc) gtk_flow_box_remove);
 
        for (i = 0; i < gs_app_list_length (list) && i < N_TILES; i++) {
                app = gs_app_list_index (list, i);
@@ -316,8 +316,8 @@ gs_overview_page_get_categories_cb (GObject *source_object,
                goto out;
        }
 
-       gs_container_remove_all (GTK_CONTAINER (self->flowbox_categories));
-       gs_container_remove_all (GTK_CONTAINER (self->flowbox_iconless_categories));
+       gs_widget_remove_all (self->flowbox_categories, (GsRemoveFunc) gtk_flow_box_remove);
+       gs_widget_remove_all (self->flowbox_iconless_categories, (GsRemoveFunc) gtk_flow_box_remove);
 
        /* Add categories to the flowboxes. Categories with icons are deemed to
         * be visually important, and are listed near the top of the page.
diff --git a/src/gs-repos-dialog.c b/src/gs-repos-dialog.c
index 7a2989a6d..3b1aac363 100644
--- a/src/gs-repos-dialog.c
+++ b/src/gs-repos-dialog.c
@@ -455,6 +455,8 @@ get_sources_cb (GsPluginLoader *plugin_loader,
        g_autoptr(GsAppList) list = NULL;
        g_autoptr(GSList) other_repos = NULL;
        g_autoptr(GList) sections = NULL;
+       AdwPreferencesGroup *added_section;
+       GHashTableIter iter;
 
        /* get the results */
        list = gs_plugin_loader_job_process_finish (plugin_loader, res, &error);
@@ -472,8 +474,12 @@ get_sources_cb (GsPluginLoader *plugin_loader,
        }
 
        /* remove previous */
-       g_hash_table_remove_all (dialog->sections);
-       gs_container_remove_all (GTK_CONTAINER (dialog->content_page));
+       g_hash_table_iter_init (&iter, dialog->sections);
+       while (g_hash_table_iter_next (&iter, NULL, (gpointer *)&added_section)) {
+               adw_preferences_page_remove (ADW_PREFERENCES_PAGE (dialog->content_page),
+                                            added_section);
+               g_hash_table_iter_remove (&iter);
+       }
 
        /* stop the spinner */
        gs_stop_spinner (GTK_SPINNER (dialog->spinner));
diff --git a/src/gs-safety-context-dialog.c b/src/gs-safety-context-dialog.c
index a93128ff4..8d6fce284 100644
--- a/src/gs-safety-context-dialog.c
+++ b/src/gs-safety-context-dialog.c
@@ -118,7 +118,7 @@ update_permissions_list (GsSafetyContextDialog *self)
         * based on app properties. */
        chosen_rating = GS_CONTEXT_DIALOG_ROW_IMPORTANCE_UNIMPORTANT;
 
-       gs_container_remove_all (GTK_CONTAINER (self->permissions_list));
+       gs_widget_remove_all (GTK_WIDGET (self->permissions_list), (GsRemoveFunc) gtk_list_box_remove);
 
        /* UI state is undefined if app is not set. */
        if (self->app == NULL)
diff --git a/src/gs-screenshot-carousel.c b/src/gs-screenshot-carousel.c
index 9c08c423a..6bba44b44 100644
--- a/src/gs-screenshot-carousel.c
+++ b/src/gs-screenshot-carousel.c
@@ -125,7 +125,7 @@ gs_screenshot_carousel_load_screenshots (GsScreenshotCarousel *self, GsApp *app,
        }
 
        /* reset screenshots */
-       gs_container_remove_all (GTK_CONTAINER (self->carousel));
+       gs_widget_remove_all (self->carousel, (GsRemoveFunc) adw_carousel_remove);
 
        for (guint i = 0; i < screenshots->len && !g_cancellable_is_cancelled (cancellable); i++) {
                AsScreenshot *ss = g_ptr_array_index (screenshots, i);
diff --git a/src/gs-search-page.c b/src/gs-search-page.c
index 81d1a5670..e210e172a 100644
--- a/src/gs-search-page.c
+++ b/src/gs-search-page.c
@@ -140,7 +140,7 @@ gs_search_page_get_search_cb (GObject *source_object,
        }
 
        /* remove old entries */
-       gs_container_remove_all (GTK_CONTAINER (self->list_box_search));
+       gs_widget_remove_all (self->list_box_search, (GsRemoveFunc) gtk_list_box_remove);
 
        gs_stop_spinner (GTK_SPINNER (self->spinner_search));
        gtk_stack_set_visible_child_name (GTK_STACK (self->stack_search), "results");
diff --git a/src/gs-star-widget.c b/src/gs-star-widget.c
index eb092d9f9..5090249e5 100644
--- a/src/gs-star-widget.c
+++ b/src/gs-star-widget.c
@@ -119,7 +119,7 @@ gs_star_widget_refresh (GsStarWidget *star)
                return;
 
        /* remove all existing widgets */
-       gs_container_remove_all (GTK_CONTAINER (priv->box1));
+       gs_widget_remove_all (priv->box1, (GsRemoveFunc) gtk_box_remove);
 
        for (guint i = 0; i < G_N_ELEMENTS (priv->images); i++) {
                GtkWidget *w;
diff --git a/src/gs-storage-context-dialog.c b/src/gs-storage-context-dialog.c
index f270ba67c..4ccbf26b9 100644
--- a/src/gs-storage-context-dialog.c
+++ b/src/gs-storage-context-dialog.c
@@ -108,7 +108,7 @@ update_sizes_list (GsStorageContextDialog *self)
        const gchar *title;
        gboolean cache_row_added = FALSE;
 
-       gs_container_remove_all (GTK_CONTAINER (self->sizes_list));
+       gs_widget_remove_all (GTK_WIDGET (self->sizes_list), (GsRemoveFunc) gtk_list_box_remove);
 
        /* UI state is undefined if app is not set. */
        if (self->app == NULL)
diff --git a/src/gs-update-dialog.c b/src/gs-update-dialog.c
index 0c423495a..2109f86d2 100644
--- a/src/gs-update-dialog.c
+++ b/src/gs-update-dialog.c
@@ -126,7 +126,7 @@ get_installed_updates_cb (GsPluginLoader *plugin_loader,
 
        gtk_stack_set_visible_child_name (GTK_STACK (dialog->stack), "installed-updates-list");
 
-       gs_container_remove_all (GTK_CONTAINER (dialog->list_box_installed_updates));
+       gs_widget_remove_all (dialog->list_box_installed_updates, (GsRemoveFunc) gtk_list_box_remove);
        for (i = 0; i < gs_app_list_length (list); i++) {
                gs_update_list_add_app (GS_UPDATE_LIST (dialog->list_box_installed_updates),
                                        gs_app_list_index (list, i));


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]