From 20c46aa5e227f2f346cfb5aad406c06d053429a3 Mon Sep 17 00:00:00 2001 From: Felipe Borges Date: Thu, 31 Jul 2025 14:49:07 +0200 Subject: [PATCH 1/2] privacy: Add stub for "Network Activity" page See https://gitlab.gnome.org/-/project/660/uploads/e732ff528cd5ed470e35c4424db24327/privacy-network-activity.png Related: #3530 --- panels/privacy/cc-privacy-panel.blp | 12 +++++ panels/privacy/cc-privacy-panel.c | 2 + panels/privacy/meson.build | 2 + .../cc-network-activity-page.blp | 33 ++++++++++++++ .../cc-network-activity-page.c | 45 +++++++++++++++++++ .../cc-network-activity-page.h | 30 +++++++++++++ panels/privacy/network-activity/meson.build | 14 ++++++ panels/privacy/privacy.gresource.xml | 1 + po/POTFILES.in | 1 + 9 files changed, 140 insertions(+) create mode 100644 panels/privacy/network-activity/cc-network-activity-page.blp create mode 100644 panels/privacy/network-activity/cc-network-activity-page.c create mode 100644 panels/privacy/network-activity/cc-network-activity-page.h create mode 100644 panels/privacy/network-activity/meson.build diff --git a/panels/privacy/cc-privacy-panel.blp b/panels/privacy/cc-privacy-panel.blp index 10e6c51793..7d916005fc 100644 --- a/panels/privacy/cc-privacy-panel.blp +++ b/panels/privacy/cc-privacy-panel.blp @@ -51,6 +51,15 @@ template $CcPrivacyPanel: $CcPanel { action-target: "'diagnostics'"; visible: bind diagnostics_page.visible; } + + $CcListRow { + title: _("Network Activity"); + subtitle: _("Services which rely on network communications"); + icon-name: "network-transmit-receive-symbolic"; + show-arrow: true; + action-name: "navigation.push"; + action-target: "'network-activity'"; + } } Adw.PreferencesGroup { @@ -98,6 +107,9 @@ template $CcPrivacyPanel: $CcPanel { [subpage] $CcUsagePage {} + [subpage] + $CcNetworkActivityPage {} + [subpage] $CcDiagnosticsPage diagnostics_page {} diff --git a/panels/privacy/cc-privacy-panel.c b/panels/privacy/cc-privacy-panel.c index 259f78f05f..136fd063a7 100644 --- a/panels/privacy/cc-privacy-panel.c +++ b/panels/privacy/cc-privacy-panel.c @@ -30,6 +30,7 @@ #include "firmware-security/cc-firmware-security-page.h" #include "cc-list-row.h" #include "location/cc-location-page.h" +#include "network-activity/cc-network-activity-page.h" #include "cc-privacy-resources.h" #include "screen/cc-screen-page.h" #include "usage/cc-usage-page.h" @@ -75,6 +76,7 @@ cc_privacy_panel_class_init (CcPrivacyPanelClass *klass) g_type_ensure (CC_TYPE_DIAGNOSTICS_PAGE); g_type_ensure (CC_TYPE_FIRMWARE_SECURITY_PAGE); g_type_ensure (CC_TYPE_LOCATION_PAGE); + g_type_ensure (CC_TYPE_NETWORK_ACTIVITYT_PAGE); g_type_ensure (CC_TYPE_SCREEN_PAGE); g_type_ensure (CC_TYPE_USAGE_PAGE); } diff --git a/panels/privacy/meson.build b/panels/privacy/meson.build index 4360b10cb1..b3f24bef82 100644 --- a/panels/privacy/meson.build +++ b/panels/privacy/meson.build @@ -18,6 +18,7 @@ subdir('diagnostics') subdir('firmware-security') subdir('icons') subdir('location') +subdir('network-activity') subdir('screen') subdir('usage') @@ -45,6 +46,7 @@ sources = files( 'firmware-security/cc-firmware-security-page.c', 'firmware-security/cc-firmware-security-utils.c', 'location/cc-location-page.c', + 'network-activity/cc-network-activity-page.c', 'cc-privacy-panel.c', 'screen/cc-screen-page.c', 'usage/cc-usage-page.c', diff --git a/panels/privacy/network-activity/cc-network-activity-page.blp b/panels/privacy/network-activity/cc-network-activity-page.blp new file mode 100644 index 0000000000..046efd7511 --- /dev/null +++ b/panels/privacy/network-activity/cc-network-activity-page.blp @@ -0,0 +1,33 @@ +using Gtk 4.0; +using Adw 1; + +template $CcNetworkActivityPage: Adw.NavigationPage { + title: _("Network Activity"); + tag: "network-activity"; + + child: Adw.ToolbarView { + [top] + Adw.HeaderBar {} + + content: Adw.PreferencesPage { + description: _("Optional services which rely on anonymous network communications.\nMore details can be found in the GNOME Privacy Policy"); + description-centered: true; + + Adw.PreferencesGroup { + Adw.SwitchRow network_login_dectection_row { + title: _("_Network Login Detection"); + subtitle: _("Detects when a network requires login to access the internet"); + use-underline: true; + } + } + + Adw.PreferencesGroup { + Adw.SwitchRow donation_prompts_row { + title: _("_Donation Prompts"); + subtitle: _("Low frequency donation requests"); + use-underline: true; + } + } + }; + }; +} diff --git a/panels/privacy/network-activity/cc-network-activity-page.c b/panels/privacy/network-activity/cc-network-activity-page.c new file mode 100644 index 0000000000..241c06221c --- /dev/null +++ b/panels/privacy/network-activity/cc-network-activity-page.c @@ -0,0 +1,45 @@ +/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- + * + * Copyright (C) 2025 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 . + * + * Author: Felipe Borges + */ + +#include "cc-network-activity-page.h" + +#include + +struct _CcNetworkActivityPage +{ + AdwNavigationPage parent_instance; +}; + +G_DEFINE_TYPE (CcNetworkActivityPage, cc_network_activity_page, ADW_TYPE_NAVIGATION_PAGE) + +static void +cc_network_activity_page_class_init (CcNetworkActivityPageClass *klass) +{ + GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass); + + gtk_widget_class_set_template_from_resource (widget_class, "/org/gnome/control-center/privacy/network-activity/cc-network-activity-page.ui"); +} + +static void +cc_network_activity_page_init (CcNetworkActivityPage *self) +{ + gtk_widget_init_template (GTK_WIDGET (self)); + +} diff --git a/panels/privacy/network-activity/cc-network-activity-page.h b/panels/privacy/network-activity/cc-network-activity-page.h new file mode 100644 index 0000000000..70b36c1b0c --- /dev/null +++ b/panels/privacy/network-activity/cc-network-activity-page.h @@ -0,0 +1,30 @@ +/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- + * + * Copyright (C) 2025 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 . + * + * Author: Felipe Borges + */ + +#pragma once + +#include + +G_BEGIN_DECLS + +#define CC_TYPE_NETWORK_ACTIVITYT_PAGE (cc_network_activity_page_get_type ()) +G_DECLARE_FINAL_TYPE (CcNetworkActivityPage, cc_network_activity_page, CC, NETWORK_ACTIVITY_PAGE, AdwNavigationPage) + +G_END_DECLS diff --git a/panels/privacy/network-activity/meson.build b/panels/privacy/network-activity/meson.build new file mode 100644 index 0000000000..34b4424da4 --- /dev/null +++ b/panels/privacy/network-activity/meson.build @@ -0,0 +1,14 @@ +ui_sources = files( + 'cc-network-activity-page.blp', +) + +ui_compiled = [] +foreach ui_source : ui_sources + ui_compiled += fs.name(fs.replace_suffix(ui_source, '.ui')) +endforeach + +blueprints += custom_target( + input: ui_sources, + output: ui_compiled, + command: [blueprint_compiler, 'batch-compile', '@OUTDIR@', '@CURRENT_SOURCE_DIR@', '@INPUT@'] +) diff --git a/panels/privacy/privacy.gresource.xml b/panels/privacy/privacy.gresource.xml index e8e28637db..e3c38bc42d 100644 --- a/panels/privacy/privacy.gresource.xml +++ b/panels/privacy/privacy.gresource.xml @@ -11,6 +11,7 @@ firmware-security/cc-firmware-security-help-dialog.ui firmware-security/cc-firmware-security-page.ui location/cc-location-page.ui + network-activity/cc-network-activity-page.ui cc-privacy-panel.ui screen/cc-screen-page.ui usage/cc-usage-page.ui diff --git a/po/POTFILES.in b/po/POTFILES.in index d3c93dc3c5..c12747be90 100644 --- a/po/POTFILES.in +++ b/po/POTFILES.in @@ -169,6 +169,7 @@ panels/privacy/firmware-security/cc-firmware-security-page.c panels/privacy/firmware-security/cc-firmware-security-utils.c panels/privacy/gnome-privacy-panel.desktop.in panels/privacy/location/cc-location-page.blp +panels/privacy/network-activity/cc-network-activity-page.blp panels/privacy/screen/cc-screen-page.blp panels/privacy/usage/cc-usage-page.blp panels/search/cc-search-locations-page.blp -- GitLab From 0452e347a66206980b11f1a58b1383c78236379c Mon Sep 17 00:00:00 2001 From: James Henstridge Date: Thu, 31 Jul 2025 15:36:05 +0200 Subject: [PATCH 2/2] privacy, network-activity: Wire network login detection toggle This patch is heavily based on the Ubuntu downstream one found at https://salsa.debian.org/gnome-team/gnome-control-center/-/blob/ubuntu/plucky/debian/patches/ubuntu/connectivity-add-network-connectivity-checking-toggle.patch?ref_type=heads For this reason, I am adding the original commit author and appending my name below. Co-authored-by: Felipe Borges --- panels/privacy/meson.build | 1 + .../cc-network-activity-page.c | 70 +++++++++++++++++++ 2 files changed, 71 insertions(+) diff --git a/panels/privacy/meson.build b/panels/privacy/meson.build index b3f24bef82..59cbd8e5c8 100644 --- a/panels/privacy/meson.build +++ b/panels/privacy/meson.build @@ -92,6 +92,7 @@ cflags += [ deps = common_deps + [ dependency('libgtop-2.0'), + network_manager_deps, ] deps = deps + [ diff --git a/panels/privacy/network-activity/cc-network-activity-page.c b/panels/privacy/network-activity/cc-network-activity-page.c index 241c06221c..cb5975db83 100644 --- a/panels/privacy/network-activity/cc-network-activity-page.c +++ b/panels/privacy/network-activity/cc-network-activity-page.c @@ -19,22 +19,85 @@ */ #include "cc-network-activity-page.h" +#include "shell/cc-object-storage.h" #include +#include struct _CcNetworkActivityPage { AdwNavigationPage parent_instance; + + AdwSwitchRow *network_login_dectection_row; + + GCancellable *cancellable; + NMClient *nm_client; + }; G_DEFINE_TYPE (CcNetworkActivityPage, cc_network_activity_page, ADW_TYPE_NAVIGATION_PAGE) +static void +setup_nm_client (CcNetworkActivityPage *self, + NMClient *client) +{ + self->nm_client = client; + + g_object_bind_property (self->nm_client, NM_CLIENT_CONNECTIVITY_CHECK_AVAILABLE, + self->network_login_dectection_row, "sensitive", + G_BINDING_SYNC_CREATE); + + g_object_bind_property (self->nm_client, NM_CLIENT_CONNECTIVITY_CHECK_ENABLED, + self->network_login_dectection_row, "active", + G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE); +} + +static void +nm_client_ready_cb (GObject *source_object, + GAsyncResult *res, + gpointer user_data) +{ + CcNetworkActivityPage *self; + NMClient *client; + g_autoptr(GError) error = NULL; + + client = nm_client_new_finish (res, &error); + if (!client) { + if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) { + g_warning ("Failed to create NetworkManager client: %s", error->message); + return; + } + } + + self = user_data; + + setup_nm_client (self, client); + cc_object_storage_add_object (CC_OBJECT_NMCLIENT, client); +} + +static void +cc_network_activity_page_finalize (GObject *object) +{ + CcNetworkActivityPage *self = CC_NETWORK_ACTIVITY_PAGE (object); + + g_cancellable_cancel (self->cancellable); + g_clear_object (&self->nm_client); + + G_OBJECT_CLASS (cc_network_activity_page_parent_class)->finalize (object); +} + + static void cc_network_activity_page_class_init (CcNetworkActivityPageClass *klass) { + GObjectClass *object_class = G_OBJECT_CLASS (klass); GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass); + object_class->finalize = cc_network_activity_page_finalize; + gtk_widget_class_set_template_from_resource (widget_class, "/org/gnome/control-center/privacy/network-activity/cc-network-activity-page.ui"); + + gtk_widget_class_bind_template_child (widget_class, CcNetworkActivityPage, network_login_dectection_row); } static void @@ -42,4 +105,11 @@ cc_network_activity_page_init (CcNetworkActivityPage *self) { gtk_widget_init_template (GTK_WIDGET (self)); + self->cancellable = g_cancellable_new (); + + if (cc_object_storage_has_object (CC_OBJECT_NMCLIENT)) { + setup_nm_client (self, cc_object_storage_get_object (CC_OBJECT_NMCLIENT)); + } else { + nm_client_new_async (self->cancellable, nm_client_ready_cb, self); + } } -- GitLab