summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPhilip Withnall <withnall@endlessm.com>2019-01-21 19:38:04 +0000
committerRichard Hughes <richard@hughsie.com>2019-01-23 15:56:25 +0000
commit6479ed4914013bc196f8df38214e164da9f34149 (patch)
tree2a47fe7195f68ca3a5fbba3550002b2de1f666c7
parent3f3b9b77fc9e592a2226718b2e2edc49c7ff8923 (diff)
downloadappstream-glib-6479ed4914013bc196f8df38214e164da9f34149.tar.gz
as-content-rating: Add a helper function to get OARS IDs
This just exposes the list of valid OARS IDs, so callers don’t have to keep a copy themselves. Signed-off-by: Philip Withnall <withnall@endlessm.com> https://github.com/hughsie/appstream-glib/issues/280
-rw-r--r--libappstream-glib/as-content-rating.c24
-rw-r--r--libappstream-glib/as-content-rating.h1
2 files changed, 25 insertions, 0 deletions
diff --git a/libappstream-glib/as-content-rating.c b/libappstream-glib/as-content-rating.c
index 02fb3d0..059a625 100644
--- a/libappstream-glib/as-content-rating.c
+++ b/libappstream-glib/as-content-rating.c
@@ -293,6 +293,30 @@ as_content_rating_attribute_to_csm_age (const gchar *id, AsContentRatingValue va
}
/**
+ * as_content_rating_get_all_rating_ids:
+ *
+ * Returns a list of all the valid OARS content rating attribute IDs as could
+ * be passed to as_content_rating_add_attribute() or
+ * as_content_rating_attribute_to_csm_age().
+ *
+ * Returns: (array zero-terminated=1) (transfer container): a %NULL-terminated
+ * array of IDs, to be freed with g_free() (the element values are owned by
+ * libappstream-glib and must not be freed)
+ * Since: 0.7.15
+ */
+const gchar **
+as_content_rating_get_all_rating_ids (void)
+{
+ g_autofree const gchar **ids = NULL;
+
+ ids = g_new0 (const gchar *, G_N_ELEMENTS (oars_to_csm_mappings) + 1 /* NULL terminator */);
+ for (gsize i = 0; i < G_N_ELEMENTS (oars_to_csm_mappings); i++)
+ ids[i] = oars_to_csm_mappings[i].id;
+
+ return g_steal_pointer (&ids);
+}
+
+/**
* as_content_rating_get_minimum_age:
* @content_rating: a #AsContentRating
*
diff --git a/libappstream-glib/as-content-rating.h b/libappstream-glib/as-content-rating.h
index 8ba3d7c..f9bcb8b 100644
--- a/libappstream-glib/as-content-rating.h
+++ b/libappstream-glib/as-content-rating.h
@@ -86,6 +86,7 @@ const gchar **as_content_rating_get_rating_ids (AsContentRating *content_rating)
guint as_content_rating_attribute_to_csm_age (const gchar *id,
AsContentRatingValue value);
+const gchar **as_content_rating_get_all_rating_ids (void);
/* setters */
void as_content_rating_set_kind (AsContentRating *content_rating,