[gnome-software/gnome-3-20] Do not show ratings and reviews for some component kinds



commit 21296ffe0a9610dcfe0d409fb9efe5184851e838
Author: Richard Hughes <richard hughsie com>
Date:   Mon Feb 29 18:14:07 2016 +0000

    Do not show ratings and reviews for some component kinds
    
    Fixes half of https://bugzilla.gnome.org/show_bug.cgi?id=762882

 src/gs-shell-details.c |  118 +++++++++++++++++++++++++-----------------------
 1 files changed, 61 insertions(+), 57 deletions(-)
---
diff --git a/src/gs-shell-details.c b/src/gs-shell-details.c
index 80a8779..dcbbd5d 100644
--- a/src/gs-shell-details.c
+++ b/src/gs-shell-details.c
@@ -54,6 +54,7 @@ struct _GsShellDetails
        GsApp                   *app;
        GsShell                 *shell;
        SoupSession             *session;
+       gboolean                 enable_reviews;
 
        GtkWidget               *application_details_icon;
        GtkWidget               *application_details_summary;
@@ -577,8 +578,6 @@ static void
 gs_shell_details_refresh_all (GsShellDetails *self)
 {
        GPtrArray *history;
-       GArray *review_ratings;
-       gint n_reviews;
        GdkPixbuf *pixbuf = NULL;
        GList *addons;
        GtkWidget *widget;
@@ -588,7 +587,6 @@ gs_shell_details_refresh_all (GsShellDetails *self)
        guint64 kudos;
        guint64 updated;
        guint64 user_integration_bf;
-       guint i;
        g_autoptr(GError) error = NULL;
 
        /* change widgets */
@@ -723,46 +721,6 @@ gs_shell_details_refresh_all (GsShellDetails *self)
                                gs_app_get_state (self->app) == AS_APP_STATE_UPDATABLE ||
                                gs_app_get_state (self->app) == AS_APP_STATE_AVAILABLE_LOCAL);
 
-       /* set the rating */
-       switch (gs_app_get_kind (self->app)) {
-       case AS_APP_KIND_WEB_APP:
-               gtk_widget_set_visible (self->star, FALSE);
-               break;
-       default:
-               gtk_widget_set_visible (self->star, TRUE);
-               if (gs_app_get_rating (self->app) >= 0) {
-                       gtk_widget_set_visible (self->star, TRUE);
-                       gs_star_widget_set_rating (GS_STAR_WIDGET (self->star),
-                                                  gs_app_get_rating (self->app));
-               } else {
-                       gtk_widget_set_visible (self->star, FALSE);
-               }
-               review_ratings = gs_app_get_review_ratings (self->app);
-               if (review_ratings != NULL) {
-                       gtk_widget_set_visible (self->histogram, TRUE);
-                       gs_review_histogram_set_ratings (GS_REVIEW_HISTOGRAM (self->histogram),
-                                                        review_ratings);
-               } else {
-                       gtk_widget_set_visible (self->histogram, FALSE);
-               }
-               n_reviews = 0;
-               if (review_ratings != NULL) {
-                       for (i = 0; i < review_ratings->len; i++)
-                               n_reviews += g_array_index (review_ratings, gint, i);
-               } else if (gs_app_get_reviews (self->app) != NULL) {
-                       n_reviews = gs_app_get_reviews (self->app)->len;
-               }
-               if (n_reviews > 0) {
-                       g_autofree gchar *text = NULL;
-                       gtk_widget_set_visible (self->label_review_count, TRUE);
-                       text = g_strdup_printf ("(%u)", n_reviews);
-                       gtk_label_set_text (GTK_LABEL (self->label_review_count), text);
-               } else {
-                       gtk_widget_set_visible (self->label_review_count, FALSE);
-               }
-               break;
-       }
-
        /* set MyLanguage kudo */
        kudos = gs_app_get_kudos (self->app);
        ret = (kudos & GS_APP_KUDO_MY_LANGUAGE) > 0;
@@ -834,11 +792,6 @@ gs_shell_details_refresh_all (GsShellDetails *self)
                }
        }
 
-       /* don't show a missing rating on a local file */
-       if (gs_app_get_state (self->app) == AS_APP_STATE_AVAILABLE_LOCAL &&
-           gs_app_get_rating (self->app) < 0)
-               gtk_widget_set_visible (self->star, FALSE);
-
        /* make history button insensitive if there is none */
        history = gs_app_get_history (self->app);
        switch (gs_app_get_kind (self->app)) {
@@ -1010,10 +963,13 @@ gs_shell_details_review_button_clicked_cb (GsReviewRow *row,
 static void
 gs_shell_details_refresh_reviews (GsShellDetails *self)
 {
+       GArray *review_ratings;
        GPtrArray *reviews;
        gboolean show_review_button = TRUE;
-       guint i;
+       gboolean show_reviews = FALSE;
+       gint n_reviews = 0;
        guint64 possible_actions = 0;
+       guint i;
        struct {
                GsReviewAction action;
                const gchar *plugin_func;
@@ -1026,11 +982,58 @@ gs_shell_details_refresh_reviews (GsShellDetails *self)
                { GS_REVIEW_ACTION_LAST,        NULL }
        };
 
-       if (!gs_plugin_loader_get_plugin_supported (self->plugin_loader,
-                                                   "gs_plugin_review_submit"))
-               return;
+       /* show or hide the entire reviews section */
+       switch (gs_app_get_kind (self->app)) {
+       case AS_APP_KIND_DESKTOP:
+       case AS_APP_KIND_FONT:
+       case AS_APP_KIND_INPUT_METHOD:
+       case AS_APP_KIND_WEB_APP:
+       case AS_APP_KIND_SHELL_EXTENSION:
+               /* don't show a missing rating on a local file */
+               if (gs_app_get_state (self->app) != AS_APP_STATE_AVAILABLE_LOCAL &&
+                   self->enable_reviews)
+                       show_reviews = TRUE;
+               break;
+       default:
+               break;
+       }
 
-       gs_container_remove_all (GTK_CONTAINER (self->list_box_reviews));
+       /* set the star rating */
+       if (show_reviews) {
+               if (gs_app_get_rating (self->app) >= 0) {
+                       gs_star_widget_set_rating (GS_STAR_WIDGET (self->star),
+                                                  gs_app_get_rating (self->app));
+               }
+               review_ratings = gs_app_get_review_ratings (self->app);
+               if (review_ratings != NULL) {
+                       gs_review_histogram_set_ratings (GS_REVIEW_HISTOGRAM (self->histogram),
+                                                        review_ratings);
+               }
+               if (review_ratings != NULL) {
+                       for (i = 0; i < review_ratings->len; i++)
+                               n_reviews += g_array_index (review_ratings, gint, i);
+               } else if (gs_app_get_reviews (self->app) != NULL) {
+                       n_reviews = gs_app_get_reviews (self->app)->len;
+               }
+       }
+
+       /* enable appropriate widgets */
+       gtk_widget_set_visible (self->star, show_reviews);
+       gtk_widget_set_visible (self->box_reviews, show_reviews);
+       gtk_widget_set_visible (self->histogram, review_ratings != NULL);
+       gtk_widget_set_visible (self->label_review_count, n_reviews > 0);
+
+       /* update the review label next to the star widget */
+       if (n_reviews > 0) {
+               g_autofree gchar *text = NULL;
+               gtk_widget_set_visible (self->label_review_count, TRUE);
+               text = g_strdup_printf ("(%u)", n_reviews);
+               gtk_label_set_text (GTK_LABEL (self->label_review_count), text);
+       }
+
+       /* no point continuing */
+       if (!show_reviews)
+               return;
 
        /* find what the plugins support */
        for (i = 0; plugin_vfuncs[i].action != GS_REVIEW_ACTION_LAST; i++) {
@@ -1041,6 +1044,7 @@ gs_shell_details_refresh_reviews (GsShellDetails *self)
        }
 
        /* add all the reviews */
+       gs_container_remove_all (GTK_CONTAINER (self->list_box_reviews));
        reviews = gs_app_get_reviews (self->app);
        for (i = 0; i < reviews->len; i++) {
                GsReview *review = g_ptr_array_index (reviews, i);
@@ -1439,10 +1443,10 @@ gs_shell_details_setup (GsShellDetails *self,
        self->builder = g_object_ref (builder);
        self->cancellable = g_object_ref (cancellable);
 
-       /* Show review widgets if we have plugins that provide them */
-       if (gs_plugin_loader_get_plugin_supported (plugin_loader,
-                                                  "gs_plugin_review_submit"))
-               gtk_widget_set_visible (self->box_reviews, TRUE);
+       /* show review widgets if we have plugins that provide them */
+       self->enable_reviews =
+               gs_plugin_loader_get_plugin_supported (plugin_loader,
+                                                      "gs_plugin_review_submit");
        g_signal_connect (self->button_review, "clicked",
                          G_CALLBACK (gs_shell_details_write_review_cb),
                          self);


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