diff --git a/libmalcontent/app-filter.c b/libmalcontent/app-filter.c index 266b3d6..3599424 100644 --- a/libmalcontent/app-filter.c +++ b/libmalcontent/app-filter.c @@ -33,7 +33,12 @@ #include "libmalcontent/app-filter-private.h" -G_DEFINE_QUARK (MctAppFilterError, mct_app_filter_error) +/* FIXME: Eventually deprecate these compatibility fallbacks. */ +GQuark +mct_app_filter_error_quark (void) +{ + return mct_manager_error_quark (); +} /* struct _MctAppFilter is defined in app-filter-private.h */ diff --git a/libmalcontent/app-filter.h b/libmalcontent/app-filter.h index 263b4ee..cc92e23 100644 --- a/libmalcontent/app-filter.h +++ b/libmalcontent/app-filter.h @@ -29,31 +29,6 @@ G_BEGIN_DECLS -/** - * MctAppFilterError: - * @MCT_APP_FILTER_ERROR_INVALID_USER: Given user ID doesn’t exist - * @MCT_APP_FILTER_ERROR_PERMISSION_DENIED: Not authorized to query the app - * filter for the given user - * @MCT_APP_FILTER_ERROR_INVALID_DATA: The data stored in the app filter for - * a user is inconsistent or invalid - * @MCT_APP_FILTER_ERROR_DISABLED: App filtering is disabled for all users (Since: 0.3.0) - * - * Errors relating to #MctAppFilter instances, which can be returned by - * mct_manager_get_app_filter_async() (for example). - * - * Since: 0.2.0 - */ -typedef enum -{ - MCT_APP_FILTER_ERROR_INVALID_USER, - MCT_APP_FILTER_ERROR_PERMISSION_DENIED, - MCT_APP_FILTER_ERROR_INVALID_DATA, - MCT_APP_FILTER_ERROR_DISABLED, -} MctAppFilterError; - -GQuark mct_app_filter_error_quark (void); -#define MCT_APP_FILTER_ERROR mct_app_filter_error_quark () - /** * MctAppFilterOarsValue: * @MCT_APP_FILTER_OARS_VALUE_UNKNOWN: Unknown value for the given @@ -197,4 +172,16 @@ void mct_app_filter_builder_set_allow_user_installation (MctAppFilterBuilder * void mct_app_filter_builder_set_allow_system_installation (MctAppFilterBuilder *builder, gboolean allow_system_installation); +#include + +/* FIXME: Eventually deprecate these compatibility fallbacks. */ +typedef MctManagerError MctAppFilterError; +#define MCT_APP_FILTER_ERROR_INVALID_USER MCT_MANAGER_ERROR_INVALID_USER +#define MCT_APP_FILTER_ERROR_PERMISSION_DENIED MCT_MANAGER_ERROR_PERMISSION_DENIED +#define MCT_APP_FILTER_ERROR_INVALID_DATA MCT_MANAGER_ERROR_INVALID_DATA +#define MCT_APP_FILTER_ERROR_DISABLED MCT_MANAGER_ERROR_DISABLED + +GQuark mct_app_filter_error_quark (void); +#define MCT_APP_FILTER_ERROR mct_app_filter_error_quark () + G_END_DECLS diff --git a/libmalcontent/manager.c b/libmalcontent/manager.c index 467357c..61d457e 100644 --- a/libmalcontent/manager.c +++ b/libmalcontent/manager.c @@ -31,6 +31,9 @@ #include "libmalcontent/app-filter-private.h" + +G_DEFINE_QUARK (MctManagerError, mct_manager_error) + /** * MctManager: * @@ -298,19 +301,19 @@ bus_remote_error_matches (const GError *error, return g_str_equal (error_name, expected_error_name); } -/* Convert a #GDBusError into a #MctAppFilterError. */ +/* Convert a #GDBusError into a #MctManagerError. */ static GError * -bus_error_to_app_filter_error (const GError *bus_error, - uid_t user_id) +bus_error_to_manager_error (const GError *bus_error, + uid_t user_id) { if (g_error_matches (bus_error, G_DBUS_ERROR, G_DBUS_ERROR_ACCESS_DENIED) || bus_remote_error_matches (bus_error, "org.freedesktop.Accounts.Error.PermissionDenied")) - return g_error_new (MCT_APP_FILTER_ERROR, MCT_APP_FILTER_ERROR_PERMISSION_DENIED, + return g_error_new (MCT_MANAGER_ERROR, MCT_MANAGER_ERROR_PERMISSION_DENIED, _("Not allowed to query app filter data for user %u"), (guint) user_id); else if (g_error_matches (bus_error, G_DBUS_ERROR, G_DBUS_ERROR_UNKNOWN_METHOD) || bus_remote_error_matches (bus_error, "org.freedesktop.Accounts.Error.Failed")) - return g_error_new (MCT_APP_FILTER_ERROR, MCT_APP_FILTER_ERROR_INVALID_USER, + return g_error_new (MCT_MANAGER_ERROR, MCT_MANAGER_ERROR_INVALID_USER, _("User %u does not exist"), (guint) user_id); else return g_error_copy (bus_error); @@ -346,8 +349,8 @@ accounts_find_user_by_id (GDBusConnection *connection, &local_error); if (local_error != NULL) { - g_autoptr(GError) app_filter_error = bus_error_to_app_filter_error (local_error, - user_id); + g_autoptr(GError) app_filter_error = bus_error_to_manager_error (local_error, + user_id); g_propagate_error (error, g_steal_pointer (&app_filter_error)); return NULL; } @@ -415,24 +418,23 @@ mct_manager_get_app_filter (MctManager *self, &local_error); if (local_error != NULL) { - g_autoptr(GError) app_filter_error = NULL; + g_autoptr(GError) manager_error = NULL; if (g_error_matches (local_error, G_DBUS_ERROR, G_DBUS_ERROR_INVALID_ARGS)) { /* o.fd.D.GetAll() will return InvalidArgs errors if * accountsservice doesn’t have the com.endlessm.ParentalControls.AppFilter * extension interface installed. */ - app_filter_error = g_error_new_literal (MCT_APP_FILTER_ERROR, - MCT_APP_FILTER_ERROR_DISABLED, - _("App filtering is globally disabled")); + manager_error = g_error_new_literal (MCT_MANAGER_ERROR, + MCT_MANAGER_ERROR_DISABLED, + _("App filtering is globally disabled")); } else { - app_filter_error = bus_error_to_app_filter_error (local_error, - user_id); + manager_error = bus_error_to_manager_error (local_error, user_id); } - g_propagate_error (error, g_steal_pointer (&app_filter_error)); + g_propagate_error (error, g_steal_pointer (&manager_error)); return NULL; } @@ -442,8 +444,8 @@ mct_manager_get_app_filter (MctManager *self, if (!g_variant_lookup (properties, "AppFilter", "(b^as)", &is_whitelist, &app_list)) { - g_set_error (error, MCT_APP_FILTER_ERROR, - MCT_APP_FILTER_ERROR_PERMISSION_DENIED, + g_set_error (error, MCT_MANAGER_ERROR, + MCT_MANAGER_ERROR_PERMISSION_DENIED, _("Not allowed to query app filter data for user %u"), (guint) user_id); return NULL; @@ -462,8 +464,8 @@ mct_manager_get_app_filter (MctManager *self, if (!g_str_equal (content_rating_kind, "oars-1.0") && !g_str_equal (content_rating_kind, "oars-1.1")) { - g_set_error (error, MCT_APP_FILTER_ERROR, - MCT_APP_FILTER_ERROR_INVALID_DATA, + g_set_error (error, MCT_MANAGER_ERROR, + MCT_MANAGER_ERROR_INVALID_DATA, _("OARS filter for user %u has an unrecognized kind ‘%s’"), (guint) user_id, content_rating_kind); return NULL; @@ -528,7 +530,7 @@ G_DEFINE_AUTOPTR_CLEANUP_FUNC (GetAppFilterData, get_app_filter_data_free) * Asynchronously get a snapshot of the app filter settings for the given * @user_id. * - * On failure, an #MctAppFilterError, a #GDBusError or a #GIOError will be + * On failure, an #MctManagerError, a #GDBusError or a #GIOError will be * returned. * * Since: 0.3.0 @@ -676,7 +678,7 @@ mct_manager_set_app_filter (MctManager *self, &local_error); if (local_error != NULL) { - g_propagate_error (error, bus_error_to_app_filter_error (local_error, user_id)); + g_propagate_error (error, bus_error_to_manager_error (local_error, user_id)); return FALSE; } @@ -699,7 +701,7 @@ mct_manager_set_app_filter (MctManager *self, &local_error); if (local_error != NULL) { - g_propagate_error (error, bus_error_to_app_filter_error (local_error, user_id)); + g_propagate_error (error, bus_error_to_manager_error (local_error, user_id)); return FALSE; } @@ -722,7 +724,7 @@ mct_manager_set_app_filter (MctManager *self, &local_error); if (local_error != NULL) { - g_propagate_error (error, bus_error_to_app_filter_error (local_error, user_id)); + g_propagate_error (error, bus_error_to_manager_error (local_error, user_id)); return FALSE; } @@ -745,7 +747,7 @@ mct_manager_set_app_filter (MctManager *self, &local_error); if (local_error != NULL) { - g_propagate_error (error, bus_error_to_app_filter_error (local_error, user_id)); + g_propagate_error (error, bus_error_to_manager_error (local_error, user_id)); return FALSE; } @@ -786,7 +788,7 @@ G_DEFINE_AUTOPTR_CLEANUP_FUNC (SetAppFilterData, set_app_filter_data_free) * Asynchronously set the app filter settings for the given @user_id to the * given @app_filter instance. This will set all fields of the app filter. * - * On failure, an #MctAppFilterError, a #GDBusError or a #GIOError will be + * On failure, an #MctManagerError, a #GDBusError or a #GIOError will be * returned. The user’s app filter settings will be left in an undefined state. * * Since: 0.3.0 diff --git a/libmalcontent/manager.h b/libmalcontent/manager.h index 83e14fa..2402b1a 100644 --- a/libmalcontent/manager.h +++ b/libmalcontent/manager.h @@ -25,7 +25,6 @@ #include #include #include -#include G_BEGIN_DECLS @@ -73,6 +72,32 @@ typedef MctManagerSetValueFlags MctSetAppFilterFlags; #define MCT_SET_APP_FILTER_FLAGS_NONE MCT_MANAGER_SET_VALUE_FLAGS_NONE #define MCT_SET_APP_FILTER_FLAGS_INTERACTIVE MCT_MANAGER_SET_VALUE_FLAGS_INTERACTIVE +/** + * MctManagerError: + * @MCT_MANAGER_ERROR_INVALID_USER: Given user ID doesn’t exist + * @MCT_MANAGER_ERROR_PERMISSION_DENIED: Not authorized to query properties of + * the given user + * @MCT_MANAGER_ERROR_INVALID_DATA: The data stored in a property of the given + * user is inconsistent or invalid + * @MCT_MANAGER_ERROR_DISABLED: Parental controls are disabled for all users + * + * Errors relating to get/set operations on an #MctManager instance. + * + * Since: 0.5.0 + */ +typedef enum +{ + MCT_MANAGER_ERROR_INVALID_USER, + MCT_MANAGER_ERROR_PERMISSION_DENIED, + MCT_MANAGER_ERROR_INVALID_DATA, + MCT_MANAGER_ERROR_DISABLED, +} MctManagerError; + +GQuark mct_manager_error_quark (void); +#define MCT_MANAGER_ERROR mct_manager_error_quark () + +#include + #define MCT_TYPE_MANAGER mct_manager_get_type () G_DECLARE_FINAL_TYPE (MctManager, mct_manager, MCT, MANAGER, GObject) diff --git a/libmalcontent/tests/app-filter.c b/libmalcontent/tests/app-filter.c index 119e54a..7ce4abc 100644 --- a/libmalcontent/tests/app-filter.c +++ b/libmalcontent/tests/app-filter.c @@ -809,7 +809,7 @@ test_app_filter_bus_get_error_invalid_user (BusFixture *fixture, &local_error); g_assert_error (local_error, - MCT_APP_FILTER_ERROR, MCT_APP_FILTER_ERROR_INVALID_USER); + MCT_MANAGER_ERROR, MCT_MANAGER_ERROR_INVALID_USER); g_assert_null (app_filter); } @@ -866,7 +866,7 @@ test_app_filter_bus_get_error_permission_denied (BusFixture *fixture, &local_error); g_assert_error (local_error, - MCT_APP_FILTER_ERROR, MCT_APP_FILTER_ERROR_PERMISSION_DENIED); + MCT_MANAGER_ERROR, MCT_MANAGER_ERROR_PERMISSION_DENIED); g_assert_null (app_filter); } @@ -924,7 +924,7 @@ test_app_filter_bus_get_error_permission_denied_missing (BusFixture *fixture, &local_error); g_assert_error (local_error, - MCT_APP_FILTER_ERROR, MCT_APP_FILTER_ERROR_PERMISSION_DENIED); + MCT_MANAGER_ERROR, MCT_MANAGER_ERROR_PERMISSION_DENIED); g_assert_null (app_filter); } @@ -1027,7 +1027,7 @@ test_app_filter_bus_get_error_disabled (BusFixture *fixture, &local_error); g_assert_error (local_error, - MCT_APP_FILTER_ERROR, MCT_APP_FILTER_ERROR_DISABLED); + MCT_MANAGER_ERROR, MCT_MANAGER_ERROR_DISABLED); g_assert_null (app_filter); } @@ -1249,7 +1249,7 @@ test_app_filter_bus_set_error_invalid_user (BusFixture *fixture, &local_error); g_assert_error (local_error, - MCT_APP_FILTER_ERROR, MCT_APP_FILTER_ERROR_INVALID_USER); + MCT_MANAGER_ERROR, MCT_MANAGER_ERROR_INVALID_USER); g_assert_false (success); } @@ -1286,7 +1286,7 @@ test_app_filter_bus_set_error_permission_denied (BusFixture *fixture, &local_error); g_assert_error (local_error, - MCT_APP_FILTER_ERROR, MCT_APP_FILTER_ERROR_PERMISSION_DENIED); + MCT_MANAGER_ERROR, MCT_MANAGER_ERROR_PERMISSION_DENIED); g_assert_false (success); }