[gnome-software/wip/rancell/reviews] Improve review widget



commit 6c5ac5d11a3377e2bff1c30d8e5bb269feee6303
Author: Robert Ancell <robert ancell canonical com>
Date:   Wed Dec 16 11:36:40 2015 +1300

    Improve review widget

 src/gs-review-widget.c  |  112 ++++++++++++++++++++++++++++++++++++++++++++---
 src/gs-review-widget.h  |    4 ++
 src/gs-review-widget.ui |   13 +++++
 src/gtk-style-hc.css    |    4 ++
 src/gtk-style.css       |    4 ++
 5 files changed, 130 insertions(+), 7 deletions(-)
---
diff --git a/src/gs-review-widget.c b/src/gs-review-widget.c
index fe89fc5..55dde63 100644
--- a/src/gs-review-widget.c
+++ b/src/gs-review-widget.c
@@ -33,12 +33,18 @@ typedef struct
        GtkWidget       *summary_label;
        GtkWidget       *author_label;
        GtkWidget       *text_label;
+       gchar           *author;
+       GDateTime       *date;
 } GsReviewWidgetPrivate;
 
 G_DEFINE_TYPE_WITH_PRIVATE (GsReviewWidget, gs_review_widget, GTK_TYPE_BIN)
 
 /**
  * gs_review_widget_set_rating:
+ * @review: The review to update.
+ * @rating: The rating, from 0-100.
+ *
+ * Set the rating given in this review.
  **/
 void
 gs_review_widget_set_rating (GsReviewWidget *review, gint rating)
@@ -46,11 +52,72 @@ gs_review_widget_set_rating (GsReviewWidget *review, gint rating)
        GsReviewWidgetPrivate *priv;
        g_return_if_fail (GS_IS_REVIEW_WIDGET (review));
        priv = gs_review_widget_get_instance_private (review);
-       gs_star_widget_set_rating (GS_STAR_WIDGET (priv->stars), GS_APP_RATING_KIND_USER, rating);
+       gs_star_widget_set_rating (GS_STAR_WIDGET (priv->stars), GS_APP_RATING_KIND_SYSTEM, rating);
+}
+
+static void
+update_author_label (GsReviewWidget *review)
+{
+       GsReviewWidgetPrivate *priv = gs_review_widget_get_instance_private (review);
+       gchar *text;
+
+       if (priv->author && priv->date) {
+               gchar *date_text = g_date_time_format (priv->date, "%e %B %Y");
+               text = g_strdup_printf ("%s, %s", priv->author, date_text);
+               g_free (date_text);
+       }
+       else if (priv->author)
+               text = g_strdup (priv->author);
+       else if (priv->date)
+               text = g_date_time_format (priv->date, "%e %B %Y");
+       else
+               text = g_strdup ("");
+       gtk_label_set_text (GTK_LABEL (priv->author_label), text);
+       g_free (text);
+}
+
+/**
+ * gs_review_widget_set_author:
+ * @review: The review to update.
+ * @author: The author name.
+ *
+ * Set the author who wrote the review.
+ **/
+void
+gs_review_widget_set_author (GsReviewWidget *review, const gchar *author)
+{
+       GsReviewWidgetPrivate *priv;
+       g_return_if_fail (GS_IS_REVIEW_WIDGET (review));
+       priv = gs_review_widget_get_instance_private (review);
+       g_free (priv->author);
+       priv->author = g_strdup (author);
+       update_author_label (review);
+}
+
+/**
+ * gs_review_widget_set_date:
+ * @review: The review to update.
+ * @date: The review date.
+ *
+ * Set the date the review was created.
+ **/
+void
+gs_review_widget_set_date (GsReviewWidget *review, GDateTime *date)
+{
+       GsReviewWidgetPrivate *priv;
+       g_return_if_fail (GS_IS_REVIEW_WIDGET (review));
+       priv = gs_review_widget_get_instance_private (review);
+       g_clear_pointer (&priv->date, g_date_time_unref);
+       priv->date = g_date_time_ref (date);
+       update_author_label (review);
 }
 
 /**
  * gs_review_widget_set_summary:
+ * @review: The review to update.
+ * @summary: Review summary.
+ *
+ * Set the summary for the review, usually a short line, e.g. "This application is great".
  **/
 void
 gs_review_widget_set_summary (GsReviewWidget *review, const gchar *summary)
@@ -63,6 +130,13 @@ gs_review_widget_set_summary (GsReviewWidget *review, const gchar *summary)
 
 /**
  * gs_review_widget_set_text:
+ * @review: The review to update.
+ * @text: The review text.
+ *
+ * Set the text of the review, usually a paragraph or more describing this application. e.g.
+ * "This application is really useful for the problem I had.
+ * It has a number of great features that make it useful.
+ * I would recommend this to all my friends".
  **/
 void
 gs_review_widget_set_text (GsReviewWidget *review, const gchar *text)
@@ -73,9 +147,6 @@ gs_review_widget_set_text (GsReviewWidget *review, const gchar *text)
        gtk_label_set_text (GTK_LABEL (priv->text_label), text);
 }
 
-/**
- * gs_review_widget_init:
- **/
 static void
 gs_review_widget_init (GsReviewWidget *review)
 {
@@ -83,14 +154,37 @@ gs_review_widget_init (GsReviewWidget *review)
        gtk_widget_init_template (GTK_WIDGET (review));
 }
 
-/**
- * gs_review_widget_class_init:
- **/
+static void
+gs_review_widget_dispose (GObject *object)
+{
+       GsReviewWidget *review = GS_REVIEW_WIDGET (object);
+       GsReviewWidgetPrivate *priv = gs_review_widget_get_instance_private (review);
+
+       g_clear_pointer (&priv->date, g_date_time_unref);
+
+       G_OBJECT_CLASS (gs_review_widget_parent_class)->dispose (object);
+}
+
+static void
+gs_review_widget_finalize (GObject *object)
+{
+       GsReviewWidget *review = GS_REVIEW_WIDGET (object);
+       GsReviewWidgetPrivate *priv = gs_review_widget_get_instance_private (review);
+
+       g_free (priv->author);
+
+       G_OBJECT_CLASS (gs_review_widget_parent_class)->finalize (object);
+}
+
 static void
 gs_review_widget_class_init (GsReviewWidgetClass *klass)
 {
+       GObjectClass *object_class = G_OBJECT_CLASS (klass);
        GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
 
+       object_class->dispose = gs_review_widget_dispose;
+       object_class->finalize = gs_review_widget_finalize;
+
        gtk_widget_class_set_template_from_resource (widget_class, "/org/gnome/Software/gs-review-widget.ui");
 
        gtk_widget_class_bind_template_child_private (widget_class, GsReviewWidget, stars);
@@ -101,6 +195,10 @@ gs_review_widget_class_init (GsReviewWidgetClass *klass)
 
 /**
  * gs_review_widget_new:
+ *
+ * Create a widget suitable for showing an application review.
+ *
+ * Return value: A new @GsReviewWidget.
  **/
 GtkWidget *
 gs_review_widget_new (void)
diff --git a/src/gs-review-widget.h b/src/gs-review-widget.h
index 7a443d9..92bdfec 100644
--- a/src/gs-review-widget.h
+++ b/src/gs-review-widget.h
@@ -40,6 +40,10 @@ struct _GsReviewWidgetClass
 GtkWidget      *gs_review_widget_new                   (void);
 void            gs_review_widget_set_rating            (GsReviewWidget *review,
                                                         gint            rating);
+void            gs_review_widget_set_author            (GsReviewWidget *review,
+                                                        const gchar    *author);
+void            gs_review_widget_set_date              (GsReviewWidget *review,
+                                                        GDateTime      *date);
 void            gs_review_widget_set_summary           (GsReviewWidget *review,
                                                         const gchar    *summary);
 void            gs_review_widget_set_text              (GsReviewWidget *review,
diff --git a/src/gs-review-widget.ui b/src/gs-review-widget.ui
index b4929dd..3043825 100644
--- a/src/gs-review-widget.ui
+++ b/src/gs-review-widget.ui
@@ -6,10 +6,13 @@
     <child>
       <object class="GtkGrid" id="grid">
         <property name="visible">True</property>
+        <property name="row-spacing">12</property>
+        <property name="column-spacing">12</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>
@@ -21,6 +24,11 @@
         <child>
           <object class="GtkLabel" id="summary_label">
             <property name="visible">True</property>
+            <property name="expand">True</property>
+            <property name="halign">start</property>
+            <style>
+              <class name="review-summary"/>
+            </style>
           </object>
           <packing>
             <property name="left-attach">1</property>
@@ -32,6 +40,10 @@
         <child>
           <object class="GtkLabel" id="author_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>
@@ -43,6 +55,7 @@
         <child>
           <object class="GtkLabel" id="text_label">
             <property name="visible">True</property>
+            <property name="halign">start</property>
           </object>
           <packing>
             <property name="left-attach">0</property>
diff --git a/src/gtk-style-hc.css b/src/gtk-style-hc.css
index ccf4189..ceebcb3 100644
--- a/src/gtk-style-hc.css
+++ b/src/gtk-style-hc.css
@@ -96,6 +96,10 @@
        font-size: 14px;
 }
 
+.review-summary {
+       font-weight: bold;
+}
+
 .application-details-description {
 }
 
diff --git a/src/gtk-style.css b/src/gtk-style.css
index ad191a5..c8d0489 100644
--- a/src/gtk-style.css
+++ b/src/gtk-style.css
@@ -103,6 +103,10 @@
        font-size: 14px;
 }
 
+.review-summary {
+       font-weight: bold;
+}
+
 .error-label {
        text-shadow: none;
 }


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