|
QtPass 2.0.0
Developer documentation
|
Dialog for creating a password entry or editing an existing one. More...
#include <passworddialog.h>
Public Slots | |
| void | cycleTemplate () |
| Cycle to next template (Ctrl+T). | |
| void | setPass (const QString &output, const QString &file=QString()) |
| Populate the dialog from a decrypted entry (Pass::finishedShow). | |
Signals | |
| void | copied (const QString &text) |
| Text was copied out of the password, a field or the body, marked as a secret: for ClipboardManager::trackCopied(), so autoclear clears it. | |
Public Member Functions | |
| PasswordDialog (PasswordConfiguration passConfig, QWidget *parent=nullptr) | |
| Construct a PasswordDialog for entering a new password. | |
| PasswordDialog (Pass *pass, const AppSettings &s, QString file, const bool &isNew, QWidget *parent=nullptr) | |
| Construct a PasswordDialog for editing an existing password file. | |
| ~PasswordDialog () override | |
| Hides the window before QDialog tears it down, so the focus-out emitted on hiding cannot reach slots of a half-destroyed dialog. | |
| void | accept () override |
| OK: for a new entry, resolve and check the name first and stay open when it is not usable; then insert the entry and close as accepted only once the insert has succeeded. | |
| void | reject () override |
| Cancel, Esc and the window's close button. While an insert is in flight they ask first: closing then means a failure can no longer hand back what was typed, but a save that never reports must not leave quitting as the only way out. | |
| void | setNewEntryLocation (const QString &storeRoot, const QStringList &folders, const QString ¤tFolder) |
| Let a new entry be named inside the dialog: a folder picker over the store's folders and a name field, instead of a separate prompt. | |
| auto | entryPath () const -> QString |
| The entry the dialog writes to, relative to the store and without the .gpg suffix (for example work/vpn). | |
| void | setPassword (const QString &password) |
| Populate the dialog's password field with the given text. | |
| auto | getPassword () -> QString |
| Retrieve the current text from the dialog's password field. | |
| void | setTemplate (const QString &rawFields, bool useTemplate) |
| Set the template fields and whether templating is enabled. | |
| void | templateAll (bool templateAll) |
| Whether every key: value line becomes a field of its own. | |
| void | setLength (int length) |
| Set the desired password length shown in the dialog. | |
| void | setPasswordCharTemplate (int templateIndex) |
| Set the password character template index. | |
| void | usePwgen (bool usePwgen) |
| Enable or disable pwgen-style password generation mode. | |
| void | setAvailableTemplates (const QHash< QString, QStringList > &templates, const QString &defaultTemplate) |
| Set available templates from file and select default. | |
Private Slots | |
| void | setPasswordVisible (bool show) |
| Show or mask the password field. | |
| void | on_createPasswordButton_clicked () |
| "Generate" button: asks the backend for a password of the chosen length from the selected character set (Pass::generatePassword, which runs pwgen when that mode is on) and puts it in the password field. An empty result leaves the field alone. | |
| void | on_rejected () |
| Connected to QDialog::rejected: blanks the password and field widgets so the decrypted secret does not linger in a dialog that is being discarded. | |
| void | onInsertFinished () |
| The insert started by accept() succeeded: close as accepted. | |
| void | onInsertFailed (const QString &err, bool written) |
| The insert started by accept() failed: unlock the fields, which still hold what was typed, and show why. | |
| void | onShowError (int exitCode, const QString &err) |
| Handle a process error while waiting for an entry's decrypt. | |
Private Member Functions | |
| void | reportCopies (SecretLineEdit *line) |
| Forwards the line edit's SecretLineEdit::copied to this dialog's copied(), so every copy out of any field reaches ClipboardManager. | |
| auto | otpLineEdit () const -> QLineEdit * |
| Locate the field that holds the one-time password configuration. | |
| void | setEditorEnabled (bool enabled) |
| Enabled or grey out every editable field of the dialog. | |
| void | save () |
| Start inserting what the dialog holds and wait for the result. | |
| void | setSaving (bool saving) |
| Lock or unlock the dialog while an insert is in flight. | |
| auto | isOwnInsertReport () -> bool |
| Whether the insert report now arriving is this dialog's own. | |
| void | showNotSaved (const QString &err) |
| Say why the entry was not saved and let the user try again; the fields keep what was typed. | |
| void | hookOtpField () |
| Connect validation and normalisation to the OTP field, if present. | |
| void | validateOtpField () |
| Flag an OTP value that is neither a URI nor valid base32. | |
| void | markOtpFieldEdited () |
| Remember, on the line edit that sent textEdited(), that the user typed in it: only such a field has a bare secret canonicalised, a loaded value is kept as it was. The mark lives on the widget, not on the dialog, so typing into a field that used to be the OTP one (renamed away) says nothing about the field that is the OTP one now. A member function: Qt::UniqueConnection, which hookOtpField() needs because it runs more than once for the same field, is refused for a lambda (a debug build asserts, a release build makes no connection). | |
| void | normalizeOtpField () |
| Rewrite the OTP field as a canonical otpauth URI. | |
| auto | resolveNewEntry (QString *problem) const -> QString |
| The name the user typed, resolved against the picked folder. | |
| void | validateNewEntry () |
| Re-runs resolveNewEntry() as the user types or picks a folder: shows the problem (if any) in the status label and enables OK only for a usable name. | |
| void | renameField (QLineEdit *line, FieldLabel *label, const QString &to) |
| Give a key: value field a new key (#132). Refused, with the reason in the status label, when another field has that name. Re-runs hookOtpField(), as the field may have become or stopped being the OTP one. | |
| void | removeField (QLineEdit *line) |
| Drop a key: value field and its row from the form. The widgets are deleted once control is back in the event loop: the request comes from the line's own trailing action or its label's context menu, both still on the stack. | |
| void | applyTemplate (const QString &templateName) |
| Switch to a named template: records it, selects it in the combo box and rebuilds the field rows through setTemplate(). Unknown names are ignored, and nothing changes while a save is in flight. | |
| void | setupTemplateBox () |
| Hides the template row until setAvailableTemplates() fills it and wires the combo box so that a user selection calls applyTemplate(). | |
Private Attributes | |
| QScopedPointer< Ui::PasswordDialog > | ui |
| Generated form (passworddialog.ui); owned. | |
| PasswordConfiguration | m_passConfig |
| Generator settings: character sets and default length. | |
| Pass * | m_pass {nullptr} |
| Backend for Show, Insert and generatePassword; not owned. | |
| QStringList | m_fields |
| Field names of the current template, in template order. | |
| QString | m_file |
| Entry path relative to the store, without .gpg; empty for a new entry until accept() resolves the typed name. | |
| QString | m_storeRoot |
| Absolute store root while a new entry is being named; empty otherwise. | |
| QString | m_newEntryFolder |
| bool | m_templating {} |
| Whether template fields get widgets of their own (the "Use template" setting). | |
| bool | m_allFields {} |
| Whether every key: value line becomes a field (the "Template
all fields" setting), as given to FileContent::parse(). | |
| bool | m_isNew {} |
| True when creating an entry, false when editing one; decides whether the name row and the decrypt-before-edit lock apply. | |
| bool | m_contentLoaded {} |
| bool | m_saving {} |
| True from accept() starting an insert until the backend reports back. | |
| int | m_insertsAhead {} |
| bool | m_usePwgen {} |
| QList< QLineEdit * > | m_templateLines |
| QList< QLineEdit * > | m_otherLines |
| QHash< QString, QStringList > | m_availableTemplates |
| QString | m_currentTemplateName |
| Name of the template currently applied; cycleTemplate() steps from it. | |
| QShortcut * | m_templateShortcut {nullptr} |
| Ctrl+T, created once templates are available; owned by the dialog. | |
| QPointer< QAction > | m_otpWarning |
| QPointer< QLineEdit > | m_otpLine |
Dialog for creating a password entry or editing an existing one.
The first line is the password, with a generator beside it; below it are one field per template line when templates are in use, and a free text box for everything else. For an existing entry the dialog asks the backend to Show() it and fills the fields when the content arrives. On OK it puts the entry together again and calls Pass::Insert(), then stays open with its fields locked until the backend reports: it closes on Pass::finishedInsert() and gives the fields back with the reason on Pass::insertFailed(), so a failed save never loses what was typed.
Definition at line 43 of file passworddialog.h.
|
explicit |
Construct a PasswordDialog for entering a new password.
| passConfig | Password generation configuration. |
| parent | Optional parent widget. |
Definition at line 54 of file passworddialog.cpp.
| PasswordDialog::PasswordDialog | ( | Pass * | pass, |
| const AppSettings & | s, | ||
| QString | file, | ||
| const bool & | isNew, | ||
| QWidget * | parent = nullptr ) |
Construct a PasswordDialog for editing an existing password file.
| pass | Backend used to show, insert, and generate passwords. |
| s | Application settings snapshot (password config, template, pwgen). |
| file | Path to the password file being edited. |
| isNew | true if creating a new entry, false if editing existing. |
| parent | Optional parent widget. |
Definition at line 79 of file passworddialog.cpp.
|
override |
Hides the window before QDialog tears it down, so the focus-out emitted on hiding cannot reach slots of a half-destroyed dialog.
Definition at line 124 of file passworddialog.cpp.
|
override |
OK: for a new entry, resolve and check the name first and stay open when it is not usable; then insert the entry and close as accepted only once the insert has succeeded.
The insert is asynchronous. Until it reports back the dialog stays open with its fields locked; when it fails (a missing recipient key, an unusable .gpg-id, a refused path) the fields come back with what was typed and the reason is shown, instead of the entry being lost with the closed dialog.
Definition at line 350 of file passworddialog.cpp.
|
private |
Switch to a named template: records it, selects it in the combo box and rebuilds the field rows through setTemplate(). Unknown names are ignored, and nothing changes while a save is in flight.
| templateName | A key of m_availableTemplates. |
Definition at line 746 of file passworddialog.cpp.
|
signal |
Text was copied out of the password, a field or the body, marked as a secret: for ClipboardManager::trackCopied(), so autoclear clears it.
| text | The text copied. |
|
slot |
Cycle to next template (Ctrl+T).
Definition at line 760 of file passworddialog.cpp.
|
inline |
The entry the dialog writes to, relative to the store and without the .gpg suffix (for example work/vpn).
Definition at line 112 of file passworddialog.h.
| auto PasswordDialog::getPassword | ( | ) | -> QString |
Retrieve the current text from the dialog's password field.
Definition at line 604 of file passworddialog.cpp.
|
private |
Connect validation and normalisation to the OTP field, if present.
Called whenever the field widgets are rebuilt, since both setTemplate() and setPassword() recreate them.
Definition at line 502 of file passworddialog.cpp.
|
private |
Whether the insert report now arriving is this dialog's own.
False when the dialog is not saving. Otherwise it lets the reports of the inserts that were already pending when save() ran pass first (one per call), so an earlier dialog's result does not close or fail this one.
Definition at line 210 of file passworddialog.cpp.
|
private |
Remember, on the line edit that sent textEdited(), that the user typed in it: only such a field has a bare secret canonicalised, a loaded value is kept as it was. The mark lives on the widget, not on the dialog, so typing into a field that used to be the OTP one (renamed away) says nothing about the field that is the OTP one now. A member function: Qt::UniqueConnection, which hookOtpField() needs because it runs more than once for the same field, is refused for a lambda (a debug build asserts, a release build makes no connection).
Definition at line 544 of file passworddialog.cpp.
|
private |
Rewrite the OTP field as a canonical otpauth URI.
A value that cannot be parsed is left exactly as the user typed it, so nothing is silently destroyed.
Definition at line 582 of file passworddialog.cpp.
|
privateslot |
"Generate" button: asks the backend for a password of the chosen length from the selected character set (Pass::generatePassword, which runs pwgen when that mode is on) and puts it in the password field. An empty result leaves the field alone.
Definition at line 139 of file passworddialog.cpp.
|
privateslot |
Connected to QDialog::rejected: blanks the password and field widgets so the decrypted secret does not linger in a dialog that is being discarded.
Definition at line 275 of file passworddialog.cpp.
|
privateslot |
The insert started by accept() failed: unlock the fields, which still hold what was typed, and show why.
| err | The reason reported by the backend. |
| written | true when the entry was written and only a later step (git) failed; a new entry then closes the dialog. |
Definition at line 234 of file passworddialog.cpp.
|
privateslot |
The insert started by accept() succeeded: close as accepted.
Definition at line 226 of file passworddialog.cpp.
|
privateslot |
Handle a process error while waiting for an entry's decrypt.
When the asynchronous Show() fails, keep the dialog open and surface the reason in statusLabel instead of closing silently: Ok stays disabled and the editor keeps its lock so the user can only Cancel/withdraw.
| exitCode | Exit code of the failed process (unused). |
| err | Error output to present to the user. |
Definition at line 810 of file passworddialog.cpp.
|
nodiscardprivate |
Locate the field that holds the one-time password configuration.
Definition at line 481 of file passworddialog.cpp.
|
override |
Cancel, Esc and the window's close button. While an insert is in flight they ask first: closing then means a failure can no longer hand back what was typed, but a save that never reports must not leave quitting as the only way out.
Definition at line 251 of file passworddialog.cpp.
|
private |
Drop a key: value field and its row from the form. The widgets are deleted once control is back in the event loop: the request comes from the line's own trailing action or its label's context menu, both still on the stack.
| line | The field's editor, one of m_otherLines. |
Definition at line 455 of file passworddialog.cpp.
|
private |
Give a key: value field a new key (#132). Refused, with the reason in the status label, when another field has that name. Re-runs hookOtpField(), as the field may have become or stopped being the OTP one.
| line | The field's editor; its object name is the key. |
| label | The field's label, updated to show the new key. |
| to | The new key. |
Definition at line 438 of file passworddialog.cpp.
|
private |
Forwards the line edit's SecretLineEdit::copied to this dialog's copied(), so every copy out of any field reaches ClipboardManager.
| line | A password or field editor just created. |
Definition at line 683 of file passworddialog.cpp.
|
private |
The name the user typed, resolved against the picked folder.
| problem | Receives a translated reason when the name is unusable. |
Definition at line 306 of file passworddialog.cpp.
|
private |
Start inserting what the dialog holds and wait for the result.
Definition at line 158 of file passworddialog.cpp.
| void PasswordDialog::setAvailableTemplates | ( | const QHash< QString, QStringList > & | templates, |
| const QString & | defaultTemplate ) |
Set available templates from file and select default.
| templates | Hash of template name to field list. |
| defaultTemplate | Name of default template. |
Definition at line 719 of file passworddialog.cpp.
|
private |
Enabled or grey out every editable field of the dialog.
Used while an existing entry's decrypted content is being fetched, so an early Ok cannot report success while writing nothing and a late setPass() cannot clobber edits made on the still-empty fields.
| enabled | true to restore the editor, false to lock it. |
Definition at line 822 of file passworddialog.cpp.
| void PasswordDialog::setLength | ( | int | length | ) |
Set the desired password length shown in the dialog.
| length | Desired password length. |
Definition at line 691 of file passworddialog.cpp.
| void PasswordDialog::setNewEntryLocation | ( | const QString & | storeRoot, |
| const QStringList & | folders, | ||
| const QString & | currentFolder ) |
Let a new entry be named inside the dialog: a folder picker over the store's folders and a name field, instead of a separate prompt.
The dialog validates as the user types (empty, escaping the store, already taken) and keeps OK off until the name is good; accept() then creates any subfolder the name needs and inserts the entry at entryPath(). Only meaningful for a dialog constructed with isNew.
| storeRoot | Absolute path of the password store. |
| folders | Folders relative to the store, "" for the root; shown in the picker in this order. |
| currentFolder | The folder to preselect (relative, may be ""). |
Definition at line 277 of file passworddialog.cpp.
|
slot |
Populate the dialog from a decrypted entry (Pass::finishedShow).
Entries with more than FileContent::kMaxDisplayLines lines are not loaded at all; the status label says so and the editor stays locked.
| output | Decrypted content of the entry. |
| file | The entry the output belongs to; output for any other entry than the one being edited is ignored. Empty means unspecified. |
Definition at line 777 of file passworddialog.cpp.
| void PasswordDialog::setPassword | ( | const QString & | password | ) |
Populate the dialog's password field with the given text.
| password | Password text to display. |
Definition at line 374 of file passworddialog.cpp.
| void PasswordDialog::setPasswordCharTemplate | ( | int | templateIndex | ) |
Set the password character template index.
| templateIndex | Index identifying the character template to use. |
Definition at line 695 of file passworddialog.cpp.
|
privateslot |
Show or mask the password field.
Connected explicitly to QCheckBox::toggled in both constructors; the box is two-state, so the deprecated stateChanged(int) is not needed.
| show | true to display the password in clear text. |
Definition at line 131 of file passworddialog.cpp.
|
private |
Lock or unlock the dialog while an insert is in flight.
| saving | true while waiting for the backend. |
Definition at line 197 of file passworddialog.cpp.
| void PasswordDialog::setTemplate | ( | const QString & | rawFields, |
| bool | useTemplate ) |
Set the template fields and whether templating is enabled.
| rawFields | Template text containing field definitions. |
| useTemplate | true to enable the template, false to disable. |
Definition at line 642 of file passworddialog.cpp.
|
private |
Hides the template row until setAvailableTemplates() fills it and wires the combo box so that a user selection calls applyTemplate().
Definition at line 706 of file passworddialog.cpp.
|
private |
Say why the entry was not saved and let the user try again; the fields keep what was typed.
| err | The reason reported by the backend. |
Definition at line 268 of file passworddialog.cpp.
| void PasswordDialog::templateAll | ( | bool | templateAll | ) |
Whether every key: value line becomes a field of its own.
Mirrors the "Template all fields" setting. Off, only the template's fields get widgets and every other line stays in the free-text body, where the user can edit key and value alike.
| templateAll | true to split every tokenisable line into a field. |
Definition at line 687 of file passworddialog.cpp.
| void PasswordDialog::usePwgen | ( | bool | usePwgen | ) |
Enable or disable pwgen-style password generation mode.
| usePwgen | true to enable pwgen mode, false to disable. |
Definition at line 699 of file passworddialog.cpp.
|
private |
Re-runs resolveNewEntry() as the user types or picks a folder: shows the problem (if any) in the status label and enables OK only for a usable name.
Definition at line 343 of file passworddialog.cpp.
|
private |
Flag an OTP value that is neither a URI nor valid base32.
Definition at line 550 of file passworddialog.cpp.
|
private |
Whether every key: value line becomes a field (the "Template all fields" setting), as given to FileContent::parse().
Definition at line 370 of file passworddialog.h.
|
private |
Named templates from .templates, name to field list, as given to setAvailableTemplates(); empty when the store has none.
Definition at line 394 of file passworddialog.h.
|
private |
True once the existing entry's decrypted content has been loaded, so save() can refuse to overwrite it with empty fields before the asynchronous Show completes.
Definition at line 377 of file passworddialog.h.
|
private |
Name of the template currently applied; cycleTemplate() steps from it.
Definition at line 396 of file passworddialog.h.
|
private |
Field names of the current template, in template order.
Definition at line 325 of file passworddialog.h.
|
private |
Entry path relative to the store, without .gpg; empty for a new entry until accept() resolves the typed name.
Definition at line 328 of file passworddialog.h.
|
private |
Inserts already pending when save() ran, whose reports must pass before one is taken as this dialog's own (counted down in isOwnInsertReport()).
Definition at line 382 of file passworddialog.h.
|
private |
True when creating an entry, false when editing one; decides whether the name row and the decrypt-before-edit lock apply.
Definition at line 373 of file passworddialog.h.
|
private |
Folder chosen when the dialog opened; the template default follows the picker, so this is what setAvailableTemplates() was computed for.
Definition at line 333 of file passworddialog.h.
|
private |
Fields that came from the entry rather than the template; their names are the user's, so their labels are FieldLabels that can be renamed.
Definition at line 391 of file passworddialog.h.
|
private |
The line edit hookOtpField() last wired up, so its signals can be disconnected when another field becomes the OTP one (a rename, a removal): a stale editingFinished from the old field must not rewrite the new one.
Definition at line 409 of file passworddialog.h.
|
private |
Warning indicator shown inside the OTP field; owned by that field.
QPointer, not a raw pointer: the QAction is parented to the QLineEdit, and setPassword() deletes the m_otherLines widgets before calling hookOtpField(), so a raw pointer would already dangle there.
Definition at line 404 of file passworddialog.h.
|
private |
Backend for Show, Insert and generatePassword; not owned.
Definition at line 323 of file passworddialog.h.
|
private |
Generator settings: character sets and default length.
Definition at line 321 of file passworddialog.h.
|
private |
True from accept() starting an insert until the backend reports back.
Definition at line 379 of file passworddialog.h.
|
private |
Absolute store root while a new entry is being named; empty otherwise.
Definition at line 330 of file passworddialog.h.
|
private |
Editors for the template's fields, in template order; rebuilt by setTemplate(). Their labels are plain QLabels: the names are fixed.
Definition at line 388 of file passworddialog.h.
|
private |
Ctrl+T, created once templates are available; owned by the dialog.
Definition at line 398 of file passworddialog.h.
|
private |
Whether template fields get widgets of their own (the "Use template" setting).
Definition at line 367 of file passworddialog.h.
|
private |
Last pwgen mode passed to usePwgen(), so the policy can be re-applied after setEditorEnabled() re-enables the character-set widgets.
Definition at line 385 of file passworddialog.h.
|
private |
Generated form (passworddialog.ui); owned.
Definition at line 319 of file passworddialog.h.