summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Winship <danw@gnome.org>2014-03-17 15:39:08 -0400
committerDan Winship <danw@gnome.org>2014-03-21 13:32:50 -0400
commitf6e2b6528fc3109463e9f288236ddb644fcb094d (patch)
tree9ba3e2c277c131f7c9967d19572b058a1a5b469b
parent941ce3523893e8083da650a5b1e59c78097d3718 (diff)
downloadNetworkManager-f6e2b6528fc3109463e9f288236ddb644fcb094d.tar.gz
tui: fix binding of some int/uint properties (rh #1078281)
GLib registers number->string value transforms (meaning that number-valued properties like NMSettingVlan:id or NMSettingWired:mtu get loaded into their NmtNewtEntries correctly), but not the corresponding string->number transforms (meaning changes made in the entries don't get propagated back to the settings, and due to http://bugzilla.gnome.org/show_bug.cgi?id=726574, there's no warning about this). Fix this by registering our own transforms.
-rw-r--r--tui/nm-editor-bindings.c36
-rw-r--r--tui/nm-editor-bindings.h2
-rw-r--r--tui/nmtui.c3
3 files changed, 41 insertions, 0 deletions
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 <nm-utils.h>
#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."));