[gnome-software] Add back an 'All' sub-category to some categories



commit 09444d46e720e64a2584d30408c17f767832e7c5
Author: Richard Hughes <richard hughsie com>
Date:   Thu Jun 2 12:12:25 2016 +0100

    Add back an 'All' sub-category to some categories

 src/gs-plugin-loader.c                       |   39 ++++++++++++++++++++++++++
 src/plugins/gs-plugin-hardcoded-categories.c |   29 ++++++++++++++++++-
 2 files changed, 66 insertions(+), 2 deletions(-)
---
diff --git a/src/gs-plugin-loader.c b/src/gs-plugin-loader.c
index 0156656..c426a98 100644
--- a/src/gs-plugin-loader.c
+++ b/src/gs-plugin-loader.c
@@ -2150,6 +2150,39 @@ gs_plugin_loader_category_sort_cb (gconstpointer a, gconstpointer b)
                          gs_category_get_name (catb));
 }
 
+static void
+gs_plugin_loader_fix_category_all (GsCategory *category)
+{
+       GPtrArray *children;
+       GsCategory *cat_all;
+       guint i, j;
+
+       /* set correct size */
+       cat_all = gs_category_find_child (category, "all");
+       if (cat_all == NULL)
+               return;
+       gs_category_set_size (cat_all, gs_category_get_size (category));
+
+       /* add the desktop groups from all children */
+       children = gs_category_get_children (category);
+       for (i = 0; i < children->len; i++) {
+               GPtrArray *desktop_groups;
+               GsCategory *child;
+
+               /* ignore the all category */
+               child = g_ptr_array_index (children, i);
+               if (g_strcmp0 (gs_category_get_id (child), "all") == 0)
+                       continue;
+
+               /* add all desktop groups */
+               desktop_groups = gs_category_get_desktop_groups (child);
+               for (j = 0; j < desktop_groups->len; j++) {
+                       const gchar *tmp = g_ptr_array_index (desktop_groups, j);
+                       gs_category_add_desktop_group (cat_all, tmp);
+               }
+       }
+}
+
 /**
  * gs_plugin_loader_get_categories_thread_cb:
  **/
@@ -2208,6 +2241,12 @@ gs_plugin_loader_get_categories_thread_cb (GTask *task,
                gs_plugin_status_update (plugin, NULL, GS_PLUGIN_STATUS_FINISHED);
        }
 
+       /* make sure 'All' has the right categories */
+       for (i = 0; i < state->catlist->len; i++) {
+               GsCategory *cat = g_ptr_array_index (state->catlist, i);
+               gs_plugin_loader_fix_category_all (cat);
+       }
+
        /* sort by name */
        g_ptr_array_sort (state->catlist, gs_plugin_loader_category_sort_cb);
        for (i = 0; i < state->catlist->len; i++) {
diff --git a/src/plugins/gs-plugin-hardcoded-categories.c b/src/plugins/gs-plugin-hardcoded-categories.c
index ff0edeb..401114e 100644
--- a/src/plugins/gs-plugin-hardcoded-categories.c
+++ b/src/plugins/gs-plugin-hardcoded-categories.c
@@ -58,8 +58,9 @@ typedef struct {
 
 /* AudioVideo */
 static const GsCategoryMap map_audiovisual[] = {
-//     { "all",                NC_("Menu of AudioVideo", "All"),
-//                                     { NULL } },
+       { "all",                NC_("Menu of AudioVideo", "All"),
+                                       { "AudioVideo",
+                                         NULL } },
        { "featured",           NC_("Menu of AudioVideo", "Featured"),
                                        { "AudioVideo::featured",
                                          NULL} },
@@ -78,6 +79,9 @@ static const GsCategoryMap map_audiovisual[] = {
 
 /* Development */
 static const GsCategoryMap map_developertools[] = {
+       { "all",                NC_("Menu of Development", "All"),
+                                       { "Development",
+                                         NULL } },
        { "featured",           NC_("Menu of Development", "Featured"),
                                        { "Development::featured",
                                          NULL} },
@@ -93,6 +97,9 @@ static const GsCategoryMap map_developertools[] = {
 
 /* Education */
 static const GsCategoryMap map_education[] = {
+       { "all",                NC_("Menu of Education", "All"),
+                                       { "Education",
+                                         NULL } },
        { "featured",           NC_("Menu of Education", "Featured"),
                                        { "Education::featured",
                                          NULL} },
@@ -115,6 +122,9 @@ static const GsCategoryMap map_education[] = {
 
 /* Games */
 static const GsCategoryMap map_games[] = {
+       { "all",                NC_("Menu of Games", "All"),
+                                       { "Game",
+                                         NULL } },
        { "featured",           NC_("Menu of Games", "Featured"),
                                        { "Game::featured",
                                          NULL} },
@@ -160,6 +170,9 @@ static const GsCategoryMap map_games[] = {
 
 /* Graphics */
 static const GsCategoryMap map_graphics[] = {
+       { "all",                NC_("Menu of Graphics", "All"),
+                                       { "Graphics",
+                                         NULL } },
        { "featured",           NC_("Menu of Graphics", "Featured"),
                                        { "Graphics::featured",
                                          NULL} },
@@ -183,6 +196,9 @@ static const GsCategoryMap map_graphics[] = {
 
 /* Office */
 static const GsCategoryMap map_productivity[] = {
+       { "all",                NC_("Menu of Office", "All"),
+                                       { "Office",
+                                         NULL } },
        { "featured",           NC_("Menu of Office", "Featured"),
                                        { "Office::featured",
                                          NULL} },
@@ -229,6 +245,9 @@ static const GsCategoryMap map_addons[] = {
 
 /* Science */
 static const GsCategoryMap map_science[] = {
+       { "all",                NC_("Menu of Science", "All"),
+                                       { "Science",
+                                         NULL } },
        { "featured",           NC_("Menu of Science", "Featured"),
                                        { "Science::featured",
                                          NULL} },
@@ -254,6 +273,9 @@ static const GsCategoryMap map_science[] = {
 
 /* Communication */
 static const GsCategoryMap map_communication[] = {
+       { "all",                NC_("Menu of Communication", "All"),
+                                       { "Network",
+                                         NULL } },
        { "featured",           NC_("Menu of Communication", "Featured"),
                                        { "Network::featured",
                                          NULL} },
@@ -276,6 +298,9 @@ static const GsCategoryMap map_communication[] = {
 
 /* Utility */
 static const GsCategoryMap map_utilities[] = {
+       { "all",                NC_("Menu of Utility", "All"),
+                                       { "Utility",
+                                         NULL } },
        { "featured",           NC_("Menu of Utility", "Featured"),
                                        { "Utility::featured",
                                          NULL} },


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