summaryrefslogtreecommitdiff
path: root/clients/tui/nm-editor-bindings.c
diff options
context:
space:
mode:
authorDan Winship <danw@gnome.org>2014-11-12 09:02:32 -0500
committerDan Winship <danw@gnome.org>2014-11-12 16:04:59 -0500
commit29ed625feac222b3632d8f1835d21afc69c0fad8 (patch)
tree3fa1433255953c24e0bc62267fe10f1d7bcf7e74 /clients/tui/nm-editor-bindings.c
parentdd9bb5f376e1367a54b307c26bf4d888976c2d20 (diff)
downloadNetworkManager-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
Diffstat (limited to 'clients/tui/nm-editor-bindings.c')
-rw-r--r--clients/tui/nm-editor-bindings.c107
1 files changed, 107 insertions, 0 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,