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]); } 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);