[gnome-control-center/wip/privacy-swarm: 8/14] Add a diagnostic panel
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-control-center/wip/privacy-swarm: 8/14] Add a diagnostic panel
- Date: Tue, 11 Dec 2018 19:33:56 +0000 (UTC)
commit 7d715598f67f6efc4b0ec1288ec6966fcbecfd3b
Author: Matthias Clasen <mclasen redhat com>
Date: Tue Dec 11 14:18:47 2018 -0500
Add a diagnostic panel
This is a broken out version of the privacy panel dialog.
panels/diagnostics/cc-diagnostics-panel.c | 225 +++++++++++++++++++++
panels/diagnostics/cc-diagnostics-panel.h | 30 +++
panels/diagnostics/cc-diagnostics-panel.ui | 123 +++++++++++
panels/diagnostics/diagnostics.gresource.xml | 6 +
.../gnome-diagnostics-panel.desktop.in.in | 19 ++
panels/diagnostics/meson.build | 40 ++++
6 files changed, 443 insertions(+)
---
diff --git a/panels/diagnostics/cc-diagnostics-panel.c b/panels/diagnostics/cc-diagnostics-panel.c
new file mode 100644
index 000000000..f9e013abf
--- /dev/null
+++ b/panels/diagnostics/cc-diagnostics-panel.c
@@ -0,0 +1,225 @@
+/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*-
+ *
+ * Copyright (C) 2018 Red Hat, Inc
+ *
+ * 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/>.
+ *
+ * Author: Matthias Clasen <mclasen redhat com>
+ */
+
+#include "list-box-helper.h"
+#include "cc-diagnostics-panel.h"
+#include "cc-diagnostics-resources.h"
+#include "cc-util.h"
+
+#include <gio/gdesktopappinfo.h>
+#include <glib/gi18n.h>
+
+struct _CcDiagnosticsPanel
+{
+ CcPanel parent_instance;
+
+ GtkLabel *diagnostics_explanation_label;
+ GtkLabel *diagnostics_learn_more_label;
+ GtkListBox *diagnostics_list_box;
+ GtkSwitch *abrt_switch;
+
+ guint abrt_watch_id;
+
+ GSettings *privacy_settings;
+};
+
+CC_PANEL_REGISTER (CcDiagnosticsPanel, cc_diagnostics_panel)
+
+static void
+cc_diagnostics_panel_finalize (GObject *object)
+{
+ CcDiagnosticsPanel *self = CC_DIAGNOSTICS_PANEL (object);
+
+ if (self->abrt_watch_id > 0)
+ {
+ g_bus_unwatch_name (self->abrt_watch_id);
+ self->abrt_watch_id = 0;
+ }
+
+ g_clear_object (&self->privacy_settings);
+
+ G_OBJECT_CLASS (cc_diagnostics_panel_parent_class)->finalize (object);
+}
+
+static char *
+get_os_name (void)
+{
+ char *buffer;
+ char *name;
+
+ name = NULL;
+
+ if (g_file_get_contents ("/etc/os-release", &buffer, NULL, NULL))
+ {
+ char *start, *end;
+
+ start = end = NULL;
+ if ((start = strstr (buffer, "NAME=")) != NULL)
+ {
+ start += strlen ("NAME=");
+ end = strchr (start, '\n');
+ }
+
+ if (start != NULL && end != NULL)
+ {
+ name = g_strndup (start, end - start);
+ }
+
+ g_free (buffer);
+ }
+
+ if (name && *name != '\0')
+ {
+ char *tmp;
+ tmp = g_shell_unquote (name, NULL);
+ g_free (name);
+ name = tmp;
+ }
+
+ if (name == NULL)
+ name = g_strdup ("GNOME");
+
+ return name;
+}
+
+static char *
+get_privacy_policy_url (void)
+{
+ char *buffer;
+ char *url;
+
+ url = NULL;
+
+ if (g_file_get_contents ("/etc/os-release", &buffer, NULL, NULL))
+ {
+ char *start, *end;
+
+ start = end = NULL;
+ if ((start = strstr (buffer, "PRIVACY_POLICY_URL=")) != NULL)
+ {
+ start += strlen ("PRIVACY_POLICY_URL=");
+ end = strchr (start, '\n');
+ }
+
+ if (start != NULL && end != NULL)
+ {
+ url = g_strndup (start, end - start);
+ }
+
+ g_free (buffer);
+ }
+
+ if (url && *url != '\0')
+ {
+ char *tmp;
+ tmp = g_shell_unquote (url, NULL);
+ g_free (url);
+ url = tmp;
+ }
+
+ if (url == NULL)
+ url = g_strdup ("http://www.gnome.org/privacy-policy");
+
+ return url;
+}
+
+static void
+abrt_appeared_cb (GDBusConnection *connection,
+ const gchar *name,
+ const gchar *name_owner,
+ gpointer user_data)
+{
+ CcDiagnosticsPanel *self = user_data;
+ g_debug ("ABRT appeared");
+ gtk_widget_show (GTK_WIDGET (self->diagnostics_list_box));
+}
+
+static void
+abrt_vanished_cb (GDBusConnection *connection,
+ const gchar *name,
+ gpointer user_data)
+{
+ CcDiagnosticsPanel *self = user_data;
+ g_debug ("ABRT vanished");
+ gtk_widget_hide (GTK_WIDGET (self->diagnostics_list_box));
+}
+
+static void
+cc_diagnostics_panel_init (CcDiagnosticsPanel *self)
+{
+ char *os_name, *url, *msg;
+
+ g_resources_register (cc_diagnostics_get_resource ());
+
+ gtk_widget_init_template (GTK_WIDGET (self));
+
+ gtk_list_box_set_header_func (self->diagnostics_list_box,
+ cc_list_box_update_header_func,
+ NULL, NULL);
+
+ self->privacy_settings = g_settings_new ("org.gnome.desktop.privacy");
+
+ g_settings_bind (self->privacy_settings, "report-technical-problems",
+ self->abrt_switch, "active",
+ G_SETTINGS_BIND_DEFAULT);
+
+ os_name = get_os_name ();
+ /* translators: '%s' is the distributor's name, such as 'Fedora' */
+ msg = g_strdup_printf (_("Sending reports of technical problems helps us improve %s. Reports are sent
anonymously and are scrubbed of personal data."),
+ os_name);
+ g_free (os_name);
+ gtk_label_set_text (self->diagnostics_explanation_label, msg);
+
+ url = get_privacy_policy_url ();
+ if (!url)
+ {
+ g_debug ("Not watching for ABRT appearing, /etc/os-release lacks a privacy policy URL");
+ return;
+ }
+ msg = g_strdup_printf ("%s <a href=\"%s\">Learn more</a>", _("Reports are sent anonymously and are
scrubbed of personal data."), url);
+ g_free (url);
+ gtk_label_set_markup (self->diagnostics_learn_more_label, msg);
+ g_free (msg);
+
+ self->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,
+ self,
+ NULL);
+}
+
+
+static void
+cc_diagnostics_panel_class_init (CcDiagnosticsPanelClass *klass)
+{
+ GObjectClass *oclass = G_OBJECT_CLASS (klass);
+ GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
+
+ oclass->finalize = cc_diagnostics_panel_finalize;
+
+ gtk_widget_class_set_template_from_resource (widget_class,
"/org/gnome/control-center/diagnostics/cc-diagnostics-panel.ui");
+
+ gtk_widget_class_bind_template_child (widget_class, CcDiagnosticsPanel, diagnostics_explanation_label);
+ gtk_widget_class_bind_template_child (widget_class, CcDiagnosticsPanel, diagnostics_learn_more_label);
+ gtk_widget_class_bind_template_child (widget_class, CcDiagnosticsPanel, diagnostics_list_box);
+ gtk_widget_class_bind_template_child (widget_class, CcDiagnosticsPanel, abrt_switch);
+}
diff --git a/panels/diagnostics/cc-diagnostics-panel.h b/panels/diagnostics/cc-diagnostics-panel.h
new file mode 100644
index 000000000..bb14ac862
--- /dev/null
+++ b/panels/diagnostics/cc-diagnostics-panel.h
@@ -0,0 +1,30 @@
+/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*-
+ *
+ * Copyright (C) 2018 Red Hat, Inc
+ *
+ * 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/>.
+ *
+ * Author: Matthias Clasen <mclasen redhat com>
+ */
+
+#pragma once
+
+#include <shell/cc-panel.h>
+
+G_BEGIN_DECLS
+
+#define CC_TYPE_DIAGNOSTICS_PANEL (cc_diagnostics_panel_get_type ())
+G_DECLARE_FINAL_TYPE (CcDiagnosticsPanel, cc_diagnostics_panel, CC, DIAGNOSTICS_PANEL, CcPanel)
+
+G_END_DECLS
diff --git a/panels/diagnostics/cc-diagnostics-panel.ui b/panels/diagnostics/cc-diagnostics-panel.ui
new file mode 100644
index 000000000..e9546320b
--- /dev/null
+++ b/panels/diagnostics/cc-diagnostics-panel.ui
@@ -0,0 +1,123 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- Generated with glade 3.18.1 -->
+<interface>
+ <requires lib="gtk+" version="3.14"/>
+ <template class="CcDiagnosticsPanel" parent="CcPanel">
+ <property name="visible">True</property>
+ <child>
+ <object class="GtkScrolledWindow">
+ <property name="visible">1</property>
+ <property name="hscrollbar-policy">never</property>
+ <child>
+ <object class="GtkBox">
+ <property name="visible">1</property>
+ <!-- Stub boxes to make the content cover 1/3 of the screen -->
+ <child>
+ <object class="GtkBox">
+ <property name="visible">1</property>
+ <property name="hexpand">1</property>
+ </object>
+ </child>
+ <child>
+ <object class="GtkBox">
+ <property name="visible">1</property>
+ <property name="hexpand">1</property>
+ </object>
+ <packing>
+ <property name="pack-type">end</property>
+ </packing>
+ </child>
+ <!-- Content -->
+ <child>
+ <object class="GtkBox">
+ <property name="visible">1</property>
+ <property name="orientation">vertical</property>
+ <property name="margin">32</property>
+ <property name="hexpand">1</property>
+ <child>
+ <object class="GtkLabel">
+ <property name="visible">1</property>
+ <property name="margin-bottom">12</property>
+ <property name="label" translatable="yes">Problem Reporting</property>
+ <property name="wrap">1</property>
+ <property name="max-width-chars">50</property>
+ <property name="xalign">0</property>
+ <attributes>
+ <attribute name="weight" value="bold"/>
+ </attributes>
+ </object>
+ </child>
+ <child>
+ <object class="GtkLabel" id="diagnostics_explanation_label">
+ <property name="visible">1</property>
+ <property name="margin-bottom">12</property>
+ <property name="label" translatable="yes">Sending reports of technical problems help us
improve this operating system.</property>
+ <property name="wrap">1</property>
+ <property name="max-width-chars">50</property>
+ <property name="xalign">0</property>
+ </object>
+ </child>
+ <child>
+ <object class="GtkLabel" id="diagnostics_learn_more_label">
+ <property name="visible">1</property>
+ <property name="margin-bottom">12</property>
+ <property name="label" translatable="yes">Reports are sent anonymously and are scrubbed
of personal data.</property>
+ <property name="use-markup">1</property>
+ <property name="wrap">1</property>
+ <property name="max-width-chars">50</property>
+ <property name="xalign">0</property>
+ </object>
+ </child>
+ <child>
+ <object class="GtkListBox" id="diagnostics_list_box">
+ <property name="visible">1</property>
+ <property name="can-focus">1</property>
+ <property name="selection-mode">none</property>
+ <child>
+ <object class="GtkListBoxRow">
+ <property name="visible">1</property>
+ <child>
+ <object class="GtkBox">
+ <property name="visible">1</property>
+ <property name="margin_start">12</property>
+ <property name="margin_end">12</property>
+ <property name="margin_top">12</property>
+ <property name="margin_bottom">12</property>
+ <child>
+ <object class="GtkLabel">
+ <property name="visible">1</property>
+ <property name="label" translatable="yes">_Automatic Problem
Reporting</property>
+ <property name="use_underline">1</property>
+ <property name="mnemonic_widget">abrt_switch</property>
+ <property name="xalign">0</property>
+ <property name="valign">center</property>
+ </object>
+ <packing>
+ <property name="expand">1</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkSwitch" id="abrt_switch">
+ <property name="visible">1</property>
+ <property name="halign">end</property>
+ <property name="valign">center</property>
+ </object>
+ </child>
+ </object>
+ </child>
+ </object>
+ </child>
+ <style>
+ <class name="view"/>
+ <class name="frame"/>
+ </style>
+ </object>
+ </child>
+ </object>
+ </child>
+ </object>
+ </child>
+ </object>
+ </child>
+ </template>
+</interface>
diff --git a/panels/diagnostics/diagnostics.gresource.xml b/panels/diagnostics/diagnostics.gresource.xml
new file mode 100644
index 000000000..541d62cb2
--- /dev/null
+++ b/panels/diagnostics/diagnostics.gresource.xml
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<gresources>
+ <gresource prefix="/org/gnome/control-center/diagnostics">
+ <file preprocess="xml-stripblanks">cc-diagnostics-panel.ui</file>
+ </gresource>
+</gresources>
diff --git a/panels/diagnostics/gnome-diagnostics-panel.desktop.in.in
b/panels/diagnostics/gnome-diagnostics-panel.desktop.in.in
new file mode 100644
index 000000000..772eb8b24
--- /dev/null
+++ b/panels/diagnostics/gnome-diagnostics-panel.desktop.in.in
@@ -0,0 +1,19 @@
+[Desktop Entry]
+Name=Diagnostics
+Comment=Report your problems
+Exec=gnome-control-center diagnostics
+# FIXME
+# Translators: Do NOT translate or transliterate this text (this is an icon file name)!
+Icon=system-help
+Terminal=false
+Type=Application
+NoDisplay=true
+StartupNotify=true
+Categories=GNOME;GTK;Settings;DesktopSettings;X-GNOME-Settings-Panel;X-GNOME-PrivacySettings;
+OnlyShowIn=GNOME;Unity;
+X-GNOME-Bugzilla-Bugzilla=GNOME
+X-GNOME-Bugzilla-Product=gnome-control-center
+X-GNOME-Bugzilla-Component=privacy
+X-GNOME-Bugzilla-Version=@VERSION@
+# Translators: Search terms to find the Privacy panel. Do NOT translate or localize the semicolons! The list
MUST also end with a semicolon!
+Keywords=screen;lock;diagnostics;crash;private;recent;temporary;tmp;index;name;network;identity;
diff --git a/panels/diagnostics/meson.build b/panels/diagnostics/meson.build
new file mode 100644
index 000000000..fac9b4cd8
--- /dev/null
+++ b/panels/diagnostics/meson.build
@@ -0,0 +1,40 @@
+panels_list += cappletname
+desktop = 'gnome-@0@-panel.desktop'.format(cappletname)
+
+desktop_in = configure_file(
+ input: desktop + '.in.in',
+ output: desktop + '.in',
+ configuration: desktop_conf
+)
+
+i18n.merge_file(
+ desktop,
+ type: 'desktop',
+ input: desktop_in,
+ output: desktop,
+ po_dir: po_dir,
+ install: true,
+ install_dir: control_center_desktopdir
+)
+
+sources = files('cc-diagnostics-panel.c')
+
+resource_data = files('cc-diagnostics-panel.ui')
+
+sources += gnome.compile_resources(
+ 'cc-' + cappletname + '-resources',
+ cappletname + '.gresource.xml',
+ c_name: 'cc_' + cappletname,
+ dependencies: resource_data,
+ export: true
+)
+
+cflags += '-DGNOMELOCALEDIR="@0@"'.format(control_center_localedir)
+
+panels_libs += static_library(
+ cappletname,
+ sources: sources,
+ include_directories: [top_inc, common_inc],
+ dependencies: common_deps,
+ c_args: cflags
+)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]