From dee4d92ea97c2ce4e919294ab9ae2cc1cb011c11 Mon Sep 17 00:00:00 2001 From: Philip Withnall Date: Mon, 24 Feb 2020 17:04:04 +0000 Subject: [PATCH] restrict-applications-dialog: Invert controls to be restrictive Signed-off-by: Philip Withnall Helps: #11 --- libmalcontent-ui/restrict-applications-dialog.c | 2 +- .../restrict-applications-dialog.ui | 2 +- .../restrict-applications-selector.c | 17 +++++++++++++++-- 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/libmalcontent-ui/restrict-applications-dialog.c b/libmalcontent-ui/restrict-applications-dialog.c index d231466..ed70c19 100644 --- a/libmalcontent-ui/restrict-applications-dialog.c +++ b/libmalcontent-ui/restrict-applications-dialog.c @@ -217,7 +217,7 @@ update_description (MctRestrictApplicationsDialog *self) } /* Translators: the placeholder is a user’s full name */ - description = g_strdup_printf (_("Allow %s to use the following installed applications."), + description = g_strdup_printf (_("Restrict %s from using the following installed applications."), self->user_display_name); gtk_label_set_text (self->description, description); gtk_widget_show (GTK_WIDGET (self->description)); diff --git a/libmalcontent-ui/restrict-applications-dialog.ui b/libmalcontent-ui/restrict-applications-dialog.ui index e95ff36..13996c0 100644 --- a/libmalcontent-ui/restrict-applications-dialog.ui +++ b/libmalcontent-ui/restrict-applications-dialog.ui @@ -22,7 +22,7 @@ - Allow {username} to use the following installed applications. + Restrict {username} from using the following installed applications. False diff --git a/libmalcontent-ui/restrict-applications-selector.c b/libmalcontent-ui/restrict-applications-selector.c index b203bee..a38d1ae 100644 --- a/libmalcontent-ui/restrict-applications-selector.c +++ b/libmalcontent-ui/restrict-applications-selector.c @@ -68,6 +68,8 @@ struct _MctRestrictApplicationsSelector FlatpakInstallation *system_installation; /* (owned) */ FlatpakInstallation *user_installation; /* (owned) */ + + GtkCssProvider *css_provider; /* (owned) */ }; G_DEFINE_TYPE (MctRestrictApplicationsSelector, mct_restrict_applications_selector, GTK_TYPE_BOX) @@ -157,6 +159,7 @@ mct_restrict_applications_selector_dispose (GObject *object) g_clear_pointer (&self->app_filter, mct_app_filter_unref); g_clear_object (&self->system_installation); g_clear_object (&self->user_installation); + g_clear_object (&self->css_provider); G_OBJECT_CLASS (mct_restrict_applications_selector_parent_class)->dispose (object); } @@ -239,6 +242,10 @@ mct_restrict_applications_selector_init (MctRestrictApplicationsSelector *self) self->system_installation = flatpak_installation_new_system (NULL, NULL); self->user_installation = flatpak_installation_new_user (NULL, NULL); + + self->css_provider = gtk_css_provider_new (); + gtk_css_provider_load_from_resource (self->css_provider, + "/org/freedesktop/MalcontentUi/ui/restricts-switch.css"); } static void @@ -251,7 +258,7 @@ on_switch_active_changed_cb (GtkSwitch *s, gboolean allowed; app = g_object_get_data (G_OBJECT (s), "GAppInfo"); - allowed = gtk_switch_get_active (s); + allowed = !gtk_switch_get_active (s); if (allowed) { @@ -286,6 +293,7 @@ create_row_for_app_cb (gpointer item, gboolean allowed; const gchar *app_name; gint size; + GtkStyleContext *context; app_name = g_app_info_get_name (app); @@ -319,6 +327,11 @@ create_row_for_app_cb (gpointer item, w = g_object_new (GTK_TYPE_SWITCH, "valign", GTK_ALIGN_CENTER, NULL); + context = gtk_widget_get_style_context (w); + gtk_style_context_add_class (context, "restricts"); + gtk_style_context_add_provider (context, + GTK_STYLE_PROVIDER (self->css_provider), + GTK_STYLE_PROVIDER_PRIORITY_APPLICATION - 1); gtk_container_add (GTK_CONTAINER (box), w); gtk_widget_show_all (box); @@ -326,7 +339,7 @@ create_row_for_app_cb (gpointer item, /* Fetch status from AccountService */ allowed = mct_app_filter_is_appinfo_allowed (self->app_filter, app); - gtk_switch_set_active (GTK_SWITCH (w), allowed); + 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)