[gnome-control-center] network: Simplify function
- From: Georges Basile Stavracas Neto <gbsneto src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-control-center] network: Simplify function
- Date: Tue, 1 Oct 2019 02:35:17 +0000 (UTC)
commit 1d43f4c0f557ce017c7d6a41698395ce7bec5e33
Author: Robert Ancell <robert ancell canonical com>
Date: Tue Oct 1 14:27:29 2019 +1300
network: Simplify function
panels/network/connection-editor/ce-page-details.c | 2 +-
panels/network/net-device-wifi.c | 2 +-
panels/network/panel-common.c | 92 ++++++----------------
panels/network/panel-common.h | 1 -
4 files changed, 26 insertions(+), 71 deletions(-)
---
diff --git a/panels/network/connection-editor/ce-page-details.c
b/panels/network/connection-editor/ce-page-details.c
index d7bfa5499..f2151ad62 100644
--- a/panels/network/connection-editor/ce-page-details.c
+++ b/panels/network/connection-editor/ce-page-details.c
@@ -256,7 +256,7 @@ connect_details_page (CEPageDetails *page)
if (device_is_active)
panel_set_device_widgets (CE_PAGE (page)->builder, page->device);
else
- panel_unset_device_widgets (CE_PAGE (page)->builder);
+ panel_set_device_widgets (CE_PAGE (page)->builder, NULL);
if (!device_is_active && CE_PAGE (page)->connection)
update_last_used (page, CE_PAGE (page)->connection);
diff --git a/panels/network/net-device-wifi.c b/panels/network/net-device-wifi.c
index f8a1b689a..114100b64 100644
--- a/panels/network/net-device-wifi.c
+++ b/panels/network/net-device-wifi.c
@@ -578,7 +578,7 @@ nm_device_wifi_refresh_ui (NetDeviceWifi *device_wifi)
/* set IP entries */
if (ap != active_ap)
- panel_unset_device_widgets (device_wifi->builder);
+ panel_set_device_widgets (device_wifi->builder, NULL);
else
panel_set_device_widgets (device_wifi->builder, nm_device);
diff --git a/panels/network/panel-common.c b/panels/network/panel-common.c
index 022243c39..57d74fbae 100644
--- a/panels/network/panel-common.c
+++ b/panels/network/panel-common.c
@@ -413,68 +413,33 @@ panel_get_ip6_address_as_string (NMIPConfig *ip6_config)
void
panel_set_device_widgets (GtkBuilder *builder, NMDevice *device)
{
- NMIPConfig *ip4_config = NULL;
- NMIPConfig *ip6_config = NULL;
- gboolean has_ip4;
- gboolean has_ip6;
- gchar *str_tmp;
-
- /* get IPv4 parameters */
- ip4_config = nm_device_get_ip4_config (device);
- if (ip4_config != NULL) {
-
- /* IPv4 address */
- str_tmp = panel_get_ip4_address_as_string (ip4_config, "address");
- panel_set_device_widget_details (builder,
- "ipv4",
- str_tmp);
- has_ip4 = str_tmp != NULL;
- g_free (str_tmp);
-
- /* IPv4 DNS */
- str_tmp = panel_get_ip4_dns_as_string (ip4_config);
- panel_set_device_widget_details (builder,
- "dns",
- str_tmp);
- g_free (str_tmp);
-
- /* IPv4 route */
- str_tmp = panel_get_ip4_address_as_string (ip4_config, "gateway");
- panel_set_device_widget_details (builder,
- "route",
- str_tmp);
- g_free (str_tmp);
-
- } else {
- /* IPv4 address */
- panel_set_device_widget_details (builder,
- "ipv4",
- NULL);
- has_ip4 = FALSE;
-
- /* IPv4 DNS */
- panel_set_device_widget_details (builder,
- "dns",
- NULL);
-
- /* IPv4 route */
- panel_set_device_widget_details (builder,
- "route",
- NULL);
+ g_autofree gchar *ipv4_text = NULL;
+ g_autofree gchar *ipv6_text = NULL;
+ g_autofree gchar *dns_text = NULL;
+ g_autofree gchar *route_text = NULL;
+ gboolean has_ip4, has_ip6;
+
+ if (device != NULL) {
+ NMIPConfig *ip4_config, *ip6_config;
+
+ ip4_config = nm_device_get_ip4_config (device);
+ if (ip4_config != NULL) {
+ ipv4_text = panel_get_ip4_address_as_string (ip4_config, "address");
+ dns_text = panel_get_ip4_dns_as_string (ip4_config);
+ route_text = panel_get_ip4_address_as_string (ip4_config, "gateway");
+ }
+ ip6_config = nm_device_get_ip6_config (device);
+ if (ip6_config != NULL)
+ ipv6_text = panel_get_ip6_address_as_string (ip6_config);
}
- /* get IPv6 parameters */
- ip6_config = nm_device_get_ip6_config (device);
- if (ip6_config != NULL) {
- str_tmp = panel_get_ip6_address_as_string (ip6_config);
- panel_set_device_widget_details (builder, "ipv6", str_tmp);
- has_ip6 = str_tmp != NULL;
- g_free (str_tmp);
- } else {
- panel_set_device_widget_details (builder, "ipv6", NULL);
- has_ip6 = FALSE;
- }
+ panel_set_device_widget_details (builder, "ipv4", ipv4_text);
+ panel_set_device_widget_details (builder, "ipv6", ipv6_text);
+ panel_set_device_widget_details (builder, "dns", dns_text);
+ panel_set_device_widget_details (builder, "route", route_text);
+ has_ip4 = ipv4_text != NULL;
+ has_ip6 = ipv6_text != NULL;
if (has_ip4 && has_ip6) {
panel_set_device_widget_header (builder, "ipv4", _("IPv4 Address"));
panel_set_device_widget_header (builder, "ipv6", _("IPv6 Address"));
@@ -484,12 +449,3 @@ panel_set_device_widgets (GtkBuilder *builder, NMDevice *device)
panel_set_device_widget_header (builder, "ipv6", _("IP Address"));
}
}
-
-void
-panel_unset_device_widgets (GtkBuilder *builder)
-{
- panel_set_device_widget_details (builder, "ipv4", NULL);
- panel_set_device_widget_details (builder, "ipv6", NULL);
- panel_set_device_widget_details (builder, "dns", NULL);
- panel_set_device_widget_details (builder, "route", NULL);
-}
diff --git a/panels/network/panel-common.h b/panels/network/panel-common.h
index 4f0631bc1..c56bd0f8c 100644
--- a/panels/network/panel-common.h
+++ b/panels/network/panel-common.h
@@ -33,7 +33,6 @@ gboolean panel_set_device_widget_details (GtkBuilder *buil
const gchar *value);
void panel_set_device_widgets (GtkBuilder *builder,
NMDevice *device);
-void panel_unset_device_widgets (GtkBuilder *builder);
gchar *panel_get_ip4_address_as_string (NMIPConfig *config, const gchar *what);
gchar *panel_get_ip4_dns_as_string (NMIPConfig *config);
gchar *panel_get_ip6_address_as_string (NMIPConfig *config);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]