summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRichard Hughes <richard@hughsie.com>2018-10-04 13:44:06 +0100
committerRichard Hughes <richard@hughsie.com>2018-10-04 13:44:06 +0100
commit55e1a51e19119e9b175b7e30c8d43279ff4c301e (patch)
tree07879b4d7d130c9841f79e3d6cbcb677a34be06a
parent5e6e49d3c76b71dc329903b2624850e2e7c26747 (diff)
downloadappstream-glib-55e1a51e19119e9b175b7e30c8d43279ff4c301e.tar.gz
Add as_content_rating_add_attribute()
This allows us to contruct a AsContentRating without using XML.
-rw-r--r--libappstream-glib/as-content-rating.c28
-rw-r--r--libappstream-glib/as-content-rating.h3
2 files changed, 30 insertions, 1 deletions
diff --git a/libappstream-glib/as-content-rating.c b/libappstream-glib/as-content-rating.c
index eb3afae..170b40d 100644
--- a/libappstream-glib/as-content-rating.c
+++ b/libappstream-glib/as-content-rating.c
@@ -410,6 +410,33 @@ as_content_rating_node_insert (AsContentRating *content_rating,
}
/**
+ * as_content_rating_add_attribute:
+ * @content_rating: a #AsContentRating instance.
+ * @id: a content rating ID, e.g. `money-gambling`.
+ * @value: a #AsContentRatingValue, e.g. %AS_CONTENT_RATING_VALUE_MODERATE.
+ *
+ * Adds an attribute value to the content rating.
+ *
+ * Since: 0.7.14
+ **/
+void
+as_content_rating_add_attribute (AsContentRating *content_rating,
+ const gchar *id,
+ AsContentRatingValue value)
+{
+ AsContentRatingKey *key = g_slice_new0 (AsContentRatingKey);
+ AsContentRatingPrivate *priv = GET_PRIVATE (content_rating);
+
+ g_return_if_fail (AS_IS_CONTENT_RATING (content_rating));
+ g_return_if_fail (id != NULL);
+ g_return_if_fail (value != AS_CONTENT_RATING_VALUE_UNKNOWN);
+
+ key->id = as_ref_string_new (id);
+ key->value = value;
+ g_ptr_array_add (priv->keys, key);
+}
+
+/**
* as_content_rating_node_parse:
* @content_rating: a #AsContentRating instance.
* @node: a #GNode.
@@ -441,7 +468,6 @@ as_content_rating_node_parse (AsContentRating *content_rating, GNode *node,
/* get keys */
for (c = node->children; c != NULL; c = c->next) {
AsContentRatingKey *key;
- g_autoptr(AsImage) image = NULL;
if (as_node_get_tag (c) != AS_TAG_CONTENT_ATTRIBUTE)
continue;
key = g_slice_new0 (AsContentRatingKey);
diff --git a/libappstream-glib/as-content-rating.h b/libappstream-glib/as-content-rating.h
index 2c4117e..0c6396c 100644
--- a/libappstream-glib/as-content-rating.h
+++ b/libappstream-glib/as-content-rating.h
@@ -78,6 +78,9 @@ const gchar *as_content_rating_get_kind (AsContentRating *content_rating);
guint as_content_rating_get_minimum_age (AsContentRating *content_rating);
AsContentRatingValue as_content_rating_get_value (AsContentRating *content_rating,
const gchar *id);
+void as_content_rating_add_attribute(AsContentRating *content_rating,
+ const gchar *id,
+ AsContentRatingValue value);
/* setters */
void as_content_rating_set_kind (AsContentRating *content_rating,