mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2026-04-23 11:00:38 +02:00
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
This commit is contained in:
parent
dd9bb5f376
commit
29ed625fea
4 changed files with 122 additions and 6 deletions
|
|
@ -272,6 +272,113 @@ nm_editor_bind_ip_addresses_to_strv (int family,
|
|||
GINT_TO_POINTER (family), NULL);
|
||||
}
|
||||
|
||||
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,
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue