[gnome-software] Add an 'All' subcategory in the category shell



commit fa34e23ee9a6fc1d6b5831ac6f969c6f196a6a85
Author: Richard Hughes <richard hughsie com>
Date:   Tue Feb 23 11:16:37 2016 +0000

    Add an 'All' subcategory in the category shell
    
    Resolves: https://bugzilla.gnome.org/show_bug.cgi?id=7338352

 src/gs-category.c                 |   39 +++++++++++++++++++++++-------------
 src/gs-plugin-loader.c            |   12 +++++++++++
 src/plugins/gs-plugin-appstream.c |    3 +-
 3 files changed, 39 insertions(+), 15 deletions(-)
---
diff --git a/src/gs-category.c b/src/gs-category.c
index a41b173..f54ae78 100644
--- a/src/gs-category.c
+++ b/src/gs-category.c
@@ -138,6 +138,24 @@ gs_category_add_subcategory (GsCategory *category, GsCategory *subcategory)
 }
 
 /**
+ * gs_category_get_sort_key:
+ **/
+static gchar *
+gs_category_get_sort_key (GsCategory *category)
+{
+       guint sort_order = 5;
+       if (g_strcmp0 (gs_category_get_id (category), "featured") == 0)
+               sort_order = 0;
+       else if (g_strcmp0 (gs_category_get_id (category), "all") == 0)
+               sort_order = 2;
+       else if (g_strcmp0 (gs_category_get_id (category), "other") == 0)
+               sort_order = 9;
+       return g_strdup_printf ("%i:%s",
+                               sort_order,
+                               gs_category_get_name (category));
+}
+
+/**
  * gs_category_sort_subcategories_cb:
  **/
 static gint
@@ -145,20 +163,9 @@ gs_category_sort_subcategories_cb (gconstpointer a, gconstpointer b)
 {
        GsCategory *ca = GS_CATEGORY ((gpointer) a);
        GsCategory *cb = GS_CATEGORY ((gpointer) b);
-       const gchar *id_a = gs_category_get_id (ca);
-       const gchar *id_b = gs_category_get_id (cb);
-
-       if (g_strcmp0 (id_a, "other") == 0)
-               return 1;
-       else if (g_strcmp0 (id_a, "featured") == 0)
-               return -1;
-
-       if (g_strcmp0 (id_b, "other") == 0)
-               return -1;
-       else if (g_strcmp0 (id_b, "featured") == 0)
-               return 1;
-
-       return g_strcmp0 (gs_category_get_name (ca), gs_category_get_name (cb));
+       g_autofree gchar *id_a = gs_category_get_sort_key (ca);
+       g_autofree gchar *id_b = gs_category_get_sort_key (cb);
+       return g_strcmp0 (id_a, id_b);
 }
 
 /**
@@ -226,6 +233,10 @@ gs_category_new (GsCategory *parent, const gchar *id, const gchar *name)
                /* TRANSLATORS: this is where all applications that don't
                 * fit in other groups are put */
                name =_("Other");
+       } else if (g_strcmp0 (id, "all") == 0) {
+               /* TRANSLATORS: this is a subcategory matching all the
+                * different apps in the parent category, e.g. "Games" */
+               name =_("All");
        }
 
        category = g_object_new (GS_TYPE_CATEGORY, NULL);
diff --git a/src/gs-plugin-loader.c b/src/gs-plugin-loader.c
index eec6903..e2dcc65 100644
--- a/src/gs-plugin-loader.c
+++ b/src/gs-plugin-loader.c
@@ -2091,6 +2091,18 @@ gs_plugin_loader_get_categories_thread_cb (GTask *task,
                gs_plugin_status_update (plugin, NULL, GS_PLUGIN_STATUS_FINISHED);
        }
 
+       /* ensure they all have an 'All' category */
+       for (l = state->list; l != NULL; l = l->next) {
+               GsCategory *parent = GS_CATEGORY (l->data);
+               if (gs_category_find_child (parent, "all") == NULL) {
+                       g_autoptr(GsCategory) child = NULL;
+                       child = gs_category_new (parent, "all", NULL);
+                       gs_category_add_subcategory (parent, child);
+                       /* this is probably valid... */
+                       gs_category_set_size (child, gs_category_get_size (parent));
+               }
+       }
+
        /* sort by name */
        state->list = g_list_sort (state->list, gs_plugin_loader_category_sort_cb);
        for (l = state->list; l != NULL; l = l->next)
diff --git a/src/plugins/gs-plugin-appstream.c b/src/plugins/gs-plugin-appstream.c
index c29f1e0..a1aa094 100644
--- a/src/plugins/gs-plugin-appstream.c
+++ b/src/plugins/gs-plugin-appstream.c
@@ -945,7 +945,8 @@ gs_plugin_add_category_apps (GsPlugin *plugin,
                item = g_ptr_array_index (array, i);
                if (as_app_get_id (item) == NULL)
                        continue;
-               if (!as_app_has_category (item, search_id1))
+               if (g_strcmp0 (search_id1, "all") != 0 &&
+                   !as_app_has_category (item, search_id1))
                        continue;
                if (search_id2 != NULL && !as_app_has_category (item, search_id2))
                        continue;


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