From 6479ed4914013bc196f8df38214e164da9f34149 Mon Sep 17 00:00:00 2001 From: Philip Withnall Date: Mon, 21 Jan 2019 19:38:04 +0000 Subject: as-content-rating: Add a helper function to get OARS IDs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This just exposes the list of valid OARS IDs, so callers don’t have to keep a copy themselves. Signed-off-by: Philip Withnall https://github.com/hughsie/appstream-glib/issues/280 --- libappstream-glib/as-content-rating.c | 24 ++++++++++++++++++++++++ libappstream-glib/as-content-rating.h | 1 + 2 files changed, 25 insertions(+) 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 @@ -292,6 +292,30 @@ as_content_rating_attribute_to_csm_age (const gchar *id, AsContentRatingValue va return 0; } +/** + * 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, -- cgit v1.2.1