[gnome-software: 4/25] plugins: Drop category enumeration from the desktop-categories plugin




commit 77c6af86b4db7b0ba96d49a8f1f163785adb673f
Author: Philip Withnall <pwithnall endlessos org>
Date:   Mon Feb 1 18:43:37 2021 +0000

    plugins: Drop category enumeration from the desktop-categories plugin
    
    Instead, enumerate the categories from the `GsCategoryManager` directly
    in the plugin loader.
    
    This is a step towards being able to drop the `desktop-categories`
    plugin.
    
    Signed-off-by: Philip Withnall <pwithnall endlessos org>

 lib/gs-plugin-loader.c                      |  8 +++++++
 plugins/core/gs-plugin-desktop-categories.c | 37 -----------------------------
 2 files changed, 8 insertions(+), 37 deletions(-)
---
diff --git a/lib/gs-plugin-loader.c b/lib/gs-plugin-loader.c
index a2fb52074..56a71dc21 100644
--- a/lib/gs-plugin-loader.c
+++ b/lib/gs-plugin-loader.c
@@ -1582,11 +1582,19 @@ gs_plugin_loader_job_get_categories_thread_cb (GTask *task,
        GsPluginLoaderHelper *helper = (GsPluginLoaderHelper *) task_data;
        g_autoptr(GMainContext) context = g_main_context_new ();
        g_autoptr(GsMainContextPusher) pusher = gs_main_context_pusher_new (context);
+       GsCategory * const *categories = NULL;
+       gsize n_categories;
 #ifdef HAVE_SYSPROF
        GsPluginLoaderPrivate *priv = gs_plugin_loader_get_instance_private (helper->plugin_loader);
        gint64 begin_time_nsec G_GNUC_UNUSED = SYSPROF_CAPTURE_CURRENT_TIME;
 #endif
 
+       /* get the categories */
+       categories = gs_category_manager_get_categories (priv->category_manager, &n_categories);
+
+       for (gsize i = 0; i < n_categories; i++)
+               g_ptr_array_add (helper->catlist, g_object_ref (categories[i]));
+
        /* run each plugin */
        if (!gs_plugin_loader_run_results (helper, cancellable, &error)) {
                g_task_return_error (task, error);
diff --git a/plugins/core/gs-plugin-desktop-categories.c b/plugins/core/gs-plugin-desktop-categories.c
index f24e12b92..289575bce 100644
--- a/plugins/core/gs-plugin-desktop-categories.c
+++ b/plugins/core/gs-plugin-desktop-categories.c
@@ -25,43 +25,6 @@ gs_plugin_initialize (GsPlugin *plugin)
        gs_plugin_add_rule (plugin, GS_PLUGIN_RULE_RUN_BEFORE, "appstream");
 }
 
-gboolean
-gs_plugin_add_categories (GsPlugin *plugin,
-                         GPtrArray *list,
-                         GCancellable *cancellable,
-                         GError **error)
-{
-       const GsDesktopData *msdata;
-       guint i, j, k;
-
-       msdata = gs_desktop_get_data ();
-       for (i = 0; msdata[i].id != NULL; i++) {
-               GsCategory *category;
-               g_autofree gchar *msgctxt = NULL;
-
-               /* add parent category */
-               category = gs_category_new (msdata[i].id);
-               gs_category_set_icon (category, msdata[i].icon);
-               gs_category_set_name (category, gettext (msdata[i].name));
-               gs_category_set_score (category, msdata[i].score);
-               g_ptr_array_add (list, category);
-               msgctxt = g_strdup_printf ("Menu of %s", msdata[i].name);
-
-               /* add subcategories */
-               for (j = 0; msdata[i].mapping[j].id != NULL; j++) {
-                       const GsDesktopMap *map = &msdata[i].mapping[j];
-                       g_autoptr(GsCategory) sub = gs_category_new (map->id);
-                       for (k = 0; map->fdo_cats[k] != NULL; k++)
-                               gs_category_add_desktop_group (sub, map->fdo_cats[k]);
-                       gs_category_set_name (sub, g_dpgettext2 (GETTEXT_PACKAGE,
-                                                                msgctxt,
-                                                                map->name));
-                       gs_category_add_child (category, sub);
-               }
-       }
-       return TRUE;
-}
-
 /* most of this time this won't be required, unless the user creates a
  * GsCategory manually and uses it to get results, for instance in the
  * overview page or `gnome-software-cmd get-category-apps games/featured` */


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