[gnome-software: 5/8] gs-app-list: Fix return type of GsAppListSortFunc




commit d2eb05c8583e63fdd591bf34ec2fed009235e6eb
Author: Philip Withnall <pwithnall endlessos org>
Date:   Wed Apr 21 14:57:33 2021 +0100

    gs-app-list: Fix return type of GsAppListSortFunc
    
    Sort functions return an order, not a filter value. In practice, this
    was working fine as `gboolean` is secretly a `gint` in disguise. But the
    type safety was definitely off.
    
    Signed-off-by: Philip Withnall <pwithnall endlessos org>

 lib/gs-app-list.h              | 14 +++++++++++++-
 src/gs-category-page.c         |  4 ++--
 src/gs-search-page.c           |  2 +-
 src/gs-shell-search-provider.c |  2 +-
 4 files changed, 17 insertions(+), 5 deletions(-)
---
diff --git a/lib/gs-app-list.h b/lib/gs-app-list.h
index 8b0e0c2b1..1330e8048 100644
--- a/lib/gs-app-list.h
+++ b/lib/gs-app-list.h
@@ -46,7 +46,19 @@ G_STATIC_ASSERT (sizeof (GsAppListFilterFlags) == sizeof (guint64));
 
 G_DECLARE_FINAL_TYPE (GsAppList, gs_app_list, GS, APP_LIST, GObject)
 
-typedef gboolean (*GsAppListSortFunc)          (GsApp          *app1,
+/**
+ * GsAppListSortFunc:
+ * @app1:
+ * @app2:
+ * @user_data: user data passed into the sort function
+ *
+ * A version of #GCompareFunc which is specific to #GsApps.
+ *
+ * Returns: zero if @app1 and @app2 are equal, a negative value if @app1 comes
+ *     before @app2, or a positive value if @app1 comes after @app2
+ * Since: 41
+ */
+typedef gint    (*GsAppListSortFunc)           (GsApp          *app1,
                                                 GsApp          *app2,
                                                 gpointer        user_data);
 typedef gboolean (*GsAppListFilterFunc)                (GsApp          *app,
diff --git a/src/gs-category-page.c b/src/gs-category-page.c
index 1b5f632c7..230591a6d 100644
--- a/src/gs-category-page.c
+++ b/src/gs-category-page.c
@@ -140,10 +140,10 @@ gs_category_page_get_apps_cb (GObject *source_object,
        g_signal_handler_unblock (self->sort_name_button, self->sort_name_handler_id);
 }
 
-static gboolean
+static gint
 _max_results_sort_cb (GsApp *app1, GsApp *app2, gpointer user_data)
 {
-       return gs_app_get_rating (app1) < gs_app_get_rating (app2);
+       return gs_app_get_rating (app1) - gs_app_get_rating (app2);
 }
 
 static gint
diff --git a/src/gs-search-page.c b/src/gs-search-page.c
index 544d53be3..17b399a1a 100644
--- a/src/gs-search-page.c
+++ b/src/gs-search-page.c
@@ -233,7 +233,7 @@ gs_search_page_get_app_sort_key (GsApp *app)
        return g_string_free (key, FALSE);
 }
 
-static gboolean
+static gint
 gs_search_page_sort_cb (GsApp *app1, GsApp *app2, gpointer user_data)
 {
        g_autofree gchar *key1 = NULL;
diff --git a/src/gs-shell-search-provider.c b/src/gs-shell-search-provider.c
index 27bbb45f7..9acde4cbc 100644
--- a/src/gs-shell-search-provider.c
+++ b/src/gs-shell-search-provider.c
@@ -134,7 +134,7 @@ gs_shell_search_provider_get_app_sort_key (GsApp *app)
        return g_string_free (key, FALSE);
 }
 
-static gboolean
+static gint
 gs_shell_search_provider_sort_cb (GsApp *app1, GsApp *app2, gpointer user_data)
 {
        g_autofree gchar *key1 = NULL;


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