summaryrefslogtreecommitdiff
path: root/libappstream-glib/as-app.c
diff options
context:
space:
mode:
authorRichard Hughes <richard@hughsie.com>2016-07-19 15:48:08 +0100
committerRichard Hughes <richard@hughsie.com>2016-07-20 11:37:52 +0100
commit90a9dda7c47a1b67dd17ef78ee77ebed5bb2c740 (patch)
tree95a59bda212e266a8dedf33de22ed024f5aa831b /libappstream-glib/as-app.c
parentaccf6cd614f1be1dec2963f72f0a419a48de69f9 (diff)
downloadappstream-glib-90a9dda7c47a1b67dd17ef78ee77ebed5bb2c740.tar.gz
This allows us to represent an end-user application review.
Diffstat (limited to 'libappstream-glib/as-app.c')
-rw-r--r--libappstream-glib/as-app.c90
1 files changed, 90 insertions, 0 deletions
diff --git a/libappstream-glib/as-app.c b/libappstream-glib/as-app.c
index dbb4f91..0765d54 100644
--- a/libappstream-glib/as-app.c
+++ b/libappstream-glib/as-app.c
@@ -45,6 +45,7 @@
#include "as-node-private.h"
#include "as-provide-private.h"
#include "as-release-private.h"
+#include "as-review-private.h"
#include "as-screenshot-private.h"
#include "as-stemmer.h"
#include "as-tag.h"
@@ -78,6 +79,7 @@ typedef struct
GPtrArray *releases; /* of AsRelease */
GPtrArray *provides; /* of AsProvide */
GPtrArray *screenshots; /* of AsScreenshot */
+ GPtrArray *reviews; /* of AsReview */
GPtrArray *content_ratings; /* of AsContentRating */
GPtrArray *icons; /* of AsIcon */
GPtrArray *bundles; /* of AsBundle */
@@ -391,6 +393,7 @@ as_app_finalize (GObject *object)
g_ptr_array_unref (priv->releases);
g_ptr_array_unref (priv->provides);
g_ptr_array_unref (priv->screenshots);
+ g_ptr_array_unref (priv->reviews);
g_ptr_array_unref (priv->icons);
g_ptr_array_unref (priv->bundles);
g_ptr_array_unref (priv->translations);
@@ -419,6 +422,7 @@ as_app_init (AsApp *app)
priv->releases = g_ptr_array_new_with_free_func ((GDestroyNotify) g_object_unref);
priv->provides = g_ptr_array_new_with_free_func ((GDestroyNotify) g_object_unref);
priv->screenshots = g_ptr_array_new_with_free_func ((GDestroyNotify) g_object_unref);
+ priv->reviews = g_ptr_array_new_with_free_func ((GDestroyNotify) g_object_unref);
priv->icons = g_ptr_array_new_with_free_func ((GDestroyNotify) g_object_unref);
priv->bundles = g_ptr_array_new_with_free_func ((GDestroyNotify) g_object_unref);
priv->translations = g_ptr_array_new_with_free_func ((GDestroyNotify) g_object_unref);
@@ -841,6 +845,23 @@ as_app_get_screenshots (AsApp *app)
}
/**
+ * as_app_get_reviews:
+ * @app: a #AsApp instance.
+ *
+ * Gets any reviews the application has defined.
+ *
+ * Returns: (element-type AsScreenshot) (transfer none): an array
+ *
+ * Since: 0.5.18
+ **/
+GPtrArray *
+as_app_get_reviews (AsApp *app)
+{
+ AsAppPrivate *priv = GET_PRIVATE (app);
+ return priv->reviews;
+}
+
+/**
* as_app_get_content_ratings:
* @app: a #AsApp instance.
*
@@ -2550,6 +2571,33 @@ as_app_add_screenshot (AsApp *app, AsScreenshot *screenshot)
}
/**
+ * as_app_add_review:
+ * @app: a #AsApp instance.
+ * @review: a #AsReview instance.
+ *
+ * Adds a review to an application.
+ *
+ * Since: 0.5.18
+ **/
+void
+as_app_add_review (AsApp *app, AsReview *review)
+{
+ AsAppPrivate *priv = GET_PRIVATE (app);
+ AsReview *review_tmp;
+ guint i;
+
+ /* handle untrusted */
+ if ((priv->trust_flags & AS_APP_TRUST_FLAG_CHECK_DUPLICATES) > 0) {
+ for (i = 0; i < priv->reviews->len; i++) {
+ review_tmp = g_ptr_array_index (priv->reviews, i);
+ if (as_review_equal (review_tmp, review))
+ return;
+ }
+ }
+ g_ptr_array_add (priv->reviews, g_object_ref (review));
+}
+
+/**
* as_app_add_content_rating:
* @app: a #AsApp instance.
* @content_rating: a #AsContentRating instance.
@@ -2997,6 +3045,7 @@ as_app_subsume_private (AsApp *app, AsApp *donor, AsAppSubsumeFlags flags)
AsAppPrivate *papp = GET_PRIVATE (app);
AsBundle *bundle;
AsTranslation *translation;
+ AsReview *review;
AsScreenshot *ss;
AsProvide *pr;
const gchar *tmp;
@@ -3086,6 +3135,12 @@ as_app_subsume_private (AsApp *app, AsApp *donor, AsAppSubsumeFlags flags)
as_app_add_screenshot (app, ss);
}
+ /* reviews */
+ for (i = 0; i < priv->reviews->len; i++) {
+ review = g_ptr_array_index (priv->reviews, i);
+ as_app_add_review (app, review);
+ }
+
/* content_ratings */
for (i = 0; i < priv->content_ratings->len; i++) {
AsContentRating *content_rating;
@@ -3546,6 +3601,16 @@ as_app_node_insert (AsApp *app, GNode *parent, AsNodeContext *ctx)
}
}
+ /* <reviews> */
+ if (priv->reviews->len > 0) {
+ AsReview *review;
+ node_tmp = as_node_insert (node_app, "reviews", NULL, 0, NULL);
+ for (i = 0; i < priv->reviews->len; i++) {
+ review = g_ptr_array_index (priv->reviews, i);
+ as_review_node_insert (review, node_tmp, ctx);
+ }
+ }
+
/* <content_ratings> */
if (priv->content_ratings->len > 0) {
for (i = 0; i < priv->content_ratings->len; i++) {
@@ -3923,6 +3988,21 @@ as_app_node_parse_child (AsApp *app, GNode *n, AsAppParseFlags flags,
}
break;
+ /* <reviews> */
+ case AS_TAG_REVIEWS:
+ if (!(flags & AS_APP_PARSE_FLAG_APPEND_DATA))
+ g_ptr_array_set_size (priv->reviews, 0);
+ for (c = n->children; c != NULL; c = c->next) {
+ g_autoptr(AsReview) review = NULL;
+ if (as_node_get_tag (c) != AS_TAG_REVIEW)
+ continue;
+ review = as_review_new ();
+ if (!as_review_node_parse (review, c, ctx, error))
+ return FALSE;
+ as_app_add_review (app, review);
+ }
+ break;
+
/* <content_ratings> */
case AS_TAG_CONTENT_RATING:
{
@@ -4328,6 +4408,16 @@ as_app_node_parse_dep11 (AsApp *app, GNode *node,
}
continue;
}
+ if (g_strcmp0 (tmp, "Reviews") == 0) {
+ for (c = n->children; c != NULL; c = c->next) {
+ g_autoptr(AsReview) review = NULL;
+ review = as_review_new ();
+ if (!as_review_node_parse_dep11 (review, c, ctx, error))
+ return FALSE;
+ as_app_add_review (app, review);
+ }
+ continue;
+ }
if (g_strcmp0 (tmp, "Extends") == 0) {
for (c = n->children; c != NULL; c = c->next)
as_app_add_extends (app, as_yaml_node_get_key (c));