[gnome-software] Add functionality to add review ratings to an application



commit 9bf4a9b4e5cbd5f062df9e9cd0689449ae26a24d
Author: Richard Hughes <richard hughsie com>
Date:   Tue Feb 9 11:45:42 2016 +0000

    Add functionality to add review ratings to an application
    
    This allows us to sow how many users voted for each star rating.
    
    This is based on a patch from Robert Ancell, many thanks.

 src/gs-app.c                  |   30 ++++++++++++++++++++++++++++++
 src/gs-app.h                  |    3 +++
 src/gs-cmd.c                  |    2 ++
 src/gs-plugin.h               |    1 +
 src/gs-shell-details.c        |    2 ++
 src/plugins/gs-plugin-dummy.c |   21 +++++++++++++++++++++
 6 files changed, 59 insertions(+), 0 deletions(-)
---
diff --git a/src/gs-app.c b/src/gs-app.c
index 4e6652a..24a1de4 100644
--- a/src/gs-app.c
+++ b/src/gs-app.c
@@ -83,6 +83,7 @@ struct _GsApp
        AsUrgencyKind            update_urgency;
        gchar                   *management_plugin;
        gint                     rating;
+       GArray                  *review_ratings;
        GPtrArray               *reviews; /* of GsReview */
        guint64                  size;
        GsAppKind                kind;
@@ -290,6 +291,13 @@ gs_app_to_string (GsApp *app)
                g_string_append_printf (str, "\torigin-ui:\t%s\n", app->origin_ui);
        if (app->rating != -1)
                g_string_append_printf (str, "\trating:\t%i\n", app->rating);
+       if (app->review_ratings != NULL) {
+               for (i = 0; i < app->review_ratings->len; i++) {
+                       gint rat = g_array_index (app->review_ratings, gint, i);
+                       g_string_append_printf (str, "\treview-rating:\t[%i:%i]\n",
+                                               i, rat);
+               }
+       }
        if (app->reviews != NULL)
                g_string_append_printf (str, "\treviews:\t%i\n", app->reviews->len);
        if (app->pixbuf != NULL)
@@ -1640,6 +1648,28 @@ gs_app_set_rating (GsApp *app, gint rating)
 }
 
 /**
+ * gs_app_get_review_ratings:
+ */
+GArray *
+gs_app_get_review_ratings (GsApp *app)
+{
+       g_return_val_if_fail (GS_IS_APP (app), FALSE);
+       return app->review_ratings;
+}
+
+/**
+ * gs_app_set_review_ratings:
+ */
+void
+gs_app_set_review_ratings (GsApp *app, GArray *review_ratings)
+{
+       g_return_if_fail (GS_IS_APP (app));
+       if (app->review_ratings != NULL)
+               g_array_unref (app->review_ratings);
+       app->review_ratings = g_array_ref (review_ratings);
+}
+
+/**
  * gs_app_get_reviews:
  */
 GPtrArray *
diff --git a/src/gs-app.h b/src/gs-app.h
index a32f093..4c90b0d 100644
--- a/src/gs-app.h
+++ b/src/gs-app.h
@@ -198,6 +198,9 @@ void                 gs_app_set_metadata            (GsApp          *app,
 gint            gs_app_get_rating              (GsApp          *app);
 void            gs_app_set_rating              (GsApp          *app,
                                                 gint            rating);
+GArray         *gs_app_get_review_ratings      (GsApp          *app);
+void            gs_app_set_review_ratings      (GsApp          *app,
+                                                GArray         *review_ratings);
 GPtrArray      *gs_app_get_reviews             (GsApp          *app);
 void            gs_app_add_review              (GsApp          *app,
                                                 GsReview       *review);
diff --git a/src/gs-cmd.c b/src/gs-cmd.c
index 1b3c2e0..8106d52 100644
--- a/src/gs-cmd.c
+++ b/src/gs-cmd.c
@@ -142,6 +142,8 @@ gs_cmd_refine_flag_from_string (const gchar *flag, GError **error)
                return GS_PLUGIN_REFINE_FLAGS_REQUIRE_PROVENANCE;
        if (g_strcmp0 (flag, "reviews") == 0)
                return GS_PLUGIN_REFINE_FLAGS_REQUIRE_REVIEWS;
+       if (g_strcmp0 (flag, "review-ratings") == 0)
+               return GS_PLUGIN_REFINE_FLAGS_REQUIRE_REVIEW_RATINGS;
        g_set_error (error,
                     GS_PLUGIN_ERROR,
                     GS_PLUGIN_ERROR_NOT_SUPPORTED,
diff --git a/src/gs-plugin.h b/src/gs-plugin.h
index baeeb51..cfbeef9 100644
--- a/src/gs-plugin.h
+++ b/src/gs-plugin.h
@@ -108,6 +108,7 @@ typedef enum {
        GS_PLUGIN_REFINE_FLAGS_REQUIRE_UPGRADE_REMOVED  = 1 << 16,
        GS_PLUGIN_REFINE_FLAGS_REQUIRE_PROVENANCE       = 1 << 17,
        GS_PLUGIN_REFINE_FLAGS_REQUIRE_REVIEWS          = 1 << 18,
+       GS_PLUGIN_REFINE_FLAGS_REQUIRE_REVIEW_RATINGS   = 1 << 19,
        GS_PLUGIN_REFINE_FLAGS_LAST
 } GsPluginRefineFlags;
 
diff --git a/src/gs-shell-details.c b/src/gs-shell-details.c
index 37bb8a3..c7316ca 100644
--- a/src/gs-shell-details.c
+++ b/src/gs-shell-details.c
@@ -1071,6 +1071,7 @@ gs_shell_details_set_filename (GsShellDetails *self, const gchar *filename)
                                                filename,
                                                GS_PLUGIN_REFINE_FLAGS_DEFAULT |
                                                GS_PLUGIN_REFINE_FLAGS_REQUIRE_RATING |
+                                               GS_PLUGIN_REFINE_FLAGS_REQUIRE_REVIEW_RATINGS |
                                                GS_PLUGIN_REFINE_FLAGS_REQUIRE_REVIEWS,
                                                self->cancellable,
                                                gs_shell_details_filename_to_app_cb,
@@ -1096,6 +1097,7 @@ gs_shell_details_load (GsShellDetails *self)
                                           GS_PLUGIN_REFINE_FLAGS_REQUIRE_SETUP_ACTION |
                                           GS_PLUGIN_REFINE_FLAGS_REQUIRE_PROVENANCE |
                                           GS_PLUGIN_REFINE_FLAGS_REQUIRE_ADDONS |
+                                          GS_PLUGIN_REFINE_FLAGS_REQUIRE_REVIEW_RATINGS |
                                           GS_PLUGIN_REFINE_FLAGS_REQUIRE_REVIEWS,
                                           self->cancellable,
                                           gs_shell_details_app_refine_cb,
diff --git a/src/plugins/gs-plugin-dummy.c b/src/plugins/gs-plugin-dummy.c
index fb843ef..cce7a13 100644
--- a/src/plugins/gs-plugin-dummy.c
+++ b/src/plugins/gs-plugin-dummy.c
@@ -176,6 +176,27 @@ gs_plugin_refine (GsPlugin *plugin,
                        gs_app_add_review (app, review);
                }
        }
+
+       /* add fake ratings */
+       if (flags & GS_PLUGIN_REFINE_FLAGS_REQUIRE_REVIEW_RATINGS) {
+               for (l = *list; l != NULL; l = l->next) {
+                       g_autoptr(GArray) ratings = NULL;
+                       const gint data[] = { 0, 10, 20, 30, 15, 2 };
+                       ratings = g_array_sized_new (FALSE, FALSE, sizeof (gint), 6);
+                       g_array_append_vals (ratings, data, 6);
+                       app = GS_APP (l->data);
+                       gs_app_set_review_ratings (app, ratings);
+               }
+       }
+
+       /* add a rating */
+       if (flags & GS_PLUGIN_REFINE_FLAGS_REQUIRE_RATING) {
+               for (l = *list; l != NULL; l = l->next) {
+                       app = GS_APP (l->data);
+                       gs_app_set_rating (app, 66);
+               }
+       }
+
        return TRUE;
 }
 


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