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.
This commit is contained in:
Beniamino Galvani 2022-07-21 10:48:44 +02:00
parent 729d00249e
commit 7f5f2eefca
2 changed files with 8 additions and 1 deletions

View file

@ -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

View file

@ -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);