diff options
author | Michael Catanzaro <mcatanzaro@redhat.com> | 2023-04-06 09:55:02 -0500 |
---|---|---|
committer | Michael Catanzaro <mcatanzaro@redhat.com> | 2023-04-06 11:36:32 -0500 |
commit | b52f4524270c7cbdac164ec5c44e0febbf42574c (patch) | |
tree | c910bd7511c3b4466cc8e6945c27c246bbc91608 | |
parent | f4aa883b1d6d92633092c70200fd60fc1d23ccda (diff) | |
download | gnome-initial-setup-mcatanzaro/metrics.tar.gz |
-rw-r--r-- | gnome-initial-setup/pages/privacy/gis-privacy-page.c | 114 | ||||
-rw-r--r-- | gnome-initial-setup/pages/privacy/gis-privacy-page.ui | 48 |
2 files changed, 146 insertions, 16 deletions
diff --git a/gnome-initial-setup/pages/privacy/gis-privacy-page.c b/gnome-initial-setup/pages/privacy/gis-privacy-page.c index b910651..87c2772 100644 --- a/gnome-initial-setup/pages/privacy/gis-privacy-page.c +++ b/gnome-initial-setup/pages/privacy/gis-privacy-page.c @@ -1,6 +1,7 @@ /* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */ /* - * Copyright (C) 2015 Red Hat + * Copyright (C) 2015, 2023 Red Hat + * Copyright (C) 2014 Endless Mobile, Inc. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as @@ -44,9 +45,14 @@ struct _GisPrivacyPagePrivate GtkWidget *reporting_group; GtkWidget *reporting_label; GtkWidget *reporting_switch; + GtkWidget *metrics_group; + GtkWidget *metrics_label; + GtkWidget *metrics_switch; GSettings *location_settings; GSettings *privacy_settings; guint abrt_watch_id; + guint metrics_watch_id; + GDBusProxy *metrics_proxy; }; typedef struct _GisPrivacyPagePrivate GisPrivacyPagePrivate; @@ -58,7 +64,8 @@ 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; + g_autofree char *metrics_subtitle = NULL; + g_autofree char *reporting_subtitle = NULL; if (!name) return FALSE; @@ -68,19 +75,31 @@ update_os_data (GisPrivacyPage *page) /* Translators: the first parameter here is the name of a distribution, * like "Fedora" or "Ubuntu". */ - subtitle = g_strdup_printf (_("Sends technical reports that do not contain personal information. " - "Data is collected by %1$s (<a href='%2$s'>privacy policy</a>)."), - name, privacy_policy); + metrics_subtitle = g_strdup_printf (_("Help improve %1$s by providing limited usage data that does not contain personal information. " + "Data is collected by %1$s (<a href='%2$s'>privacy policy</a>)."), name, privacy_policy); + + /* Translators: the first parameter here is the name of a distribution, + * like "Fedora" or "Ubuntu". + */ + reporting_subtitle = g_strdup_printf (_("Sends technical reports that do not contain personal information. " + "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". */ - subtitle = g_strdup_printf (_("Sends technical reports that do not contain personal information. " - "Data is collected by %s."), name); + metrics_subtitle = g_strdup_printf (_("Help improve %1$s by providing limited usage data that does not contain personal information. " + "Data is collected by %1$s."), name); + + /* Translators: the parameter here is the name of a distribution, + * like "Fedora" or "Ubuntu". + */ + reporting_subtitle = g_strdup_printf (_("Sends technical reports that do not contain personal information. " + "Data is collected by %s."), name); } - gtk_label_set_markup (GTK_LABEL (priv->reporting_label), subtitle); + gtk_label_set_markup (GTK_LABEL (priv->metrics_label), metrics_subtitle); + gtk_label_set_markup (GTK_LABEL (priv->reporting_label), reporting_subtitle); return TRUE; } @@ -108,10 +127,48 @@ abrt_vanished_cb (GDBusConnection *connection, } static void +metrics_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); + g_autoptr (GError) error = NULL; + + gtk_widget_set_visible (priv->metrics_group, TRUE); + + /* FIXME: make async, add cancellable */ + priv->metrics_proxy = g_dbus_proxy_new_sync (connection, + G_DBUS_PROXY_FLAGS_NONE, + NULL, + "com.endlessm.Metrics", + "/com/endlessm/Metrics", + "com.endlessm.Metrics.EventRecorderServer", + NULL, + &error); + if (error != NULL) + g_warning ("Unable to create metrics daemon proxy: %s", error->message); +} + +static void +metrics_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_set_visible (priv->metrics_group, FALSE); + g_clear_object (&priv->metrics_proxy); +} + +static void gis_privacy_page_constructed (GObject *object) { GisPrivacyPage *page = GIS_PRIVACY_PAGE (object); GisPrivacyPagePrivate *priv = gis_privacy_page_get_instance_private (page); + //g_autoptr (GError) error = NULL; G_OBJECT_CLASS (gis_privacy_page_parent_class)->constructed (object); @@ -122,9 +179,19 @@ gis_privacy_page_constructed (GObject *object) gtk_switch_set_active (GTK_SWITCH (priv->location_switch), TRUE); gtk_switch_set_active (GTK_SWITCH (priv->reporting_switch), TRUE); + gtk_switch_set_active (GTK_SWITCH (priv->metrics_switch), TRUE); if (update_os_data (page)) { + /* FIXME: check error */ + priv->metrics_watch_id = g_bus_watch_name (G_BUS_TYPE_SYSTEM, + "com.endlessm.Metrics", + G_BUS_NAME_WATCHER_FLAGS_AUTO_START, + metrics_appeared_cb, + metrics_vanished_cb, + page, + NULL); + priv->abrt_watch_id = g_bus_watch_name (G_BUS_TYPE_SYSTEM, "org.freedesktop.problems.daemon", G_BUS_NAME_WATCHER_FLAGS_NONE, @@ -143,12 +210,38 @@ gis_privacy_page_dispose (GObject *object) g_clear_object (&priv->location_settings); g_clear_object (&priv->privacy_settings); + g_clear_object (&priv->metrics_proxy); + g_clear_handle_id (&priv->metrics_watch_id, g_bus_unwatch_name); g_clear_handle_id (&priv->abrt_watch_id, g_bus_unwatch_name); G_OBJECT_CLASS (gis_privacy_page_parent_class)->dispose (object); } +static void +sync_metrics_active_state (GisPrivacyPage *page) +{ + GisPrivacyPagePrivate *priv = gis_privacy_page_get_instance_private (page); + gboolean metrics_active; + g_autoptr (GError) error = NULL; + + if (!priv->metrics_proxy) + return; + + metrics_active = gtk_widget_is_visible (priv->metrics_switch) && gtk_switch_get_active (GTK_SWITCH (priv->metrics_switch)); + + /* FIXME: make async, add cancellable */ + g_dbus_proxy_call_sync (priv->metrics_proxy, + "SetEnabled", + g_variant_new ("(b)", metrics_active), + G_DBUS_CALL_FLAGS_NONE, + -1, + NULL, + &error); + if (error != NULL) + g_warning ("Unable to set the enabled state of metrics daemon: %s", error->message); +} + static gboolean gis_privacy_page_apply (GisPage *gis_page, GCancellable *cancellable) @@ -163,6 +256,8 @@ gis_privacy_page_apply (GisPage *gis_page, active = gtk_widget_is_visible (priv->reporting_switch) && gtk_switch_get_active (GTK_SWITCH (priv->reporting_switch)); g_settings_set_boolean (priv->privacy_settings, "report-technical-problems", active); + sync_metrics_active_state (page); + return FALSE; } @@ -239,6 +334,9 @@ gis_privacy_page_class_init (GisPrivacyPageClass *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, metrics_group); + gtk_widget_class_bind_template_child_private (GTK_WIDGET_CLASS (klass), GisPrivacyPage, metrics_label); + gtk_widget_class_bind_template_child_private (GTK_WIDGET_CLASS (klass), GisPrivacyPage, metrics_switch); 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_label); diff --git a/gnome-initial-setup/pages/privacy/gis-privacy-page.ui b/gnome-initial-setup/pages/privacy/gis-privacy-page.ui index 9ce8447..07f141a 100644 --- a/gnome-initial-setup/pages/privacy/gis-privacy-page.ui +++ b/gnome-initial-setup/pages/privacy/gis-privacy-page.ui @@ -20,28 +20,28 @@ </child> <child> - <object class="AdwPreferencesGroup"> + <object class="AdwPreferencesGroup" id="metrics_group"> + <property name="margin-top">12</property> + <property name="visible">False</property> <child> - <object class="AdwActionRow"> - <property name="use-markup">True</property> - <property name="title" translatable="yes">Location Services</property> - <property name="activatable-widget">location_switch</property> + <object class="AdwActionRow" id="metrics_row"> + <property name="title" translatable="yes">Data Collection</property> + <property name="activatable-widget">metrics_switch</property> <child> - <object class="GtkSwitch" id="location_switch"> + <object class="GtkSwitch" id="metrics_switch"> <property name="valign">center</property> </object> </child> </object> </child> <child> - <object class="GtkLabel"> + <object class="GtkLabel" id="metrics_label"> <property name="margin-top">12</property> <property name="wrap">True</property> <property name="wrap-mode">word-char</property> <property name="use-markup">True</property> <property name="ellipsize">none</property> <property name="xalign">0.0</property> - <property name="label" 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> <signal name="activate-link" handler="activate_link" object="GisPrivacyPage" swapped="no" /> <style> <class name="caption" /> @@ -86,6 +86,38 @@ <child> <object class="AdwPreferencesGroup"> <child> + <object class="AdwActionRow"> + <property name="use-markup">True</property> + <property name="title" translatable="yes">Location Services</property> + <property name="activatable-widget">location_switch</property> + <child> + <object class="GtkSwitch" id="location_switch"> + <property name="valign">center</property> + </object> + </child> + </object> + </child> + <child> + <object class="GtkLabel"> + <property name="margin-top">12</property> + <property name="wrap">True</property> + <property name="wrap-mode">word-char</property> + <property name="use-markup">True</property> + <property name="ellipsize">none</property> + <property name="xalign">0.0</property> + <property name="label" 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> + <signal name="activate-link" handler="activate_link" object="GisPrivacyPage" swapped="no" /> + <style> + <class name="caption" /> + </style> + </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> |