From e7588a2333c4e51229f126f826e0f7db73dc20ea Mon Sep 17 00:00:00 2001 From: Philip Withnall Date: Thu, 29 Oct 2020 19:20:14 +0000 Subject: [PATCH 1/2] libmalcontent-ui: Sync switches with app filter when loading selector MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Since the changes to avoid reloading the app list entirely when loading an app filter (commit 9d4639cf49f), the switch states haven’t been set properly when loading a new app filter, since the app rows already exist, and the switch states were only set on creation. Signed-off-by: Philip Withnall --- .../restrict-applications-selector.c | 53 +++++++++++++++---- 1 file changed, 42 insertions(+), 11 deletions(-) diff --git a/libmalcontent-ui/restrict-applications-selector.c b/libmalcontent-ui/restrict-applications-selector.c index b595793..3cafa9e 100644 --- a/libmalcontent-ui/restrict-applications-selector.c +++ b/libmalcontent-ui/restrict-applications-selector.c @@ -290,6 +290,21 @@ on_switch_active_changed_cb (GtkSwitch *s, g_signal_emit (self, signals[SIGNAL_CHANGED], 0); } +static void +update_listbox_row_switch (MctRestrictApplicationsSelector *self, + GtkSwitch *w) +{ + GAppInfo *app = g_object_get_data (G_OBJECT (w), "GAppInfo"); + gboolean allowed = mct_app_filter_is_appinfo_allowed (self->app_filter, app); + + gtk_switch_set_active (w, !allowed); + + if (allowed) + g_hash_table_remove (self->blocklisted_apps, app); + else + g_hash_table_add (self->blocklisted_apps, g_object_ref (app)); +} + static GtkWidget * create_row_for_app_cb (gpointer item, gpointer user_data) @@ -298,7 +313,6 @@ create_row_for_app_cb (gpointer item, GAppInfo *app = G_APP_INFO (item); g_autoptr(GIcon) icon = NULL; GtkWidget *box, *w; - gboolean allowed; const gchar *app_name; gint size; GtkStyleContext *context; @@ -345,16 +359,8 @@ create_row_for_app_cb (gpointer item, gtk_widget_show_all (box); /* Fetch status from AccountService */ - allowed = mct_app_filter_is_appinfo_allowed (self->app_filter, app); - - gtk_switch_set_active (GTK_SWITCH (w), !allowed); g_object_set_data_full (G_OBJECT (w), "GAppInfo", g_object_ref (app), g_object_unref); - - if (allowed) - g_hash_table_remove (self->blocklisted_apps, app); - else - g_hash_table_add (self->blocklisted_apps, g_object_ref (app)); - + update_listbox_row_switch (self, GTK_SWITCH (w)); g_signal_connect (w, "notify::active", G_CALLBACK (on_switch_active_changed_cb), self); return box; @@ -751,6 +757,7 @@ mct_restrict_applications_selector_set_app_filter (MctRestrictApplicationsSelect MctAppFilter *app_filter) { g_autoptr(MctAppFilter) owned_app_filter = NULL; + guint n_apps; g_return_if_fail (MCT_IS_RESTRICT_APPLICATIONS_SELECTOR (self)); @@ -768,6 +775,30 @@ mct_restrict_applications_selector_set_app_filter (MctRestrictApplicationsSelect g_clear_pointer (&self->app_filter, mct_app_filter_unref); self->app_filter = mct_app_filter_ref (app_filter); - reload_apps (self); + /* Update the status of each app row. */ + n_apps = g_list_model_get_n_items (G_LIST_MODEL (self->apps)); + + for (guint i = 0; i < n_apps; i++) + { + GtkListBoxRow *row; + GtkWidget *box, *w; + g_autoptr(GList) children = NULL; /* (element-type GtkWidget) */ + + /* Navigate the widget hierarchy set up in create_row_for_app_cb(). */ + row = gtk_list_box_get_row_at_index (self->listbox, i); + g_assert (row != NULL && GTK_IS_LIST_BOX_ROW (row)); + + box = gtk_bin_get_child (GTK_BIN (row)); + g_assert (box != NULL && GTK_IS_BOX (box)); + + children = gtk_container_get_children (GTK_CONTAINER (box)); + g_assert (children != NULL); + + w = g_list_nth_data (children, 2); + g_assert (w != NULL && GTK_IS_SWITCH (w)); + + update_listbox_row_switch (self, GTK_SWITCH (w)); + } + g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_APP_FILTER]); } From ecfb3035d53ef971c84daf31dd13292c6fc5317d Mon Sep 17 00:00:00 2001 From: Philip Withnall Date: Thu, 29 Oct 2020 19:22:13 +0000 Subject: [PATCH 2/2] libmalcontent-ui: Load restricted apps and OARS when loading app filter MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit While the label for the OARS pseudo-combobox was updated when loading a user’s app filter, the internal state (`self->selected_age`) was not. Similarly, the set of restricted apps wasn’t loaded until the restricted apps dialog was opened. This caused problems when loading a user’s parental controls and then editing a control which *wasn’t* restricted apps or the OARS level. The resulting app filter would be built using default values for those two controls, overwriting and losing their previous values when it was saved. Signed-off-by: Philip Withnall --- libmalcontent-ui/user-controls.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/libmalcontent-ui/user-controls.c b/libmalcontent-ui/user-controls.c index 8689a78..22942fd 100644 --- a/libmalcontent-ui/user-controls.c +++ b/libmalcontent-ui/user-controls.c @@ -313,6 +313,12 @@ update_app_filter_from_user (MctUserControls *self) g_debug ("Retrieved new app filter for user '%s'", act_user_get_user_name (self->user)); } +static void +update_restricted_apps (MctUserControls *self) +{ + mct_restrict_applications_dialog_set_app_filter (self->restrict_applications_dialog, self->filter); +} + static void update_categories_from_language (MctUserControls *self) { @@ -385,7 +391,7 @@ update_oars_level (MctUserControls *self) { GsContentRatingSystem rating_system; g_autofree gchar *rating_age_category = NULL; - guint maximum_age; + guint maximum_age, selected_age; gsize i; gboolean all_categories_unset; #if AS_CHECK_VERSION(0, 7, 15) @@ -423,9 +429,15 @@ update_oars_level (MctUserControls *self) { g_clear_pointer (&rating_age_category, g_free); rating_age_category = g_strdup (_("All Ages")); + selected_age = oars_disabled_age; + } + else + { + selected_age = maximum_age; } gtk_label_set_label (self->oars_button_label, rating_age_category); + self->selected_age = selected_age; } static void @@ -550,6 +562,7 @@ setup_parental_control_settings (MctUserControls *self) gtk_widget_set_sensitive (GTK_WIDGET (self), is_authorized); + update_restricted_apps (self); update_categories_from_language (self); update_oars_level (self); update_allow_app_installation (self);