From 7f5f2eefca05c36dfced3318a449de1cab93d40c Mon Sep 17 00:00:00 2001 From: Beniamino Galvani Date: Thu, 21 Jul 2022 10:48:44 +0200 Subject: [PATCH] nmtui: add NOT_EMPTY flag to NmtPasswordFields Add a new flag to return a NULL string when the password is empty. This is needed when creating the binding to some properties that don't accept an empty value. --- src/nmtui/nmt-password-fields.c | 8 +++++++- src/nmtui/nmt-password-fields.h | 1 + 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/nmtui/nmt-password-fields.c b/src/nmtui/nmt-password-fields.c index 1d03e4014b..de3ab6509d 100644 --- a/src/nmtui/nmt-password-fields.c +++ b/src/nmtui/nmt-password-fields.c @@ -47,6 +47,7 @@ enum { * NmtPasswordFieldsExtras: * @NMT_PASSWORD_FIELDS_ALWAYS_ASK: show an "Always ask" checkbox * @NMT_PASSWORD_FIELDS_SHOW_PASSWORD: show a "Show password" checkbox + * @NMT_PASSWORD_FIELDS_NOT_EMPTY: return NULL instead of empty string * * Extra widgets to include in an #NmtPasswordFields */ @@ -82,8 +83,13 @@ static const char * nmt_password_fields_get_password(NmtPasswordFields *fields) { NmtPasswordFieldsPrivate *priv = NMT_PASSWORD_FIELDS_GET_PRIVATE(fields); + const char *text; - return nmt_newt_entry_get_text(priv->entry); + text = nmt_newt_entry_get_text(priv->entry); + if (priv->extras & NMT_PASSWORD_FIELDS_NOT_EMPTY) + return nm_str_not_empty(text); + + return text; } static void diff --git a/src/nmtui/nmt-password-fields.h b/src/nmtui/nmt-password-fields.h index 3e3d8145bd..0fda7fc9d8 100644 --- a/src/nmtui/nmt-password-fields.h +++ b/src/nmtui/nmt-password-fields.h @@ -34,6 +34,7 @@ GType nmt_password_fields_get_type(void); typedef enum { NMT_PASSWORD_FIELDS_ALWAYS_ASK = (1 << 0), NMT_PASSWORD_FIELDS_SHOW_PASSWORD = (1 << 1), + NMT_PASSWORD_FIELDS_NOT_EMPTY = (1 << 2), /* Return NULL instead of empty string */ } NmtPasswordFieldsExtras; NmtNewtWidget *nmt_password_fields_new(int width, NmtPasswordFieldsExtras extras);