mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2026-02-06 23:20:34 +01:00
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.
This commit is contained in:
parent
941ce35238
commit
f6e2b6528f
3 changed files with 41 additions and 0 deletions
|
|
@ -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."));
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue