[gnome-control-center/T20771: 12/44] privacy: add integration with metrics service
- From: Georges Basile Stavracas Neto <gbsneto src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-control-center/T20771: 12/44] privacy: add integration with metrics service
- Date: Tue, 23 Jan 2018 21:07:34 +0000 (UTC)
commit 16012dd97d3eec0c79f248d97879da683103728f
Author: Cosimo Cecchi <cosimo endlessm com>
Date: Fri Jun 13 15:08:56 2014 -0700
privacy: add integration with metrics service
[endlessm/eos-shell#2728]
configure.ac | 3 +-
panels/common/gnome-control-center.rules | 3 +-
panels/privacy/cc-privacy-panel.c | 114 ++++++++++++++++++++++++++++++
panels/privacy/privacy.ui | 112 +++++++++++++++++++++++++++++
4 files changed, 230 insertions(+), 2 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 63a6581..ff1ec1e 100644
--- a/configure.ac
+++ b/configure.ac
@@ -150,7 +150,8 @@ PKG_CHECK_MODULES(COLOR_PANEL, $COMMON_MODULES
PKG_CHECK_MODULES(PRINTERS_PANEL, $COMMON_MODULES
polkit-gobject-1 >= $POLKIT_REQUIRED_VERSION
smbclient)
-PKG_CHECK_MODULES(PRIVACY_PANEL, $COMMON_MODULES)
+PKG_CHECK_MODULES(PRIVACY_PANEL, $COMMON_MODULES
+ polkit-gobject-1 >= $POLKIT_REQUIRED_VERSION)
PKG_CHECK_MODULES(REGION_PANEL, $COMMON_MODULES
polkit-gobject-1 >= $POLKIT_REQUIRED_VERSION
gnome-desktop-3.0 >= $GNOME_DESKTOP_REQUIRED_VERSION
diff --git a/panels/common/gnome-control-center.rules b/panels/common/gnome-control-center.rules
index 29bd1b0..8cb2170 100644
--- a/panels/common/gnome-control-center.rules
+++ b/panels/common/gnome-control-center.rules
@@ -1,5 +1,6 @@
polkit.addRule(function(action, subject) {
- if ((action.id == "org.freedesktop.locale1.set-locale" ||
+ if ((action.id == "com.endlessm.Metrics.SetEnabled" ||
+ action.id == "org.freedesktop.locale1.set-locale" ||
action.id == "org.freedesktop.locale1.set-keyboard" ||
action.id == "org.freedesktop.hostname1.set-static-hostname" ||
action.id == "org.freedesktop.hostname1.set-hostname" ||
diff --git a/panels/privacy/cc-privacy-panel.c b/panels/privacy/cc-privacy-panel.c
index fe2e5c7..c00675b 100644
--- a/panels/privacy/cc-privacy-panel.c
+++ b/panels/privacy/cc-privacy-panel.c
@@ -25,6 +25,7 @@
#include <gio/gdesktopappinfo.h>
#include <glib/gi18n.h>
+#include <polkit/polkit.h>
CC_PANEL_REGISTER (CcPrivacyPanel, cc_privacy_panel)
@@ -46,6 +47,7 @@ struct _CcPrivacyPanelPrivate
{
GtkBuilder *builder;
GtkWidget *recent_dialog;
+ GtkWidget *metrics_dialog;
GtkWidget *screen_lock_dialog;
GtkWidget *location_dialog;
GtkWidget *location_label;
@@ -55,6 +57,7 @@ struct _CcPrivacyPanelPrivate
GtkWidget *location_apps_list_box;
GtkWidget *location_apps_label;
GtkWidget *location_apps_frame;
+ GtkWidget *metrics_label;
GSettings *lockdown_settings;
GSettings *lock_settings;
@@ -75,6 +78,8 @@ struct _CcPrivacyPanelPrivate
GHashTable *location_app_switches;
GtkSizeGroup *location_icon_size_group;
+
+ GDBusProxy *metrics_proxy;
};
static char *
@@ -864,6 +869,112 @@ add_location (CcPrivacyPanel *self)
}
static void
+set_on_off_label_for_metrics (GtkWidget *label,
+ gboolean is_active)
+{
+ gtk_label_set_text (GTK_LABEL (label), is_active ? _("On") : _("Off"));
+}
+
+static void
+metrics_switch_active_changed_cb (GtkSwitch *widget,
+ GParamSpec *pspec,
+ CcPrivacyPanel *self)
+{
+ gboolean metrics_active;
+ g_autoptr(GError) error = NULL;
+
+ metrics_active = gtk_switch_get_active (widget);
+ g_dbus_proxy_call_sync (self->priv->metrics_proxy,
+ "SetEnabled",
+ g_variant_new ("(b)", metrics_active),
+ G_DBUS_CALL_FLAGS_NONE, -1,
+ NULL, &error);
+
+ if (error != NULL)
+ g_critical ("Unable to set the enabled state of metrics daemon: %s", error->message);
+}
+
+static void
+on_metrics_proxy_properties_changed (GDBusProxy *proxy,
+ GVariant *changed_properties,
+ GStrv invalidated_properties,
+ CcPrivacyPanel *self)
+{
+ g_autoptr(GVariant) enabled_prop = NULL;
+ gboolean metrics_active;
+ GtkWidget *w;
+
+ enabled_prop = g_variant_lookup_value (changed_properties, "Enabled", G_VARIANT_TYPE_BOOLEAN);
+ if (!enabled_prop)
+ return;
+
+ metrics_active = g_variant_get_boolean (enabled_prop);
+
+ w = GTK_WIDGET (gtk_builder_get_object (self->priv->builder, "metrics_enable_switch"));
+ gtk_switch_set_active (GTK_SWITCH (w), metrics_active);
+
+ set_on_off_label_for_metrics (self->priv->metrics_label, metrics_active);
+}
+
+static void
+add_metrics (CcPrivacyPanel *self)
+{
+ g_autoptr(GPermission) permission = NULL;
+ g_autoptr(GVariant) value = NULL;
+ g_autoptr(GError) error = NULL;
+ GtkWidget *w;
+ GtkWidget *dialog;
+ gboolean metrics_active;
+ gboolean metrics_can_change;
+
+ self->priv->metrics_proxy = g_dbus_proxy_new_for_bus_sync (G_BUS_TYPE_SYSTEM,
+ G_DBUS_PROXY_FLAGS_NONE,
+ NULL,
+ "com.endlessm.Metrics",
+ "/com/endlessm/Metrics",
+ "com.endlessm.Metrics.EventRecorderServer",
+ NULL, &error);
+ if (error != NULL)
+ {
+ g_critical ("Unable to create a DBus proxy for the metrics daemon: %s", error->message);
+ metrics_active = FALSE;
+ }
+ else
+ {
+ g_signal_connect (self->priv->metrics_proxy, "g-properties-changed",
+ G_CALLBACK (on_metrics_proxy_properties_changed), self);
+
+ value = g_dbus_proxy_get_cached_property (self->priv->metrics_proxy, "Enabled");
+ metrics_active = g_variant_get_boolean (value);
+ }
+
+ permission = polkit_permission_new_sync ("com.endlessm.Metrics.SetEnabled",
+ NULL, NULL, NULL);
+ if (!permission)
+ metrics_can_change = FALSE;
+ else
+ metrics_can_change = g_permission_get_allowed (permission);
+
+ self->priv->metrics_label = gtk_label_new (NULL);
+ set_on_off_label_for_metrics (self->priv->metrics_label, metrics_active);
+ add_row (self, _("Metrics"), "metrics_dialog", self->priv->metrics_label);
+
+ w = GTK_WIDGET (gtk_builder_get_object (self->priv->builder, "metrics_done"));
+ dialog = self->priv->metrics_dialog;
+ g_signal_connect_swapped (w, "clicked",
+ G_CALLBACK (gtk_widget_hide), dialog);
+ g_signal_connect (dialog, "delete-event",
+ G_CALLBACK (gtk_widget_hide_on_delete), NULL);
+
+ w = GTK_WIDGET (gtk_builder_get_object (self->priv->builder, "metrics_enable_switch"));
+ gtk_widget_set_sensitive (w, metrics_can_change);
+ gtk_switch_set_active (GTK_SWITCH (w), metrics_active);
+
+ g_signal_connect (w, "notify::active",
+ G_CALLBACK (metrics_switch_active_changed_cb), self);
+}
+
+static void
retain_history_combo_changed_cb (GtkWidget *widget,
CcPrivacyPanel *self)
{
@@ -1273,6 +1384,7 @@ cc_privacy_panel_finalize (GObject *object)
g_clear_pointer (&priv->location_apps_perms, g_variant_unref);
g_clear_pointer (&priv->location_apps_data, g_variant_unref);
g_clear_pointer (&priv->location_app_switches, g_hash_table_unref);
+ g_clear_object (&priv->metrics_proxy);
G_OBJECT_CLASS (cc_privacy_panel_parent_class)->finalize (object);
}
@@ -1333,6 +1445,7 @@ cc_privacy_panel_init (CcPrivacyPanel *self)
}
self->priv->recent_dialog = GTK_WIDGET (gtk_builder_get_object (self->priv->builder, "recent_dialog"));
+ self->priv->metrics_dialog = GTK_WIDGET (gtk_builder_get_object (self->priv->builder, "metrics_dialog"));
self->priv->screen_lock_dialog = GTK_WIDGET (gtk_builder_get_object (self->priv->builder,
"screen_lock_dialog"));
self->priv->location_dialog = GTK_WIDGET (gtk_builder_get_object (self->priv->builder, "location_dialog"));
self->priv->trash_dialog = GTK_WIDGET (gtk_builder_get_object (self->priv->builder, "trash_dialog"));
@@ -1368,6 +1481,7 @@ cc_privacy_panel_init (CcPrivacyPanel *self)
add_screen_lock (self);
add_location (self);
+ add_metrics (self);
add_usage_history (self);
add_trash_temp (self);
add_software (self);
diff --git a/panels/privacy/privacy.ui b/panels/privacy/privacy.ui
index ae0471d..57addd3 100644
--- a/panels/privacy/privacy.ui
+++ b/panels/privacy/privacy.ui
@@ -274,6 +274,118 @@
<action-widget response="0">clear_recent_button</action-widget>
</action-widgets>
</object>
+ <object class="GtkDialog" id="metrics_dialog">
+ <property name="can_focus">False</property>
+ <property name="border_width">5</property>
+ <property name="title" translatable="yes">Metrics</property>
+ <property name="resizable">False</property>
+ <property name="type_hint">dialog</property>
+ <child internal-child="vbox">
+ <object class="GtkBox" id="metrics_dialog_vbox">
+ <property name="can_focus">False</property>
+ <property name="orientation">vertical</property>
+ <property name="spacing">2</property>
+ <child internal-child="action_area">
+ <object class="GtkButtonBox" id="metrics_dialog_action_area">
+ <property name="can_focus">False</property>
+ <property name="layout_style">end</property>
+ <child>
+ <object class="GtkButton" id="metrics_done">
+ <property name="label" translatable="yes">_Close</property>
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="can_default">True</property>
+ <property name="has_default">True</property>
+ <property name="receives_default">True</property>
+ <property name="use_underline">True</property>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">True</property>
+ <property name="position">1</property>
+ </packing>
+ </child>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">True</property>
+ <property name="pack_type">end</property>
+ <property name="position">0</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkLabel" id="metrics_title_label">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="margin_left">12</property>
+ <property name="margin_right">12</property>
+ <property name="margin_top">6</property>
+ <property name="margin_bottom">12</property>
+ <property name="xalign">0</property>
+ <property name="label" translatable="yes">Endless collects metrics on user behavior and actions.
All data sent is anonymous. We use the data to improve the system.</property>
+ <property name="wrap">True</property>
+ <property name="max_width_chars">50</property>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">True</property>
+ <property name="position">1</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkGrid" id="metrics_grid">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="margin_left">12</property>
+ <property name="margin_right">2</property>
+ <property name="margin_top">6</property>
+ <property name="margin_bottom">12</property>
+ <property name="row_spacing">12</property>
+ <property name="column_spacing">6</property>
+ <child>
+ <object class="GtkLabel" id="metrics_enable_label">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="xalign">0</property>
+ <property name="hexpand">True</property>
+ <property name="label" translatable="yes">Enable Metrics Collection</property>
+ <property name="use_underline">True</property>
+ <property name="mnemonic_widget">metrics_enable_switch</property>
+ </object>
+ <packing>
+ <property name="left_attach">0</property>
+ <property name="top_attach">0</property>
+ <property name="width">1</property>
+ <property name="height">1</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkSwitch" id="metrics_enable_switch">
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="halign">end</property>
+ <property name="valign">center</property>
+ </object>
+ <packing>
+ <property name="left_attach">1</property>
+ <property name="top_attach">0</property>
+ <property name="width">1</property>
+ <property name="height">1</property>
+ </packing>
+ </child>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">True</property>
+ <property name="position">2</property>
+ </packing>
+ </child>
+ </object>
+ </child>
+ <action-widgets>
+ <action-widget response="-1">metrics_done</action-widget>
+ </action-widgets>
+ </object>
<object class="GtkDialog" id="screen_lock_dialog">
<property name="can_focus">False</property>
<property name="border_width">5</property>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]