diff options
Diffstat (limited to 'gnome-initial-setup/pages/privacy')
5 files changed, 424 insertions, 0 deletions
diff --git a/gnome-initial-setup/pages/privacy/gis-privacy-page.c b/gnome-initial-setup/pages/privacy/gis-privacy-page.c new file mode 100644 index 0000000..3632142 --- /dev/null +++ b/gnome-initial-setup/pages/privacy/gis-privacy-page.c @@ -0,0 +1,272 @@ +/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */ +/* + * Copyright (C) 2015 Red Hat + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see <http://www.gnu.org/licenses/>. + * + * Written by: + * Matthias Clasen <mclasen@redhat.com> + */ + +/* Privacy page {{{1 */ + +#define PAGE_ID "privacy" + +#include "config.h" +#include "privacy-resources.h" +#include "gis-privacy-page.h" + +#ifdef HAVE_WEBKITGTK_6_0 +#include <webkit/webkit.h> +#else +#include <webkit2/webkit2.h> +#endif + +#include <locale.h> +#include <gtk/gtk.h> + +#include "gis-page-header.h" + +struct _GisPrivacyPagePrivate +{ + GtkWidget *location_switch; + GtkWidget *reporting_group; + GtkWidget *reporting_row; + GtkWidget *reporting_switch; + GSettings *location_settings; + GSettings *privacy_settings; + guint abrt_watch_id; +}; +typedef struct _GisPrivacyPagePrivate GisPrivacyPagePrivate; + +G_DEFINE_TYPE_WITH_PRIVATE (GisPrivacyPage, gis_privacy_page, GIS_TYPE_PAGE); + +static void +update_os_data (GisPrivacyPage *page) +{ + GisPrivacyPagePrivate *priv = gis_privacy_page_get_instance_private (page); + g_autofree char *name = g_get_os_info (G_OS_INFO_KEY_NAME); + g_autofree char *privacy_policy = g_get_os_info (G_OS_INFO_KEY_PRIVACY_POLICY_URL); + g_autofree char *subtitle = NULL; + + if (!name) + name = g_strdup ("GNOME"); + + if (privacy_policy) + { + /* Translators: the first parameter here is the name of a distribution, + * like "Fedora" or "Ubuntu". It falls back to "GNOME" if we can't + * detect any distribution. + */ + subtitle = g_strdup_printf (_("Sends technical reports that have personal information automatically " + "removed. Data is collected by %1$s (<a href='%2$s'>privacy policy</a>)."), + name, privacy_policy); + } + else + { + /* Translators: the parameter here is the name of a distribution, + * like "Fedora" or "Ubuntu". It falls back to "GNOME" if we can't + * detect any distribution. + */ + subtitle = g_strdup_printf (_("Sends technical reports that have personal information automatically " + "removed. Data is collected by %s."), name); + } + adw_action_row_set_subtitle (ADW_ACTION_ROW (priv->reporting_row), subtitle); +} + +static void +abrt_appeared_cb (GDBusConnection *connection, + const gchar *name, + const gchar *name_owner, + gpointer user_data) +{ + GisPrivacyPage *page = user_data; + GisPrivacyPagePrivate *priv = gis_privacy_page_get_instance_private (page); + + gtk_widget_show (priv->reporting_group); +} + +static void +abrt_vanished_cb (GDBusConnection *connection, + const gchar *name, + gpointer user_data) +{ + GisPrivacyPage *page = user_data; + GisPrivacyPagePrivate *priv = gis_privacy_page_get_instance_private (page); + + gtk_widget_hide (priv->reporting_group); +} + +static void +gis_privacy_page_constructed (GObject *object) +{ + GisPrivacyPage *page = GIS_PRIVACY_PAGE (object); + GisPrivacyPagePrivate *priv = gis_privacy_page_get_instance_private (page); + + G_OBJECT_CLASS (gis_privacy_page_parent_class)->constructed (object); + + gis_page_set_complete (GIS_PAGE (page), TRUE); + + priv->location_settings = g_settings_new ("org.gnome.system.location"); + priv->privacy_settings = g_settings_new ("org.gnome.desktop.privacy"); + + gtk_switch_set_active (GTK_SWITCH (priv->location_switch), TRUE); + gtk_switch_set_active (GTK_SWITCH (priv->reporting_switch), TRUE); + + update_os_data (page); + + priv->abrt_watch_id = g_bus_watch_name (G_BUS_TYPE_SYSTEM, + "org.freedesktop.problems.daemon", + G_BUS_NAME_WATCHER_FLAGS_NONE, + abrt_appeared_cb, + abrt_vanished_cb, + page, + NULL); +} + +static void +gis_privacy_page_dispose (GObject *object) +{ + GisPrivacyPage *page = GIS_PRIVACY_PAGE (object); + GisPrivacyPagePrivate *priv = gis_privacy_page_get_instance_private (page); + + g_clear_object (&priv->location_settings); + g_clear_object (&priv->privacy_settings); + + if (priv->abrt_watch_id > 0) + { + g_bus_unwatch_name (priv->abrt_watch_id); + priv->abrt_watch_id = 0; + } + + G_OBJECT_CLASS (gis_privacy_page_parent_class)->dispose (object); +} + +static gboolean +gis_privacy_page_apply (GisPage *gis_page, + GCancellable *cancellable) +{ + GisPrivacyPage *page = GIS_PRIVACY_PAGE (gis_page); + GisPrivacyPagePrivate *priv = gis_privacy_page_get_instance_private (page); + gboolean active; + + active = gtk_switch_get_active (GTK_SWITCH (priv->location_switch)); + g_settings_set_boolean (priv->location_settings, "enabled", active); + + active = gtk_switch_get_active (GTK_SWITCH (priv->reporting_switch)); + g_settings_set_boolean (priv->privacy_settings, "report-technical-problems", active); + + return FALSE; +} + +static void +notify_progress_cb (GObject *object, GParamSpec *pspec, gpointer user_data) +{ + GtkWidget *progress_bar = user_data; + WebKitWebView *web_view = WEBKIT_WEB_VIEW (object); + gdouble progress; + + progress = webkit_web_view_get_estimated_load_progress (web_view); + + if (progress == 1.0) + gtk_widget_hide (progress_bar); + else + gtk_widget_show (progress_bar); + + gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR (progress_bar), progress); +} + +static gboolean +activate_link (GtkLabel *label, + const gchar *uri, + GisPrivacyPage *page) +{ + GtkWidget *dialog; + GtkWidget *overlay; + GtkWidget *view; + GtkWidget *progress_bar; + + dialog = gtk_dialog_new_with_buttons (_("Privacy Policy"), + GTK_WINDOW (gtk_widget_get_root (GTK_WIDGET (page))), + GTK_DIALOG_MODAL + | GTK_DIALOG_DESTROY_WITH_PARENT + | GTK_DIALOG_USE_HEADER_BAR, + NULL, NULL); + + overlay = gtk_overlay_new (); + gtk_box_append (GTK_BOX (gtk_dialog_get_content_area (GTK_DIALOG (dialog))), overlay); + + progress_bar = gtk_progress_bar_new (); + gtk_widget_add_css_class (progress_bar, "osd"); + gtk_widget_set_halign (progress_bar, GTK_ALIGN_FILL); + gtk_widget_set_valign (progress_bar, GTK_ALIGN_START); + gtk_overlay_add_overlay (GTK_OVERLAY (overlay), progress_bar); + + view = webkit_web_view_new (); + gtk_widget_set_size_request (view, 600, 500); + gtk_widget_set_hexpand (view, TRUE); + gtk_widget_set_vexpand (view, TRUE); + g_signal_connect (view, "notify::estimated-load-progress", + G_CALLBACK (notify_progress_cb), progress_bar); + gtk_overlay_set_child (GTK_OVERLAY (overlay), view); + + + gtk_window_present (GTK_WINDOW (dialog)); + + webkit_web_view_load_uri (WEBKIT_WEB_VIEW (view), uri); + + return TRUE; +} + +static void +gis_privacy_page_locale_changed (GisPage *page) +{ + gis_page_set_title (GIS_PAGE (page), _("Privacy")); +} + +static void +gis_privacy_page_class_init (GisPrivacyPageClass *klass) +{ + GisPageClass *page_class = GIS_PAGE_CLASS (klass); + GObjectClass *object_class = G_OBJECT_CLASS (klass); + + gtk_widget_class_set_template_from_resource (GTK_WIDGET_CLASS (klass), "/org/gnome/initial-setup/gis-privacy-page.ui"); + gtk_widget_class_bind_template_child_private (GTK_WIDGET_CLASS (klass), GisPrivacyPage, location_switch); + gtk_widget_class_bind_template_child_private (GTK_WIDGET_CLASS (klass), GisPrivacyPage, reporting_group); + gtk_widget_class_bind_template_child_private (GTK_WIDGET_CLASS (klass), GisPrivacyPage, reporting_row); + gtk_widget_class_bind_template_child_private (GTK_WIDGET_CLASS (klass), GisPrivacyPage, reporting_switch); + gtk_widget_class_bind_template_callback (GTK_WIDGET_CLASS (klass), activate_link); + + page_class->page_id = PAGE_ID; + page_class->locale_changed = gis_privacy_page_locale_changed; + page_class->apply = gis_privacy_page_apply; + object_class->constructed = gis_privacy_page_constructed; + object_class->dispose = gis_privacy_page_dispose; +} + +static void +gis_privacy_page_init (GisPrivacyPage *page) +{ + g_resources_register (privacy_get_resource ()); + g_type_ensure (GIS_TYPE_PAGE_HEADER); + gtk_widget_init_template (GTK_WIDGET (page)); +} + +GisPage * +gis_prepare_privacy_page (GisDriver *driver) +{ + return g_object_new (GIS_TYPE_PRIVACY_PAGE, + "driver", driver, + NULL); +} diff --git a/gnome-initial-setup/pages/privacy/gis-privacy-page.h b/gnome-initial-setup/pages/privacy/gis-privacy-page.h new file mode 100644 index 0000000..9596b36 --- /dev/null +++ b/gnome-initial-setup/pages/privacy/gis-privacy-page.h @@ -0,0 +1,57 @@ +/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */ +/* + * Copyright (C) 2015 Red Hat + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see <http://www.gnu.org/licenses/>. + * + * Written by: + * Matthias Clasen <mclasen@redhat.com> + */ + +#ifndef __GIS_PRIVACY_PAGE_H__ +#define __GIS_PRIVACY_PAGE_H__ + +#include <glib-object.h> + +#include "gnome-initial-setup.h" + +G_BEGIN_DECLS + +#define GIS_TYPE_PRIVACY_PAGE (gis_privacy_page_get_type ()) +#define GIS_PRIVACY_PAGE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GIS_TYPE_PRIVACY_PAGE, GisPrivacyPage)) +#define GIS_PRIVACY_PAGE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GIS_TYPE_PRIVACY_PAGE, GisPrivacyPageClass)) +#define GIS_IS_PRIVACY_PAGE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GIS_TYPE_PRIVACY_PAGE)) +#define GIS_IS_PRIVACY_PAGE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GIS_TYPE_PRIVACY_PAGE)) +#define GIS_PRIVACY_PAGE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GIS_TYPE_PRIVACY_PAGE, GisPrivacyPageClass)) + +typedef struct _GisPrivacyPage GisPrivacyPage; +typedef struct _GisPrivacyPageClass GisPrivacyPageClass; + +struct _GisPrivacyPage +{ + GisPage parent; +}; + +struct _GisPrivacyPageClass +{ + GisPageClass parent_class; +}; + +GType gis_privacy_page_get_type (void); + +GisPage *gis_prepare_privacy_page (GisDriver *driver); + +G_END_DECLS + +#endif /* __GIS_PRIVACY_PAGE_H__ */ diff --git a/gnome-initial-setup/pages/privacy/gis-privacy-page.ui b/gnome-initial-setup/pages/privacy/gis-privacy-page.ui new file mode 100644 index 0000000..84ea8e3 --- /dev/null +++ b/gnome-initial-setup/pages/privacy/gis-privacy-page.ui @@ -0,0 +1,79 @@ +<?xml version="1.0"?> +<interface> + <requires lib="gtk+" version="3.0"/> + <template class="GisPrivacyPage" parent="GisPage"> + + <child> + <object class="AdwPreferencesPage"> + + <child> + <object class="AdwPreferencesGroup"> + <child> + <object class="GisPageHeader" id="header"> + <property name="margin_top">24</property> + <property name="title" translatable="yes">Privacy</property> + <property name="icon_name">preferences-system-privacy-symbolic</property> + <property name="show_icon" bind-source="GisPrivacyPage" bind-property="small-screen" bind-flags="invert-boolean|sync-create"/> + </object> + </child> + </object> + </child> + + <child> + <object class="AdwPreferencesGroup"> + <child> + <object class="AdwActionRow"> + <property name="use-markup">True</property> + <property name="title" translatable="yes">Location Services</property> + <property name="subtitle" translatable="yes">Allows applications to determine your geographical location. Uses the Mozilla Location Service (<a href='https://location.services.mozilla.com/privacy'>privacy policy</a>).</property> + <property name="activatable-widget">location_switch</property> + <child> + <object class="GtkSwitch" id="location_switch"> + <property name="valign">center</property> + </object> + </child> + </object> + </child> + </object> + </child> + + <child> + <object class="AdwPreferencesGroup" id="reporting_group"> + <child> + <object class="AdwActionRow" id="reporting_row"> + <property name="title" translatable="yes">Automatic Problem Reporting</property> + <property name="activatable-widget">reporting_switch</property> + <child> + <object class="GtkSwitch" id="reporting_switch"> + <property name="valign">center</property> + </object> + </child> + </object> + </child> + </object> + </child> + + <child> + <object class="AdwPreferencesGroup"> + <child> + <object class="GtkLabel" id="footer_label"> + <property name="valign">end</property> + <property name="vexpand">True</property> + <property name="label" translatable="yes">Privacy controls can be changed at any time from the Settings application.</property> + <property name="xalign">0.5</property> + <property name="justify">center</property> + <property name="wrap">True</property> + <property name="margin_bottom">18</property> + <style> + <class name="dim-label"/> + </style> + </object> + </child> + </object> + </child> + + </object> + </child> + + </template> +</interface> diff --git a/gnome-initial-setup/pages/privacy/meson.build b/gnome-initial-setup/pages/privacy/meson.build new file mode 100644 index 0000000..560831c --- /dev/null +++ b/gnome-initial-setup/pages/privacy/meson.build @@ -0,0 +1,10 @@ +sources += gnome.compile_resources( + 'privacy-resources', + files('privacy.gresource.xml'), + c_name: 'privacy' +) + +sources += files( + 'gis-privacy-page.c', + 'gis-privacy-page.h' +) diff --git a/gnome-initial-setup/pages/privacy/privacy.gresource.xml b/gnome-initial-setup/pages/privacy/privacy.gresource.xml new file mode 100644 index 0000000..be75b34 --- /dev/null +++ b/gnome-initial-setup/pages/privacy/privacy.gresource.xml @@ -0,0 +1,6 @@ +<?xml version="1.0" encoding="UTF-8"?> +<gresources> + <gresource prefix="/org/gnome/initial-setup"> + <file preprocess="xml-stripblanks" alias="gis-privacy-page.ui">gis-privacy-page.ui</file> + </gresource> +</gresources> |