diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 974a4ac..a204fb3 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -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: diff --git a/README.md b/README.md index 512fb48..ca2d8de 100644 --- a/README.md +++ b/README.md @@ -89,6 +89,7 @@ Dependencies ------------ * accounts-service + * appstream-glib * dbus-daemon * flatpak * gio-2.0 ≥ 2.60 diff --git a/libmalcontent-ui/gs-content-rating.c b/libmalcontent-ui/gs-content-rating.c index deddc4f..8351501 100644 --- a/libmalcontent-ui/gs-content-rating.c +++ b/libmalcontent-ui/gs-content-rating.c @@ -21,11 +21,13 @@ #include "config.h" +#include #include #include #include "gs-content-rating.h" +#if !AS_CHECK_VERSION(0, 7, 18) const gchar * gs_content_rating_system_to_str (GsContentRatingSystem system) { @@ -573,7 +575,9 @@ static const struct { { "violence-desecration", OARS_1_1, 0, 13, 15, 18 }, { "violence-slavery", OARS_1_1, 0, 13, 15, 18 }, }; +#endif /* appstream-glib < 0.7.18 */ +#if !AS_CHECK_VERSION(0, 7, 15) /** * as_content_rating_id_value_to_csm_age: * @id: the subsection ID e.g. "violence-cartoon" @@ -616,7 +620,9 @@ as_content_rating_id_value_to_csm_age (const gchar *id, MctAppFilterOarsValue va /* @id not found. */ return 0; } +#endif /* appstream-glib < 0.7.15 */ +#if !AS_CHECK_VERSION(0, 7, 18) /** * as_content_rating_id_csm_age_to_value: * @id: the subsection ID e.g. "violence-cartoon" @@ -646,3 +652,4 @@ as_content_rating_id_csm_age_to_value (const gchar *id, guint age) return MCT_APP_FILTER_OARS_VALUE_UNKNOWN; } +#endif /* appstream-glib < 0.7.18 */ diff --git a/libmalcontent-ui/gs-content-rating.h b/libmalcontent-ui/gs-content-rating.h index 59f5415..b903bf4 100644 --- a/libmalcontent-ui/gs-content-rating.h +++ b/libmalcontent-ui/gs-content-rating.h @@ -23,9 +23,37 @@ G_BEGIN_DECLS +#include #include #include +#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, @@ -53,7 +81,13 @@ GsContentRatingSystem gs_utils_content_rating_system_from_locale (const gchar *l 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, 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); +#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 diff --git a/libmalcontent-ui/meson.build b/libmalcontent-ui/meson.build index 31241ed..38601f3 100644 --- a/libmalcontent-ui/meson.build +++ b/libmalcontent-ui/meson.build @@ -36,6 +36,7 @@ libmalcontent_ui_public_deps = [ libmalcontent_dep, ] libmalcontent_ui_private_deps = [ + dependency('appstream-glib'), dependency('flatpak'), ] diff --git a/libmalcontent-ui/user-controls.c b/libmalcontent-ui/user-controls.c index 84d0d13..fa9e85d 100644 --- a/libmalcontent-ui/user-controls.c +++ b/libmalcontent-ui/user-controls.c @@ -22,6 +22,7 @@ #include "config.h" +#include #include #include #include @@ -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 */ @@ -372,6 +373,13 @@ 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) { @@ -380,6 +388,9 @@ update_oars_level (MctUserControls *self) 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); @@ -393,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)); @@ -1484,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); @@ -1509,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));