diff options
author | Richard Hughes <richard@hughsie.com> | 2016-09-21 08:05:06 +0100 |
---|---|---|
committer | Richard Hughes <richard@hughsie.com> | 2016-09-21 08:05:09 +0100 |
commit | e4e38f9788da6bf88607660f48df0038cc13b56e (patch) | |
tree | 2db7d12b1deb69d85dfd22309bf082358f6d2512 | |
parent | fcb2bd867482ada4bf967652e11e722b04792ece (diff) | |
download | appstream-glib-e4e38f9788da6bf88607660f48df0038cc13b56e.tar.gz |
Add as_content_rating_get_value()
This allows us to get the specific enumerated value for a classification ID
which we can use in gnome-software to explain the rating to the user.
-rw-r--r-- | libappstream-glib/as-content-rating.c | 24 | ||||
-rw-r--r-- | libappstream-glib/as-content-rating.h | 2 | ||||
-rw-r--r-- | libappstream-glib/as-self-test.c | 6 |
3 files changed, 32 insertions, 0 deletions
diff --git a/libappstream-glib/as-content-rating.c b/libappstream-glib/as-content-rating.c index 6ec9cfd..488fdc9 100644 --- a/libappstream-glib/as-content-rating.c +++ b/libappstream-glib/as-content-rating.c @@ -85,6 +85,30 @@ as_content_rating_class_init (AsContentRatingClass *klass) } /** + * as_content_rating_get_value: + * @content_rating: a #AsContentRating + * @id: A ratings ID, e.g. `violence-bloodshed`. + * + * Gets the set value of a content rating key. + * + * Returns: the #AsContentRatingValue, or %AS_CONTENT_RATING_VALUE_UNKNOWN + * + * Since: 0.6.4 + **/ +AsContentRatingValue +as_content_rating_get_value (AsContentRating *content_rating, const gchar *id) +{ + AsContentRatingPrivate *priv = GET_PRIVATE (content_rating); + guint i; + for (i = 0; i < priv->keys->len; i++) { + AsContentRatingKey *key = g_ptr_array_index (priv->keys, i); + if (g_strcmp0 (key->id, id) == 0) + return key->value; + } + return AS_CONTENT_RATING_VALUE_UNKNOWN; +} + +/** * as_content_rating_value_to_string: * @value: the #AsContentRatingValue. * diff --git a/libappstream-glib/as-content-rating.h b/libappstream-glib/as-content-rating.h index ba5ed1a..2c4117e 100644 --- a/libappstream-glib/as-content-rating.h +++ b/libappstream-glib/as-content-rating.h @@ -76,6 +76,8 @@ AsContentRatingValue as_content_rating_value_from_string (const gchar *value); /* getters */ 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); /* setters */ void as_content_rating_set_kind (AsContentRating *content_rating, diff --git a/libappstream-glib/as-self-test.c b/libappstream-glib/as-self-test.c index 892ad28..5aff325 100644 --- a/libappstream-glib/as-self-test.c +++ b/libappstream-glib/as-self-test.c @@ -1465,6 +1465,12 @@ as_test_content_rating_func (void) /* verify */ g_assert_cmpstr (as_content_rating_get_kind (content_rating), ==, "oars-1.0"); + g_assert_cmpint (as_content_rating_get_value (content_rating, "drugs-alcohol"), ==, + AS_CONTENT_RATING_VALUE_MODERATE); + g_assert_cmpint (as_content_rating_get_value (content_rating, "violence-cartoon"), ==, + AS_CONTENT_RATING_VALUE_MILD); + g_assert_cmpint (as_content_rating_get_value (content_rating, "violence-bloodshed"), ==, + AS_CONTENT_RATING_VALUE_UNKNOWN); as_node_unref (root); /* check CSM */ |