[gnome-software/wip/temp/ubuntu-xenial-rebased: 5/326] Pull review information from GsApp object
- From: Iain Lane <iainl src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-software/wip/temp/ubuntu-xenial-rebased: 5/326] Pull review information from GsApp object
- Date: Fri, 29 Apr 2016 09:47:43 +0000 (UTC)
commit 80dabd5f64d3452e1e5e8c2e7b285d0d9efcc998
Author: Robert Ancell <robert ancell canonical com>
Date: Wed Dec 16 15:46:07 2015 +1300
Pull review information from GsApp object
po/POTFILES.in | 2 +
src/Makefile.am | 4 +-
src/gs-app-review-row.c | 154 +++++++++++++++
src/{gs-app-reviews.h => gs-app-review-row.h} | 15 +-
src/{gs-review-widget.ui => gs-app-review-row.ui} | 2 +-
src/gs-app-review.c | 36 ++--
src/gs-app-review.h | 6 +-
src/gs-app-reviews.c | 63 ------
src/gs-review-widget.c | 211 ---------------------
src/gs-review-widget.h | 56 ------
src/gs-shell-details.c | 23 +++
11 files changed, 213 insertions(+), 359 deletions(-)
---
diff --git a/po/POTFILES.in b/po/POTFILES.in
index dcb1383..bcd4f34 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -7,6 +7,8 @@ data/org.gnome.software.gschema.xml
src/gnome-software-local-file.desktop.in
[type: gettext/glade]src/gnome-software.ui
src/gs-app-addon-row.c
+src/gs-app-review-row.c
+[type: gettext/glade]src/gs-app-review-row.ui
src/gs-app.c
src/gs-app-folder-dialog.c
src/gs-application.c
diff --git a/src/Makefile.am b/src/Makefile.am
index 85f8f9a..67fb0e6 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -129,8 +129,8 @@ gnome_software_SOURCES = \
gs-category-tile.h \
gs-app-review.c \
gs-app-review.h \
- gs-app-reviews.c \
- gs-app-reviews.h \
+ gs-app-review-row.c \
+ gs-app-review-row.h \
gs-app-tile.c \
gs-app-tile.h \
gs-app-folder-dialog.c \
diff --git a/src/gs-app-review-row.c b/src/gs-app-review-row.c
new file mode 100644
index 0000000..a78c9ef
--- /dev/null
+++ b/src/gs-app-review-row.c
@@ -0,0 +1,154 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
+ *
+ * Copyright (C) 2015 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-app-review-row.h"
+#include "gs-star-widget.h"
+
+struct _GsAppReviewRow
+{
+ GtkListBoxRow parent_instance;
+
+ GsAppReview *review;
+ GtkWidget *stars;
+ GtkWidget *summary_label;
+ GtkWidget *author_label;
+ GtkWidget *text_label;
+};
+
+G_DEFINE_TYPE (GsAppReviewRow, gs_app_review_row, GTK_TYPE_LIST_BOX_ROW)
+
+static void
+gs_app_review_row_refresh (GsAppReviewRow *row)
+{
+ const gchar *reviewer;
+ GDateTime *date;
+ gchar *text;
+
+ gs_star_widget_set_rating (GS_STAR_WIDGET (row->stars), gs_app_review_get_rating (row->review));
+ reviewer = gs_app_review_get_reviewer (row->review);
+ date = gs_app_review_get_date (row->review);
+ if (reviewer && date) {
+ gchar *date_text = g_date_time_format (date, "%e %B %Y");
+ text = g_strdup_printf ("%s, %s", reviewer, date_text);
+ g_free (date_text);
+ }
+ else if (reviewer)
+ text = g_strdup (reviewer);
+ else if (date)
+ text = g_date_time_format (date, "%e %B %Y");
+ else
+ text = g_strdup ("");
+ gtk_label_set_text (GTK_LABEL (row->author_label), text);
+ g_free (text);
+ gtk_label_set_text (GTK_LABEL (row->summary_label), gs_app_review_get_summary (row->review));
+ gtk_label_set_text (GTK_LABEL (row->text_label), gs_app_review_get_text (row->review));
+}
+
+static gboolean
+gs_app_review_row_refresh_idle (gpointer user_data)
+{
+ GsAppReviewRow *row = GS_APP_REVIEW_ROW (user_data);
+
+ gs_app_review_row_refresh (row);
+
+ g_object_unref (row);
+ return G_SOURCE_REMOVE;
+}
+
+static void
+gs_app_review_row_notify_props_changed_cb (GsApp *app,
+ GParamSpec *pspec,
+ GsAppReviewRow *row)
+{
+ g_idle_add (gs_app_review_row_refresh_idle, g_object_ref (row));
+}
+
+static void
+gs_app_review_row_set_review (GsAppReviewRow *row, GsAppReview *review)
+{
+ row->review = g_object_ref (review);
+
+ g_signal_connect_object (row->review, "notify::state",
+ G_CALLBACK (gs_app_review_row_notify_props_changed_cb),
+ row, 0);
+ gs_app_review_row_refresh (row);
+}
+
+static void
+gs_app_review_row_init (GsAppReviewRow *row)
+{
+ gtk_widget_set_has_window (GTK_WIDGET (row), FALSE);
+ gtk_widget_init_template (GTK_WIDGET (row));
+}
+
+static void
+gs_app_review_row_dispose (GObject *object)
+{
+ GsAppReviewRow *row = GS_APP_REVIEW_ROW (object);
+
+ g_clear_object (&row->review);
+
+ G_OBJECT_CLASS (gs_app_review_row_parent_class)->dispose (object);
+}
+
+static void
+gs_app_review_row_class_init (GsAppReviewRowClass *klass)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+ GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
+
+ object_class->dispose = gs_app_review_row_dispose;
+
+ gtk_widget_class_set_template_from_resource (widget_class,
"/org/gnome/Software/gs-app-review-row.ui");
+
+ gtk_widget_class_bind_template_child (widget_class, GsAppReviewRow, stars);
+ gtk_widget_class_bind_template_child (widget_class, GsAppReviewRow, summary_label);
+ gtk_widget_class_bind_template_child (widget_class, GsAppReviewRow, author_label);
+ gtk_widget_class_bind_template_child (widget_class, GsAppReviewRow, text_label);
+}
+
+/**
+ * gs_app_review_row_new:
+ * @review: The review to show
+ *
+ * Create a widget suitable for showing an application review.
+ *
+ * Return value: A new @GsAppReviewRow.
+ **/
+GtkWidget *
+gs_app_review_row_new (GsAppReview *review)
+{
+ GtkWidget *row;
+
+ g_return_val_if_fail (GS_IS_APP_REVIEW (review), NULL);
+
+ row = g_object_new (GS_TYPE_APP_REVIEW_ROW, NULL);
+ gs_app_review_row_set_review (GS_APP_REVIEW_ROW (row), review);
+
+ return row;
+}
+
+/* vim: set noexpandtab: */
diff --git a/src/gs-app-reviews.h b/src/gs-app-review-row.h
similarity index 75%
rename from src/gs-app-reviews.h
rename to src/gs-app-review-row.h
index b0d0dfd..abff670 100644
--- a/src/gs-app-reviews.h
+++ b/src/gs-app-review-row.h
@@ -19,22 +19,23 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
-#ifndef __GS_APP_REVIEWS_H
-#define __GS_APP_REVIEWS_H
+#ifndef GS_APP_REVIEW_ROW_H
+#define GS_APP_REVIEW_ROW_H
+
+#include <gtk/gtk.h>
-#include <glib-object.h>
#include "gs-app-review.h"
G_BEGIN_DECLS
-#define GS_TYPE_APP_REVIEWS (gs_app_reviews_get_type ())
+#define GS_TYPE_APP_REVIEW_ROW (gs_app_review_row_get_type ())
-G_DECLARE_FINAL_TYPE (GsAppReviews, gs_app_reviews, GS, APP_REVIEWS, GObject)
+G_DECLARE_FINAL_TYPE (GsAppReviewRow, gs_app_review_row, GS, APP_REVIEW_ROW, GtkListBoxRow)
-GsAppReviews *gs_app_reviews_new (void);
+GtkWidget *gs_app_review_row_new (GsAppReview *review);
G_END_DECLS
-#endif /* __GS_APP_REVIEWS_H */
+#endif /* GS_APP_REVIEW_ROW_H */
/* vim: set noexpandtab: */
diff --git a/src/gs-review-widget.ui b/src/gs-app-review-row.ui
similarity index 97%
rename from src/gs-review-widget.ui
rename to src/gs-app-review-row.ui
index 3043825..179d2fa 100644
--- a/src/gs-review-widget.ui
+++ b/src/gs-app-review-row.ui
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<interface>
<!-- interface-requires gtk+ 3.10 -->
- <template class="GsReviewWidget" parent="GtkBin">
+ <template class="GsReviewWidget" parent="GtkListBoxRow">
<property name="visible">True</property>
<child>
<object class="GtkGrid" id="grid">
diff --git a/src/gs-app-review.c b/src/gs-app-review.c
index d8081f5..fb27c1d 100644
--- a/src/gs-app-review.c
+++ b/src/gs-app-review.c
@@ -32,7 +32,7 @@ struct _GsAppReview
gint rating;
gchar *version;
gchar *reviewer;
- guint64 date;
+ GDateTime *date;
};
enum {
@@ -155,7 +155,7 @@ gs_app_review_set_reviewer (GsAppReview *review, const gchar *reviewer)
/**
* gs_app_review_get_date:
**/
-guint64
+GDateTime *
gs_app_review_get_date (GsAppReview *review)
{
g_return_val_if_fail (GS_IS_APP_REVIEW (review), 0);
@@ -166,10 +166,11 @@ gs_app_review_get_date (GsAppReview *review)
* gs_app_review_set_date:
*/
void
-gs_app_review_set_date (GsAppReview *review, guint64 date)
+gs_app_review_set_date (GsAppReview *review, GDateTime *date)
{
g_return_if_fail (GS_IS_APP_REVIEW (review));
- review->date = date;
+ g_clear_pointer (&review->date, g_date_time_unref);
+ review->date = g_date_time_ref (date);
}
/**
@@ -197,7 +198,7 @@ gs_app_review_get_property (GObject *object, guint prop_id, GValue *value, GPara
g_value_set_string (value, review->reviewer);
break;
case PROP_DATE:
- g_value_set_uint64 (value, review->rating);
+ g_value_set_object (value, review->date);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
@@ -230,7 +231,7 @@ gs_app_review_set_property (GObject *object, guint prop_id, const GValue *value,
gs_app_review_set_reviewer (review, g_value_get_string (value));
break;
case PROP_DATE:
- gs_app_review_set_date (review, g_value_get_uint64 (value));
+ gs_app_review_set_date (review, g_value_get_object (value));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
@@ -238,10 +239,16 @@ gs_app_review_set_property (GObject *object, guint prop_id, const GValue *value,
}
}
-/**
- * gs_app_review_finalize:
- * @object: The object to finalize
- **/
+static void
+gs_app_review_dispose (GObject *object)
+{
+ GsAppReview *review = GS_APP_REVIEW (object);
+
+ g_clear_pointer (&review->date, g_date_time_unref);
+
+ G_OBJECT_CLASS (gs_app_review_parent_class)->dispose (object);
+}
+
static void
gs_app_review_finalize (GObject *object)
{
@@ -254,15 +261,12 @@ gs_app_review_finalize (GObject *object)
G_OBJECT_CLASS (gs_app_review_parent_class)->finalize (object);
}
-/**
- * gs_app_review_class_init:
- * @klass: The GsAppReviewClass
- **/
static void
gs_app_review_class_init (GsAppReviewClass *klass)
{
GParamSpec *pspec;
GObjectClass *object_class = G_OBJECT_CLASS (klass);
+ object_class->dispose = gs_app_review_dispose;
object_class->finalize = gs_app_review_finalize;
object_class->get_property = gs_app_review_get_property;
object_class->set_property = gs_app_review_set_property;
@@ -311,8 +315,8 @@ gs_app_review_class_init (GsAppReviewClass *klass)
/**
* GsApp:date:
*/
- pspec = g_param_spec_uint64 ("date", NULL, NULL,
- 0, G_MAXUINT64, 0,
+ pspec = g_param_spec_object ("date", NULL, NULL,
+ GS_TYPE_APP_REVIEW,
G_PARAM_READWRITE | G_PARAM_CONSTRUCT);
g_object_class_install_property (object_class, PROP_DATE, pspec);
}
diff --git a/src/gs-app-review.h b/src/gs-app-review.h
index e9e2566..2b1f1bd 100644
--- a/src/gs-app-review.h
+++ b/src/gs-app-review.h
@@ -41,7 +41,7 @@ const gchar *gs_app_review_get_text (GsAppReview *review);
void gs_app_review_set_text (GsAppReview *review,
const gchar *text);
-gint gs_app_review_get_rating (GsAppReview *review);
+gint gs_app_review_get_rating (GsAppReview *review);
void gs_app_review_set_rating (GsAppReview *review,
gint rating);
@@ -53,9 +53,9 @@ const gchar *gs_app_review_get_reviewer (GsAppReview *review);
void gs_app_review_set_reviewer (GsAppReview *review,
const gchar *reviewer);
-guint64 gs_app_review_get_date (GsAppReview *review);
+GDateTime *gs_app_review_get_date (GsAppReview *review);
void gs_app_review_set_date (GsAppReview *review,
- guint64 date);
+ GDateTime *date);
void gs_app_review_set_is_useful (GsAppReview *review,
gboolean is_useful);
diff --git a/src/gs-shell-details.c b/src/gs-shell-details.c
index 7e1982f..c1d7b45 100644
--- a/src/gs-shell-details.c
+++ b/src/gs-shell-details.c
@@ -955,6 +955,29 @@ gs_shell_details_refresh_addons (GsShellDetails *self)
G_CALLBACK (gs_shell_details_addon_selected_cb),
self);
}
+
+}
+
+static void
+gs_shell_details_refresh_reviews (GsShellDetails *self)
+{
+ GPtrArray *reviews;
+ guint i;
+
+ gs_container_remove_all (GTK_CONTAINER (self->list_box_reviews));
+
+ reviews = gs_app_get_reviews (self->app);
+ for (i = 0; i < reviews->len; i++) {
+ GsAppReview *review;
+ GtkWidget *row;
+
+ review = g_ptr_array_index (reviews, i);
+
+ row = gs_app_review_row_new (review);
+
+ gtk_container_add (GTK_CONTAINER (self->list_box_reviews), row);
+ gtk_widget_show (row);
+ }
}
static void gs_shell_details_refresh_reviews (GsShellDetails *self);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]