summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Winship <danw@gnome.org>2014-01-21 11:45:46 -0500
committerDan Winship <danw@gnome.org>2014-04-09 10:58:14 -0400
commit6aa43b50d0c0cc9f2f775a2b6716383ea7cf1e00 (patch)
treec33e0fbfe8500c7e92600a7c52edd572914d03b9
parentc62f115fcf1543f1401d2e784937f656671798e7 (diff)
downloadNetworkManager-danw/wip/tui-help.tar.gz
tui: implement help text in the various entry widgetsdanw/wip/tui-help
-rw-r--r--tui/newt/nmt-newt-entry-numeric.c25
-rw-r--r--tui/newt/nmt-newt-entry.c25
-rw-r--r--tui/newt/nmt-newt-entry.h1
-rw-r--r--tui/nmt-device-entry.c17
-rw-r--r--tui/nmt-ip-entry.c33
-rw-r--r--tui/nmt-mac-entry.c5
-rw-r--r--tui/nmt-mtu-entry.c2
7 files changed, 95 insertions, 13 deletions
diff --git a/tui/newt/nmt-newt-entry-numeric.c b/tui/newt/nmt-newt-entry-numeric.c
index 753c209a3d..dfb3a8da57 100644
--- a/tui/newt/nmt-newt-entry-numeric.c
+++ b/tui/newt/nmt-newt-entry-numeric.c
@@ -30,6 +30,8 @@
#include <stdlib.h>
+#include <glib/gi18n-lib.h>
+
#include "nmt-newt-entry-numeric.h"
G_DEFINE_TYPE (NmtNewtEntryNumeric, nmt_newt_entry_numeric, NMT_TYPE_NEWT_ENTRY)
@@ -113,20 +115,33 @@ newt_entry_numeric_validate (NmtNewtEntry *entry,
static void
nmt_newt_entry_numeric_init (NmtNewtEntryNumeric *entry)
{
- nmt_newt_entry_set_filter (NMT_NEWT_ENTRY (entry), newt_entry_numeric_filter, NULL);
- nmt_newt_entry_set_validator (NMT_NEWT_ENTRY (entry), newt_entry_numeric_validate, NULL);
}
static void
nmt_newt_entry_numeric_constructed (GObject *object)
{
+ NmtNewtEntry *entry = NMT_NEWT_ENTRY (object);
NmtNewtEntryNumericPrivate *priv = NMT_NEWT_ENTRY_NUMERIC_GET_PRIVATE (object);
-
- if (!*nmt_newt_entry_get_text (NMT_NEWT_ENTRY (object))) {
+ char *help_text;
+
+ nmt_newt_entry_set_filter (entry, newt_entry_numeric_filter, NULL);
+
+ if (priv->max == G_MAXINT && (priv->min == 0 || priv->min == G_MININT))
+ help_text = g_strdup (_("Value must be a number"));
+ else if (priv->max != G_MAXINT && (priv->min == 0 || priv->min == G_MININT))
+ help_text = g_strdup_printf (_("Value must be a number less than %d"), priv->max);
+ else if (priv->max == G_MAXINT && priv->min != 0 && priv->min != G_MININT)
+ help_text = g_strdup_printf (_("Value must be a number greater than %d"), priv->min);
+ else
+ help_text = g_strdup_printf (_("Value must be a number between %d and %d"), priv->min, priv->max);
+ nmt_newt_entry_set_validator (entry, help_text, newt_entry_numeric_validate, NULL);
+ g_free (help_text);
+
+ if (!*nmt_newt_entry_get_text (entry)) {
char buf[32];
g_snprintf (buf, sizeof (buf), "%d", priv->min);
- nmt_newt_entry_set_text (NMT_NEWT_ENTRY (object), buf);
+ nmt_newt_entry_set_text (entry, buf);
}
G_OBJECT_CLASS (nmt_newt_entry_numeric_parent_class)->constructed (object);
diff --git a/tui/newt/nmt-newt-entry.c b/tui/newt/nmt-newt-entry.c
index c98fcee8a4..7f87decade 100644
--- a/tui/newt/nmt-newt-entry.c
+++ b/tui/newt/nmt-newt-entry.c
@@ -30,6 +30,8 @@
#include <string.h>
+#include <glib/gi18n-lib.h>
+
#include "nmt-newt-entry.h"
#include "nmt-newt-form.h"
#include "nmt-newt-hacks.h"
@@ -51,6 +53,7 @@ typedef struct {
NmtNewtEntryValidator validator;
gpointer validator_data;
+ char *help_text;
} NmtNewtEntryPrivate;
enum {
@@ -136,17 +139,24 @@ static void
nmt_newt_entry_check_valid (NmtNewtEntry *entry)
{
NmtNewtEntryPrivate *priv = NMT_NEWT_ENTRY_GET_PRIVATE (entry);
+ const char *help_text;
gboolean valid;
if ( (priv->flags & NMT_NEWT_ENTRY_NONEMPTY)
- && *priv->text == '\0')
+ && *priv->text == '\0') {
valid = FALSE;
- else if (priv->validator)
+ help_text = _("A non-empty value is required");
+ } else if (priv->validator) {
valid = !!priv->validator (entry, priv->text, priv->validator_data);
- else
+ help_text = priv->help_text;
+ } else
valid = TRUE;
nmt_newt_widget_set_valid (NMT_NEWT_WIDGET (entry), valid);
+ if (valid)
+ nmt_newt_widget_set_help_text (NMT_NEWT_WIDGET (entry), NULL);
+ else
+ nmt_newt_widget_set_help_text (NMT_NEWT_WIDGET (entry), help_text);
}
/**
@@ -163,20 +173,25 @@ nmt_newt_entry_check_valid (NmtNewtEntry *entry)
/**
* nmt_newt_entry_set_validator:
* @entry: an #NmtNewtEntry
+ * @help_text: the help text to display when @entry is invalid
* @validator: the function to use to validate the entry
* @user_data: data for @validator
*
* Sets a #NmtNewtEntryValidator on @entry, to allow validation of
* the entry contents. If @validator returns %FALSE, then the entry
- * will not be considered #NmtNewtWidget:valid.
+ * will not be considered #NmtNewtWidget:valid, and the entry's
+ * form will display @help_text in the status line.
*/
void
nmt_newt_entry_set_validator (NmtNewtEntry *entry,
+ const char *help_text,
NmtNewtEntryValidator validator,
gpointer user_data)
{
NmtNewtEntryPrivate *priv = NMT_NEWT_ENTRY_GET_PRIVATE (entry);
+ g_free (priv->help_text);
+ priv->help_text = g_strdup (help_text);
priv->validator = validator;
priv->validator_data = user_data;
@@ -310,6 +325,8 @@ nmt_newt_entry_finalize (GObject *object)
NmtNewtEntryPrivate *priv = NMT_NEWT_ENTRY_GET_PRIVATE (object);
g_free (priv->text);
+ g_free (priv->help_text);
+
if (priv->idle_update)
g_source_remove (priv->idle_update);
diff --git a/tui/newt/nmt-newt-entry.h b/tui/newt/nmt-newt-entry.h
index 8df0b13701..436ee6c120 100644
--- a/tui/newt/nmt-newt-entry.h
+++ b/tui/newt/nmt-newt-entry.h
@@ -58,6 +58,7 @@ void nmt_newt_entry_set_filter (NmtNewtEntry *entry,
NmtNewtEntryFilter filter,
gpointer user_data);
void nmt_newt_entry_set_validator (NmtNewtEntry *entry,
+ const char *help_text,
NmtNewtEntryValidator validator,
gpointer user_data);
diff --git a/tui/nmt-device-entry.c b/tui/nmt-device-entry.c
index 7ce6d7d420..f610cd2df1 100644
--- a/tui/nmt-device-entry.c
+++ b/tui/nmt-device-entry.c
@@ -383,7 +383,6 @@ nmt_device_entry_init (NmtDeviceEntry *deventry)
entry = nmt_newt_entry_new (-1, 0);
priv->entry = NMT_NEWT_ENTRY (entry);
- nmt_newt_entry_set_validator (priv->entry, device_entry_validate, deventry);
g_signal_connect (priv->entry, "notify::text",
G_CALLBACK (entry_text_changed), deventry);
@@ -395,10 +394,24 @@ nmt_device_entry_init (NmtDeviceEntry *deventry)
}
static void
+update_help_text (NmtDeviceEntry *deventry)
+{
+ NmtDeviceEntryPrivate *priv = NMT_DEVICE_ENTRY_GET_PRIVATE (deventry);
+ const char *help_text;
+
+ if (priv->hardware_type == G_TYPE_NONE && !priv->device_filter)
+ help_text = _("Value must be a valid interface name");
+ else
+ help_text = _("Value must be a valid interface name or hardware address");
+ nmt_newt_entry_set_validator (priv->entry, help_text, device_entry_validate, deventry);
+}
+
+static void
nmt_device_entry_constructed (GObject *object)
{
NmtDeviceEntryPrivate *priv = NMT_DEVICE_ENTRY_GET_PRIVATE (object);
+ update_help_text (NMT_DEVICE_ENTRY (object));
nmt_page_grid_append (NMT_PAGE_GRID (object), priv->label, NMT_NEWT_WIDGET (priv->entry), NULL);
G_OBJECT_CLASS (nmt_device_entry_parent_class)->constructed (object);
@@ -450,6 +463,7 @@ nmt_device_entry_set_device_filter (NmtDeviceEntry *deventry,
priv->device_filter = filter;
priv->device_filter_data = user_data;
+ update_help_text (deventry);
}
static void
@@ -565,6 +579,7 @@ nmt_device_entry_class_init (NmtDeviceEntryClass *deventry_class)
g_param_spec_gtype ("hardware-type", "", "",
G_TYPE_NONE,
G_PARAM_READWRITE |
+ G_PARAM_CONSTRUCT_ONLY |
G_PARAM_STATIC_STRINGS));
/**
* NmtDeviceEntry:interface-name:
diff --git a/tui/nmt-ip-entry.c b/tui/nmt-ip-entry.c
index 85a29fcce5..b425835562 100644
--- a/tui/nmt-ip-entry.c
+++ b/tui/nmt-ip-entry.c
@@ -163,8 +163,38 @@ ip_entry_validate (NmtNewtEntry *entry,
static void
nmt_ip_entry_init (NmtIPEntry *entry)
{
+}
+
+static void
+nmt_ip_entry_constructed (GObject *object)
+{
+ NmtNewtEntry *entry = NMT_NEWT_ENTRY (object);
+ NmtIPEntryPrivate *priv = NMT_IP_ENTRY_GET_PRIVATE (object);
+ const char *help_text;
+
nmt_newt_entry_set_filter (NMT_NEWT_ENTRY (entry), ip_entry_filter, NULL);
- nmt_newt_entry_set_validator (NMT_NEWT_ENTRY (entry), ip_entry_validate, NULL);
+
+ if (priv->family == AF_INET) {
+ if (priv->prefix) {
+ /* Translators: this describes the format that the entry accepts,
+ and the "/" must remain an ASCII "/" in the translation.
+ */
+ help_text = _("Value must be <IPv4-address>/<prefix>");
+ } else
+ help_text = _("Value must be a valid IPv4 address");
+ } else if (priv->family == AF_INET6) {
+ if (priv->prefix) {
+ /* Translators: this describes the format that the entry accepts,
+ and the "/" must remain an ASCII "/" in the translation.
+ */
+ help_text = _("Value must be <IPv6-address>/<prefix>");
+ } else
+ help_text = _("Value must be a valid IPv6 address");
+ } else
+ help_text = NULL;
+ nmt_newt_entry_set_validator (NMT_NEWT_ENTRY (entry), help_text, ip_entry_validate, NULL);
+
+ G_OBJECT_CLASS (nmt_ip_entry_parent_class)->constructed (object);
}
static void
@@ -223,6 +253,7 @@ nmt_ip_entry_class_init (NmtIPEntryClass *entry_class)
g_type_class_add_private (entry_class, sizeof (NmtIPEntryPrivate));
/* virtual methods */
+ object_class->constructed = nmt_ip_entry_constructed;
object_class->set_property = nmt_ip_entry_set_property;
object_class->get_property = nmt_ip_entry_get_property;
diff --git a/tui/nmt-mac-entry.c b/tui/nmt-mac-entry.c
index d76c097f20..6afb330640 100644
--- a/tui/nmt-mac-entry.c
+++ b/tui/nmt-mac-entry.c
@@ -28,6 +28,7 @@
#include "config.h"
+#include <glib/gi18n-lib.h>
#include <dbus/dbus-glib.h>
#include <nm-utils.h>
@@ -125,7 +126,9 @@ static void
nmt_mac_entry_init (NmtMacEntry *entry)
{
nmt_newt_entry_set_filter (NMT_NEWT_ENTRY (entry), mac_filter, NULL);
- nmt_newt_entry_set_validator (NMT_NEWT_ENTRY (entry), mac_validator, NULL);
+ nmt_newt_entry_set_validator (NMT_NEWT_ENTRY (entry),
+ _("Value must be a valid hardware address"),
+ mac_validator, NULL);
}
static void
diff --git a/tui/nmt-mtu-entry.c b/tui/nmt-mtu-entry.c
index da3746ccbb..2665b4535f 100644
--- a/tui/nmt-mtu-entry.c
+++ b/tui/nmt-mtu-entry.c
@@ -123,7 +123,7 @@ nmt_mtu_entry_init (NmtMtuEntry *entry)
nmt_newt_grid_add (grid, label, 1, 0);
nmt_newt_widget_set_padding (label, 1, 0, 0, 0);
- nmt_newt_entry_set_validator (priv->entry, mtu_validator, entry);
+ nmt_newt_entry_set_validator (priv->entry, NULL, mtu_validator, entry);
g_object_bind_property_full (entry, "mtu", real_entry, "text",
G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE,
mtu_transform_to_text,