[gnome-control-center/wip/privacy-swarm: 153/160] Add a diagnostic panel
- From: Georges Basile Stavracas Neto <gbsneto src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-control-center/wip/privacy-swarm: 153/160] Add a diagnostic panel
- Date: Wed, 6 Nov 2019 00:25:37 +0000 (UTC)
commit a0800f3dbe174308f2a3159a55d12dbc7f8d6e32
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 | 238 +++++++++++++++++++++
panels/diagnostics/cc-diagnostics-panel.h | 32 +++
panels/diagnostics/cc-diagnostics-panel.ui | 113 ++++++++++
panels/diagnostics/diagnostics.gresource.xml | 6 +
.../gnome-diagnostics-panel.desktop.in.in | 19 ++
panels/diagnostics/meson.build | 40 ++++
shell/cc-panel-loader.c | 3 +-
7 files changed, 450 insertions(+), 1 deletion(-)
---
diff --git a/panels/diagnostics/cc-diagnostics-panel.c b/panels/diagnostics/cc-diagnostics-panel.c
new file mode 100644
index 000000000..951def0ca
--- /dev/null
+++ b/panels/diagnostics/cc-diagnostics-panel.c
@@ -0,0 +1,238 @@
+/* -*- 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 "shell/cc-application.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;
+
+ GSettings *privacy_settings;
+};
+
+CC_PANEL_REGISTER (CcDiagnosticsPanel, cc_diagnostics_panel)
+
+/* Static init function */
+
+static void
+set_panel_visibility (CcPanelVisibility visibility)
+{
+ CcApplication *application;
+
+ application = CC_APPLICATION (g_application_get_default ());
+ cc_shell_model_set_panel_visibility (cc_application_get_model (application),
+ "diagnostics",
+ visibility);
+
+}
+
+static void
+abrt_appeared_cb (GDBusConnection *connection,
+ const gchar *name,
+ const gchar *name_owner,
+ gpointer user_data)
+{
+ g_debug ("ABRT appeared");
+ set_panel_visibility (CC_PANEL_VISIBLE);
+}
+
+static void
+abrt_vanished_cb (GDBusConnection *connection,
+ const gchar *name,
+ gpointer user_data)
+{
+ g_debug ("ABRT vanished");
+ set_panel_visibility (CC_PANEL_VISIBLE_IN_SEARCH);
+}
+
+void
+cc_diagnostics_panel_static_init_func (void)
+{
+ g_bus_watch_name (G_BUS_TYPE_SYSTEM,
+ "org.freedesktop.problems.daemon",
+ G_BUS_NAME_WATCHER_FLAGS_NONE,
+ abrt_appeared_cb,
+ abrt_vanished_cb,
+ NULL,
+ NULL);
+
+ set_panel_visibility (CC_PANEL_VISIBLE_IN_SEARCH);
+}
+
+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
+cc_diagnostics_panel_finalize (GObject *object)
+{
+ CcDiagnosticsPanel *self = CC_DIAGNOSTICS_PANEL (object);
+
+ g_clear_object (&self->privacy_settings);
+
+ G_OBJECT_CLASS (cc_diagnostics_panel_parent_class)->finalize (object);
+}
+
+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);
+}
+
+static void
+cc_diagnostics_panel_init (CcDiagnosticsPanel *self)
+{
+ g_autofree gchar *os_name = NULL;
+ g_autofree gchar *url = NULL;
+ g_autofree gchar *msg = NULL;
+
+ 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);
+ 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);
+ gtk_label_set_markup (self->diagnostics_learn_more_label, msg);
+}
diff --git a/panels/diagnostics/cc-diagnostics-panel.h b/panels/diagnostics/cc-diagnostics-panel.h
new file mode 100644
index 000000000..3875ec554
--- /dev/null
+++ b/panels/diagnostics/cc-diagnostics-panel.h
@@ -0,0 +1,32 @@
+/* -*- 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)
+
+void cc_diagnostics_panel_static_init_func (void);
+
+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..a76afa71b
--- /dev/null
+++ b/panels/diagnostics/cc-diagnostics-panel.ui
@@ -0,0 +1,113 @@
+<?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="HdyColumn">
+ <property name="visible">True</property>
+ <property name="maximum_width">600</property>
+ <property name="linear_growth_width">400</property>
+ <property name="margin_top">32</property>
+ <property name="margin_bottom">32</property>
+ <property name="margin_start">12</property>
+ <property name="margin_end">12</property>
+
+ <child>
+ <object class="GtkBox">
+ <property name="visible">1</property>
+ <property name="orientation">vertical</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
+)
diff --git a/shell/cc-panel-loader.c b/shell/cc-panel-loader.c
index 819747aa7..2d5e11db7 100644
--- a/shell/cc-panel-loader.c
+++ b/shell/cc-panel-loader.c
@@ -73,6 +73,7 @@ extern GType cc_lock_panel_get_type (void);
extern GType cc_diagnostics_panel_get_type (void);
/* Static init functions */
+extern void cc_diagnostics_panel_static_init_func (void);
#ifdef BUILD_NETWORK
extern void cc_wifi_panel_static_init_func (void);
#endif /* BUILD_NETWORK */
@@ -99,7 +100,7 @@ static CcPanelLoaderVtable default_panels[] =
PANEL_TYPE("color", cc_color_panel_get_type, NULL),
PANEL_TYPE("datetime", cc_date_time_panel_get_type, NULL),
PANEL_TYPE("default-apps", cc_default_apps_panel_get_type, NULL),
- PANEL_TYPE("diagnostics", cc_diagnostics_panel_get_type, NULL),
+ PANEL_TYPE("diagnostics", cc_diagnostics_panel_get_type,
cc_diagnostics_panel_static_init_func),
PANEL_TYPE("display", cc_display_panel_get_type, NULL),
PANEL_TYPE("info-overview", cc_info_overview_panel_get_type, NULL),
PANEL_TYPE("keyboard", cc_keyboard_panel_get_type, NULL),
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]