[gnome-control-center] network: Simplify helper function



commit 75b4e5e061599d4f0b725c33ed3239da4ff1c7a9
Author: Robert Ancell <robert ancell canonical com>
Date:   Fri Oct 18 15:03:20 2019 +1300

    network: Simplify helper function

 panels/network/connection-editor/ce-page-details.c |  6 +++---
 panels/network/net-device-ethernet.c               |  6 +++---
 panels/network/net-device-mobile.c                 |  6 +++---
 panels/network/panel-common.c                      | 23 ++++++++--------------
 panels/network/panel-common.h                      |  2 +-
 5 files changed, 18 insertions(+), 25 deletions(-)
---
diff --git a/panels/network/connection-editor/ce-page-details.c 
b/panels/network/connection-editor/ce-page-details.c
index f7f399ca1..68ab27824 100644
--- a/panels/network/connection-editor/ce-page-details.c
+++ b/panels/network/connection-editor/ce-page-details.c
@@ -266,9 +266,9 @@ connect_details_page (CEPageDetails *self)
         if (ipv4_config != NULL) {
                 g_autofree gchar *ipv4_text = NULL;
                 g_autofree gchar *dns_text = NULL;
-                g_autofree gchar *route_text = NULL;
+                const gchar *route_text;
 
-                ipv4_text = panel_get_ip4_address_as_string (ipv4_config, "address");
+                ipv4_text = panel_get_ip4_address_as_string (ipv4_config);
                 gtk_label_set_label (self->ipv4_label, ipv4_text);
                 gtk_widget_set_visible (GTK_WIDGET (self->ipv4_heading_label), ipv4_text != NULL);
                 gtk_widget_set_visible (GTK_WIDGET (self->ipv4_label), ipv4_text != NULL);
@@ -279,7 +279,7 @@ connect_details_page (CEPageDetails *self)
                 gtk_widget_set_visible (GTK_WIDGET (self->dns_heading_label), dns_text != NULL);
                 gtk_widget_set_visible (GTK_WIDGET (self->dns_label), dns_text != NULL);
 
-                route_text = panel_get_ip4_address_as_string (ipv4_config, "gateway");
+                route_text = nm_ip_config_get_gateway (ipv4_config);
                 gtk_label_set_label (self->route_label, route_text);
                 gtk_widget_set_visible (GTK_WIDGET (self->route_heading_label), route_text != NULL);
                 gtk_widget_set_visible (GTK_WIDGET (self->route_label), route_text != NULL);
diff --git a/panels/network/net-device-ethernet.c b/panels/network/net-device-ethernet.c
index eee67357a..c70197d16 100644
--- a/panels/network/net-device-ethernet.c
+++ b/panels/network/net-device-ethernet.c
@@ -143,15 +143,15 @@ add_details (GtkWidget *details, NMDevice *device, NMConnection *connection)
         NMIPConfig *ip4_config = NULL;
         NMIPConfig *ip6_config = NULL;
         g_autofree gchar *ip4_address = NULL;
-        g_autofree gchar *ip4_route = NULL;
+        const gchar *ip4_route = NULL;
         g_autofree gchar *ip4_dns = NULL;
         g_autofree gchar *ip6_address = NULL;
         gint i = 0;
 
         ip4_config = nm_device_get_ip4_config (device);
         if (ip4_config) {
-                ip4_address = panel_get_ip4_address_as_string (ip4_config, "address");
-                ip4_route = panel_get_ip4_address_as_string (ip4_config, "gateway");
+                ip4_address = panel_get_ip4_address_as_string (ip4_config);
+                ip4_route = nm_ip_config_get_gateway (ip4_config);
                 ip4_dns = panel_get_ip4_dns_as_string (ip4_config);
         }
         ip6_config = nm_device_get_ip6_config (device);
diff --git a/panels/network/net-device-mobile.c b/panels/network/net-device-mobile.c
index f622de598..73152b754 100644
--- a/panels/network/net-device-mobile.c
+++ b/panels/network/net-device-mobile.c
@@ -421,9 +421,9 @@ nm_device_mobile_refresh_ui (NetDeviceMobile *self)
         if (ipv4_config != NULL) {
                 g_autofree gchar *ipv4_text = NULL;
                 g_autofree gchar *dns_text = NULL;
-                g_autofree gchar *route_text = NULL;
+                const gchar *route_text;
 
-                ipv4_text = panel_get_ip4_address_as_string (ipv4_config, "address");
+                ipv4_text = panel_get_ip4_address_as_string (ipv4_config);
                 gtk_label_set_label (self->ipv4_label, ipv4_text);
                 gtk_widget_set_visible (GTK_WIDGET (self->ipv4_heading_label), ipv4_text != NULL);
                 gtk_widget_set_visible (GTK_WIDGET (self->ipv4_label), ipv4_text != NULL);
@@ -434,7 +434,7 @@ nm_device_mobile_refresh_ui (NetDeviceMobile *self)
                 gtk_widget_set_visible (GTK_WIDGET (self->dns_heading_label), dns_text != NULL);
                 gtk_widget_set_visible (GTK_WIDGET (self->dns_label), dns_text != NULL);
 
-                route_text = panel_get_ip4_address_as_string (ipv4_config, "gateway");
+                route_text = nm_ip_config_get_gateway (ipv4_config);
                 gtk_label_set_label (self->route_label, route_text);
                 gtk_widget_set_visible (GTK_WIDGET (self->route_heading_label), route_text != NULL);
                 gtk_widget_set_visible (GTK_WIDGET (self->route_label), route_text != NULL);
diff --git a/panels/network/panel-common.c b/panels/network/panel-common.c
index 0e5bf580b..5e099a364 100644
--- a/panels/network/panel-common.c
+++ b/panels/network/panel-common.c
@@ -315,23 +315,16 @@ panel_device_status_to_localized_string (NMDevice *nm_device,
 }
 
 gchar *
-panel_get_ip4_address_as_string (NMIPConfig *ip4_config, const char *what)
+panel_get_ip4_address_as_string (NMIPConfig *ip4_config)
 {
-        /* we only care about one address */
-        if (!strcmp (what, "address")) {
-                GPtrArray *array;
-                NMIPAddress *address;
-
-                array = nm_ip_config_get_addresses (ip4_config);
-                if (array->len < 1)
-                        return NULL;
-                address = array->pdata[0];
-                return g_strdup (nm_ip_address_get_address (address));
-        } else if (!strcmp (what, "gateway")) {
-                return g_strdup (nm_ip_config_get_gateway (ip4_config));
-        }
+        GPtrArray *array;
+        NMIPAddress *address;
 
-        return NULL;
+        array = nm_ip_config_get_addresses (ip4_config);
+        if (array->len < 1)
+                return NULL;
+        address = array->pdata[0];
+        return g_strdup (nm_ip_address_get_address (address));
 }
 
 gchar *
diff --git a/panels/network/panel-common.h b/panels/network/panel-common.h
index be3e2814a..dcb6a54a0 100644
--- a/panels/network/panel-common.h
+++ b/panels/network/panel-common.h
@@ -28,7 +28,7 @@ G_BEGIN_DECLS
 
 gchar           *panel_device_status_to_localized_string       (NMDevice *nm_device,
                                                                 const gchar *speed);
-gchar           *panel_get_ip4_address_as_string               (NMIPConfig *config, const gchar *what);
+gchar           *panel_get_ip4_address_as_string               (NMIPConfig *config);
 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]