[gnome-software] Show application reviews in a row widget



commit 93ba24df8dbfc00b4ca5c0e0f81ee7d19b94b9e4
Author: Robert Ancell <robert ancell canonical com>
Date:   Tue Feb 9 09:58:13 2016 +0000

    Show application reviews in a row widget
    
    Signed-off-by: Richard Hughes <richard hughsie com>

 po/POTFILES.in                   |    2 +
 src/Makefile.am                  |    3 +
 src/gnome-software.gresource.xml |    1 +
 src/gs-review-row.c              |  142 ++++++++++++++++++++++++++++++++++++++
 src/gs-review-row.h              |   41 +++++++++++
 src/gs-review-row.ui             |   91 ++++++++++++++++++++++++
 6 files changed, 280 insertions(+), 0 deletions(-)
---
diff --git a/po/POTFILES.in b/po/POTFILES.in
index 56ea9e7..aba0a13 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -22,6 +22,8 @@ src/gs-main.c
 src/gs-page.c
 src/gs-plugin-loader.c
 src/gs-popular-tile.c
+src/gs-review-row.c
+[type: gettext/glade]src/gs-review-row.ui
 src/gs-screenshot-image.c
 src/gs-shell.c
 src/gs-shell-extras.c
diff --git a/src/Makefile.am b/src/Makefile.am
index fb54fba..74c3130 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -37,6 +37,7 @@ UI_FILES =                                            \
        gs-app-row.ui                                   \
        gs-first-run-dialog.ui                          \
        gs-history-dialog.ui                            \
+       gs-review-row.ui                                \
        gs-shell-category.ui                            \
        gs-shell-extras.ui                              \
        gs-shell-details.ui                             \
@@ -142,6 +143,8 @@ gnome_software_SOURCES =                            \
        gs-progress-button.h                            \
        gs-review.c                                     \
        gs-review.h                                     \
+       gs-review-row.c                                 \
+       gs-review-row.h                                 \
        gs-screenshot-image.c                           \
        gs-screenshot-image.h                           \
        gs-shell.c                                      \
diff --git a/src/gnome-software.gresource.xml b/src/gnome-software.gresource.xml
index a53ef00..746492d 100644
--- a/src/gnome-software.gresource.xml
+++ b/src/gnome-software.gresource.xml
@@ -13,6 +13,7 @@
   <file preprocess="xml-stripblanks">gs-app-row.ui</file>
   <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-row.ui</file>
   <file preprocess="xml-stripblanks">gs-shell-category.ui</file>
   <file preprocess="xml-stripblanks">gs-shell-extras.ui</file>
   <file preprocess="xml-stripblanks">gs-shell-details.ui</file>
diff --git a/src/gs-review-row.c b/src/gs-review-row.c
new file mode 100644
index 0000000..2dea624
--- /dev/null
+++ b/src/gs-review-row.c
@@ -0,0 +1,142 @@
+/* -*- 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-row.h"
+#include "gs-star-widget.h"
+
+struct _GsReviewRow
+{
+       GtkListBoxRow    parent_instance;
+
+       GsReview        *review;
+       GtkWidget       *stars;
+       GtkWidget       *summary_label;
+       GtkWidget       *author_label;
+       GtkWidget       *date_label;
+       GtkWidget       *text_label;
+};
+
+G_DEFINE_TYPE (GsReviewRow, gs_review_row, GTK_TYPE_LIST_BOX_ROW)
+
+static void
+gs_review_row_refresh (GsReviewRow *row)
+{
+       const gchar *reviewer;
+       GDateTime *date;
+       g_autofree gchar *text;
+
+       gs_star_widget_set_rating (GS_STAR_WIDGET (row->stars), gs_review_get_rating (row->review));
+       reviewer = gs_review_get_reviewer (row->review);
+       gtk_label_set_text (GTK_LABEL (row->author_label), reviewer ? reviewer : "");
+       date = gs_review_get_date (row->review);
+       if (date != NULL)
+               text = g_date_time_format (date, "%e %B %Y");
+       else
+               text = g_strdup ("");
+       gtk_label_set_text (GTK_LABEL (row->date_label), text);
+       gtk_label_set_text (GTK_LABEL (row->summary_label), gs_review_get_summary (row->review));
+       gtk_label_set_text (GTK_LABEL (row->text_label), gs_review_get_text (row->review));
+}
+
+static gboolean
+gs_review_row_refresh_idle (gpointer user_data)
+{
+       GsReviewRow *row = GS_REVIEW_ROW (user_data);
+
+       gs_review_row_refresh (row);
+
+       g_object_unref (row);
+       return G_SOURCE_REMOVE;
+}
+
+static void
+gs_review_row_notify_props_changed_cb (GsApp *app,
+                                      GParamSpec *pspec,
+                                      GsReviewRow *row)
+{
+       g_idle_add (gs_review_row_refresh_idle, g_object_ref (row));
+}
+
+static void
+gs_review_row_init (GsReviewRow *row)
+{
+       gtk_widget_set_has_window (GTK_WIDGET (row), FALSE);
+       gtk_widget_init_template (GTK_WIDGET (row));
+}
+
+static void
+gs_review_row_dispose (GObject *object)
+{
+       GsReviewRow *row = GS_REVIEW_ROW (object);
+
+       g_clear_object (&row->review);
+
+       G_OBJECT_CLASS (gs_review_row_parent_class)->dispose (object);
+}
+
+static void
+gs_review_row_class_init (GsReviewRowClass *klass)
+{
+       GObjectClass *object_class = G_OBJECT_CLASS (klass);
+       GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
+
+       object_class->dispose = gs_review_row_dispose;
+
+       gtk_widget_class_set_template_from_resource (widget_class, "/org/gnome/Software/gs-review-row.ui");
+
+       gtk_widget_class_bind_template_child (widget_class, GsReviewRow, stars);
+       gtk_widget_class_bind_template_child (widget_class, GsReviewRow, summary_label);
+       gtk_widget_class_bind_template_child (widget_class, GsReviewRow, author_label);
+       gtk_widget_class_bind_template_child (widget_class, GsReviewRow, date_label);
+       gtk_widget_class_bind_template_child (widget_class, GsReviewRow, text_label);
+}
+
+/**
+ * gs_review_row_new:
+ * @review: The review to show
+ *
+ * Create a widget suitable for showing an application review.
+ *
+ * Return value: A new @GsReviewRow.
+ **/
+GtkWidget *
+gs_review_row_new (GsReview *review)
+{
+       GsReviewRow *row;
+
+       g_return_val_if_fail (GS_IS_REVIEW (review), NULL);
+
+       row = g_object_new (GS_TYPE_REVIEW_ROW, NULL);
+       row->review = g_object_ref (review);
+       g_signal_connect_object (row->review, "notify::state",
+                                G_CALLBACK (gs_review_row_notify_props_changed_cb),
+                                row, 0);
+       gs_review_row_refresh (row);
+
+       return GTK_WIDGET (row);
+}
+
+/* vim: set noexpandtab: */
diff --git a/src/gs-review-row.h b/src/gs-review-row.h
new file mode 100644
index 0000000..3ed6aa7
--- /dev/null
+++ b/src/gs-review-row.h
@@ -0,0 +1,41 @@
+/* -*- 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_ROW_H
+#define GS_REVIEW_ROW_H
+
+#include <gtk/gtk.h>
+
+#include "gs-review.h"
+
+G_BEGIN_DECLS
+
+#define GS_TYPE_REVIEW_ROW (gs_review_row_get_type ())
+
+G_DECLARE_FINAL_TYPE (GsReviewRow, gs_review_row, GS, REVIEW_ROW, GtkListBoxRow)
+
+GtkWidget      *gs_review_row_new      (GsReview *review);
+
+G_END_DECLS
+
+#endif /* GS_REVIEW_ROW_H */
+
+/* vim: set noexpandtab: */
diff --git a/src/gs-review-row.ui b/src/gs-review-row.ui
new file mode 100644
index 0000000..4e281b4
--- /dev/null
+++ b/src/gs-review-row.ui
@@ -0,0 +1,91 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface>
+  <!-- interface-requires gtk+ 3.10 -->
+  <template class="GsReviewRow" parent="GtkListBoxRow">
+    <property name="visible">True</property>
+    <child>
+      <object class="GtkGrid" id="grid">
+        <property name="visible">True</property>
+        <property name="row-spacing">5</property>
+        <property name="column-spacing">10</property>
+        <property name="margin-top">20</property>
+        <property name="margin-bottom">20</property>
+        <child>
+          <object class="GsStarWidget" id="stars">
+            <property name="visible">True</property>
+            <property name="halign">start</property>
+            <property name="sensitive">False</property>
+          </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="summary_label">
+            <property name="visible">True</property>
+            <property name="expand">True</property>
+            <property name="halign">start</property>
+            <property name="ellipsize">end</property>
+            <style>
+              <class name="review-summary"/>
+            </style>
+          </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="GtkLabel" id="date_label">
+            <property name="visible">True</property>
+            <property name="halign">end</property>
+            <style>
+              <class name="dim-label"/>
+            </style>
+          </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="author_label">
+            <property name="visible">True</property>
+            <property name="halign">start</property>
+            <style>
+              <class name="dim-label"/>
+            </style>
+          </object>
+          <packing>
+            <property name="left-attach">0</property>
+            <property name="top-attach">1</property>
+            <property name="width">3</property>
+            <property name="height">1</property>
+          </packing>
+        </child>
+        <child>
+          <object class="GtkLabel" id="text_label">
+            <property name="visible">True</property>
+            <property name="halign">start</property>
+            <property name="wrap">True</property>
+            <property name="xalign">0</property>
+            <property name="margin-top">10</property>
+          </object>
+          <packing>
+            <property name="left-attach">0</property>
+            <property name="top-attach">2</property>
+            <property name="width">3</property>
+            <property name="height">1</property>
+          </packing>
+        </child>
+      </object>
+    </child>
+  </template>
+</interface>


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