Merge branch 'content-rating-rationalisation' into 'master'

Use appstream-glib implementation of content rating systems

Closes #7

See merge request pwithnall/malcontent!70
This commit is contained in:
Philip Withnall 2020-06-09 09:06:22 +00:00
commit 14f0284a60
6 changed files with 349 additions and 608 deletions

View File

@ -6,7 +6,7 @@ before_script:
libglib2.0-dev libgirepository1.0-dev libpam0g-dev
gettext policykit-1 libpolkit-gobject-1-dev git
lcov libgtk-3-dev libaccountsservice-dev libflatpak-dev
libglib-testing-0-dev
libglib-testing-0-dev libappstream-glib-dev
- export LANG=C.UTF-8
stages:

View File

@ -89,6 +89,7 @@ Dependencies
------------
* accounts-service
* appstream-glib
* dbus-daemon
* flatpak
* gio-2.0 ≥ 2.60

File diff suppressed because it is too large Load Diff

View File

@ -23,9 +23,37 @@
G_BEGIN_DECLS
#include <appstream-glib.h>
#include <glib-object.h>
#include <libmalcontent/malcontent.h>
#if AS_CHECK_VERSION(0, 7, 18)
#define GS_CONTENT_RATING_SYSTEM_UNKNOWN AS_CONTENT_RATING_SYSTEM_UNKNOWN
#define GS_CONTENT_RATING_SYSTEM_INCAA AS_CONTENT_RATING_SYSTEM_INCAA
#define GS_CONTENT_RATING_SYSTEM_ACB AS_CONTENT_RATING_SYSTEM_ACB
#define GS_CONTENT_RATING_SYSTEM_DJCTQ AS_CONTENT_RATING_SYSTEM_DJCTQ
#define GS_CONTENT_RATING_SYSTEM_GSRR AS_CONTENT_RATING_SYSTEM_GSRR
#define GS_CONTENT_RATING_SYSTEM_PEGI AS_CONTENT_RATING_SYSTEM_PEGI
#define GS_CONTENT_RATING_SYSTEM_KAVI AS_CONTENT_RATING_SYSTEM_KAVI
#define GS_CONTENT_RATING_SYSTEM_USK AS_CONTENT_RATING_SYSTEM_USK
#define GS_CONTENT_RATING_SYSTEM_ESRA AS_CONTENT_RATING_SYSTEM_ESRA
#define GS_CONTENT_RATING_SYSTEM_CERO AS_CONTENT_RATING_SYSTEM_CERO
#define GS_CONTENT_RATING_SYSTEM_OFLCNZ AS_CONTENT_RATING_SYSTEM_OFLCNZ
#define GS_CONTENT_RATING_SYSTEM_RUSSIA AS_CONTENT_RATING_SYSTEM_RUSSIA
#define GS_CONTENT_RATING_SYSTEM_MDA AS_CONTENT_RATING_SYSTEM_MDA
#define GS_CONTENT_RATING_SYSTEM_GRAC AS_CONTENT_RATING_SYSTEM_GRAC
#define GS_CONTENT_RATING_SYSTEM_ESRB AS_CONTENT_RATING_SYSTEM_ESRB
#define GS_CONTENT_RATING_SYSTEM_IARC AS_CONTENT_RATING_SYSTEM_IARC
#define GS_CONTENT_RATING_SYSTEM_LAST AS_CONTENT_RATING_SYSTEM_LAST
#define GsContentRatingSystem AsContentRatingSystem
#define gs_utils_content_rating_age_to_str as_content_rating_system_format_age
#define gs_utils_content_rating_system_from_locale as_content_rating_system_from_locale
#define gs_content_rating_system_to_str as_content_rating_system_to_string
#define gs_utils_content_rating_get_values as_content_rating_system_get_formatted_ages
#define gs_utils_content_rating_get_ages as_content_rating_system_get_csm_ages
#define as_content_rating_id_csm_age_to_value as_content_rating_attribute_from_csm_age
#else
typedef enum {
GS_CONTENT_RATING_SYSTEM_UNKNOWN,
GS_CONTENT_RATING_SYSTEM_INCAA,
@ -47,15 +75,19 @@ typedef enum {
GS_CONTENT_RATING_SYSTEM_LAST
} GsContentRatingSystem;
const gchar *gs_utils_content_rating_age_to_str (GsContentRatingSystem system,
gchar *gs_utils_content_rating_age_to_str (GsContentRatingSystem system,
guint age);
GsContentRatingSystem gs_utils_content_rating_system_from_locale (const gchar *locale);
const gchar *gs_content_rating_key_value_to_str (const gchar *id,
MctAppFilterOarsValue value);
const gchar *gs_content_rating_system_to_str (GsContentRatingSystem system);
const gchar * const *gs_utils_content_rating_get_values (GsContentRatingSystem system);
const guint *gs_utils_content_rating_get_ages (GsContentRatingSystem system);
guint as_content_rating_id_value_to_csm_age (const gchar *id, MctAppFilterOarsValue value);
gchar **gs_utils_content_rating_get_values (GsContentRatingSystem system);
const guint *gs_utils_content_rating_get_ages (GsContentRatingSystem system, gsize *length_out);
MctAppFilterOarsValue as_content_rating_id_csm_age_to_value (const gchar *id, guint age);
#endif /* appstream-glib < 0.7.18 */
#if AS_CHECK_VERSION(0, 7, 15)
#define as_content_rating_id_value_to_csm_age as_content_rating_attribute_to_csm_age
#else
guint as_content_rating_id_value_to_csm_age (const gchar *id, MctAppFilterOarsValue value);
#endif /* appstream-glib < 0.7.15 */
G_END_DECLS

View File

@ -36,6 +36,7 @@ libmalcontent_ui_public_deps = [
libmalcontent_dep,
]
libmalcontent_ui_private_deps = [
dependency('appstream-glib'),
dependency('flatpak'),
]

View File

@ -22,6 +22,7 @@
#include "config.h"
#include <appstream-glib.h>
#include <libmalcontent/malcontent.h>
#include <locale.h>
#include <gio/gio.h>
@ -166,8 +167,7 @@ static const GActionEntry actions[] = {
{ "set-age", on_set_age_action_activated, "u", NULL, NULL, { 0, }}
};
/* FIXME: Factor this out and rely on code from libappstream-glib or gnome-software
* to do it. See: https://gitlab.freedesktop.org/pwithnall/malcontent/issues/7 */
#if !AS_CHECK_VERSION(0, 7, 15)
static const gchar * const oars_categories[] =
{
"violence-cartoon",
@ -199,6 +199,7 @@ static const gchar * const oars_categories[] =
"money-gambling",
NULL
};
#endif /* appstream-glib < 0.7.15 */
/* Auxiliary methods */
@ -316,10 +317,10 @@ static void
update_categories_from_language (MctUserControls *self)
{
GsContentRatingSystem rating_system;
const gchar * const * entries;
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 +329,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 +347,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
@ -370,14 +373,24 @@ oars_value_to_string (MctAppFilterOarsValue oars_value)
}
}
/* Ensure the enum casts below are safe. */
G_STATIC_ASSERT ((int) MCT_APP_FILTER_OARS_VALUE_UNKNOWN == (int) AS_CONTENT_RATING_VALUE_UNKNOWN);
G_STATIC_ASSERT ((int) MCT_APP_FILTER_OARS_VALUE_NONE == (int) AS_CONTENT_RATING_VALUE_NONE);
G_STATIC_ASSERT ((int) MCT_APP_FILTER_OARS_VALUE_MILD == (int) AS_CONTENT_RATING_VALUE_MILD);
G_STATIC_ASSERT ((int) MCT_APP_FILTER_OARS_VALUE_MODERATE == (int) AS_CONTENT_RATING_VALUE_MODERATE);
G_STATIC_ASSERT ((int) MCT_APP_FILTER_OARS_VALUE_INTENSE == (int) AS_CONTENT_RATING_VALUE_INTENSE);
static void
update_oars_level (MctUserControls *self)
{
GsContentRatingSystem rating_system;
const gchar *rating_age_category;
g_autofree gchar *rating_age_category = NULL;
guint maximum_age;
gsize i;
gboolean all_categories_unset;
#if AS_CHECK_VERSION(0, 7, 15)
g_autofree const gchar **oars_categories = as_content_rating_get_all_rating_ids ();
#endif
g_assert (self->filter != NULL);
@ -391,7 +404,7 @@ update_oars_level (MctUserControls *self)
oars_value = mct_app_filter_get_oars_value (self->filter, oars_categories[i]);
all_categories_unset &= (oars_value == MCT_APP_FILTER_OARS_VALUE_UNKNOWN);
age = as_content_rating_id_value_to_csm_age (oars_categories[i], oars_value);
age = as_content_rating_id_value_to_csm_age (oars_categories[i], (AsContentRatingValue) oars_value);
g_debug ("OARS value for '%s': %s", oars_categories[i], oars_value_to_string (oars_value));
@ -407,7 +420,10 @@ update_oars_level (MctUserControls *self)
/* Unrestricted? */
if (rating_age_category == NULL || all_categories_unset)
rating_age_category = _("All Ages");
{
g_clear_pointer (&rating_age_category, g_free);
rating_age_category = g_strdup (_("All Ages"));
}
gtk_label_set_label (self->oars_button_label, rating_age_category);
}
@ -677,17 +693,18 @@ on_set_age_action_activated (GSimpleAction *action,
{
GsContentRatingSystem rating_system;
MctUserControls *self;
const gchar * const * entries;
g_auto(GStrv) entries = NULL;
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)
@ -1478,6 +1495,9 @@ mct_user_controls_build_app_filter (MctUserControls *self,
{
gboolean restrict_web_browsers;
gsize i;
#if AS_CHECK_VERSION(0, 7, 15)
g_autofree const gchar **oars_categories = as_content_rating_get_all_rating_ids ();
#endif
g_return_if_fail (MCT_IS_USER_CONTROLS (self));
g_return_if_fail (builder != NULL);
@ -1503,7 +1523,7 @@ mct_user_controls_build_app_filter (MctUserControls *self,
const gchar *oars_category;
oars_category = oars_categories[i];
oars_value = as_content_rating_id_csm_age_to_value (oars_category, self->selected_age);
oars_value = (MctAppFilterOarsValue) as_content_rating_id_csm_age_to_value (oars_category, self->selected_age);
g_debug ("\t\t → %s: %s", oars_category, oars_value_to_string (oars_value));