[gnome-software/wip/rancell/reviews] Show total review count
- From: Robert Ancell <rancell src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-software/wip/rancell/reviews] Show total review count
- Date: Tue, 9 Feb 2016 02:34:12 +0000 (UTC)
commit 3b89e806c7550794f6af67a2bdf70cd4b1d47d72
Author: Robert Ancell <robert ancell canonical com>
Date: Tue Feb 9 12:04:39 2016 +1300
Show total review count
src/gs-app.c | 39 ++++++++++++++++++++++++++++++++
src/gs-app.h | 3 ++
src/gs-shell-details.c | 20 ++++++++++-----
src/gs-shell-details.ui | 39 ++++++++++++++++++++++++++++++++
src/plugins/gs-plugin-ubuntu-reviews.c | 32 ++++++++++++++------------
5 files changed, 111 insertions(+), 22 deletions(-)
---
diff --git a/src/gs-app.c b/src/gs-app.c
index 812d393..d0c9269 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;
+ guint review_count;
GsReview *self_review;
GPtrArray *reviews; /* of GsReview */
guint64 size;
@@ -112,6 +113,7 @@ enum {
PROP_SUMMARY,
PROP_DESCRIPTION,
PROP_RATING,
+ PROP_REVIEW_COUNT,
PROP_KIND,
PROP_STATE,
PROP_PROGRESS,
@@ -291,6 +293,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->review_count != 0)
+ g_string_append_printf (str, "\treview-count:\t%u\n", app->review_count);
if (app->self_review != NULL)
g_string_append_printf (str, "\tself-review:\t%p\n", app->self_review);
if (app->reviews != NULL)
@@ -1643,6 +1647,27 @@ gs_app_set_rating (GsApp *app, gint rating)
}
/**
+ * gs_app_get_review_count:
+ */
+guint
+gs_app_get_review_count (GsApp *app)
+{
+ g_return_val_if_fail (GS_IS_APP (app), 0);
+ return app->review_count;
+}
+
+/**
+ * gs_app_set_review_count:
+ */
+void
+gs_app_set_review_count (GsApp *app, guint review_count)
+{
+ g_return_if_fail (GS_IS_APP (app));
+ app->review_count = review_count;
+ gs_app_queue_notify (app, "review-count");
+}
+
+/**
* gs_app_get_self_review:
*/
GsReview *
@@ -2163,6 +2188,9 @@ gs_app_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *
case PROP_RATING:
g_value_set_int (value, app->rating);
break;
+ case PROP_REVIEW_COUNT:
+ g_value_set_int (value, app->review_count);
+ break;
case PROP_KIND:
g_value_set_uint (value, app->kind);
break;
@@ -2214,6 +2242,9 @@ gs_app_set_property (GObject *object, guint prop_id, const GValue *value, GParam
case PROP_RATING:
gs_app_set_rating (app, g_value_get_int (value));
break;
+ case PROP_REVIEW_COUNT:
+ gs_app_set_review_count (app, g_value_get_uint (value));
+ break;
case PROP_KIND:
gs_app_set_kind (app, g_value_get_uint (value));
break;
@@ -2350,6 +2381,14 @@ gs_app_class_init (GsAppClass *klass)
g_object_class_install_property (object_class, PROP_RATING, pspec);
/**
+ * GsApp:review-count:
+ */
+ pspec = g_param_spec_uint ("review-count", NULL, NULL,
+ 0, G_MAXUINT, 0,
+ G_PARAM_READWRITE | G_PARAM_CONSTRUCT);
+ g_object_class_install_property (object_class, PROP_REVIEW_COUNT, pspec);
+
+ /**
* GsApp:kind:
*/
pspec = g_param_spec_uint ("kind", NULL, NULL,
diff --git a/src/gs-app.h b/src/gs-app.h
index f5ea9b2..614edea 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);
+guint gs_app_get_review_count (GsApp *app);
+void gs_app_set_review_count (GsApp *app,
+ guint review_count);
GsReview *gs_app_get_self_review (GsApp *app);
void gs_app_set_self_review (GsApp *app,
GsReview *review);
diff --git a/src/gs-shell-details.c b/src/gs-shell-details.c
index 5ffcb89..730ddf8 100644
--- a/src/gs-shell-details.c
+++ b/src/gs-shell-details.c
@@ -52,7 +52,6 @@ struct _GsShellDetails
GCancellable *cancellable;
GsApp *app;
GsShell *shell;
- GtkWidget *star;
SoupSession *session;
GtkWidget *application_details_icon;
@@ -61,7 +60,8 @@ struct _GsShellDetails
GtkWidget *box_addons;
GtkWidget *box_details;
GtkWidget *box_details_description;
- GtkWidget *box_details_header;
+ GtkWidget *star;
+ GtkWidget *label_review_count;
GtkWidget *box_details_screenshot;
GtkWidget *box_details_screenshot_main;
GtkWidget *box_details_screenshot_thumbnails;
@@ -734,6 +734,15 @@ gs_shell_details_refresh_all (GsShellDetails *self)
} else {
gtk_widget_set_visible (self->star, FALSE);
}
+ if (gs_app_get_review_count (self->app) != 0) {
+ g_autofree gchar *text = NULL;
+
+ gtk_widget_set_visible (self->label_review_count, TRUE);
+ text = g_strdup_printf ("(%u)", gs_app_get_review_count (self->app));
+ gtk_label_set_text (GTK_LABEL (self->label_review_count), text);
+ } else {
+ gtk_widget_set_visible (self->label_review_count, FALSE);
+ }
break;
}
@@ -1440,13 +1449,9 @@ gs_shell_details_setup (GsShellDetails *self,
self);
/* set up star ratings */
- self->star = gs_star_widget_new ();
g_signal_connect (self->star, "rating-changed",
G_CALLBACK (gs_shell_details_rating_changed_cb),
self);
- gtk_widget_set_visible (self->star, TRUE);
- gtk_widget_set_valign (self->star, GTK_ALIGN_START);
- gtk_box_pack_start (GTK_BOX (self->box_details_header), self->star, FALSE, FALSE, 0);
/* setup details */
g_signal_connect (self->button_install, "clicked",
@@ -1518,7 +1523,8 @@ gs_shell_details_class_init (GsShellDetailsClass *klass)
gtk_widget_class_bind_template_child (widget_class, GsShellDetails, box_addons);
gtk_widget_class_bind_template_child (widget_class, GsShellDetails, box_details);
gtk_widget_class_bind_template_child (widget_class, GsShellDetails, box_details_description);
- gtk_widget_class_bind_template_child (widget_class, GsShellDetails, box_details_header);
+ gtk_widget_class_bind_template_child (widget_class, GsShellDetails, star);
+ gtk_widget_class_bind_template_child (widget_class, GsShellDetails, label_review_count);
gtk_widget_class_bind_template_child (widget_class, GsShellDetails, box_details_screenshot);
gtk_widget_class_bind_template_child (widget_class, GsShellDetails, box_details_screenshot_main);
gtk_widget_class_bind_template_child (widget_class, GsShellDetails,
box_details_screenshot_thumbnails);
diff --git a/src/gs-shell-details.ui b/src/gs-shell-details.ui
index e49c105..839881b 100644
--- a/src/gs-shell-details.ui
+++ b/src/gs-shell-details.ui
@@ -227,6 +227,45 @@
<property name="position">1</property>
</packing>
</child>
+ <child>
+ <object class="GtkBox" id="star_box">
+ <property name="visible">True</property>
+ <property name="valign">start</property>
+ <child>
+ <object class="GsStarWidget" id="star">
+ <property name="visible">True</property>
+ <property name="halign">start</property>
+ <property name="valign">center</property>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">False</property>
+ <property name="position">0</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkLabel" id="label_review_count">
+ <property name="visible">True</property>
+ <property name="margin_start">5</property>
+ <property name="halign">start</property>
+ <property name="valign">center</property>
+ <style>
+ <class name="dim-label"/>
+ </style>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">False</property>
+ <property name="position">1</property>
+ </packing>
+ </child>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">False</property>
+ <property name="position">2</property>
+ </packing>
+ </child>
</object>
<packing>
<property name="expand">False</property>
diff --git a/src/plugins/gs-plugin-ubuntu-reviews.c b/src/plugins/gs-plugin-ubuntu-reviews.c
index 8d7d129..46ea549 100644
--- a/src/plugins/gs-plugin-ubuntu-reviews.c
+++ b/src/plugins/gs-plugin-ubuntu-reviews.c
@@ -183,10 +183,10 @@ set_timestamp (GsPlugin *plugin,
}
static gint
-get_rating_sqlite_cb (void *data,
- gint argc,
- gchar **argv,
- gchar **col_name)
+get_review_stats_sqlite_cb (void *data,
+ gint argc,
+ gchar **argv,
+ gchar **col_name)
{
Histogram *histogram = (Histogram *) data;
histogram->one_star_count = g_ascii_strtoll (argv[0], NULL, 10);
@@ -198,14 +198,15 @@ get_rating_sqlite_cb (void *data,
}
static gboolean
-get_rating (GsPlugin *plugin,
- const gchar *package_name,
- gint *rating,
- GError **error)
+get_review_stats (GsPlugin *plugin,
+ const gchar *package_name,
+ gint *rating,
+ gint *review_count,
+ GError **error)
{
Histogram histogram = { 0, 0, 0, 0, 0 };
gchar *error_msg = NULL;
- gint result, n_ratings;
+ gint result;
g_autofree gchar *statement = NULL;
/* Get histogram from the database */
@@ -213,7 +214,7 @@ get_rating (GsPlugin *plugin,
"WHERE package_name = '%s'", package_name);
result = sqlite3_exec (plugin->priv->db,
statement,
- get_rating_sqlite_cb,
+ get_review_stats_sqlite_cb,
&histogram,
&error_msg);
if (result != SQLITE_OK) {
@@ -227,12 +228,11 @@ get_rating (GsPlugin *plugin,
/* Convert to a rating */
// FIXME: Convert to a Wilson score
- 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)
+ *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)
*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)) /
n_ratings;
-g_warning ("%s %zi %zi %zi %zi %zi / %d -> %d", package_name, histogram.one_star_count,
histogram.two_star_count, histogram.three_star_count, histogram.four_star_count, histogram.five_star_count,
n_ratings, *rating);
+ *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;
return TRUE;
}
@@ -601,6 +601,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;
gboolean ret;
/* If we have a local review, use that as the rating */
@@ -608,13 +609,14 @@ refine_rating (GsPlugin *plugin, GsApp *app, GError **error)
/* Otherwise use the statistics */
package_name = g_ptr_array_index (sources, i);
- ret = get_rating (plugin, package_name, &rating, error);
+ ret = get_review_stats (plugin, package_name, &rating, &review_count, 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);
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]