diff --git a/libmalcontent-ui/gs-content-rating.c b/libmalcontent-ui/gs-content-rating.c index e7b0eea..bf18894 100644 --- a/libmalcontent-ui/gs-content-rating.c +++ b/libmalcontent-ui/gs-content-rating.c @@ -509,9 +509,16 @@ static guint content_rating_ages[GS_CONTENT_RATING_SYSTEM_LAST][7] = { }; const guint * -gs_utils_content_rating_get_ages (GsContentRatingSystem system) +gs_utils_content_rating_get_ages (GsContentRatingSystem system, gsize *length_out) { - g_assert (system < GS_CONTENT_RATING_SYSTEM_LAST); + g_return_val_if_fail ((int) system < GS_CONTENT_RATING_SYSTEM_LAST, NULL); + g_return_val_if_fail (length_out != NULL, NULL); + + /* IARC is the fallback for everything */ + if (system == GS_CONTENT_RATING_SYSTEM_UNKNOWN) + system = GS_CONTENT_RATING_SYSTEM_IARC; + + *length_out = g_strv_length ((gchar **) content_rating_strings[system]); return content_rating_ages[system]; } diff --git a/libmalcontent-ui/gs-content-rating.h b/libmalcontent-ui/gs-content-rating.h index 3b79460..59f5415 100644 --- a/libmalcontent-ui/gs-content-rating.h +++ b/libmalcontent-ui/gs-content-rating.h @@ -52,7 +52,7 @@ gchar *gs_utils_content_rating_age_to_str (GsContentRatingSystem system, GsContentRatingSystem gs_utils_content_rating_system_from_locale (const gchar *locale); const gchar *gs_content_rating_system_to_str (GsContentRatingSystem system); gchar **gs_utils_content_rating_get_values (GsContentRatingSystem system); -const guint *gs_utils_content_rating_get_ages (GsContentRatingSystem system); +const guint *gs_utils_content_rating_get_ages (GsContentRatingSystem system, gsize *length_out); guint as_content_rating_id_value_to_csm_age (const gchar *id, MctAppFilterOarsValue value); MctAppFilterOarsValue as_content_rating_id_csm_age_to_value (const gchar *id, guint age); diff --git a/libmalcontent-ui/user-controls.c b/libmalcontent-ui/user-controls.c index e1baf7b..84d0d13 100644 --- a/libmalcontent-ui/user-controls.c +++ b/libmalcontent-ui/user-controls.c @@ -319,7 +319,7 @@ update_categories_from_language (MctUserControls *self) g_auto(GStrv) entries = NULL; const gchar *rating_system_str; const guint *ages; - gsize i; + gsize i, n_ages; g_autofree gchar *disabled_action = NULL; rating_system = get_content_rating_system (self); @@ -328,7 +328,7 @@ update_categories_from_language (MctUserControls *self) g_debug ("Using rating system %s", rating_system_str); entries = gs_utils_content_rating_get_values (rating_system); - ages = gs_utils_content_rating_get_ages (rating_system); + ages = gs_utils_content_rating_get_ages (rating_system, &n_ages); /* Fill in the age menu */ g_menu_remove_all (self->age_menu); @@ -346,6 +346,8 @@ update_categories_from_language (MctUserControls *self) g_menu_append (self->age_menu, entries[i], action); } + + g_assert (i == n_ages); } /* Returns a human-readable but untranslated string, not suitable @@ -684,13 +686,14 @@ on_set_age_action_activated (GSimpleAction *action, const guint *ages; guint age; guint i; + gsize n_ages; self = MCT_USER_CONTROLS (user_data); age = g_variant_get_uint32 (param); rating_system = get_content_rating_system (self); entries = gs_utils_content_rating_get_values (rating_system); - ages = gs_utils_content_rating_get_ages (rating_system); + ages = gs_utils_content_rating_get_ages (rating_system, &n_ages); /* Update the button */ if (age == oars_disabled_age)