[gnome-software/gnome-3-20] Ensure reviews are shown in the correct order



commit 4b5b80301237865310f7e566d416be0f3fc2b187
Author: Richard Hughes <richard hughsie com>
Date:   Thu Jun 23 09:52:30 2016 +0100

    Ensure reviews are shown in the correct order

 src/gs-plugin-loader.c |   23 +++++++++++++++++++++++
 1 files changed, 23 insertions(+), 0 deletions(-)
---
diff --git a/src/gs-plugin-loader.c b/src/gs-plugin-loader.c
index c651a4a..fb3c50f 100644
--- a/src/gs-plugin-loader.c
+++ b/src/gs-plugin-loader.c
@@ -108,6 +108,18 @@ gs_plugin_loader_app_sort_cb (gconstpointer a, gconstpointer b)
                          gs_app_get_name (GS_APP ((gpointer) b)));
 }
 
+static gint
+gs_plugin_loader_review_score_sort_cb (gconstpointer a, gconstpointer b)
+{
+       GsReview *ra = *((GsReview **) a);
+       GsReview *rb = *((GsReview **) b);
+       if (gs_review_get_score (ra) < gs_review_get_score (rb))
+               return 1;
+       if (gs_review_get_score (ra) > gs_review_get_score (rb))
+               return -1;
+       return 0;
+}
+
 /**
  * gs_plugin_loader_run_refine:
  **/
@@ -207,6 +219,17 @@ gs_plugin_loader_run_refine (GsPluginLoader *plugin_loader,
                gs_plugin_status_update (plugin, NULL, GS_PLUGIN_STATUS_FINISHED);
        }
 
+       /* ensure these are sorted by score */
+       if ((flags & GS_PLUGIN_REFINE_FLAGS_REQUIRE_REVIEWS) > 0) {
+               GPtrArray *reviews;
+               for (l = *list; l != NULL; l = l->next) {
+                       app = GS_APP (l->data);
+                       reviews = gs_app_get_reviews (app);
+                       g_ptr_array_sort (reviews,
+                                         gs_plugin_loader_review_score_sort_cb);
+               }
+       }
+
        /* refine addons one layer deep */
        if ((flags & GS_PLUGIN_REFINE_FLAGS_REQUIRE_ADDONS) > 0) {
                flags &= ~GS_PLUGIN_REFINE_FLAGS_REQUIRE_ADDONS;


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