[gnome-software: 3/4] gs-details-page: Decide which content rating IDs to show based on age




commit 55f7967eea4bc7122fb12e8d8a6d80562fa37482
Author: Philip Withnall <pwithnall endlessos org>
Date:   Mon Nov 2 16:26:49 2020 +0000

    gs-details-page: Decide which content rating IDs to show based on age
    
    Previously, the list of content rating IDs to highlight in the content
    rating popover would be decided by whichever ones had the highest value
    (intense, moderate, mild, none). However, it was possible for the CSM
    age corresponding to a certain (ID, value) pair to be higher than the
    age for a different ID with a higher value. This would result in a
    relevant ID being missed off the list.
    
    So convert the code to compare in terms of CSM ages, rather than the
    content rating values which they are mapped from.
    
    Continue checking for ‘none’ ratings using the `AsContentRatingValue`
    rather than the CSM age, as it’s possible for the CSM age for
    `AS_CONTENT_RATING_VALUE_NONE` to be >0.
    
    An example of an app whose list of relevant IDs changes with this commit
    is EDuke32, which goes from listing:
     * Rape or other violent sexual behavior
     * Prolonged nudity
     * Graphic sexual behavior
     * Strong or frequent use of profanity
     * Mature or sexual humour
     * Explicit discrimination based on gender, sexuality or religion
     * Graphic depictions of the act of prostitution
     * Overtly sexualised human characters
     * Depictions of bloodshed and the mutilation of body parts
     * Uncontrolled chat functionality between users
    to listing only the ‘worst’ of those:
     * Rape or other violent sexual behaviour
     * Graphic depictions of the act of prostitution
     * Depictions of bloodshed and the mutilation of body parts
    
    Spotted by Phaedrus Leeds.
    
    Signed-off-by: Philip Withnall <pwithnall endlessos org>

 src/gs-details-page.c | 43 ++++++++++++++++++++++++++++++-------------
 1 file changed, 30 insertions(+), 13 deletions(-)
---
diff --git a/src/gs-details-page.c b/src/gs-details-page.c
index babd554b..03263d69 100644
--- a/src/gs-details-page.c
+++ b/src/gs-details-page.c
@@ -2354,11 +2354,24 @@ gs_details_page_more_reviews_button_cb (GtkWidget *widget, GsDetailsPage *self)
        gtk_widget_set_visible (self->button_more_reviews, FALSE);
 }
 
+static guint
+content_rating_get_age (AsContentRating *content_rating, const gchar *id)
+{
+       AsContentRatingValue value = as_content_rating_get_value (content_rating, id);
+#if AS_CHECK_VERSION (0, 7, 15)
+       return as_content_rating_attribute_to_csm_age (id, value);
+#else
+       /* Hackily treat the value as an age; it should compare the same */
+       return (guint) value;
+#endif
+}
+
 static void
 gs_details_page_content_rating_button_cb (GtkWidget *widget, GsDetailsPage *self)
 {
        AsContentRating *cr;
        AsContentRatingValue value_bad = AS_CONTENT_RATING_VALUE_NONE;
+       guint age_bad = 0;
        const gchar *tmp;
        g_autofree const gchar **ids = NULL;
        g_autoptr(GString) str = g_string_new (NULL);
@@ -2392,8 +2405,12 @@ gs_details_page_content_rating_button_cb (GtkWidget *widget, GsDetailsPage *self
 
        /* get the worst thing */
        for (gsize i = 0; ids[i] != NULL; i++) {
+               guint age;
                AsContentRatingValue value;
                value = as_content_rating_get_value (cr, ids[i]);
+               age = content_rating_get_age (cr, ids[i]);
+               if (age > age_bad)
+                       age_bad = age;
                if (value > value_bad)
                        value_bad = value;
        }
@@ -2421,39 +2438,39 @@ gs_details_page_content_rating_button_cb (GtkWidget *widget, GsDetailsPage *self
        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, ids[i]);
-                       if (value < value_bad)
+                       guint age;
+                       age = content_rating_get_age (cr, ids[i]);
+                       if (age < age_bad)
                                continue;
 
                        /* coalesce down to the first element in @coalesce_groups,
                         * unless this group’s value differs. currently only one
                         * coalesce group is supported */
                        if (g_strv_contains (coalesce_groups + 1, ids[i]) &&
-                           as_content_rating_get_value (cr, coalesce_groups[0]) == value)
+                           content_rating_get_age (cr, coalesce_groups[0]) == age)
                                continue;
 
-                       tmp = gs_content_rating_key_value_to_str (ids[i], value);
+                       tmp = gs_content_rating_key_value_to_str (ids[i], as_content_rating_get_value (cr, 
ids[i]));
                        g_string_append_printf (str, "• %s\n", tmp);
                }
        }
 
        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)
+               guint age;
+               age = content_rating_get_age (cr, violence_group[i]);
+               if (age < age_bad)
                        continue;
-               tmp = gs_content_rating_key_value_to_str (violence_group[i], value);
+               tmp = gs_content_rating_key_value_to_str (violence_group[i], as_content_rating_get_value (cr, 
violence_group[i]));
                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)
+               guint age;
+               age = content_rating_get_age (cr, social_group[i]);
+               if (age < age_bad)
                        continue;
-               tmp = gs_content_rating_key_value_to_str (social_group[i], value);
+               tmp = gs_content_rating_key_value_to_str (social_group[i], as_content_rating_get_value (cr, 
social_group[i]));
                g_string_append_printf (str, "• %s\n", tmp);
                break;
        }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]