libmalcontent: Rename flags types
If we have a flag type for getting and for setting every type of value which can be stored on an `MctManager`, that will lead to a load of flag types which all look identical. Refactor the types so we only have one shared flags type for getters, and one for setters. Add compatibility defines so that this doesn’t break API. It’s not an ABI break because the flag member values don’t change. Signed-off-by: Philip Withnall <withnall@endlessm.com>
This commit is contained in:
parent
282cf9c66b
commit
acf2738d56
|
@ -373,7 +373,7 @@ accounts_find_user_by_id (GDBusConnection *connection,
|
|||
MctAppFilter *
|
||||
mct_manager_get_app_filter (MctManager *self,
|
||||
uid_t user_id,
|
||||
MctGetAppFilterFlags flags,
|
||||
MctManagerGetValueFlags flags,
|
||||
GCancellable *cancellable,
|
||||
GError **error)
|
||||
{
|
||||
|
@ -394,7 +394,7 @@ mct_manager_get_app_filter (MctManager *self,
|
|||
g_return_val_if_fail (error == NULL || *error == NULL, NULL);
|
||||
|
||||
object_path = accounts_find_user_by_id (self->connection, user_id,
|
||||
(flags & MCT_GET_APP_FILTER_FLAGS_INTERACTIVE),
|
||||
(flags & MCT_MANAGER_GET_VALUE_FLAGS_INTERACTIVE),
|
||||
cancellable, error);
|
||||
if (object_path == NULL)
|
||||
return NULL;
|
||||
|
@ -407,7 +407,7 @@ mct_manager_get_app_filter (MctManager *self,
|
|||
"GetAll",
|
||||
g_variant_new ("(s)", "com.endlessm.ParentalControls.AppFilter"),
|
||||
G_VARIANT_TYPE ("(a{sv})"),
|
||||
(flags & MCT_GET_APP_FILTER_FLAGS_INTERACTIVE)
|
||||
(flags & MCT_MANAGER_GET_VALUE_FLAGS_INTERACTIVE)
|
||||
? G_DBUS_CALL_FLAGS_ALLOW_INTERACTIVE_AUTHORIZATION
|
||||
: G_DBUS_CALL_FLAGS_NONE,
|
||||
-1, /* timeout, ms */
|
||||
|
@ -505,7 +505,7 @@ static void get_app_filter_thread_cb (GTask *task,
|
|||
typedef struct
|
||||
{
|
||||
uid_t user_id;
|
||||
MctGetAppFilterFlags flags;
|
||||
MctManagerGetValueFlags flags;
|
||||
} GetAppFilterData;
|
||||
|
||||
static void
|
||||
|
@ -536,7 +536,7 @@ G_DEFINE_AUTOPTR_CLEANUP_FUNC (GetAppFilterData, get_app_filter_data_free)
|
|||
void
|
||||
mct_manager_get_app_filter_async (MctManager *self,
|
||||
uid_t user_id,
|
||||
MctGetAppFilterFlags flags,
|
||||
MctManagerGetValueFlags flags,
|
||||
GCancellable *cancellable,
|
||||
GAsyncReadyCallback callback,
|
||||
gpointer user_data)
|
||||
|
@ -623,7 +623,7 @@ gboolean
|
|||
mct_manager_set_app_filter (MctManager *self,
|
||||
uid_t user_id,
|
||||
MctAppFilter *app_filter,
|
||||
MctSetAppFilterFlags flags,
|
||||
MctManagerSetValueFlags flags,
|
||||
GCancellable *cancellable,
|
||||
GError **error)
|
||||
{
|
||||
|
@ -646,7 +646,7 @@ mct_manager_set_app_filter (MctManager *self,
|
|||
g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
|
||||
|
||||
object_path = accounts_find_user_by_id (self->connection, user_id,
|
||||
(flags & MCT_SET_APP_FILTER_FLAGS_INTERACTIVE),
|
||||
(flags & MCT_MANAGER_SET_VALUE_FLAGS_INTERACTIVE),
|
||||
cancellable, error);
|
||||
if (object_path == NULL)
|
||||
return FALSE;
|
||||
|
@ -668,7 +668,7 @@ mct_manager_set_app_filter (MctManager *self,
|
|||
"AppFilter",
|
||||
g_steal_pointer (&app_filter_variant)),
|
||||
G_VARIANT_TYPE ("()"),
|
||||
(flags & MCT_SET_APP_FILTER_FLAGS_INTERACTIVE)
|
||||
(flags & MCT_MANAGER_SET_VALUE_FLAGS_INTERACTIVE)
|
||||
? G_DBUS_CALL_FLAGS_ALLOW_INTERACTIVE_AUTHORIZATION
|
||||
: G_DBUS_CALL_FLAGS_NONE,
|
||||
-1, /* timeout, ms */
|
||||
|
@ -691,7 +691,7 @@ mct_manager_set_app_filter (MctManager *self,
|
|||
"OarsFilter",
|
||||
g_steal_pointer (&oars_filter_variant)),
|
||||
G_VARIANT_TYPE ("()"),
|
||||
(flags & MCT_SET_APP_FILTER_FLAGS_INTERACTIVE)
|
||||
(flags & MCT_MANAGER_SET_VALUE_FLAGS_INTERACTIVE)
|
||||
? G_DBUS_CALL_FLAGS_ALLOW_INTERACTIVE_AUTHORIZATION
|
||||
: G_DBUS_CALL_FLAGS_NONE,
|
||||
-1, /* timeout, ms */
|
||||
|
@ -714,7 +714,7 @@ mct_manager_set_app_filter (MctManager *self,
|
|||
"AllowUserInstallation",
|
||||
g_steal_pointer (&allow_user_installation_variant)),
|
||||
G_VARIANT_TYPE ("()"),
|
||||
(flags & MCT_SET_APP_FILTER_FLAGS_INTERACTIVE)
|
||||
(flags & MCT_MANAGER_SET_VALUE_FLAGS_INTERACTIVE)
|
||||
? G_DBUS_CALL_FLAGS_ALLOW_INTERACTIVE_AUTHORIZATION
|
||||
: G_DBUS_CALL_FLAGS_NONE,
|
||||
-1, /* timeout, ms */
|
||||
|
@ -737,7 +737,7 @@ mct_manager_set_app_filter (MctManager *self,
|
|||
"AllowSystemInstallation",
|
||||
g_steal_pointer (&allow_system_installation_variant)),
|
||||
G_VARIANT_TYPE ("()"),
|
||||
(flags & MCT_SET_APP_FILTER_FLAGS_INTERACTIVE)
|
||||
(flags & MCT_MANAGER_SET_VALUE_FLAGS_INTERACTIVE)
|
||||
? G_DBUS_CALL_FLAGS_ALLOW_INTERACTIVE_AUTHORIZATION
|
||||
: G_DBUS_CALL_FLAGS_NONE,
|
||||
-1, /* timeout, ms */
|
||||
|
@ -761,7 +761,7 @@ typedef struct
|
|||
{
|
||||
uid_t user_id;
|
||||
MctAppFilter *app_filter; /* (owned) */
|
||||
MctSetAppFilterFlags flags;
|
||||
MctManagerSetValueFlags flags;
|
||||
} SetAppFilterData;
|
||||
|
||||
static void
|
||||
|
@ -795,7 +795,7 @@ void
|
|||
mct_manager_set_app_filter_async (MctManager *self,
|
||||
uid_t user_id,
|
||||
MctAppFilter *app_filter,
|
||||
MctSetAppFilterFlags flags,
|
||||
MctManagerSetValueFlags flags,
|
||||
GCancellable *cancellable,
|
||||
GAsyncReadyCallback callback,
|
||||
gpointer user_data)
|
||||
|
|
|
@ -30,38 +30,48 @@
|
|||
G_BEGIN_DECLS
|
||||
|
||||
/**
|
||||
* MctGetAppFilterFlags:
|
||||
* @MCT_GET_APP_FILTER_FLAGS_NONE: No flags set.
|
||||
* @MCT_GET_APP_FILTER_FLAGS_INTERACTIVE: Allow interactive polkit dialogs when
|
||||
* requesting authorization.
|
||||
* MctManagerGetValueFlags:
|
||||
* @MCT_MANAGER_GET_VALUE_FLAGS_NONE: No flags set.
|
||||
* @MCT_MANAGER_GET_VALUE_FLAGS_INTERACTIVE: Allow interactive polkit dialogs
|
||||
* when requesting authorization.
|
||||
*
|
||||
* Flags to control the behaviour of mct_manager_get_app_filter() and
|
||||
* mct_manager_get_app_filter_async().
|
||||
* Flags to control the behaviour of getter functions like
|
||||
* mct_manager_get_app_filter() and mct_manager_get_app_filter_async().
|
||||
*
|
||||
* Since: 0.3.0
|
||||
* Since: 0.5.0
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
MCT_GET_APP_FILTER_FLAGS_NONE = 0,
|
||||
MCT_GET_APP_FILTER_FLAGS_INTERACTIVE = (1 << 0),
|
||||
} MctGetAppFilterFlags;
|
||||
MCT_MANAGER_GET_VALUE_FLAGS_NONE = 0,
|
||||
MCT_MANAGER_GET_VALUE_FLAGS_INTERACTIVE = (1 << 0),
|
||||
} MctManagerGetValueFlags;
|
||||
|
||||
/* FIXME: Eventually deprecate these compatibility fallbacks. */
|
||||
typedef MctManagerGetValueFlags MctGetAppFilterFlags;
|
||||
#define MCT_GET_APP_FILTER_FLAGS_NONE MCT_MANAGER_GET_VALUE_FLAGS_NONE
|
||||
#define MCT_GET_APP_FILTER_FLAGS_INTERACTIVE MCT_MANAGER_GET_VALUE_FLAGS_INTERACTIVE
|
||||
|
||||
/**
|
||||
* MctSetAppFilterFlags:
|
||||
* @MCT_SET_APP_FILTER_FLAGS_NONE: No flags set.
|
||||
* @MCT_SET_APP_FILTER_FLAGS_INTERACTIVE: Allow interactive polkit dialogs when
|
||||
* requesting authorization.
|
||||
* MctManagerSetValueFlags:
|
||||
* @MCT_MANAGER_SET_VALUE_FLAGS_NONE: No flags set.
|
||||
* @MCT_MANAGER_SET_VALUE_FLAGS_INTERACTIVE: Allow interactive polkit dialogs
|
||||
* when requesting authorization.
|
||||
*
|
||||
* Flags to control the behaviour of mct_manager_set_app_filter() and
|
||||
* mct_manager_set_app_filter_async().
|
||||
* Flags to control the behaviour of setter functions like
|
||||
* mct_manager_set_app_filter() and mct_manager_set_app_filter_async().
|
||||
*
|
||||
* Since: 0.3.0
|
||||
* Since: 0.5.0
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
MCT_SET_APP_FILTER_FLAGS_NONE = 0,
|
||||
MCT_SET_APP_FILTER_FLAGS_INTERACTIVE = (1 << 0),
|
||||
} MctSetAppFilterFlags;
|
||||
MCT_MANAGER_SET_VALUE_FLAGS_NONE = 0,
|
||||
MCT_MANAGER_SET_VALUE_FLAGS_INTERACTIVE = (1 << 0),
|
||||
} MctManagerSetValueFlags;
|
||||
|
||||
/* FIXME: Eventually deprecate these compatibility fallbacks. */
|
||||
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
|
||||
|
||||
#define MCT_TYPE_MANAGER mct_manager_get_type ()
|
||||
G_DECLARE_FINAL_TYPE (MctManager, mct_manager, MCT, MANAGER, GObject)
|
||||
|
@ -70,12 +80,12 @@ MctManager *mct_manager_new (GDBusConnection *connection);
|
|||
|
||||
MctAppFilter *mct_manager_get_app_filter (MctManager *self,
|
||||
uid_t user_id,
|
||||
MctGetAppFilterFlags flags,
|
||||
MctManagerGetValueFlags flags,
|
||||
GCancellable *cancellable,
|
||||
GError **error);
|
||||
void mct_manager_get_app_filter_async (MctManager *self,
|
||||
uid_t user_id,
|
||||
MctGetAppFilterFlags flags,
|
||||
MctManagerGetValueFlags flags,
|
||||
GCancellable *cancellable,
|
||||
GAsyncReadyCallback callback,
|
||||
gpointer user_data);
|
||||
|
@ -86,13 +96,13 @@ MctAppFilter *mct_manager_get_app_filter_finish (MctManager *self,
|
|||
gboolean mct_manager_set_app_filter (MctManager *self,
|
||||
uid_t user_id,
|
||||
MctAppFilter *app_filter,
|
||||
MctSetAppFilterFlags flags,
|
||||
MctManagerSetValueFlags flags,
|
||||
GCancellable *cancellable,
|
||||
GError **error);
|
||||
void mct_manager_set_app_filter_async (MctManager *self,
|
||||
uid_t user_id,
|
||||
MctAppFilter *app_filter,
|
||||
MctSetAppFilterFlags flags,
|
||||
MctManagerSetValueFlags flags,
|
||||
GCancellable *cancellable,
|
||||
GAsyncReadyCallback callback,
|
||||
gpointer user_data);
|
||||
|
|
|
@ -594,7 +594,7 @@ test_app_filter_bus_get (BusFixture *fixture,
|
|||
|
||||
mct_manager_get_app_filter_async (fixture->manager,
|
||||
fixture->valid_uid,
|
||||
MCT_GET_APP_FILTER_FLAGS_NONE, NULL,
|
||||
MCT_MANAGER_GET_VALUE_FLAGS_NONE, NULL,
|
||||
async_result_cb, &result);
|
||||
|
||||
while (result == NULL)
|
||||
|
@ -605,7 +605,7 @@ test_app_filter_bus_get (BusFixture *fixture,
|
|||
{
|
||||
app_filter = mct_manager_get_app_filter (fixture->manager,
|
||||
fixture->valid_uid,
|
||||
MCT_GET_APP_FILTER_FLAGS_NONE, NULL,
|
||||
MCT_MANAGER_GET_VALUE_FLAGS_NONE, NULL,
|
||||
&local_error);
|
||||
}
|
||||
|
||||
|
@ -650,7 +650,7 @@ test_app_filter_bus_get_whitelist (BusFixture *fixture,
|
|||
|
||||
app_filter = mct_manager_get_app_filter (fixture->manager,
|
||||
fixture->valid_uid,
|
||||
MCT_GET_APP_FILTER_FLAGS_NONE, NULL,
|
||||
MCT_MANAGER_GET_VALUE_FLAGS_NONE, NULL,
|
||||
&local_error);
|
||||
|
||||
g_assert_no_error (local_error);
|
||||
|
@ -705,7 +705,7 @@ test_app_filter_bus_get_all_oars_values (BusFixture *fixture,
|
|||
|
||||
app_filter = mct_manager_get_app_filter (fixture->manager,
|
||||
fixture->valid_uid,
|
||||
MCT_GET_APP_FILTER_FLAGS_NONE, NULL,
|
||||
MCT_MANAGER_GET_VALUE_FLAGS_NONE, NULL,
|
||||
&local_error);
|
||||
|
||||
g_assert_no_error (local_error);
|
||||
|
@ -753,7 +753,7 @@ test_app_filter_bus_get_defaults (BusFixture *fixture,
|
|||
|
||||
app_filter = mct_manager_get_app_filter (fixture->manager,
|
||||
fixture->valid_uid,
|
||||
MCT_GET_APP_FILTER_FLAGS_NONE, NULL,
|
||||
MCT_MANAGER_GET_VALUE_FLAGS_NONE, NULL,
|
||||
&local_error);
|
||||
|
||||
g_assert_no_error (local_error);
|
||||
|
@ -785,7 +785,7 @@ test_app_filter_bus_get_error_invalid_user (BusFixture *fixture,
|
|||
|
||||
mct_manager_get_app_filter_async (fixture->manager,
|
||||
fixture->missing_uid,
|
||||
MCT_GET_APP_FILTER_FLAGS_NONE, NULL,
|
||||
MCT_MANAGER_GET_VALUE_FLAGS_NONE, NULL,
|
||||
async_result_cb, &result);
|
||||
|
||||
/* Handle the FindUserById() call and claim the user doesn’t exist. */
|
||||
|
@ -831,7 +831,7 @@ test_app_filter_bus_get_error_permission_denied (BusFixture *fixture,
|
|||
|
||||
mct_manager_get_app_filter_async (fixture->manager,
|
||||
fixture->valid_uid,
|
||||
MCT_GET_APP_FILTER_FLAGS_NONE, NULL,
|
||||
MCT_MANAGER_GET_VALUE_FLAGS_NONE, NULL,
|
||||
async_result_cb, &result);
|
||||
|
||||
/* Handle the FindUserById() call. */
|
||||
|
@ -888,7 +888,7 @@ test_app_filter_bus_get_error_permission_denied_missing (BusFixture *fixture,
|
|||
|
||||
mct_manager_get_app_filter_async (fixture->manager,
|
||||
fixture->valid_uid,
|
||||
MCT_GET_APP_FILTER_FLAGS_NONE, NULL,
|
||||
MCT_MANAGER_GET_VALUE_FLAGS_NONE, NULL,
|
||||
async_result_cb, &result);
|
||||
|
||||
/* Handle the FindUserById() call. */
|
||||
|
@ -943,7 +943,7 @@ test_app_filter_bus_get_error_unknown (BusFixture *fixture,
|
|||
|
||||
mct_manager_get_app_filter_async (fixture->manager,
|
||||
fixture->valid_uid,
|
||||
MCT_GET_APP_FILTER_FLAGS_NONE, NULL,
|
||||
MCT_MANAGER_GET_VALUE_FLAGS_NONE, NULL,
|
||||
async_result_cb, &result);
|
||||
|
||||
/* Handle the FindUserById() call and return a bogus error. */
|
||||
|
@ -991,7 +991,7 @@ test_app_filter_bus_get_error_disabled (BusFixture *fixture,
|
|||
|
||||
mct_manager_get_app_filter_async (fixture->manager,
|
||||
fixture->valid_uid,
|
||||
MCT_GET_APP_FILTER_FLAGS_NONE, NULL,
|
||||
MCT_MANAGER_GET_VALUE_FLAGS_NONE, NULL,
|
||||
async_result_cb, &result);
|
||||
|
||||
/* Handle the FindUserById() call. */
|
||||
|
@ -1184,7 +1184,7 @@ test_app_filter_bus_set (BusFixture *fixture,
|
|||
|
||||
mct_manager_set_app_filter_async (fixture->manager,
|
||||
fixture->valid_uid, app_filter,
|
||||
MCT_SET_APP_FILTER_FLAGS_NONE, NULL,
|
||||
MCT_MANAGER_SET_VALUE_FLAGS_NONE, NULL,
|
||||
async_result_cb, &result);
|
||||
|
||||
while (result == NULL)
|
||||
|
@ -1196,7 +1196,7 @@ test_app_filter_bus_set (BusFixture *fixture,
|
|||
{
|
||||
success = mct_manager_set_app_filter (fixture->manager,
|
||||
fixture->valid_uid, app_filter,
|
||||
MCT_SET_APP_FILTER_FLAGS_NONE, NULL,
|
||||
MCT_MANAGER_SET_VALUE_FLAGS_NONE, NULL,
|
||||
&local_error);
|
||||
}
|
||||
|
||||
|
@ -1225,7 +1225,7 @@ test_app_filter_bus_set_error_invalid_user (BusFixture *fixture,
|
|||
|
||||
mct_manager_set_app_filter_async (fixture->manager,
|
||||
fixture->missing_uid, app_filter,
|
||||
MCT_SET_APP_FILTER_FLAGS_NONE, NULL,
|
||||
MCT_MANAGER_SET_VALUE_FLAGS_NONE, NULL,
|
||||
async_result_cb, &result);
|
||||
|
||||
/* Handle the FindUserById() call and claim the user doesn’t exist. */
|
||||
|
@ -1282,7 +1282,7 @@ test_app_filter_bus_set_error_permission_denied (BusFixture *fixture,
|
|||
|
||||
success = mct_manager_set_app_filter (fixture->manager,
|
||||
fixture->valid_uid, app_filter,
|
||||
MCT_SET_APP_FILTER_FLAGS_NONE, NULL,
|
||||
MCT_MANAGER_SET_VALUE_FLAGS_NONE, NULL,
|
||||
&local_error);
|
||||
|
||||
g_assert_error (local_error,
|
||||
|
@ -1320,7 +1320,7 @@ test_app_filter_bus_set_error_unknown (BusFixture *fixture,
|
|||
|
||||
success = mct_manager_set_app_filter (fixture->manager,
|
||||
fixture->valid_uid, app_filter,
|
||||
MCT_SET_APP_FILTER_FLAGS_NONE, NULL,
|
||||
MCT_MANAGER_SET_VALUE_FLAGS_NONE, NULL,
|
||||
&local_error);
|
||||
|
||||
g_assert_error (local_error, G_IO_ERROR, G_IO_ERROR_DBUS_ERROR);
|
||||
|
@ -1363,7 +1363,7 @@ test_app_filter_bus_set_error_invalid_property (BusFixture *fixture,
|
|||
|
||||
success = mct_manager_set_app_filter (fixture->manager,
|
||||
fixture->valid_uid, app_filter,
|
||||
MCT_SET_APP_FILTER_FLAGS_NONE, NULL,
|
||||
MCT_MANAGER_SET_VALUE_FLAGS_NONE, NULL,
|
||||
&local_error);
|
||||
|
||||
g_assert_error (local_error, G_DBUS_ERROR, G_DBUS_ERROR_INVALID_ARGS);
|
||||
|
|
|
@ -38,9 +38,9 @@ def __get_app_filter(user_id, interactive):
|
|||
If `interactive` is `True`, interactive polkit authorisation dialogues will
|
||||
be allowed. An exception will be raised on failure."""
|
||||
if interactive:
|
||||
flags = Malcontent.GetAppFilterFlags.INTERACTIVE
|
||||
flags = Malcontent.ManagerGetValueFlags.INTERACTIVE
|
||||
else:
|
||||
flags = Malcontent.GetAppFilterFlags.NONE
|
||||
flags = Malcontent.ManagerGetValueFlags.NONE
|
||||
|
||||
connection = Gio.bus_get_sync(Gio.BusType.SYSTEM)
|
||||
manager = Malcontent.Manager.new(connection)
|
||||
|
@ -66,9 +66,9 @@ def __set_app_filter(user_id, app_filter, interactive):
|
|||
If `interactive` is `True`, interactive polkit authorisation dialogues will
|
||||
be allowed. An exception will be raised on failure."""
|
||||
if interactive:
|
||||
flags = Malcontent.SetAppFilterFlags.INTERACTIVE
|
||||
flags = Malcontent.ManagerSetValueFlags.INTERACTIVE
|
||||
else:
|
||||
flags = Malcontent.SetAppFilterFlags.NONE
|
||||
flags = Malcontent.ManagerSetValueFlags.NONE
|
||||
|
||||
connection = Gio.bus_get_sync(Gio.BusType.SYSTEM)
|
||||
manager = Malcontent.Manager.new(connection)
|
||||
|
|
Loading…
Reference in New Issue