diff options
author | Dan Winship <danw@gnome.org> | 2014-11-12 09:02:32 -0500 |
---|---|---|
committer | Dan Winship <danw@gnome.org> | 2014-11-12 16:04:59 -0500 |
commit | 29ed625feac222b3632d8f1835d21afc69c0fad8 (patch) | |
tree | 3fa1433255953c24e0bc62267fe10f1d7bcf7e74 | |
parent | dd9bb5f376e1367a54b307c26bf4d888976c2d20 (diff) | |
download | NetworkManager-29ed625feac222b3632d8f1835d21afc69c0fad8.tar.gz |
tui: fix gateway editing
Since adding NMSettingIPConfig:gateway, we were just binding that
property to the Gateway entry as a string. But this caused two
different problems: first, we were trying to set the :gateway property
from the entry even when the IP address in the entry was incomplete
(causing warnings), and second, we were no longer enforcing the rule
that the gateway can only be set when there are static addresses
configured.
Fix this by adding back nm_editor_bind_ip_gateway_to_string(), but
with new semantics reflecting the new way NMSettingIPConfig:addresses
and :gateway work. (Besides just fixing the new bugs, this also makes
the Gateway entry insensitive when there are no addresses; before,
nmtui would allow you to type there, but the value would not be
saved.)
Fixes: Test263_nmtui_ipv4_addresses_delete_ip_and_back_to_auto
https://bugzilla.gnome.org/show_bug.cgi?id=740017
-rw-r--r-- | clients/tui/nm-editor-bindings.c | 107 | ||||
-rw-r--r-- | clients/tui/nm-editor-bindings.h | 7 | ||||
-rw-r--r-- | clients/tui/nmt-page-ip4.c | 7 | ||||
-rw-r--r-- | clients/tui/nmt-page-ip6.c | 7 |
4 files changed, 122 insertions, 6 deletions
diff --git a/clients/tui/nm-editor-bindings.c b/clients/tui/nm-editor-bindings.c index 5560f83ca6..c95f55a44e 100644 --- a/clients/tui/nm-editor-bindings.c +++ b/clients/tui/nm-editor-bindings.c @@ -273,6 +273,113 @@ nm_editor_bind_ip_addresses_to_strv (int family, } static gboolean +ip_gateway_to_string (GBinding *binding, + const GValue *source_value, + GValue *target_value, + gpointer user_data) +{ + g_value_set_string (target_value, g_value_get_string (source_value)); + return TRUE; +} + +static gboolean +ip_gateway_from_string (GBinding *binding, + const GValue *source_value, + GValue *target_value, + gpointer user_data) +{ + int family = GPOINTER_TO_INT (user_data); + const char *gateway; + + gateway = g_value_get_string (source_value); + if (*gateway && !nm_utils_ipaddr_valid (family, gateway)) + gateway = NULL; + + g_value_set_string (target_value, gateway); + return TRUE; +} + +static gboolean +ip_addresses_to_gateway (GBinding *binding, + const GValue *source_value, + GValue *target_value, + gpointer user_data) +{ + GPtrArray *addrs; + + addrs = g_value_get_boxed (source_value); + if (addrs->len == 0) { + g_value_set_string (target_value, NULL); + return TRUE; + } else + return FALSE; +} + +static gboolean +ip_addresses_to_sensitivity (GBinding *binding, + const GValue *source_value, + GValue *target_value, + gpointer user_data) +{ + GPtrArray *addrs; + + addrs = g_value_get_boxed (source_value); + g_value_set_boolean (target_value, addrs->len != 0); + return TRUE; +} + +/** + * nm_editor_bind_ip_gateway_to_string: + * @family: the IP address family + * @source: the source #NMSettingIPConfig + * @target: the target object (eg, an #NmtIPEntry) + * @target_property: the property on @target to bind (eg, "text") + * @target_sensitive_property: the "sensitivity" property on @target to bind + * @flags: %GBindingFlags + * + * Binds the #NMSettingIPConfig:gateway property on @source to the + * %G_TYPE_STRING property @target_property and %G_TYPE_BOOLEAN property + * @target_sensitive_property on @target, also taking the + * #NMSettingIPConfig:addresses property on @source into account. + * + * In particular, if @source has no static IP addresses, then @target_property + * will be set to "" and @target_sensitive_property will be set to %FALSE. + * + * If @source has at least one static IP address, then + * @target_sensitive_property will be set to %TRUE, @target_property will be + * initialized from @source's #NMSettingIPConfig:gateway, and @source will be + * updated with the value of @target_property whenever it contains a valid IP + * address. + */ +void +nm_editor_bind_ip_gateway_to_string (int family, + NMSettingIPConfig *source, + gpointer target, + const gchar *target_property, + const gchar *target_sensitive_property, + GBindingFlags flags) +{ + g_object_bind_property_full (source, "gateway", + target, target_property, + flags, + ip_gateway_to_string, + ip_gateway_from_string, + GINT_TO_POINTER (family), NULL); + g_object_bind_property_full (source, "addresses", + source, "gateway", + (flags & G_BINDING_SYNC_CREATE), + ip_addresses_to_gateway, + NULL, + NULL, NULL); + g_object_bind_property_full (source, "addresses", + target, target_sensitive_property, + (flags & G_BINDING_SYNC_CREATE), + ip_addresses_to_sensitivity, + NULL, + NULL, NULL); +} + +static gboolean ip_route_transform_to_dest_string (GBinding *binding, const GValue *source_value, GValue *target_value, diff --git a/clients/tui/nm-editor-bindings.h b/clients/tui/nm-editor-bindings.h index 19a172f344..c4ed95d53e 100644 --- a/clients/tui/nm-editor-bindings.h +++ b/clients/tui/nm-editor-bindings.h @@ -38,6 +38,13 @@ void nm_editor_bind_ip_addresses_to_strv (int family, const gchar *target_property, GBindingFlags flags); +void nm_editor_bind_ip_gateway_to_string (int family, + NMSettingIPConfig *source, + gpointer target, + const gchar *target_property, + const gchar *target_sensitive_property, + GBindingFlags flags); + void nm_editor_bind_ip_route_to_strings (int family, gpointer source, const gchar *source_property, diff --git a/clients/tui/nmt-page-ip4.c b/clients/tui/nmt-page-ip4.c index b365cc41a2..2595f425d6 100644 --- a/clients/tui/nmt-page-ip4.c +++ b/clients/tui/nmt-page-ip4.c @@ -145,9 +145,10 @@ nmt_page_ip4_constructed (GObject *object) nmt_page_grid_append (grid, _("Addresses"), widget, NULL); widget = nmt_ip_entry_new (25, AF_INET, FALSE, TRUE); - g_object_bind_property (s_ip4, NM_SETTING_IP_CONFIG_GATEWAY, - widget, "text", - G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE); + nm_editor_bind_ip_gateway_to_string (AF_INET, + s_ip4, + widget, "text", "sensitive", + G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE); nmt_page_grid_append (grid, _("Gateway"), widget, NULL); widget = nmt_address_list_new (NMT_ADDRESS_LIST_IP4); diff --git a/clients/tui/nmt-page-ip6.c b/clients/tui/nmt-page-ip6.c index 1003c1a8aa..2f9463c410 100644 --- a/clients/tui/nmt-page-ip6.c +++ b/clients/tui/nmt-page-ip6.c @@ -145,9 +145,10 @@ nmt_page_ip6_constructed (GObject *object) nmt_page_grid_append (grid, _("Addresses"), widget, NULL); widget = nmt_ip_entry_new (25, AF_INET6, FALSE, TRUE); - g_object_bind_property (s_ip6, NM_SETTING_IP_CONFIG_GATEWAY, - widget, "text", - G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE); + nm_editor_bind_ip_gateway_to_string (AF_INET6, + s_ip6, + widget, "text", "sensitive", + G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE); nmt_page_grid_append (grid, _("Gateway"), widget, NULL); widget = nmt_address_list_new (NMT_ADDRESS_LIST_IP6); |