[gnome-software: 17/25] gs-category: Add desktop groups for ‘all’ subcategory automatically
- From: Philip Withnall <pwithnall src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-software: 17/25] gs-category: Add desktop groups for ‘all’ subcategory automatically
- Date: Wed, 3 Feb 2021 23:15:46 +0000 (UTC)
commit 2848949d312fff44eb837798183ee31886445ebf
Author: Philip Withnall <pwithnall endlessos org>
Date: Tue Feb 2 00:27:05 2021 +0000
gs-category: Add desktop groups for ‘all’ subcategory automatically
This allows the second pass which previously added them to be removed
completely, which simplifies the code a little.
Signed-off-by: Philip Withnall <pwithnall endlessos org>
lib/gs-category.c | 25 +++++++++++++++++++++++++
lib/gs-plugin-loader.c | 37 -------------------------------------
2 files changed, 25 insertions(+), 37 deletions(-)
---
diff --git a/lib/gs-category.c b/lib/gs-category.c
index faedcbc31..b7bf92629 100644
--- a/lib/gs-category.c
+++ b/lib/gs-category.c
@@ -703,6 +703,7 @@ gs_category_new_for_desktop_data (const GsDesktopData *data)
{
g_autofree gchar *msgctxt = NULL;
g_autoptr(GsCategory) category = NULL;
+ GsCategory *subcategory_all = NULL;
/* parent category */
category = g_object_new (GS_TYPE_CATEGORY, NULL);
@@ -723,6 +724,30 @@ gs_category_new_for_desktop_data (const GsDesktopData *data)
msgctxt,
map->name));
gs_category_add_child (category, sub);
+
+ if (g_str_equal (map->id, "all"))
+ subcategory_all = sub;
+ }
+
+ /* set up the ‘all’ subcategory specially, adding all the desktop groups
+ * from all other child categories to it */
+ if (subcategory_all != NULL) {
+ for (guint i = 0; i < category->children->len; i++) {
+ GPtrArray *desktop_groups;
+ GsCategory *child;
+
+ /* ignore the all category */
+ child = g_ptr_array_index (category->children, i);
+ if (child == subcategory_all)
+ continue;
+
+ /* add all desktop groups */
+ desktop_groups = gs_category_get_desktop_groups (child);
+ for (guint j = 0; j < desktop_groups->len; j++) {
+ const gchar *tmp = g_ptr_array_index (desktop_groups, j);
+ gs_category_add_desktop_group (subcategory_all, tmp);
+ }
+ }
}
return g_steal_pointer (&category);
diff --git a/lib/gs-plugin-loader.c b/lib/gs-plugin-loader.c
index 02747d128..3767f37d8 100644
--- a/lib/gs-plugin-loader.c
+++ b/lib/gs-plugin-loader.c
@@ -1539,37 +1539,6 @@ 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;
-
- cat_all = gs_category_find_child (category, "all");
- if (cat_all == NULL)
- return;
-
- /* 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);
- }
- }
-}
-
static void
gs_plugin_loader_job_get_categories_thread_cb (GTask *task,
gpointer object,
@@ -1599,12 +1568,6 @@ gs_plugin_loader_job_get_categories_thread_cb (GTask *task,
return;
}
- /* make sure 'All' has the right categories */
- for (guint i = 0; i < helper->catlist->len; i++) {
- GsCategory *cat = g_ptr_array_index (helper->catlist, i);
- gs_plugin_loader_fix_category_all (cat);
- }
-
/* sort by name */
g_ptr_array_sort (helper->catlist, gs_plugin_loader_category_sort_cb);
for (guint i = 0; i < helper->catlist->len; i++) {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]