[gnome-software/wip/rancell/reviews] Show review histogram



commit 7b0d8c1233671abc9ceb96cc3f3495615d7f41f7
Author: Robert Ancell <robert ancell canonical com>
Date:   Tue Feb 9 15:33:57 2016 +1300

    Show review histogram

 src/Makefile.am                        |    3 +
 src/gnome-software.gresource.xml       |    1 +
 src/gs-app.c                           |   41 +++++
 src/gs-app.h                           |   12 ++
 src/gs-review-histogram.c              |  129 +++++++++++++
 src/gs-review-histogram.h              |   51 ++++++
 src/gs-review-histogram.ui             |  307 ++++++++++++++++++++++++++++++++
 src/gs-shell-details.c                 |   10 +
 src/gs-shell-details.ui                |    9 +-
 src/plugins/gs-plugin-ubuntu-reviews.c |   25 ++-
 10 files changed, 579 insertions(+), 9 deletions(-)
---
diff --git a/src/Makefile.am b/src/Makefile.am
index ee053e4..cbbcefc 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -38,6 +38,7 @@ UI_FILES =                                            \
        gs-first-run-dialog.ui                          \
        gs-history-dialog.ui                            \
        gs-review-dialog.ui                             \
+       gs-review-histogram.ui                          \
        gs-review-row.ui                                \
        gs-shell-category.ui                            \
        gs-shell-extras.ui                              \
@@ -145,6 +146,8 @@ gnome_software_SOURCES =                            \
        gs-review.h                                     \
        gs-review-dialog.c                              \
        gs-review-dialog.h                              \
+       gs-review-histogram.c                           \
+       gs-review-histogram.h                           \
        gs-review-row.c                                 \
        gs-review-row.h                                 \
        gs-screenshot-image.c                           \
diff --git a/src/gnome-software.gresource.xml b/src/gnome-software.gresource.xml
index 9cc13b1..261562f 100644
--- a/src/gnome-software.gresource.xml
+++ b/src/gnome-software.gresource.xml
@@ -14,6 +14,7 @@
   <file preprocess="xml-stripblanks">gs-first-run-dialog.ui</file>
   <file preprocess="xml-stripblanks">gs-history-dialog.ui</file>
   <file preprocess="xml-stripblanks">gs-review-dialog.ui</file>
+  <file preprocess="xml-stripblanks">gs-review-histogram.ui</file>
   <file preprocess="xml-stripblanks">gs-review-row.ui</file>
   <file preprocess="xml-stripblanks">gs-shell-category.ui</file>
   <file preprocess="xml-stripblanks">gs-shell-extras.ui</file>
diff --git a/src/gs-app.c b/src/gs-app.c
index d0c9269..466311b 100644
--- a/src/gs-app.c
+++ b/src/gs-app.c
@@ -83,6 +83,12 @@ struct _GsApp
        AsUrgencyKind            update_urgency;
        gchar                   *management_plugin;
        gint                     rating;
+       gboolean                 have_rating_counts;
+       guint                    rating_count1;
+       guint                    rating_count2;
+       guint                    rating_count3;
+       guint                    rating_count4;
+       guint                    rating_count5;
        guint                    review_count;
        GsReview                *self_review;
        GPtrArray               *reviews; /* of GsReview */
@@ -293,6 +299,8 @@ 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->have_rating_counts)
+               g_string_append_printf (str, "\trating-counts:\t[1:%u, 2:%u, 3:%u, 4:%u, 5:%u]\n", 
app->rating_count1, app->rating_count2, app->rating_count3, app->rating_count4, app->rating_count5);
        if (app->review_count != 0)
                g_string_append_printf (str, "\treview-count:\t%u\n", app->review_count);
        if (app->self_review != NULL)
@@ -1647,6 +1655,39 @@ gs_app_set_rating (GsApp *app, gint rating)
 }
 
 /**
+ * gs_app_get_rating_counts:
+ */
+gboolean
+gs_app_get_rating_counts (GsApp *app, guint *count1, guint *count2, guint *count3, guint *count4, guint 
*count5)
+{
+       g_return_val_if_fail (GS_IS_APP (app), FALSE);
+       if (!app->have_rating_counts)
+               return FALSE;
+       *count1 = app->rating_count1;
+       *count2 = app->rating_count2;
+       *count3 = app->rating_count3;
+       *count4 = app->rating_count4;
+       *count5 = app->rating_count5;
+       return TRUE;
+}
+
+/**
+ * gs_app_set_rating_counts:
+ */
+void
+gs_app_set_rating_counts (GsApp *app, guint count1, guint count2, guint count3, guint count4, guint count5)
+{
+       g_return_if_fail (GS_IS_APP (app));
+       app->have_rating_counts = TRUE;
+       app->rating_count1 = count1;
+       app->rating_count2 = count2;
+       app->rating_count3 = count3;
+       app->rating_count4 = count4;
+       app->rating_count5 = count5;
+       app->review_count = count1 + count2 + count3 + count4 + count5;
+}
+
+/**
  * gs_app_get_review_count:
  */
 guint
diff --git a/src/gs-app.h b/src/gs-app.h
index 614edea..fb653f4 100644
--- a/src/gs-app.h
+++ b/src/gs-app.h
@@ -198,6 +198,18 @@ void                gs_app_set_metadata            (GsApp          *app,
 gint            gs_app_get_rating              (GsApp          *app);
 void            gs_app_set_rating              (GsApp          *app,
                                                 gint            rating);
+gboolean        gs_app_get_rating_counts       (GsApp          *app,
+                                                guint          *count1,
+                                                guint          *count2,
+                                                guint          *count3,
+                                                guint          *count4,
+                                                guint          *count5);
+void            gs_app_set_rating_counts       (GsApp          *app,
+                                                guint           count1,
+                                                guint           count2,
+                                                guint           count3,
+                                                guint           count4,
+                                                guint           count5);
 guint           gs_app_get_review_count        (GsApp          *app);
 void            gs_app_set_review_count        (GsApp          *app,
                                                 guint           review_count);
diff --git a/src/gs-review-histogram.c b/src/gs-review-histogram.c
new file mode 100644
index 0000000..3ad12b7
--- /dev/null
+++ b/src/gs-review-histogram.c
@@ -0,0 +1,129 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
+ *
+ * Copyright (C) 2016 Canonical Ltd.
+ *
+ * Licensed under the GNU General Public License Version 2
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#include "config.h"
+
+#include <glib/gi18n.h>
+#include <gtk/gtk.h>
+
+#include "gs-review-histogram.h"
+
+typedef struct
+{
+       GtkWidget       *progress5;
+       GtkWidget       *progress4;
+       GtkWidget       *progress3;
+       GtkWidget       *progress2;
+       GtkWidget       *progress1;
+       GtkWidget       *label_count5;
+       GtkWidget       *label_count4;
+       GtkWidget       *label_count3;
+       GtkWidget       *label_count2;
+       GtkWidget       *label_count1;
+       GtkWidget       *label_total;
+} GsReviewHistogramPrivate;
+
+G_DEFINE_TYPE_WITH_PRIVATE (GsReviewHistogram, gs_review_histogram, GTK_TYPE_BIN)
+
+static void
+set_label (GtkWidget *label, guint value)
+{
+       g_autofree gchar *text = NULL;
+
+       text = g_strdup_printf ("%u", value);
+       gtk_label_set_text (GTK_LABEL (label), text);
+}
+
+/**
+ * gs_review_histogram_set_ratings:
+ **/
+void
+gs_review_histogram_set_ratings (GsReviewHistogram *histogram,
+                                guint count1,
+                                guint count2,
+                                guint count3,
+                                guint count4,
+                                guint count5)
+{
+       GsReviewHistogramPrivate *priv;
+       gdouble max;
+
+       g_return_if_fail (GS_IS_REVIEW_HISTOGRAM (histogram));
+       priv = gs_review_histogram_get_instance_private (histogram);
+
+       /* Scale to maximum value */
+       max = count1;
+       max = count2 > max ? count2 : max;
+       max = count3 > max ? count3 : max;
+       max = count4 > max ? count4 : max;
+       max = count5 > max ? count5 : max;
+
+       gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR (priv->progress5), count5 / max);
+       set_label (priv->label_count5, count5);
+       gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR (priv->progress4), count4 / max);
+       set_label (priv->label_count4, count4);
+       gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR (priv->progress3), count3 / max);
+       set_label (priv->label_count3, count3);
+       gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR (priv->progress2), count2 / max);
+       set_label (priv->label_count2, count2);
+       gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR (priv->progress1), count1 / max);
+       set_label (priv->label_count1, count1);
+       set_label (priv->label_total, count1 + count2 + count3 + count4 + count5);
+}
+
+static void
+gs_review_histogram_init (GsReviewHistogram *histogram)
+{
+       gtk_widget_init_template (GTK_WIDGET (histogram));
+}
+
+static void
+gs_review_histogram_class_init (GsReviewHistogramClass *klass)
+{
+       GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
+
+       gtk_widget_class_set_template_from_resource (widget_class, 
"/org/gnome/Software/gs-review-histogram.ui");
+
+       gtk_widget_class_bind_template_child_private (widget_class, GsReviewHistogram, progress5);
+       gtk_widget_class_bind_template_child_private (widget_class, GsReviewHistogram, progress4);
+       gtk_widget_class_bind_template_child_private (widget_class, GsReviewHistogram, progress3);
+       gtk_widget_class_bind_template_child_private (widget_class, GsReviewHistogram, progress2);
+       gtk_widget_class_bind_template_child_private (widget_class, GsReviewHistogram, progress1);
+       gtk_widget_class_bind_template_child_private (widget_class, GsReviewHistogram, label_count5);
+       gtk_widget_class_bind_template_child_private (widget_class, GsReviewHistogram, label_count4);
+       gtk_widget_class_bind_template_child_private (widget_class, GsReviewHistogram, label_count3);
+       gtk_widget_class_bind_template_child_private (widget_class, GsReviewHistogram, label_count2);
+       gtk_widget_class_bind_template_child_private (widget_class, GsReviewHistogram, label_count1);
+       gtk_widget_class_bind_template_child_private (widget_class, GsReviewHistogram, label_total);
+}
+
+/**
+ * gs_review_histogram_new:
+ **/
+GtkWidget *
+gs_review_histogram_new (void)
+{
+       GsReviewHistogram *histogram;
+       histogram = g_object_new (GS_TYPE_REVIEW_HISTOGRAM, NULL);
+       return GTK_WIDGET (histogram);
+}
+
+/* vim: set noexpandtab: */
diff --git a/src/gs-review-histogram.h b/src/gs-review-histogram.h
new file mode 100644
index 0000000..75ef3b0
--- /dev/null
+++ b/src/gs-review-histogram.h
@@ -0,0 +1,51 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
+ *
+ * Copyright (C) 2016 Canonical Ltd.
+ *
+ * Licensed under the GNU General Public License Version 2
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#ifndef GS_REVIEW_HISTOGRAM_H
+#define GS_REVIEW_HISTOGRAM_H
+
+#include <gtk/gtk.h>
+
+G_BEGIN_DECLS
+
+#define GS_TYPE_REVIEW_HISTOGRAM (gs_review_histogram_get_type ())
+
+G_DECLARE_DERIVABLE_TYPE (GsReviewHistogram, gs_review_histogram, GS, REVIEW_HISTOGRAM, GtkBin)
+
+struct _GsReviewHistogramClass
+{
+       GtkBinClass      parent_class;
+};
+
+GtkWidget      *gs_review_histogram_new                        (void);
+
+void            gs_review_histogram_set_ratings                (GsReviewHistogram *histogram,
+                                                                guint count1,
+                                                                guint count2,
+                                                                guint count3,
+                                                                guint count4,
+                                                                guint count5);
+
+G_END_DECLS
+
+#endif /* GS_REVIEW_HISTOGRAM_H */
+
+/* vim: set noexpandtab: */
diff --git a/src/gs-review-histogram.ui b/src/gs-review-histogram.ui
new file mode 100644
index 0000000..3dc75b0
--- /dev/null
+++ b/src/gs-review-histogram.ui
@@ -0,0 +1,307 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface>
+  <!-- interface-requires gtk+ 3.10 -->
+  <template class="GsReviewHistogram" parent="GtkBin">
+    <property name="visible">True</property>
+    <child>
+      <object class="GtkGrid" id="grid1">
+        <property name="visible">True</property>
+        <property name="can_focus">False</property>
+        <property name="row-spacing">10</property>
+        <property name="column-spacing">5</property>
+        <child>
+          <object class="GtkImage" id="star5">
+            <property name="visible">True</property>
+            <property name="icon_name">starred-symbolic</property>
+            <style>
+              <class name="star"/>
+            </style>
+          </object>
+          <packing>
+            <property name="left-attach">0</property>
+            <property name="top-attach">0</property>
+            <property name="width">1</property>
+            <property name="height">1</property>
+          </packing>
+        </child>
+        <child>
+          <object class="GtkLabel" id="star_label5">
+            <property name="visible">True</property>
+            <property name="label">5</property>
+          </object>
+          <packing>
+            <property name="left-attach">1</property>
+            <property name="top-attach">0</property>
+            <property name="width">1</property>
+            <property name="height">1</property>
+          </packing>
+        </child>
+        <child>
+          <object class="GtkProgressBar" id="progress5">
+            <property name="visible">True</property>
+            <property name="margin-left">25</property>
+          </object>
+          <packing>
+            <property name="left-attach">2</property>
+            <property name="top-attach">0</property>
+            <property name="width">1</property>
+            <property name="height">1</property>
+          </packing>
+        </child>
+        <child>
+          <object class="GtkLabel" id="label_count5">
+            <property name="visible">True</property>
+            <property name="label">0</property>
+            <property name="margin-left">5</property>
+          </object>
+          <packing>
+            <property name="left-attach">3</property>
+            <property name="top-attach">0</property>
+            <property name="width">1</property>
+            <property name="height">1</property>
+          </packing>
+        </child>
+        <child>
+          <object class="GtkImage" id="star4">
+            <property name="visible">True</property>
+            <property name="icon_name">starred-symbolic</property>
+            <style>
+              <class name="star"/>
+            </style>
+          </object>
+          <packing>
+            <property name="left-attach">0</property>
+            <property name="top-attach">1</property>
+            <property name="width">1</property>
+            <property name="height">1</property>
+          </packing>
+        </child>
+        <child>
+          <object class="GtkLabel" id="star_label4">
+            <property name="visible">True</property>
+            <property name="label">4</property>
+          </object>
+          <packing>
+            <property name="left-attach">1</property>
+            <property name="top-attach">1</property>
+            <property name="width">1</property>
+            <property name="height">1</property>
+          </packing>
+        </child>
+        <child>
+          <object class="GtkProgressBar" id="progress4">
+            <property name="visible">True</property>
+            <property name="margin-left">25</property>
+          </object>
+          <packing>
+            <property name="left-attach">2</property>
+            <property name="top-attach">1</property>
+            <property name="width">1</property>
+            <property name="height">1</property>
+          </packing>
+        </child>
+        <child>
+          <object class="GtkLabel" id="label_count4">
+            <property name="visible">True</property>
+            <property name="label">0</property>
+            <property name="margin-left">5</property>
+          </object>
+          <packing>
+            <property name="left-attach">3</property>
+            <property name="top-attach">1</property>
+            <property name="width">1</property>
+            <property name="height">1</property>
+          </packing>
+        </child>
+        <child>
+          <object class="GtkImage" id="star3">
+            <property name="visible">True</property>
+            <property name="icon_name">starred-symbolic</property>
+            <style>
+              <class name="star"/>
+            </style>
+          </object>
+          <packing>
+            <property name="left-attach">0</property>
+            <property name="top-attach">2</property>
+            <property name="width">1</property>
+            <property name="height">1</property>
+          </packing>
+        </child>
+        <child>
+          <object class="GtkLabel" id="star_label3">
+            <property name="visible">True</property>
+            <property name="label">3</property>
+          </object>
+          <packing>
+            <property name="left-attach">1</property>
+            <property name="top-attach">2</property>
+            <property name="width">1</property>
+            <property name="height">1</property>
+          </packing>
+        </child>
+        <child>
+          <object class="GtkProgressBar" id="progress3">
+            <property name="visible">True</property>
+            <property name="margin-left">25</property>
+          </object>
+          <packing>
+            <property name="left-attach">2</property>
+            <property name="top-attach">2</property>
+            <property name="width">1</property>
+            <property name="height">1</property>
+          </packing>
+        </child>
+        <child>
+          <object class="GtkLabel" id="label_count3">
+            <property name="visible">True</property>
+            <property name="label">0</property>
+            <property name="margin-left">5</property>
+          </object>
+          <packing>
+            <property name="left-attach">3</property>
+            <property name="top-attach">2</property>
+            <property name="width">1</property>
+            <property name="height">1</property>
+          </packing>
+        </child>
+        <child>
+          <object class="GtkImage" id="star2">
+            <property name="visible">True</property>
+            <property name="icon_name">starred-symbolic</property>
+            <style>
+              <class name="star"/>
+            </style>
+          </object>
+          <packing>
+            <property name="left-attach">0</property>
+            <property name="top-attach">3</property>
+            <property name="width">1</property>
+            <property name="height">1</property>
+          </packing>
+        </child>
+        <child>
+          <object class="GtkLabel" id="star_label2">
+            <property name="visible">True</property>
+            <property name="label">2</property>
+          </object>
+          <packing>
+            <property name="left-attach">1</property>
+            <property name="top-attach">3</property>
+            <property name="width">1</property>
+            <property name="height">1</property>
+          </packing>
+        </child>
+        <child>
+          <object class="GtkProgressBar" id="progress2">
+            <property name="visible">True</property>
+            <property name="margin-left">25</property>
+          </object>
+          <packing>
+            <property name="left-attach">2</property>
+            <property name="top-attach">3</property>
+            <property name="width">1</property>
+            <property name="height">1</property>
+          </packing>
+        </child>
+        <child>
+          <object class="GtkLabel" id="label_count2">
+            <property name="visible">True</property>
+            <property name="label">0</property>
+            <property name="margin-left">5</property>
+          </object>
+          <packing>
+            <property name="left-attach">3</property>
+            <property name="top-attach">3</property>
+            <property name="width">1</property>
+            <property name="height">1</property>
+          </packing>
+        </child>
+        <child>
+          <object class="GtkImage" id="star1">
+            <property name="visible">True</property>
+            <property name="icon_name">starred-symbolic</property>
+            <style>
+              <class name="star"/>
+            </style>
+          </object>
+          <packing>
+            <property name="left-attach">0</property>
+            <property name="top-attach">4</property>
+            <property name="width">1</property>
+            <property name="height">1</property>
+          </packing>
+        </child>
+        <child>
+          <object class="GtkLabel" id="star_label1">
+            <property name="visible">True</property>
+            <property name="label">1</property>
+          </object>
+          <packing>
+            <property name="left-attach">1</property>
+            <property name="top-attach">4</property>
+            <property name="width">1</property>
+            <property name="height">1</property>
+          </packing>
+        </child>
+        <child>
+          <object class="GtkProgressBar" id="progress1">
+            <property name="visible">True</property>
+            <property name="margin-left">25</property>
+          </object>
+          <packing>
+            <property name="left-attach">2</property>
+            <property name="top-attach">4</property>
+            <property name="width">1</property>
+            <property name="height">1</property>
+          </packing>
+        </child>
+        <child>
+          <object class="GtkLabel" id="label_count1">
+            <property name="visible">True</property>
+            <property name="label">0</property>
+            <property name="margin-left">5</property>
+          </object>
+          <packing>
+            <property name="left-attach">3</property>
+            <property name="top-attach">4</property>
+            <property name="width">1</property>
+            <property name="height">1</property>
+          </packing>
+        </child>
+        <child>
+          <object class="GtkLabel" id="label1">
+            <property name="visible">True</property>
+            <property name="label" translatable="yes">Total</property>
+            <property name="halign">start</property>
+            <style>
+              <class name="dim-label"/>
+            </style>
+          </object>
+          <packing>
+            <property name="left-attach">0</property>
+            <property name="top-attach">5</property>
+            <property name="width">3</property>
+            <property name="height">1</property>
+          </packing>
+        </child>
+        <child>
+          <object class="GtkLabel" id="label_total">
+            <property name="visible">True</property>
+            <property name="label">0</property>
+            <property name="margin-left">5</property>
+            <style>
+              <class name="dim-label"/>
+            </style>
+          </object>
+          <packing>
+            <property name="left-attach">3</property>
+            <property name="top-attach">5</property>
+            <property name="width">1</property>
+            <property name="height">1</property>
+          </packing>
+        </child>
+      </object>
+    </child>
+  </template>
+</interface>
diff --git a/src/gs-shell-details.c b/src/gs-shell-details.c
index 730ddf8..09f1d58 100644
--- a/src/gs-shell-details.c
+++ b/src/gs-shell-details.c
@@ -34,6 +34,7 @@
 #include "gs-screenshot-image.h"
 #include "gs-progress-button.h"
 #include "gs-star-widget.h"
+#include "gs-review-histogram.h"
 #include "gs-review-dialog.h"
 #include "gs-review-row.h"
 
@@ -92,6 +93,7 @@ struct _GsShellDetails
        GtkWidget               *label_details_info_text;
        GtkWidget               *list_box_addons;
        GtkWidget               *box_reviews;
+       GtkWidget               *histogram;
        GtkWidget               *button_review;
        GtkWidget               *list_box_reviews;
        GtkWidget               *scrolledwindow_details;
@@ -583,6 +585,7 @@ gs_shell_details_refresh_all (GsShellDetails *self)
        const gchar *tmp;
        gboolean ret;
        gchar **menu_path;
+       guint count1, count2, count3, count4, count5;
        guint64 kudos;
        guint64 updated;
        guint64 user_integration_bf;
@@ -734,6 +737,12 @@ gs_shell_details_refresh_all (GsShellDetails *self)
                } else {
                        gtk_widget_set_visible (self->star, FALSE);
                }
+               if (gs_app_get_rating_counts (self->app, &count1, &count2, &count3, &count4, &count5)) {
+                       gtk_widget_set_visible (self->histogram, TRUE);
+                       gs_review_histogram_set_ratings (GS_REVIEW_HISTOGRAM (self->histogram), count1, 
count2, count3, count4, count5);
+               } else {
+                       gtk_widget_set_visible (self->histogram, FALSE);
+               }
                if (gs_app_get_review_count (self->app) != 0) {
                        g_autofree gchar *text = NULL;
 
@@ -1555,6 +1564,7 @@ gs_shell_details_class_init (GsShellDetailsClass *klass)
        gtk_widget_class_bind_template_child (widget_class, GsShellDetails, label_details_info_text);
        gtk_widget_class_bind_template_child (widget_class, GsShellDetails, list_box_addons);
        gtk_widget_class_bind_template_child (widget_class, GsShellDetails, box_reviews);
+       gtk_widget_class_bind_template_child (widget_class, GsShellDetails, histogram);
        gtk_widget_class_bind_template_child (widget_class, GsShellDetails, button_review);
        gtk_widget_class_bind_template_child (widget_class, GsShellDetails, list_box_reviews);
        gtk_widget_class_bind_template_child (widget_class, GsShellDetails, scrolledwindow_details);
diff --git a/src/gs-shell-details.ui b/src/gs-shell-details.ui
index 839881b..2569214 100644
--- a/src/gs-shell-details.ui
+++ b/src/gs-shell-details.ui
@@ -1171,7 +1171,7 @@
                           <object class="GtkLabel" id="application_details_reviews_title">
                             <property name="visible">True</property>
                             <property name="can_focus">False</property>
-                            <property name="margin_bottom">12</property>
+                            <property name="margin_bottom">20</property>
                             <property name="halign">start</property>
                             <property name="valign">start</property>
                             <property name="hexpand">True</property>
@@ -1183,6 +1183,13 @@
                           </object>
                         </child>
                         <child>
+                          <object class="GsReviewHistogram" id="histogram">
+                            <property name="halign">start</property>
+                            <property name="valign">center</property>
+                            <property name="margin_bottom">20</property>
+                          </object>
+                        </child>
+                        <child>
                           <object class="GtkButton" id="button_review">
                             <property name="use_underline">True</property>
                             <property name="label" translatable="yes">_Write a Review</property>
diff --git a/src/plugins/gs-plugin-ubuntu-reviews.c b/src/plugins/gs-plugin-ubuntu-reviews.c
index 46ea549..23b47a9 100644
--- a/src/plugins/gs-plugin-ubuntu-reviews.c
+++ b/src/plugins/gs-plugin-ubuntu-reviews.c
@@ -201,12 +201,16 @@ static gboolean
 get_review_stats (GsPlugin *plugin,
                  const gchar *package_name,
                  gint *rating,
-                 gint *review_count,
+                 guint *count1,
+                 guint *count2,
+                 guint *count3,
+                 guint *count4,
+                 guint *count5,
                  GError **error)
 {
        Histogram histogram = { 0, 0, 0, 0, 0 };
        gchar *error_msg = NULL;
-       gint result;
+       gint result, n_ratings;
        g_autofree gchar *statement = NULL;
 
        /* Get histogram from the database */
@@ -228,11 +232,16 @@ get_review_stats (GsPlugin *plugin,
 
        /* Convert to a rating */
        // FIXME: Convert to a Wilson score
-       *review_count = histogram.one_star_count + histogram.two_star_count + histogram.three_star_count + 
histogram.four_star_count + histogram.five_star_count;
-       if (*review_count == 0)
+       n_ratings = histogram.one_star_count + histogram.two_star_count + histogram.three_star_count + 
histogram.four_star_count + histogram.five_star_count;
+       if (n_ratings == 0)
                *rating = -1;
        else
-               *rating = ((histogram.one_star_count * 20) + (histogram.two_star_count * 40) + 
(histogram.three_star_count * 60) + (histogram.four_star_count * 80) + (histogram.five_star_count * 100)) / 
*review_count;
+               *rating = ((histogram.one_star_count * 20) + (histogram.two_star_count * 40) + 
(histogram.three_star_count * 60) + (histogram.four_star_count * 80) + (histogram.five_star_count * 100)) / 
n_ratings;
+       *count1 = histogram.one_star_count;
+       *count2 = histogram.two_star_count;
+       *count3 = histogram.three_star_count;
+       *count4 = histogram.four_star_count;
+       *count5 = histogram.five_star_count;
 
        return TRUE;
 }
@@ -601,7 +610,7 @@ refine_rating (GsPlugin *plugin, GsApp *app, GError **error)
        for (i = 0; i < sources->len; i++) {
                const gchar *package_name;
                gint rating;
-               guint review_count;
+               guint count1, count2, count3, count4, count5, review_count;
                gboolean ret;
 
                /* If we have a local review, use that as the rating */
@@ -609,14 +618,14 @@ refine_rating (GsPlugin *plugin, GsApp *app, GError **error)
 
                /* Otherwise use the statistics */
                package_name = g_ptr_array_index (sources, i);
-               ret = get_review_stats (plugin, package_name, &rating, &review_count, error);
+               ret = get_review_stats (plugin, package_name, &rating, &count1, &count2, &count3, &count4, 
&count5, error);
                if (!ret)
                        return FALSE;
                if (rating != -1) {
                        g_debug ("ubuntu-reviews setting rating on %s to %i%%",
                                 package_name, rating);
                        gs_app_set_rating (app, rating);
-                       gs_app_set_review_count (app, review_count);
+                       gs_app_set_rating_counts (app, count1, count2, count3, count4, count5);
                        if (rating > 80)
                                gs_app_add_kudo (app, GS_APP_KUDO_POPULAR);
                }


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