Commit f6e2b652 authored by Dan Winship's avatar Dan Winship
Browse files

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.
parent 941ce352
......@@ -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,
......
......@@ -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,
......
......@@ -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."));
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment