mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2026-06-10 18:28:27 +02:00
nmtui: add show pw toggle to secret request dialog
The connection editor pages already offer a "Show password" checkbox via NmtPasswordFields, but the dialog shown when activating a connection that needs secrets masked every entry with no way to reveal it. Users typing a long Wi-Fi password at connect time could not verify their input. Add a "Show password" checkbox below the secret entries that toggles the mask on every entry rendered as a password.
This commit is contained in:
parent
cb71852c20
commit
c660502db8
1 changed files with 25 additions and 8 deletions
|
|
@ -109,12 +109,13 @@ maybe_save_input_and_exit(NmtNewtWidget *widget, gpointer dialog)
|
|||
static void
|
||||
nmt_password_dialog_constructed(GObject *object)
|
||||
{
|
||||
NmtPasswordDialog *dialog = NMT_PASSWORD_DIALOG(object);
|
||||
NmtPasswordDialogPrivate *priv = NMT_PASSWORD_DIALOG_GET_PRIVATE(dialog);
|
||||
NmtNewtWidget *widget;
|
||||
NmtNewtGrid *grid, *secret_grid;
|
||||
NmtNewtButtonBox *bbox;
|
||||
int i;
|
||||
NmtPasswordDialog *dialog = NMT_PASSWORD_DIALOG(object);
|
||||
NmtPasswordDialogPrivate *priv = NMT_PASSWORD_DIALOG_GET_PRIVATE(dialog);
|
||||
NmtNewtWidget *widget;
|
||||
NmtNewtGrid *grid, *secret_grid;
|
||||
NmtNewtButtonBox *bbox;
|
||||
gs_unref_ptrarray GPtrArray *masked_entries = g_ptr_array_new();
|
||||
int i;
|
||||
|
||||
widget = nmt_newt_grid_new();
|
||||
nmt_newt_form_set_content(NMT_NEWT_FORM(dialog), widget);
|
||||
|
|
@ -133,19 +134,23 @@ nmt_password_dialog_constructed(GObject *object)
|
|||
for (i = 0; i < priv->secrets->len; i++) {
|
||||
NMSecretAgentSimpleSecret *secret = priv->secrets->pdata[i];
|
||||
NmtNewtEntryFlags flags;
|
||||
gboolean masked;
|
||||
|
||||
widget = nmt_newt_label_new(secret->pretty_name);
|
||||
nmt_newt_grid_add(secret_grid, widget, 0, i);
|
||||
nmt_newt_widget_set_padding(widget, 4, 0, 1, 0);
|
||||
|
||||
flags = NMT_NEWT_ENTRY_NONEMPTY;
|
||||
if (secret->is_secret && !secret->force_echo)
|
||||
flags = NMT_NEWT_ENTRY_NONEMPTY;
|
||||
masked = secret->is_secret && !secret->force_echo;
|
||||
if (masked)
|
||||
flags |= NMT_NEWT_ENTRY_PASSWORD;
|
||||
widget = nmt_newt_entry_new(30, flags);
|
||||
if (secret->value)
|
||||
nmt_newt_entry_set_text(NMT_NEWT_ENTRY(widget), secret->value);
|
||||
nmt_newt_grid_add(secret_grid, widget, 1, i);
|
||||
g_ptr_array_add(priv->entries, widget);
|
||||
if (masked)
|
||||
g_ptr_array_add(masked_entries, widget);
|
||||
|
||||
if (i == priv->secrets->len - 1) {
|
||||
priv->last_entry = widget;
|
||||
|
|
@ -153,6 +158,18 @@ nmt_password_dialog_constructed(GObject *object)
|
|||
}
|
||||
}
|
||||
|
||||
if (masked_entries->len > 0) {
|
||||
widget = nmt_newt_checkbox_new(_("Show password"));
|
||||
nmt_newt_grid_add(secret_grid, widget, 1, priv->secrets->len);
|
||||
for (i = 0; i < masked_entries->len; i++) {
|
||||
g_object_bind_property(widget,
|
||||
"active",
|
||||
masked_entries->pdata[i],
|
||||
"password",
|
||||
G_BINDING_INVERT_BOOLEAN | G_BINDING_SYNC_CREATE);
|
||||
}
|
||||
}
|
||||
|
||||
widget = nmt_newt_button_box_new(NMT_NEWT_BUTTON_BOX_HORIZONTAL);
|
||||
nmt_newt_grid_add(grid, widget, 0, 2);
|
||||
bbox = NMT_NEWT_BUTTON_BOX(widget);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue