network: Simplify helper function
This commit is contained in:
parent
f03ae7ff93
commit
75b4e5e061
5 changed files with 18 additions and 25 deletions
|
@ -266,9 +266,9 @@ connect_details_page (CEPageDetails *self)
|
||||||
if (ipv4_config != NULL) {
|
if (ipv4_config != NULL) {
|
||||||
g_autofree gchar *ipv4_text = NULL;
|
g_autofree gchar *ipv4_text = NULL;
|
||||||
g_autofree gchar *dns_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_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_heading_label), ipv4_text != NULL);
|
||||||
gtk_widget_set_visible (GTK_WIDGET (self->ipv4_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_heading_label), dns_text != NULL);
|
||||||
gtk_widget_set_visible (GTK_WIDGET (self->dns_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_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_heading_label), route_text != NULL);
|
||||||
gtk_widget_set_visible (GTK_WIDGET (self->route_label), route_text != NULL);
|
gtk_widget_set_visible (GTK_WIDGET (self->route_label), route_text != NULL);
|
||||||
|
|
|
@ -143,15 +143,15 @@ add_details (GtkWidget *details, NMDevice *device, NMConnection *connection)
|
||||||
NMIPConfig *ip4_config = NULL;
|
NMIPConfig *ip4_config = NULL;
|
||||||
NMIPConfig *ip6_config = NULL;
|
NMIPConfig *ip6_config = NULL;
|
||||||
g_autofree gchar *ip4_address = 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 *ip4_dns = NULL;
|
||||||
g_autofree gchar *ip6_address = NULL;
|
g_autofree gchar *ip6_address = NULL;
|
||||||
gint i = 0;
|
gint i = 0;
|
||||||
|
|
||||||
ip4_config = nm_device_get_ip4_config (device);
|
ip4_config = nm_device_get_ip4_config (device);
|
||||||
if (ip4_config) {
|
if (ip4_config) {
|
||||||
ip4_address = panel_get_ip4_address_as_string (ip4_config, "address");
|
ip4_address = panel_get_ip4_address_as_string (ip4_config);
|
||||||
ip4_route = panel_get_ip4_address_as_string (ip4_config, "gateway");
|
ip4_route = nm_ip_config_get_gateway (ip4_config);
|
||||||
ip4_dns = panel_get_ip4_dns_as_string (ip4_config);
|
ip4_dns = panel_get_ip4_dns_as_string (ip4_config);
|
||||||
}
|
}
|
||||||
ip6_config = nm_device_get_ip6_config (device);
|
ip6_config = nm_device_get_ip6_config (device);
|
||||||
|
|
|
@ -421,9 +421,9 @@ nm_device_mobile_refresh_ui (NetDeviceMobile *self)
|
||||||
if (ipv4_config != NULL) {
|
if (ipv4_config != NULL) {
|
||||||
g_autofree gchar *ipv4_text = NULL;
|
g_autofree gchar *ipv4_text = NULL;
|
||||||
g_autofree gchar *dns_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_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_heading_label), ipv4_text != NULL);
|
||||||
gtk_widget_set_visible (GTK_WIDGET (self->ipv4_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_heading_label), dns_text != NULL);
|
||||||
gtk_widget_set_visible (GTK_WIDGET (self->dns_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_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_heading_label), route_text != NULL);
|
||||||
gtk_widget_set_visible (GTK_WIDGET (self->route_label), route_text != NULL);
|
gtk_widget_set_visible (GTK_WIDGET (self->route_label), route_text != NULL);
|
||||||
|
|
|
@ -315,23 +315,16 @@ panel_device_status_to_localized_string (NMDevice *nm_device,
|
||||||
}
|
}
|
||||||
|
|
||||||
gchar *
|
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 */
|
GPtrArray *array;
|
||||||
if (!strcmp (what, "address")) {
|
NMIPAddress *address;
|
||||||
GPtrArray *array;
|
|
||||||
NMIPAddress *address;
|
|
||||||
|
|
||||||
array = nm_ip_config_get_addresses (ip4_config);
|
array = nm_ip_config_get_addresses (ip4_config);
|
||||||
if (array->len < 1)
|
if (array->len < 1)
|
||||||
return NULL;
|
return NULL;
|
||||||
address = array->pdata[0];
|
address = array->pdata[0];
|
||||||
return g_strdup (nm_ip_address_get_address (address));
|
return g_strdup (nm_ip_address_get_address (address));
|
||||||
} else if (!strcmp (what, "gateway")) {
|
|
||||||
return g_strdup (nm_ip_config_get_gateway (ip4_config));
|
|
||||||
}
|
|
||||||
|
|
||||||
return NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
gchar *
|
gchar *
|
||||||
|
|
|
@ -28,7 +28,7 @@ G_BEGIN_DECLS
|
||||||
|
|
||||||
gchar *panel_device_status_to_localized_string (NMDevice *nm_device,
|
gchar *panel_device_status_to_localized_string (NMDevice *nm_device,
|
||||||
const gchar *speed);
|
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_ip4_dns_as_string (NMIPConfig *config);
|
||||||
gchar *panel_get_ip6_address_as_string (NMIPConfig *config);
|
gchar *panel_get_ip6_address_as_string (NMIPConfig *config);
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue