[gnome-software] gs-details-page: Rework age ratings handling to avoid hard-coded list
- From: Richard Hughes <rhughes src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-software] gs-details-page: Rework age ratings handling to avoid hard-coded list
- Date: Mon, 18 Nov 2019 14:11:04 +0000 (UTC)
commit 03c18196882844d74dba9c03cb0010b090bf7a9f
Author: Philip Withnall <withnall endlessm com>
Date: Tue Nov 12 13:30:27 2019 +0000
gs-details-page: Rework age ratings handling to avoid hard-coded list
The list of OARS categories in the code to build age ratings was not in
sync with the latest OARS release (v1.1). In particular, it was missing
`drugs-tobacco` from v1.0, and all of the categories from v1.1.
Fix that, and try to avoid it happening again in future, by querying
`gs-content-rating.c` for the list of categories, and only maintaining lists
of categories we want to group together in GNOME Software.
Signed-off-by: Philip Withnall <withnall endlessm com>
src/gs-details-page.c | 94 +++++++++++++++++++++++++++++----------------------
1 file changed, 54 insertions(+), 40 deletions(-)
---
diff --git a/src/gs-details-page.c b/src/gs-details-page.c
index 4d88fe88..b5da78b4 100644
--- a/src/gs-details-page.c
+++ b/src/gs-details-page.c
@@ -2297,59 +2297,73 @@ gs_details_page_content_rating_button_cb (GtkWidget *widget, GsDetailsPage *self
AsContentRating *cr;
AsContentRatingValue value_bad = AS_CONTENT_RATING_VALUE_NONE;
const gchar *tmp;
- guint i, j;
+ g_autofree const gchar **ids = NULL;
g_autoptr(GString) str = g_string_new (NULL);
- struct {
- const gchar *ids[5]; /* ordered inside from worst to best */
- } id_map[] = {
- {{"violence-bloodshed",
- "violence-realistic",
- "violence-fantasy",
- "violence-cartoon", NULL }},
- {{"violence-sexual", NULL }},
- {{"drugs-alcohol", NULL }},
- {{"drugs-narcotics", NULL }},
- {{"sex-nudity", NULL }},
- {{"sex-themes", NULL }},
- {{"language-profanity", NULL }},
- {{"language-humor", NULL }},
- {{"language-discrimination", NULL }},
- {{"money-advertising", NULL }},
- {{"money-gambling", NULL }},
- {{"money-purchasing", NULL }},
- {{"social-audio",
- "social-chat",
- "social-contacts",
- "social-info", NULL }},
- {{"social-location", NULL }},
- {{ NULL }}
+
+ /* Ordered from worst to best */
+ const gchar *violence_group[] = {
+ "violence-bloodshed",
+ "violence-realistic",
+ "violence-fantasy",
+ "violence-cartoon",
+ NULL
+ };
+ const gchar *social_group[] = {
+ "social-audio",
+ "social-chat",
+ "social-contacts",
+ "social-info",
+ NULL
};
- /* get the worst thing */
cr = gs_app_get_content_rating (self->app);
if (cr == NULL)
return;
- for (j = 0; id_map[j].ids[0] != NULL; j++) {
- for (i = 0; id_map[j].ids[i] != NULL; i++) {
- AsContentRatingValue value;
- value = as_content_rating_get_value (cr, id_map[j].ids[i]);
- if (value > value_bad)
- value_bad = value;
- }
- }
- /* get the content rating description for the worst things about the app */
- for (j = 0; id_map[j].ids[0] != NULL; j++) {
- for (i = 0; id_map[j].ids[i] != NULL; i++) {
+ ids = gs_content_rating_get_all_rating_ids ();
+
+ /* get the worst thing */
+ for (gsize i = 0; ids[i] != NULL; i++) {
+ AsContentRatingValue value;
+ value = as_content_rating_get_value (cr, ids[i]);
+ if (value > value_bad)
+ value_bad = value;
+ }
+
+ /* get the content rating description for the worst things about the app;
+ * handle the groups separately*/
+ for (gsize i = 0; ids[i] != NULL; i++) {
+ if (!g_strv_contains (violence_group, ids[i]) &&
+ !g_strv_contains (social_group, ids[i])) {
AsContentRatingValue value;
- value = as_content_rating_get_value (cr, id_map[j].ids[i]);
+ value = as_content_rating_get_value (cr, ids[i]);
if (value < value_bad)
continue;
- tmp = gs_content_rating_key_value_to_str (id_map[j].ids[i], value);
+ tmp = gs_content_rating_key_value_to_str (ids[i], value);
g_string_append_printf (str, "• %s\n", tmp);
- break;
}
}
+
+ for (gsize i = 0; violence_group[i] != NULL; i++) {
+ AsContentRatingValue value;
+ value = as_content_rating_get_value (cr, violence_group[i]);
+ if (value < value_bad)
+ continue;
+ tmp = gs_content_rating_key_value_to_str (violence_group[i], value);
+ g_string_append_printf (str, "• %s\n", tmp);
+ break;
+ }
+
+ for (gsize i = 0; social_group[i] != NULL; i++) {
+ AsContentRatingValue value;
+ value = as_content_rating_get_value (cr, social_group[i]);
+ if (value < value_bad)
+ continue;
+ tmp = gs_content_rating_key_value_to_str (social_group[i], value);
+ g_string_append_printf (str, "• %s\n", tmp);
+ break;
+ }
+
if (str->len > 0)
g_string_truncate (str, str->len - 1);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]