[gnome-software: 10/14] gs-plugin-loader: Move default category-apps sort function to callers
- From: Milan Crha <mcrha src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-software: 10/14] gs-plugin-loader: Move default category-apps sort function to callers
- Date: Mon, 9 May 2022 13:34:15 +0000 (UTC)
commit 922971dac1fbfdaeb3e1311f6ac5eb4a27a40cce
Author: Philip Withnall <pwithnall endlessos org>
Date: Wed May 4 14:51:29 2022 +0100
gs-plugin-loader: Move default category-apps sort function to callers
Callers shouldn’t be relying on a default sort order which is
unspecified. Providing a default like this ties down the API of the
plugin loader.
It’s clearer and more maintainable for callers to set their own sort
functions explicitly, and have no default.
This introduces no functional changes.
Signed-off-by: Philip Withnall <pwithnall endlessos org>
Helps: #1472
lib/gs-cmd.c | 9 +++++++++
lib/gs-plugin-loader.c | 12 ------------
src/gs-category-page.c | 9 +++++++++
3 files changed, 18 insertions(+), 12 deletions(-)
---
diff --git a/lib/gs-cmd.c b/lib/gs-cmd.c
index e0b8ff62c..4fe87b924 100644
--- a/lib/gs-cmd.c
+++ b/lib/gs-cmd.c
@@ -285,6 +285,14 @@ gs_cmd_self_free (GsCmdSelf *self)
G_DEFINE_AUTOPTR_CLEANUP_FUNC(GsCmdSelf, gs_cmd_self_free)
+static gint
+app_sort_name_cb (GsApp *app1,
+ GsApp *app2,
+ gpointer user_data)
+{
+ return gs_utils_sort_strcmp (gs_app_get_name (app1), gs_app_get_name (app2));
+}
+
static gint
app_sort_kind_cb (GsApp *app1, GsApp *app2, gpointer user_data)
{
@@ -718,6 +726,7 @@ main (int argc, char **argv)
"max-results", self->max_results,
"interactive", self->interactive,
NULL);
+ gs_plugin_job_set_sort_func (plugin_job, app_sort_name_cb, NULL);
list = gs_plugin_loader_job_process (self->plugin_loader, plugin_job, NULL, &error);
if (list == NULL) {
ret = FALSE;
diff --git a/lib/gs-plugin-loader.c b/lib/gs-plugin-loader.c
index 2016f7621..d3dbef2c9 100644
--- a/lib/gs-plugin-loader.c
+++ b/lib/gs-plugin-loader.c
@@ -271,12 +271,6 @@ gs_plugin_loader_helper_free (GsPluginLoaderHelper *helper)
G_DEFINE_AUTOPTR_CLEANUP_FUNC(GsPluginLoaderHelper, gs_plugin_loader_helper_free)
-static gint
-gs_plugin_loader_app_sort_name_cb (GsApp *app1, GsApp *app2, gpointer user_data)
-{
- return gs_utils_sort_strcmp (gs_app_get_name (app1), gs_app_get_name (app2));
-}
-
GsPlugin *
gs_plugin_loader_find_plugin (GsPluginLoader *plugin_loader,
const gchar *plugin_name)
@@ -4067,12 +4061,6 @@ job_process_cb (GTask *task)
gs_plugin_loader_app_sort_match_value_cb, NULL);
}
break;
- case GS_PLUGIN_ACTION_GET_CATEGORY_APPS:
- if (gs_plugin_job_get_sort_func (plugin_job, NULL) == NULL) {
- gs_plugin_job_set_sort_func (plugin_job,
- gs_plugin_loader_app_sort_name_cb, NULL);
- }
- break;
case GS_PLUGIN_ACTION_GET_ALTERNATES:
if (gs_plugin_job_get_sort_func (plugin_job, NULL) == NULL) {
gs_plugin_job_set_sort_func (plugin_job,
diff --git a/src/gs-category-page.c b/src/gs-category-page.c
index 93a45486d..621684ff8 100644
--- a/src/gs-category-page.c
+++ b/src/gs-category-page.c
@@ -74,6 +74,14 @@ top_carousel_app_clicked_cb (GsFeaturedCarousel *carousel,
g_signal_emit (self, obj_signals[SIGNAL_APP_CLICKED], 0, app);
}
+static gint
+app_sort_name_cb (GsApp *app1,
+ GsApp *app2,
+ gpointer user_data)
+{
+ return gs_utils_sort_strcmp (gs_app_get_name (app1), gs_app_get_name (app2));
+}
+
static gint
_max_results_sort_cb (GsApp *app1, GsApp *app2, gpointer user_data)
{
@@ -426,6 +434,7 @@ gs_category_page_load_category (GsCategoryPage *self)
"category", featured_subcat,
"refine-flags",
GS_PLUGIN_REFINE_FLAGS_REQUIRE_KUDOS,
NULL);
+ gs_plugin_job_set_sort_func (featured_plugin_job, app_sort_name_cb, NULL);
gs_plugin_loader_job_process_async (self->plugin_loader,
featured_plugin_job,
self->cancellable,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]