From 6f09483b4c34b039489eab605f373e31c707e1ff Mon Sep 17 00:00:00 2001 From: Philip Withnall Date: Tue, 7 Apr 2020 12:47:16 +0100 Subject: [PATCH 1/2] libmalcontent: Clarify nullability of MctManager:connection MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit It’s not. Signed-off-by: Philip Withnall --- libmalcontent/manager.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libmalcontent/manager.c b/libmalcontent/manager.c index 62c340e..1a69ba2 100644 --- a/libmalcontent/manager.c +++ b/libmalcontent/manager.c @@ -98,7 +98,7 @@ mct_manager_set_property (GObject *object, switch ((MctManagerProperty) property_id) { case PROP_CONNECTION: - /* Construct-only. May be %NULL. */ + /* Construct-only. May not be %NULL. */ g_assert (self->connection == NULL); self->connection = g_value_dup_object (value); g_assert (self->connection != NULL); @@ -167,7 +167,7 @@ mct_manager_class_init (MctManagerClass *klass) object_class->set_property = mct_manager_set_property; /** - * MctManager:connection: + * MctManager:connection: (not nullable) * * A connection to the system bus, where accounts-service runs. It’s provided * mostly for testing purposes, or to allow an existing connection to be From 28992ac7f3b779b0a03c3c37a2ddfa630d604952 Mon Sep 17 00:00:00 2001 From: Philip Withnall Date: Tue, 7 Apr 2020 12:47:59 +0100 Subject: [PATCH 2/2] user-controls: Add a fallback bus connection MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This is a hack to allow `MctUserControls` to be used from `GtkBuilder` templates, where it’s not possible to pass construct-only properties in to the `MctUserControls` constructor. It’s not feasible to make `MctUserControls:dbus-connection` not construct-only, because it gets used to construct an `MctManager` which then subscribes to various signals. So for the cases where `MctUserControls` is used from a builder template, the code has to connect to the system bus manually, which is possibly (though unlikely) a blocking operation. This fixes a critical warning when enabling parental controls in gnome-initial-setup. Signed-off-by: Philip Withnall --- libmalcontent-ui/user-controls.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/libmalcontent-ui/user-controls.c b/libmalcontent-ui/user-controls.c index fd4f147..bec59e7 100644 --- a/libmalcontent-ui/user-controls.c +++ b/libmalcontent-ui/user-controls.c @@ -728,6 +728,17 @@ mct_user_controls_constructed (GObject *object) /* Chain up. */ G_OBJECT_CLASS (mct_user_controls_parent_class)->constructed (object); + /* FIXME: Ideally there wouldn’t be this sync call in a constructor, but there + * seems to be no way around it if #MctUserControls is to be used from a + * GtkBuilder template: templates are initialised from within the parent + * widget’s init() function (not its constructed() function), so none of its + * properties will have been set and it won’t reasonably have been able to + * make an async call to initialise the bus connection itself. Binding + * construct-only properties in GtkBuilder doesn’t work (and wouldn’t help if + * it did). */ + if (self->dbus_connection == NULL) + self->dbus_connection = g_bus_get_sync (G_BUS_TYPE_SYSTEM, NULL, NULL); + g_assert (self->dbus_connection != NULL); self->manager = mct_manager_new (self->dbus_connection); }