[gnome-software: 8/24] gs-category-page: Simplify some more category code




commit 8320c304c744ca4b44a1756db347d25c9a15085a
Author: Philip Withnall <pwithnall endlessos org>
Date:   Wed Apr 21 16:35:02 2021 +0100

    gs-category-page: Simplify some more category code
    
    This one *does* introduce some functional changes. It adds a ‘featured’
    subcategory for addons, to allow the code to assume a ‘featured’
    subcategory will exist for every category.
    
    I don’t expect any addons to ever be featured, but having the category
    there won’t hurt.
    
    Signed-off-by: Philip Withnall <pwithnall endlessos org>

 lib/gs-desktop-data.c  |  3 +++
 src/gs-category-page.c | 31 ++++++-------------------------
 2 files changed, 9 insertions(+), 25 deletions(-)
---
diff --git a/lib/gs-desktop-data.c b/lib/gs-desktop-data.c
index 34e48238a..05ae704e9 100644
--- a/lib/gs-desktop-data.c
+++ b/lib/gs-desktop-data.c
@@ -192,6 +192,9 @@ static const GsDesktopMap map_productivity[] = {
 
 /* Addons */
 static const GsDesktopMap map_addons[] = {
+       { "all",                NC_("Menu of Add-ons", "All"),
+                                       { "Addon",
+                                         NULL} },
        { "fonts",              NC_("Menu of Add-ons", "Fonts"),
                                        { "Addon::Font",
                                          NULL} },
diff --git a/src/gs-category-page.c b/src/gs-category-page.c
index 2e9843df8..cc1e676ad 100644
--- a/src/gs-category-page.c
+++ b/src/gs-category-page.c
@@ -231,37 +231,18 @@ static void
 gs_category_page_create_filter (GsCategoryPage *self,
                                GsCategory *category)
 {
-       GsCategory *s, *first_subcat = NULL;
-       guint i;
-       GPtrArray *children;
-       gboolean featured_category_found = FALSE;
+       GsCategory *featured_subcat = NULL, *all_subcat = NULL;
 
        gs_container_remove_all (GTK_CONTAINER (self->category_detail_box));
 
-       children = gs_category_get_children (category);
-       for (i = 0; i < children->len; i++) {
-               s = GS_CATEGORY (g_ptr_array_index (children, i));
-               /* don't include the featured subcategory (those will appear as banners) */
-               if (g_strcmp0 (gs_category_get_id (s), "featured") == 0) {
-                       featured_category_found = TRUE;
-                       continue;
-               }
-               if (gs_category_get_size (s) < 1) {
-                       g_debug ("not showing %s/%s as no apps",
-                                gs_category_get_id (category),
-                                gs_category_get_id (s));
-                       continue;
-               }
-
-               if (first_subcat == NULL)
-                       first_subcat = s;
-       }
+       featured_subcat = gs_category_find_child (category, "featured");
+       all_subcat = gs_category_find_child (category, "all");
 
-       g_set_object (&self->subcategory, first_subcat);
-       if (first_subcat != NULL)
+       g_set_object (&self->subcategory, all_subcat);
+       if (all_subcat != NULL)
                gs_category_page_reload (GS_PAGE (self));
 
-       if (featured_category_found) {
+       if (featured_subcat != NULL) {
                /* set up the placeholders as having the featured category is a good
                 * indicator that there will be featured apps */
                gs_category_page_set_featured_placeholders (self);


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