user-controls: Split out app filter construction into a new method

This means that calling code can extract the app filter manually rather
than having to rely on the `MctUserControls` to save it. This will be
useful in a few commits’ time when support is added for using
`MctUserControls` for not-yet-created users.

Signed-off-by: Philip Withnall <withnall@endlessm.com>
This commit is contained in:
Philip Withnall 2020-02-06 12:06:03 +00:00
parent e3f923b294
commit 7dfd03907d
2 changed files with 78 additions and 54 deletions

View File

@ -444,63 +444,10 @@ blacklist_apps_cb (gpointer data)
g_autoptr(MctAppFilter) new_filter = NULL; g_autoptr(MctAppFilter) new_filter = NULL;
g_autoptr(GError) error = NULL; g_autoptr(GError) error = NULL;
MctUserControls *self = data; MctUserControls *self = data;
gboolean allow_web_browsers;
gsize i;
self->blacklist_apps_source_id = 0; self->blacklist_apps_source_id = 0;
g_debug ("Building parental controls settings…"); mct_user_controls_build_app_filter (self, &builder);
/* Blacklist */
g_debug ("\t → Blacklisting apps");
mct_restrict_applications_dialog_build_app_filter (self->restrict_applications_dialog, &builder);
/* Maturity level */
g_debug ("\t → Maturity level");
if (self->selected_age == oars_disabled_age)
g_debug ("\t\t → Disabled");
for (i = 0; self->selected_age != oars_disabled_age && oars_categories[i] != NULL; i++)
{
MctAppFilterOarsValue oars_value;
const gchar *oars_category;
oars_category = oars_categories[i];
oars_value = 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));
mct_app_filter_builder_set_oars_value (&builder, oars_category, oars_value);
}
/* Web browsers */
allow_web_browsers = gtk_switch_get_active (self->allow_web_browsers_switch);
g_debug ("\t → %s web browsers", allow_web_browsers ? "Enabling" : "Disabling");
if (!allow_web_browsers)
mct_app_filter_builder_blacklist_content_type (&builder, WEB_BROWSERS_CONTENT_TYPE);
/* App installation */
if (act_user_get_account_type (self->user) != ACT_USER_ACCOUNT_TYPE_ADMINISTRATOR)
{
gboolean allow_system_installation;
gboolean allow_user_installation;
allow_system_installation = gtk_switch_get_active (self->allow_system_installation_switch);
allow_user_installation = gtk_switch_get_active (self->allow_user_installation_switch);
g_debug ("\t → %s system installation", allow_system_installation ? "Enabling" : "Disabling");
g_debug ("\t → %s user installation", allow_user_installation ? "Enabling" : "Disabling");
mct_app_filter_builder_set_allow_user_installation (&builder, allow_user_installation);
mct_app_filter_builder_set_allow_system_installation (&builder, allow_system_installation);
}
new_filter = mct_app_filter_builder_end (&builder); new_filter = mct_app_filter_builder_end (&builder);
/* FIXME: should become asynchronous */ /* FIXME: should become asynchronous */
@ -905,3 +852,76 @@ mct_user_controls_set_permission (MctUserControls *self,
g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_PERMISSION]); g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_PERMISSION]);
} }
/**
* mct_user_controls_build_app_filter:
* @self: an #MctUserControls
* @builder: an existing #MctAppFilterBuilder to modify
*
* Get the app filter settings currently configured in the user controls, by
* modifying the given @builder. This can be used to save the settings manually.
*
* Since: 0.5.0
*/
void
mct_user_controls_build_app_filter (MctUserControls *self,
MctAppFilterBuilder *builder)
{
gboolean allow_web_browsers;
gsize i;
g_return_if_fail (MCT_IS_USER_CONTROLS (self));
g_return_if_fail (builder != NULL);
g_debug ("Building parental controls settings…");
/* Blacklist */
g_debug ("\t → Blacklisting apps");
mct_restrict_applications_dialog_build_app_filter (self->restrict_applications_dialog, builder);
/* Maturity level */
g_debug ("\t → Maturity level");
if (self->selected_age == oars_disabled_age)
g_debug ("\t\t → Disabled");
for (i = 0; self->selected_age != oars_disabled_age && oars_categories[i] != NULL; i++)
{
MctAppFilterOarsValue oars_value;
const gchar *oars_category;
oars_category = oars_categories[i];
oars_value = 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));
mct_app_filter_builder_set_oars_value (builder, oars_category, oars_value);
}
/* Web browsers */
allow_web_browsers = gtk_switch_get_active (self->allow_web_browsers_switch);
g_debug ("\t → %s web browsers", allow_web_browsers ? "Enabling" : "Disabling");
if (!allow_web_browsers)
mct_app_filter_builder_blacklist_content_type (builder, WEB_BROWSERS_CONTENT_TYPE);
/* App installation */
if (self->user_account_type != ACT_USER_ACCOUNT_TYPE_ADMINISTRATOR)
{
gboolean allow_system_installation;
gboolean allow_user_installation;
allow_system_installation = gtk_switch_get_active (self->allow_system_installation_switch);
allow_user_installation = gtk_switch_get_active (self->allow_user_installation_switch);
g_debug ("\t → %s system installation", allow_system_installation ? "Enabling" : "Disabling");
g_debug ("\t → %s user installation", allow_user_installation ? "Enabling" : "Disabling");
mct_app_filter_builder_set_allow_user_installation (builder, allow_user_installation);
mct_app_filter_builder_set_allow_system_installation (builder, allow_system_installation);
}
}

View File

@ -24,6 +24,7 @@
#include <act/act.h> #include <act/act.h>
#include <gtk/gtk.h> #include <gtk/gtk.h>
#include <libmalcontent/malcontent.h>
G_BEGIN_DECLS G_BEGIN_DECLS
@ -39,4 +40,7 @@ GPermission *mct_user_controls_get_permission (MctUserControls *self);
void mct_user_controls_set_permission (MctUserControls *self, void mct_user_controls_set_permission (MctUserControls *self,
GPermission *permission); GPermission *permission);
void mct_user_controls_build_app_filter (MctUserControls *self,
MctAppFilterBuilder *builder);
G_END_DECLS G_END_DECLS