[gnome-software/uajain/handle-all-category: 2/2] appstream: Properly handle "all" desktop group for a category



commit 4981ac0a82c3a2f9d2140fe4db13da08ae813916
Author: Umang Jain <umang endlessm com>
Date:   Sat Aug 3 23:58:02 2019 +0530

    appstream: Properly handle "all" desktop group for a category
    
    The current logic only updates app-counter for parent categories
    only if there are multiple groups/subcategories. However, this
    is not correct as it may  lead to categories with no groups/
    subcategories, be hidden from the overview-page.
    
    This bug was discovered inside Endless, where a custom category
    with no groups/subcategories was added and it was not ending
    up in the UI. Pendatically speaking, each parent category has
    atleast one group/subcategory i.e. "all". In this patch,
    we correct the handling of "all" and update the app-counter for
    parent cateogory. Then if the parent cateogory has multiple
    groups/subcategories, app-counter for those subcategories are
    updated as well.
    
    https://phabricator.endlessm.com/T27329

 plugins/core/gs-appstream.c | 24 ++++++++++++++++--------
 1 file changed, 16 insertions(+), 8 deletions(-)
---
diff --git a/plugins/core/gs-appstream.c b/plugins/core/gs-appstream.c
index 8e4b85f0..cd3be529 100644
--- a/plugins/core/gs-appstream.c
+++ b/plugins/core/gs-appstream.c
@@ -1200,13 +1200,19 @@ gs_appstream_count_component_for_groups (GsPlugin *plugin, XbSilo *silo, const g
        g_autoptr(GPtrArray) array = NULL;
        g_autoptr(GError) error_local = NULL;
 
-       if (g_strv_length (split) != 2)
+       if (g_strv_length (split) == 1) { /* "all" group for a parent category */
+               xpath = g_strdup_printf ("components/component/categories/"
+                                        "category[text()='%s']/../..",
+                                        split[0]);
+       } else if (g_strv_length (split) == 2) {
+               xpath = g_strdup_printf ("components/component/categories/"
+                                        "category[text()='%s']/../"
+                                        "category[text()='%s']/../..",
+                                        split[0], split[1]);
+       } else {
                return 0;
+       }
 
-       xpath = g_strdup_printf ("components/component/categories/"
-                                "category[text()='%s']/../"
-                                "category[text()='%s']/../..",
-                                split[0], split[1]);
        array = xb_silo_query (silo, xpath, limit, &error_local);
        if (array == NULL) {
                if (g_error_matches (error_local, G_IO_ERROR, G_IO_ERROR_NOT_FOUND))
@@ -1235,14 +1241,16 @@ gs_appstream_add_categories (GsPlugin *plugin,
                for (guint i = 0; i < children->len; i++) {
                        GsCategory *cat = g_ptr_array_index (children, i);
                        GPtrArray *groups = gs_category_get_desktop_groups (cat);
-                       if (g_strcmp0 (gs_category_get_id (cat), "all") == 0)
-                               continue;
                        for (guint k = 0; k < groups->len; k++) {
                                const gchar *group = g_ptr_array_index (groups, k);
                                guint cnt = gs_appstream_count_component_for_groups (plugin, silo, group);
                                for (guint l = 0; l < cnt; l++) {
                                        gs_category_increment_size (parent);
-                                       gs_category_increment_size (cat);
+                                       if (children->len > 1) {
+                                               /* Parent category has multiple groups, so increment
+                                                * each group's size too */
+                                               gs_category_increment_size (cat);
+                                       }
                                }
                        }
                }


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