app-filter: Add mct_app_filter_is_enabled() API
This is a high-level API to indicate whether parental controls are ‘enabled’ for the given user. Specifically, whether any of the properties of the `MctAppFilter` differ from their default value. Includes tests. Signed-off-by: Philip Withnall <withnall@endlessm.com>
This commit is contained in:
parent
faa0b9a3eb
commit
f106319fdd
3 changed files with 112 additions and 0 deletions
|
@ -123,6 +123,54 @@ oars_str_to_enum (const gchar *value_str)
|
|||
return MCT_APP_FILTER_OARS_VALUE_UNKNOWN;
|
||||
}
|
||||
|
||||
/**
|
||||
* mct_app_filter_is_enabled:
|
||||
* @filter: an #MctAppFilter
|
||||
*
|
||||
* Check whether the app filter is enabled and is going to impose at least one
|
||||
* restriction on the user. This gives a high level view of whether app filter
|
||||
* parental controls are ‘enabled’ for the given user.
|
||||
*
|
||||
* Returns: %TRUE if the app filter contains at least one non-default value,
|
||||
* %FALSE if it’s entirely default
|
||||
* Since: 0.7.0
|
||||
*/
|
||||
gboolean
|
||||
mct_app_filter_is_enabled (MctAppFilter *filter)
|
||||
{
|
||||
gboolean oars_ratings_all_intense_or_unknown;
|
||||
GVariantIter iter;
|
||||
const gchar *oars_value;
|
||||
|
||||
g_return_val_if_fail (filter != NULL, FALSE);
|
||||
g_return_val_if_fail (filter->ref_count >= 1, FALSE);
|
||||
|
||||
/* The least restrictive OARS filter has all values as intense, or unknown. */
|
||||
oars_ratings_all_intense_or_unknown = TRUE;
|
||||
g_variant_iter_init (&iter, filter->oars_ratings);
|
||||
|
||||
while (g_variant_iter_loop (&iter, "{&s&s}", NULL, &oars_value))
|
||||
{
|
||||
MctAppFilterOarsValue value = oars_str_to_enum (oars_value);
|
||||
|
||||
if (value != MCT_APP_FILTER_OARS_VALUE_UNKNOWN &&
|
||||
value != MCT_APP_FILTER_OARS_VALUE_INTENSE)
|
||||
{
|
||||
oars_ratings_all_intense_or_unknown = FALSE;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* Check all fields against their default values. Ignore
|
||||
* `allow_system_installation` since it’s false by default, so the default
|
||||
* value is already the most restrictive. */
|
||||
return ((filter->app_list_type == MCT_APP_FILTER_LIST_BLACKLIST &&
|
||||
filter->app_list[0] != NULL) ||
|
||||
filter->app_list_type == MCT_APP_FILTER_LIST_WHITELIST ||
|
||||
!oars_ratings_all_intense_or_unknown ||
|
||||
!filter->allow_user_installation);
|
||||
}
|
||||
|
||||
/**
|
||||
* mct_app_filter_is_path_allowed:
|
||||
* @filter: an #MctAppFilter
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue