diff --git a/tui/nm-editor-bindings.c b/tui/nm-editor-bindings.c index 8dbe578402..44c9ec9f7a 100644 --- a/tui/nm-editor-bindings.c +++ b/tui/nm-editor-bindings.c @@ -37,6 +37,42 @@ #include "nm-editor-bindings.h" #include "nm-gvaluearray-compat.h" +static void +value_transform_string_int (const GValue *src_value, + GValue *dest_value) +{ + long val; + char *end; + + val = strtol (g_value_get_string (src_value), &end, 10); + if (val < G_MININT || val > G_MAXINT || *end) + return; + + g_value_set_int (dest_value, (int) val); +} + +static void +value_transform_string_uint (const GValue *src_value, + GValue *dest_value) +{ + long val; + char *end; + + val = strtol (g_value_get_string (src_value), &end, 10); + if (val < 0 || val > G_MAXUINT || *end) + return; + + g_value_set_uint (dest_value, (gint) val); +} + +void +nm_editor_bindings_init (void) +{ + /* glib registers number -> string, but not string -> number */ + g_value_register_transform_func (G_TYPE_STRING, G_TYPE_INT, value_transform_string_int); + g_value_register_transform_func (G_TYPE_STRING, G_TYPE_UINT, value_transform_string_uint); +} + static gboolean ip_string_parse (const char *text, int family, diff --git a/tui/nm-editor-bindings.h b/tui/nm-editor-bindings.h index 56f1ec23d9..a7a32dd142 100644 --- a/tui/nm-editor-bindings.h +++ b/tui/nm-editor-bindings.h @@ -26,6 +26,8 @@ G_BEGIN_DECLS +void nm_editor_bindings_init (void); + void nm_editor_bind_ip4_addresses_with_prefix_to_strv (gpointer source, const gchar *source_property, gpointer target, diff --git a/tui/nmtui.c b/tui/nmtui.c index 2c1a75df30..7861dcb968 100644 --- a/tui/nmtui.c +++ b/tui/nmtui.c @@ -39,6 +39,7 @@ #include #include "nmt-newt.h" +#include "nm-editor-bindings.h" #include "nmtui.h" #include "nmtui-edit.h" @@ -242,6 +243,8 @@ main (int argc, char **argv) } g_option_context_free (opts); + nm_editor_bindings_init (); + nm_client = nm_client_new (); if (!nm_client_get_manager_running (nm_client)) { g_printerr ("%s\n", _("NetworkManager is not running."));