session-limits: Add mct_session_limits_is_enabled() API
This is a high-level API to indicate whether parental controls are ‘enabled’ for the given user. It’s a mirror of `mct_app_filter_is_enabled()`, and exposes the existing `time_limit_enabled_out` argument of `mct_session_limits_check_time_remaining()` more conveniently. Includes tests. Signed-off-by: Philip Withnall <withnall@endlessm.com>
This commit is contained in:
parent
f106319fdd
commit
04705c079a
|
@ -98,6 +98,31 @@ mct_session_limits_get_user_id (MctSessionLimits *limits)
|
||||||
return limits->user_id;
|
return limits->user_id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* mct_session_limits_is_enabled:
|
||||||
|
* @limits: an #MctSessionLimits
|
||||||
|
*
|
||||||
|
* Check whether any session limits are enabled and are going to impose at least
|
||||||
|
* one restriction on the user. This gives a high level view of whether session
|
||||||
|
* limit parental controls are ‘enabled’ for the given user.
|
||||||
|
*
|
||||||
|
* This function is equivalent to the value returned by the
|
||||||
|
* `time_limit_enabled_out` argument of
|
||||||
|
* mct_session_limits_check_time_remaining().
|
||||||
|
*
|
||||||
|
* Returns: %TRUE if the session limits object contains at least one restrictive
|
||||||
|
* session limit, %FALSE if there are no limits in place
|
||||||
|
* Since: 0.7.0
|
||||||
|
*/
|
||||||
|
gboolean
|
||||||
|
mct_session_limits_is_enabled (MctSessionLimits *limits)
|
||||||
|
{
|
||||||
|
g_return_val_if_fail (limits != NULL, FALSE);
|
||||||
|
g_return_val_if_fail (limits->ref_count >= 1, FALSE);
|
||||||
|
|
||||||
|
return (limits->limit_type != MCT_SESSION_LIMITS_TYPE_NONE);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* mct_session_limits_check_time_remaining:
|
* mct_session_limits_check_time_remaining:
|
||||||
* @limits: an #MctSessionLimits
|
* @limits: an #MctSessionLimits
|
||||||
|
|
|
@ -52,6 +52,9 @@ void mct_session_limits_unref (MctSessionLimits *limits);
|
||||||
G_DEFINE_AUTOPTR_CLEANUP_FUNC (MctSessionLimits, mct_session_limits_unref)
|
G_DEFINE_AUTOPTR_CLEANUP_FUNC (MctSessionLimits, mct_session_limits_unref)
|
||||||
|
|
||||||
uid_t mct_session_limits_get_user_id (MctSessionLimits *limits);
|
uid_t mct_session_limits_get_user_id (MctSessionLimits *limits);
|
||||||
|
|
||||||
|
gboolean mct_session_limits_is_enabled (MctSessionLimits *limits);
|
||||||
|
|
||||||
gboolean mct_session_limits_check_time_remaining (MctSessionLimits *limits,
|
gboolean mct_session_limits_check_time_remaining (MctSessionLimits *limits,
|
||||||
guint64 now_usecs,
|
guint64 now_usecs,
|
||||||
guint64 *time_remaining_secs_out,
|
guint64 *time_remaining_secs_out,
|
||||||
|
|
|
@ -518,6 +518,7 @@ test_session_limits_bus_get (BusFixture *fixture,
|
||||||
|
|
||||||
/* Check the session limits properties. */
|
/* Check the session limits properties. */
|
||||||
g_assert_cmpuint (mct_session_limits_get_user_id (session_limits), ==, fixture->valid_uid);
|
g_assert_cmpuint (mct_session_limits_get_user_id (session_limits), ==, fixture->valid_uid);
|
||||||
|
g_assert_true (mct_session_limits_is_enabled (session_limits));
|
||||||
g_assert_false (mct_session_limits_check_time_remaining (session_limits, usec (0),
|
g_assert_false (mct_session_limits_check_time_remaining (session_limits, usec (0),
|
||||||
&time_remaining_secs, &time_limit_enabled));
|
&time_remaining_secs, &time_limit_enabled));
|
||||||
g_assert_true (time_limit_enabled);
|
g_assert_true (time_limit_enabled);
|
||||||
|
@ -580,6 +581,7 @@ test_session_limits_bus_get_none (BusFixture *fixture,
|
||||||
|
|
||||||
/* Check the session limits properties. */
|
/* Check the session limits properties. */
|
||||||
g_assert_cmpuint (mct_session_limits_get_user_id (session_limits), ==, fixture->valid_uid);
|
g_assert_cmpuint (mct_session_limits_get_user_id (session_limits), ==, fixture->valid_uid);
|
||||||
|
g_assert_false (mct_session_limits_is_enabled (session_limits));
|
||||||
g_assert_true (mct_session_limits_check_time_remaining (session_limits, usec (0),
|
g_assert_true (mct_session_limits_check_time_remaining (session_limits, usec (0),
|
||||||
&time_remaining_secs, &time_limit_enabled));
|
&time_remaining_secs, &time_limit_enabled));
|
||||||
g_assert_false (time_limit_enabled);
|
g_assert_false (time_limit_enabled);
|
||||||
|
|
Loading…
Reference in New Issue