[gnome-control-center] network: Move common code UI into each widget using it
- From: Georges Basile Stavracas Neto <gbsneto src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-control-center] network: Move common code UI into each widget using it
- Date: Tue, 22 Oct 2019 20:18:12 +0000 (UTC)
commit f03ae7ff9342cd28893b640b662c60210727755e
Author: Robert Ancell <robert ancell canonical com>
Date: Fri Oct 18 14:52:26 2019 +1300
network: Move common code UI into each widget using it
It was only used twice and better managed in the actual widgets.
panels/network/connection-editor/ce-page-details.c | 62 +++++++++++++++++++---
panels/network/net-device-mobile.c | 60 ++++++++++++++++++---
panels/network/panel-common.c | 62 ----------------------
panels/network/panel-common.h | 5 --
4 files changed, 110 insertions(+), 79 deletions(-)
---
diff --git a/panels/network/connection-editor/ce-page-details.c
b/panels/network/connection-editor/ce-page-details.c
index 820df6c0b..f7f399ca1 100644
--- a/panels/network/connection-editor/ce-page-details.c
+++ b/panels/network/connection-editor/ce-page-details.c
@@ -186,6 +186,8 @@ connect_details_page (CEPageDetails *self)
g_autofree gchar *security_string = NULL;
const gchar *strength_label;
gboolean device_is_active;
+ NMIPConfig *ipv4_config = NULL, *ipv6_config = NULL;
+ gboolean have_ipv4_address = FALSE, have_ipv6_address = FALSE;
sc = nm_connection_get_setting_connection (CE_PAGE (self)->connection);
type = nm_setting_connection_get_connection_type (sc);
@@ -259,12 +261,60 @@ connect_details_page (CEPageDetails *self)
gtk_widget_set_visible (GTK_WIDGET (self->strength_heading_label), strength_label != NULL);
gtk_widget_set_visible (GTK_WIDGET (self->strength_label), strength_label != NULL);
- /* set IP entries */
- panel_set_device_widgets (self->ipv4_heading_label, self->ipv4_label,
- self->ipv6_heading_label, self->ipv6_label,
- self->dns_heading_label, self->dns_label,
- self->route_heading_label, self->route_label,
- device_is_active ? self->device : NULL);
+ if (device_is_active && self->device != NULL)
+ ipv4_config = nm_device_get_ip4_config (self->device);
+ if (ipv4_config != NULL) {
+ g_autofree gchar *ipv4_text = NULL;
+ g_autofree gchar *dns_text = NULL;
+ g_autofree gchar *route_text = NULL;
+
+ ipv4_text = panel_get_ip4_address_as_string (ipv4_config, "address");
+ 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);
+ have_ipv4_address = ipv4_text != NULL;
+
+ dns_text = panel_get_ip4_dns_as_string (ipv4_config);
+ gtk_label_set_label (self->dns_label, dns_text);
+ 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");
+ 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);
+ } else {
+ gtk_widget_hide (GTK_WIDGET (self->ipv4_heading_label));
+ gtk_widget_hide (GTK_WIDGET (self->ipv4_label));
+ gtk_widget_hide (GTK_WIDGET (self->dns_heading_label));
+ gtk_widget_hide (GTK_WIDGET (self->dns_label));
+ gtk_widget_hide (GTK_WIDGET (self->route_heading_label));
+ gtk_widget_hide (GTK_WIDGET (self->route_label));
+ }
+
+ if (device_is_active && self->device != NULL)
+ ipv6_config = nm_device_get_ip6_config (self->device);
+ if (ipv6_config != NULL) {
+ g_autofree gchar *ipv6_text = NULL;
+
+ ipv6_text = panel_get_ip6_address_as_string (ipv6_config);
+ gtk_label_set_label (self->ipv6_label, ipv6_text);
+ gtk_widget_set_visible (GTK_WIDGET (self->ipv6_heading_label), ipv6_text != NULL);
+ gtk_widget_set_visible (GTK_WIDGET (self->ipv6_label), ipv6_text != NULL);
+ have_ipv6_address = ipv6_text != NULL;
+ } else {
+ gtk_widget_hide (GTK_WIDGET (self->ipv6_heading_label));
+ gtk_widget_hide (GTK_WIDGET (self->ipv6_label));
+ }
+
+ if (have_ipv4_address && have_ipv6_address) {
+ gtk_label_set_label (self->ipv4_heading_label, _("IPv4 Address"));
+ gtk_label_set_label (self->ipv6_heading_label, _("IPv6 Address"));
+ }
+ else {
+ gtk_label_set_label (self->ipv4_heading_label, _("IP Address"));
+ gtk_label_set_label (self->ipv6_heading_label, _("IP Address"));
+ }
if (!device_is_active && CE_PAGE (self)->connection)
update_last_used (self, CE_PAGE (self)->connection);
diff --git a/panels/network/net-device-mobile.c b/panels/network/net-device-mobile.c
index 365fe9c05..f622de598 100644
--- a/panels/network/net-device-mobile.c
+++ b/panels/network/net-device-mobile.c
@@ -383,6 +383,8 @@ nm_device_mobile_refresh_ui (NetDeviceMobile *self)
NMDeviceModemCapabilities caps;
NMDevice *nm_device;
g_autofree gchar *status = NULL;
+ NMIPConfig *ipv4_config = NULL, *ipv6_config = NULL;
+ gboolean have_ipv4_address = FALSE, have_ipv6_address = FALSE;
nm_device = net_device_get_nm_device (NET_DEVICE (self));
@@ -415,12 +417,58 @@ nm_device_mobile_refresh_ui (NetDeviceMobile *self)
self->mobile_connections_list_store,
self->network_combo);
- /* set IP entries */
- panel_set_device_widgets (self->ipv4_heading_label, self->ipv4_label,
- self->ipv6_heading_label, self->ipv6_label,
- self->dns_heading_label, self->dns_label,
- self->route_heading_label, self->route_label,
- nm_device);
+ ipv4_config = nm_device_get_ip4_config (nm_device);
+ if (ipv4_config != NULL) {
+ g_autofree gchar *ipv4_text = NULL;
+ g_autofree gchar *dns_text = NULL;
+ g_autofree gchar *route_text = NULL;
+
+ ipv4_text = panel_get_ip4_address_as_string (ipv4_config, "address");
+ 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);
+ have_ipv4_address = ipv4_text != NULL;
+
+ dns_text = panel_get_ip4_dns_as_string (ipv4_config);
+ gtk_label_set_label (self->dns_label, dns_text);
+ 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");
+ 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);
+ } else {
+ gtk_widget_hide (GTK_WIDGET (self->ipv4_heading_label));
+ gtk_widget_hide (GTK_WIDGET (self->ipv4_label));
+ gtk_widget_hide (GTK_WIDGET (self->dns_heading_label));
+ gtk_widget_hide (GTK_WIDGET (self->dns_label));
+ gtk_widget_hide (GTK_WIDGET (self->route_heading_label));
+ gtk_widget_hide (GTK_WIDGET (self->route_label));
+ }
+
+ ipv6_config = nm_device_get_ip6_config (nm_device);
+ if (ipv6_config != NULL) {
+ g_autofree gchar *ipv6_text = NULL;
+
+ ipv6_text = panel_get_ip6_address_as_string (ipv6_config);
+ gtk_label_set_label (self->ipv6_label, ipv6_text);
+ gtk_widget_set_visible (GTK_WIDGET (self->ipv6_heading_label), ipv6_text != NULL);
+ gtk_widget_set_visible (GTK_WIDGET (self->ipv6_label), ipv6_text != NULL);
+ have_ipv6_address = ipv6_text != NULL;
+ } else {
+ gtk_widget_hide (GTK_WIDGET (self->ipv6_heading_label));
+ gtk_widget_hide (GTK_WIDGET (self->ipv6_label));
+ }
+
+ if (have_ipv4_address && have_ipv6_address) {
+ gtk_label_set_label (self->ipv4_heading_label, _("IPv4 Address"));
+ gtk_label_set_label (self->ipv6_heading_label, _("IPv6 Address"));
+ }
+ else {
+ gtk_label_set_label (self->ipv4_heading_label, _("IP Address"));
+ gtk_label_set_label (self->ipv6_heading_label, _("IP Address"));
+ }
}
static void
diff --git a/panels/network/panel-common.c b/panels/network/panel-common.c
index 24e61f475..0e5bf580b 100644
--- a/panels/network/panel-common.c
+++ b/panels/network/panel-common.c
@@ -314,24 +314,6 @@ panel_device_status_to_localized_string (NMDevice *nm_device,
return g_string_free (string, FALSE);
}
-static gboolean
-panel_set_device_widget_details (GtkLabel *heading,
- GtkLabel *widget,
- const gchar *value)
-{
- /* hide the row if there is no value */
- if (value == NULL) {
- gtk_widget_hide (GTK_WIDGET (heading));
- gtk_widget_hide (GTK_WIDGET (widget));
- } else {
- /* there exists a value */
- gtk_widget_show (GTK_WIDGET (heading));
- gtk_widget_show (GTK_WIDGET (widget));
- gtk_label_set_label (widget, value);
- }
- return TRUE;
-}
-
gchar *
panel_get_ip4_address_as_string (NMIPConfig *ip4_config, const char *what)
{
@@ -371,47 +353,3 @@ panel_get_ip6_address_as_string (NMIPConfig *ip6_config)
address = array->pdata[0];
return g_strdup (nm_ip_address_get_address (address));
}
-
-void
-panel_set_device_widgets (GtkLabel *ipv4_heading_label, GtkLabel *ipv4_label,
- GtkLabel *ipv6_heading_label, GtkLabel *ipv6_label,
- GtkLabel *heading_dns, GtkLabel *dns_label,
- GtkLabel *route_heading_label, GtkLabel *route_label,
- NMDevice *device)
-{
- 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);
- }
-
- panel_set_device_widget_details (ipv4_heading_label, ipv4_label, ipv4_text);
- panel_set_device_widget_details (ipv6_heading_label, ipv6_label, ipv6_text);
- panel_set_device_widget_details (heading_dns, dns_label, dns_text);
- panel_set_device_widget_details (route_heading_label, route_label, route_text);
-
- has_ip4 = ipv4_text != NULL;
- has_ip6 = ipv6_text != NULL;
- if (has_ip4 && has_ip6) {
- gtk_label_set_label (ipv4_heading_label, _("IPv4 Address"));
- gtk_label_set_label (ipv6_heading_label, _("IPv6 Address"));
- } else if (has_ip4) {
- gtk_label_set_label (ipv4_heading_label, _("IP Address"));
- } else if (has_ip6) {
- gtk_label_set_label (ipv6_heading_label, _("IP Address"));
- }
-}
diff --git a/panels/network/panel-common.h b/panels/network/panel-common.h
index b1cf16e75..be3e2814a 100644
--- a/panels/network/panel-common.h
+++ b/panels/network/panel-common.h
@@ -28,11 +28,6 @@ G_BEGIN_DECLS
gchar *panel_device_status_to_localized_string (NMDevice *nm_device,
const gchar *speed);
-void panel_set_device_widgets (GtkLabel *ipv4_heading_label, GtkLabel
*ipv4_label,
- GtkLabel *ipv6_heading_label, GtkLabel
*ipv6_label,
- GtkLabel *heading_dns, GtkLabel *dns_label,
- GtkLabel *route_heading_label, GtkLabel
*route_label,
- NMDevice *device);
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]