libmalcontent: Factor getting/setting app filter into a manager

Create a new MctManager object which is used as the anchor for getting
or setting MctAppFilters.

This changes the API naming around quite a bit, but doesn’t really
change its behaviour or functionality — see the tests for examples of
how little things change.

This is one step on the way to emitting a signal (from MctManager) when
a user’s parental controls change.

Signed-off-by: Philip Withnall <withnall@endlessm.com>

https://gitlab.freedesktop.org/pwithnall/malcontent/issues/1
This commit is contained in:
Philip Withnall 2019-04-24 12:44:50 +01:00
parent 388dedbff2
commit 68ebe8b568
8 changed files with 1074 additions and 829 deletions

View file

@ -22,7 +22,7 @@ import pwd
import sys
import gi
gi.require_version('Malcontent', '0') # noqa
from gi.repository import Malcontent, GLib
from gi.repository import Malcontent, GLib, Gio
# Exit codes, which are a documented part of the API.
@ -42,8 +42,10 @@ def __get_app_filter(user_id, interactive):
else:
flags = Malcontent.GetAppFilterFlags.NONE
return Malcontent.get_app_filter(
connection=None, user_id=user_id,
connection = Gio.bus_get_sync(Gio.BusType.SYSTEM)
manager = Malcontent.Manager.new(connection)
return manager.get_app_filter(
user_id=user_id,
flags=flags, cancellable=None)
@ -68,8 +70,10 @@ def __set_app_filter(user_id, app_filter, interactive):
else:
flags = Malcontent.GetAppFilterFlags.NONE
Malcontent.set_app_filter(
connection=None, user_id=user_id, app_filter=app_filter,
connection = Gio.bus_get_sync(Gio.BusType.SYSTEM)
manager = Malcontent.Manager.new(connection)
manager.set_app_filter(
user_id=user_id, app_filter=app_filter,
flags=flags, cancellable=None)