[gnome-software/wip/rancell/reviews: 1/33] Add stub reviews API



commit 44284540322f694ad16601f31eedea8c1ed61ddb
Author: Robert Ancell <robert ancell canonical com>
Date:   Thu Oct 15 14:32:31 2015 +0100

    Add stub reviews API

 src/Makefile.am      |    4 +
 src/gs-app-review.c  |  342 ++++++++++++++++++++++++++++++++++++++++++++++++++
 src/gs-app-review.h  |   69 ++++++++++
 src/gs-app-reviews.c |   65 ++++++++++
 src/gs-app-reviews.h |   40 ++++++
 src/gs-app.c         |   25 ++++
 src/gs-app.h         |    5 +
 7 files changed, 550 insertions(+), 0 deletions(-)
---
diff --git a/src/Makefile.am b/src/Makefile.am
index a7df5b5..bf453ab 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -117,6 +117,10 @@ gnome_software_SOURCES =                           \
        gs-feature-tile.h                               \
        gs-category-tile.c                              \
        gs-category-tile.h                              \
+       gs-app-review.c                                 \
+       gs-app-review.h                                 \
+       gs-app-reviews.c                                \
+       gs-app-reviews.h                                \
        gs-app-tile.c                                   \
        gs-app-tile.h                                   \
        gs-app-folder-dialog.c                          \
diff --git a/src/gs-app-review.c b/src/gs-app-review.c
new file mode 100644
index 0000000..d8081f5
--- /dev/null
+++ b/src/gs-app-review.c
@@ -0,0 +1,342 @@
+/* -*- 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 "gs-app-review.h"
+
+struct _GsAppReview
+{
+       GObject                  parent_instance;
+
+       gchar                   *summary;
+       gchar                   *text;
+       gint                     rating;
+       gchar                   *version;
+       gchar                   *reviewer;
+       guint64                  date;  
+};
+
+enum {
+       PROP_0,
+       PROP_SUMMARY,
+       PROP_TEXT,
+       PROP_RATING,
+       PROP_VERSION,
+       PROP_REVIEWER,
+       PROP_DATE,
+       PROP_LAST
+};
+
+G_DEFINE_TYPE (GsAppReview, gs_app_review, G_TYPE_OBJECT)
+
+/**
+ * gs_app_review_get_summary:
+ **/
+const gchar *
+gs_app_review_get_summary (GsAppReview *review)
+{
+       g_return_val_if_fail (GS_IS_APP_REVIEW (review), NULL);
+       return review->summary;
+}
+
+/**
+ * gs_app_review_set_summary:
+ */
+void
+gs_app_review_set_summary (GsAppReview *review, const gchar *summary)
+{
+       g_return_if_fail (GS_IS_APP_REVIEW (review));
+       g_free (review->summary);
+       review->summary = g_strdup (summary);
+}
+
+/**
+ * gs_app_review_get_text:
+ **/
+const gchar *
+gs_app_review_get_text (GsAppReview *review)
+{
+       g_return_val_if_fail (GS_IS_APP_REVIEW (review), NULL);
+       return review->text;
+}
+
+/**
+ * gs_app_review_set_text:
+ */
+void
+gs_app_review_set_text (GsAppReview *review, const gchar *text)
+{
+       g_return_if_fail (GS_IS_APP_REVIEW (review));
+       g_free (review->text);
+       review->text = g_strdup (text);
+}
+
+/**
+ * gs_app_review_get_rating:
+ **/
+gint
+gs_app_review_get_rating (GsAppReview *review)
+{
+       g_return_val_if_fail (GS_IS_APP_REVIEW (review), -1);
+       return review->rating;
+}
+
+/**
+ * gs_app_review_set_rating:
+ */
+void
+gs_app_review_set_rating (GsAppReview *review, gint rating)
+{
+       g_return_if_fail (GS_IS_APP_REVIEW (review));
+       review->rating = rating;
+}
+
+/**
+ * gs_app_review_get_reviewer:
+ **/
+const gchar *
+gs_app_review_get_reviewer (GsAppReview *review)
+{
+       g_return_val_if_fail (GS_IS_APP_REVIEW (review), NULL);
+       return review->reviewer;
+}
+
+/**
+ * gs_app_review_set_version:
+ */
+void
+gs_app_review_set_version (GsAppReview *review, const gchar *version)
+{
+       g_return_if_fail (GS_IS_APP_REVIEW (review));
+       g_free (review->version);
+       review->version = g_strdup (version);
+}
+
+/**
+ * gs_app_review_get_version:
+ **/
+const gchar *
+gs_app_review_get_version (GsAppReview *review)
+{
+       g_return_val_if_fail (GS_IS_APP_REVIEW (review), NULL);
+       return review->version;
+}
+
+/**
+ * gs_app_review_set_reviewer:
+ */
+void
+gs_app_review_set_reviewer (GsAppReview *review, const gchar *reviewer)
+{
+       g_return_if_fail (GS_IS_APP_REVIEW (review));
+       g_free (review->reviewer);
+       review->reviewer = g_strdup (reviewer);
+}
+
+/**
+ * gs_app_review_get_date:
+ **/
+guint64
+gs_app_review_get_date (GsAppReview *review)
+{
+       g_return_val_if_fail (GS_IS_APP_REVIEW (review), 0);
+       return review->date;
+}
+
+/**
+ * gs_app_review_set_date:
+ */
+void
+gs_app_review_set_date (GsAppReview *review, guint64 date)
+{
+       g_return_if_fail (GS_IS_APP_REVIEW (review));
+       review->date = date;
+}
+
+/**
+ * gs_app_review_get_property:
+ */
+static void
+gs_app_review_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec)
+{
+       GsAppReview *review = GS_APP_REVIEW (object);
+
+       switch (prop_id) {
+       case PROP_SUMMARY:
+               g_value_set_string (value, review->summary);
+               break;
+       case PROP_TEXT:
+               g_value_set_string (value, review->text);
+               break;
+       case PROP_RATING:
+               g_value_set_int (value, review->rating);
+               break;
+       case PROP_VERSION:
+               g_value_set_string (value, review->version);
+               break;
+       case PROP_REVIEWER:
+               g_value_set_string (value, review->reviewer);
+               break;
+       case PROP_DATE:
+               g_value_set_uint64 (value, review->rating);
+               break;
+       default:
+               G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+               break;
+       }
+}
+
+/**
+ * gs_app_review_set_property:
+ */
+static void
+gs_app_review_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec)
+{
+       GsAppReview *review = GS_APP_REVIEW (object);
+
+       switch (prop_id) {
+       case PROP_SUMMARY:
+               gs_app_review_set_summary (review, g_value_get_string (value));
+               break;
+       case PROP_TEXT:
+               gs_app_review_set_text (review, g_value_get_string (value));
+               break;
+       case PROP_RATING:
+               gs_app_review_set_rating (review, g_value_get_int (value));
+               break;
+       case PROP_VERSION:
+               gs_app_review_set_version (review, g_value_get_string (value));
+               break;
+       case PROP_REVIEWER:
+               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));
+               break;
+       default:
+               G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+               break;
+       }
+}
+
+/**
+ * gs_app_review_finalize:
+ * @object: The object to finalize
+ **/
+static void
+gs_app_review_finalize (GObject *object)
+{
+       GsAppReview *review = GS_APP_REVIEW (object);
+
+       g_free (review->summary);
+       g_free (review->text);
+       g_free (review->reviewer);
+
+       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->finalize = gs_app_review_finalize;
+       object_class->get_property = gs_app_review_get_property;
+       object_class->set_property = gs_app_review_set_property;
+
+       /**
+        * GsApp:summary:
+        */
+       pspec = g_param_spec_string ("summary", NULL, NULL,
+                                    NULL,
+                                    G_PARAM_READWRITE | G_PARAM_CONSTRUCT);
+       g_object_class_install_property (object_class, PROP_SUMMARY, pspec);
+
+       /**
+        * GsApp:text:
+        */
+       pspec = g_param_spec_string ("text", NULL, NULL,
+                                    NULL,
+                                    G_PARAM_READWRITE | G_PARAM_CONSTRUCT);
+       g_object_class_install_property (object_class, PROP_TEXT, pspec);
+
+       /**
+        * GsApp:rating:
+        */
+       pspec = g_param_spec_int ("rating", NULL, NULL,
+                                 -1, 100, -1,
+                                 G_PARAM_READWRITE | G_PARAM_CONSTRUCT);
+       g_object_class_install_property (object_class, PROP_RATING, pspec);
+
+       /**
+        * GsApp:version:
+        */
+       pspec = g_param_spec_string ("version", NULL, NULL,
+                                    NULL,
+                                    G_PARAM_READWRITE | G_PARAM_CONSTRUCT);
+       g_object_class_install_property (object_class, PROP_VERSION, pspec);
+
+       /**
+        * GsApp:reviewer:
+        */
+       pspec = g_param_spec_string ("reviewer", NULL, NULL,
+                                    NULL,
+                                    G_PARAM_READWRITE | G_PARAM_CONSTRUCT);
+       g_object_class_install_property (object_class, PROP_REVIEWER, pspec);
+
+
+       /**
+        * GsApp:date:
+        */
+       pspec = g_param_spec_uint64 ("date", NULL, NULL,
+                                    0, G_MAXUINT64, 0,
+                                    G_PARAM_READWRITE | G_PARAM_CONSTRUCT);
+       g_object_class_install_property (object_class, PROP_DATE, pspec);
+}
+
+/**
+ * gs_app_review_init:
+ **/
+static void
+gs_app_review_init (GsAppReview *review)
+{
+       review->rating = -1;
+}
+
+/**
+ * gs_app_review_new:
+ *
+ * Return value: a new GsAppReview object.
+ **/
+GsAppReview *
+gs_app_review_new (void)
+{
+       GsAppReview *review;
+       review = g_object_new (GS_TYPE_APP_REVIEW, NULL);
+       return GS_APP_REVIEW (review);
+}
+
+/* vim: set noexpandtab: */
diff --git a/src/gs-app-review.h b/src/gs-app-review.h
new file mode 100644
index 0000000..65ad238
--- /dev/null
+++ b/src/gs-app-review.h
@@ -0,0 +1,69 @@
+/* -*- 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.
+ */
+
+#ifndef __GS_APP_REVIEW_H
+#define __GS_APP_REVIEW_H
+
+#include <glib-object.h>
+#include "gs-app-review.h"
+
+G_BEGIN_DECLS
+
+#define GS_TYPE_APP_REVIEW (gs_app_review_get_type ())
+
+G_DECLARE_FINAL_TYPE (GsAppReview, gs_app_review, GS, APP_REVIEW, GObject)
+
+GsAppReview    *gs_app_review_new                      (void);
+
+const gchar    *gs_app_review_get_summary                      (GsAppReview    *review);
+void            gs_app_review_set_summary                      (GsAppReview    *review,
+                                                const gchar    *summary);
+
+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);
+void            gs_app_review_set_rating                       (GsAppReview    *review,
+                                                gint   rating);
+
+const gchar    *gs_app_review_get_version                      (GsAppReview    *review);
+void            gs_app_review_set_version                      (GsAppReview    *review,
+                                                const gchar    *version);
+
+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);
+void            gs_app_review_set_date                 (GsAppReview    *review,
+                                                guint64        date);
+
+void            gs_app_review_set_is_useful                    (GsAppReview    *review,
+                                                gboolen        is_useful);
+
+void            gs_app_review_mark_innapropriate                       (GsAppReview    *review);
+
+G_END_DECLS
+
+#endif /* __GS_APP_REVIEW_H */
+
+/* vim: set noexpandtab: */
diff --git a/src/gs-app-reviews.c b/src/gs-app-reviews.c
new file mode 100644
index 0000000..7868285
--- /dev/null
+++ b/src/gs-app-reviews.c
@@ -0,0 +1,65 @@
+/* -*- 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 "gs-app-reviews.h"
+
+struct _GsAppReviews
+{
+       GObject                  parent_instance;
+};
+
+G_DEFINE_TYPE (GsAppReviews, gs_app_reviews, G_TYPE_OBJECT)
+
+/**
+ * gs_app_reviews_class_init:
+ * @klass: The GsAppReviewClass
+ **/
+static void
+gs_app_reviews_class_init (GsAppReviewClass *klass)
+{
+       GParamSpec *pspec;
+       GObjectClass *object_class = G_OBJECT_CLASS (klass);
+}
+
+/**
+ * gs_app_reviews_init:
+ **/
+static void
+gs_app_review_init (GsAppReviews *reviews)
+{
+}
+
+/**
+ * gs_app_reviews_new:
+ *
+ * Return value: a new GsAppReviews object.
+ **/
+GsAppReviews *
+gs_app_reviews_new (void)
+{
+       GsAppReview *reviews;
+       reviews = g_object_new (GS_TYPE_APP_REVIEWS, NULL);
+       return GS_APP_REVIEWS (reviews);
+}
+
+/* vim: set noexpandtab: */
diff --git a/src/gs-app-reviews.h b/src/gs-app-reviews.h
new file mode 100644
index 0000000..b0d0dfd
--- /dev/null
+++ b/src/gs-app-reviews.h
@@ -0,0 +1,40 @@
+/* -*- 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.
+ */
+
+#ifndef __GS_APP_REVIEWS_H
+#define __GS_APP_REVIEWS_H
+
+#include <glib-object.h>
+#include "gs-app-review.h"
+
+G_BEGIN_DECLS
+
+#define GS_TYPE_APP_REVIEWS (gs_app_reviews_get_type ())
+
+G_DECLARE_FINAL_TYPE (GsAppReviews, gs_app_reviews, GS, APP_REVIEWS, GObject)
+
+GsAppReviews   *gs_app_reviews_new                     (void);
+
+G_END_DECLS
+
+#endif /* __GS_APP_REVIEWS_H */
+
+/* vim: set noexpandtab: */
diff --git a/src/gs-app.c b/src/gs-app.c
index 21839c3..47bc3da 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;
+       GsAppReviews            *reviews;
        guint64                  size;
        GsAppKind                kind;
        AsIdKind                 id_kind;
@@ -289,6 +290,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->reviews != NULL)
+               g_string_append_printf (str, "\treviews:\t%p\n", app->reviews);
        if (app->pixbuf != NULL)
                g_string_append_printf (str, "\tpixbuf:\t%p\n", app->pixbuf);
        if (app->install_date != 0) {
@@ -1637,6 +1640,27 @@ gs_app_set_rating (GsApp *app, gint rating)
 }
 
 /**
+ * gs_app_get_reviews:
+ */
+GsAppReviews *
+gs_app_get_reviews (GsApp *app)
+{
+       g_return_val_if_fail (GS_IS_APP (app), NULL);
+       return app->reviews;
+}
+
+/**
+ * gs_app_set_reviews:
+ */
+void
+gs_app_set_reviews (GsApp *app, GsAppReviews *reviews)
+{
+       g_return_if_fail (GS_IS_APP (app));
+       g_clear_object (&app->reviews);
+       app->reviews = g_object_ref (reviews);
+}
+
+/**
  * gs_app_get_size:
  */
 guint64
@@ -2193,6 +2217,7 @@ gs_app_dispose (GObject *object)
        GsApp *app = GS_APP (object);
 
        g_clear_object (&app->icon);
+       g_clear_object (&app->reviews);
        g_clear_object (&app->pixbuf);
 
        g_clear_pointer (&app->addons, g_ptr_array_unref);
diff --git a/src/gs-app.h b/src/gs-app.h
index 4be59d8..fa9aaae 100644
--- a/src/gs-app.h
+++ b/src/gs-app.h
@@ -26,6 +26,8 @@
 #include <gdk-pixbuf/gdk-pixbuf.h>
 #include <appstream-glib.h>
 
+#include "gs-app-reviews.h"
+
 G_BEGIN_DECLS
 
 #define GS_TYPE_APP (gs_app_get_type ())
@@ -196,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);
+GsAppReviews   *gs_app_get_reviews             (GsApp          *app);
+void            gs_app_set_reviews             (GsApp          *app,
+                                                GsAppReviews   *reviews);
 guint64                 gs_app_get_size                (GsApp          *app);
 void            gs_app_set_size                (GsApp          *app,
                                                 guint64         size);


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