[gnome-software] trivial: Sort the alternatives by the application priority by default



commit 89cc1b89ceb771bfa3d903155ead07032f561a5b
Author: Richard Hughes <richard hughsie com>
Date:   Thu Sep 27 19:36:42 2018 +0100

    trivial: Sort the alternatives by the application priority by default

 lib/gs-plugin-loader.c | 23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)
---
diff --git a/lib/gs-plugin-loader.c b/lib/gs-plugin-loader.c
index e745e1dc..fd79e884 100644
--- a/lib/gs-plugin-loader.c
+++ b/lib/gs-plugin-loader.c
@@ -1399,6 +1399,23 @@ gs_plugin_loader_app_sort_match_value_cb (GsApp *app1, GsApp *app2, gpointer use
        return 0;
 }
 
+static gint
+gs_plugin_loader_app_sort_prio_cb (GsApp *app1, GsApp *app2, gpointer user_data)
+{
+       /* prefer prio */
+       if (gs_app_get_priority (app1) > gs_app_get_priority (app2))
+               return -1;
+       if (gs_app_get_priority (app1) < gs_app_get_priority (app2))
+               return 1;
+
+       /* fall back to bundle kind */
+       if (gs_app_get_bundle_kind (app1) < gs_app_get_bundle_kind (app2))
+               return -1;
+       if (gs_app_get_bundle_kind (app1) > gs_app_get_bundle_kind (app2))
+               return 1;
+       return 0;
+}
+
 /******************************************************************************/
 
 static gboolean
@@ -3630,6 +3647,12 @@ gs_plugin_loader_job_process_async (GsPluginLoader *plugin_loader,
                                                     gs_plugin_loader_app_sort_name_cb);
                }
                break;
+       case GS_PLUGIN_ACTION_GET_ALTERNATES:
+               if (gs_plugin_job_get_sort_func (plugin_job) == NULL) {
+                       gs_plugin_job_set_sort_func (plugin_job,
+                                                    gs_plugin_loader_app_sort_prio_cb);
+               }
+               break;
        default:
                break;
        }


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