|
QtPass 2.0.0
Developer documentation
|
A QLineEdit for a password that can be shown: whatever is copied out of it is marked as a secret and reported for autoclear. More...
#include <secretlineedit.h>
Signals | |
| void | copied (const QString &text) |
| Selected text was copied out of the line edit. | |
Public Member Functions | |
| SecretLineEdit (QWidget *parent=nullptr) | |
| Constructs the line edit. | |
| SecretLineEdit (const QString &text, QWidget *parent=nullptr) | |
Constructs the line edit showing text. | |
| auto | createSecretContextMenu () -> QMenu * |
| The standard context menu, with Copy and Cut going through the secret copy. | |
| void | setStoredText (const QString &text) |
| Shows a value read from the entry exactly as it is stored. | |
Static Public Member Functions | |
| static auto | isLineBreak (QChar ch) -> bool |
Whether ch breaks a line: LF, CR, NEL (U+0085), or the Unicode line and paragraph separators (U+2028, U+2029). | |
| static auto | withoutLineBreaks (QString text) -> QString |
text with every line break (see isLineBreak()) removed: what a one-line field keeps of a paste. | |
Static Public Attributes | |
| static constexpr int | kMaxLength = 1 << 20 |
| Most characters the line edit holds (1 MiB of them): its maxLength in place of QLineEdit's 32767. | |
Protected Member Functions | |
| void | keyPressEvent (QKeyEvent *event) override |
| Ctrl+C copies with the hints, Ctrl+X as well before it deletes; after any other key the primary selection gets the marked selection, not QLineEdit's plain-text copy. | |
| void | mouseReleaseEvent (QMouseEvent *event) override |
| Fills the primary selection with the marked selection on a left-button release, instead of QLineEdit's plain-text copy. | |
| void | contextMenuEvent (QContextMenuEvent *event) override |
| Shows createSecretContextMenu(). | |
Private Member Functions | |
| void | copySelection (QClipboard::Mode mode) |
| Puts the selection on the clipboard or in the primary selection as secret-marked MIME data and emits copied(). Does nothing in Password echo mode or without a selection, as QLineEdit::copy() itself. | |
| void | cutSelection () |
| Copies the selection through copySelection() and then deletes it. Does nothing when read-only or without a selection, as QLineEdit::cut(). | |
| void | withoutPlainSelectionCopy (const std::function< void()> &handler) |
| Runs a base-class event handler so that it cannot fill the primary selection with plain text: in a read-only field in Normal echo mode the handler runs under Password mode, which makes QLineEdit skip the copy without moving cursor or selection. Editable fields run the handler as is and rely on publishSelection() replacing the plain copy at once. | |
| void | publishSelection () |
| Fills the X11 primary selection with the marked selection, on platforms that have one; called after a handled key or a left-button release, where QLineEdit would have copied plain text. | |
| void | pasteOneLine (QClipboard::Mode mode) |
| Pastes the clipboard or the primary selection with its line breaks removed, as one undoable edit. Does nothing when read-only. | |
| void | markUndoBoundary () |
| Ends the current undo step, so that the next edit starts its own, as QLineEdit::paste() does around a paste. Moves the cursor away and back, which is the public way to reach QLineEdit's private separate(). | |
A QLineEdit for a password that can be shown: whatever is copied out of it is marked as a secret and reported for autoclear.
QLineEdit copies nothing in Password echo mode, but once a "show" button switches it to Normal it copies plain text, without the hints, on four paths: Ctrl+C, the context menu's Copy, and the X11 primary selection after a mouse selection or a key. Unlike QTextEdit it has no createMimeDataFromSelection() to hook. Here Ctrl+C and Copy put buildClipboardMimeData() on the clipboard instead, and the key and mouse handlers keep QLineEdit from filling the primary selection at all (it runs them in Password echo mode) and fill it with the marked data instead, so plain text never gets there, not even for a moment. Each copy emits copied() so the text is cleared with the rest when the autoclear timer runs. Dragging is off, as QLineEdit has it by default.
In an editable field (the password editor) Ctrl+X, Cut, and the keys that delete to the end of the line or the whole line copy the same way before they delete. Password mode would turn off undo, make Ctrl+arrow jump to the ends and change the input method hints there, so the base handlers run as they are and the marked selection replaces QLineEdit's plain one at once, in the same event: X11 and Wayland hand selection data over only when another program asks for it, which reaches QtPass through its event loop, after the replacement.
Definition at line 44 of file secretlineedit.h.
|
explicit |
Constructs the line edit.
| parent | Owner. |
Definition at line 75 of file secretlineedit.cpp.
|
explicit |
Constructs the line edit showing text.
Not the same as setText() afterwards: QLineEdit takes the constructor's text as already finished, so losing focus without a change does not emit editingFinished().
| text | The initial text. |
| parent | Owner. |
Definition at line 82 of file secretlineedit.cpp.
|
overrideprotected |
Shows createSecretContextMenu().
| event | The context menu event. |
Definition at line 167 of file secretlineedit.cpp.
|
signal |
Selected text was copied out of the line edit.
| text | The text, as put on the clipboard or in the selection. |
|
private |
Puts the selection on the clipboard or in the primary selection as secret-marked MIME data and emits copied(). Does nothing in Password echo mode or without a selection, as QLineEdit::copy() itself.
| mode | Clipboard for Ctrl+C and Copy, Selection for the X11 primary selection. |
Definition at line 173 of file secretlineedit.cpp.
|
nodiscard |
The standard context menu, with Copy and Cut going through the secret copy.
Definition at line 88 of file secretlineedit.cpp.
|
private |
Copies the selection through copySelection() and then deletes it. Does nothing when read-only or without a selection, as QLineEdit::cut().
Definition at line 183 of file secretlineedit.cpp.
|
staticnodiscard |
Whether ch breaks a line: LF, CR, NEL (U+0085), or the Unicode line and paragraph separators (U+2028, U+2029).
| ch | The character. |
Definition at line 55 of file secretlineedit.cpp.
|
overrideprotected |
Ctrl+C copies with the hints, Ctrl+X as well before it deletes; after any other key the primary selection gets the marked selection, not QLineEdit's plain-text copy.
| event | The key event. |
Definition at line 109 of file secretlineedit.cpp.
|
private |
Ends the current undo step, so that the next edit starts its own, as QLineEdit::paste() does around a paste. Moves the cursor away and back, which is the public way to reach QLineEdit's private separate().
Definition at line 234 of file secretlineedit.cpp.
|
overrideprotected |
Fills the primary selection with the marked selection on a left-button release, instead of QLineEdit's plain-text copy.
| event | The mouse event. |
Definition at line 151 of file secretlineedit.cpp.
|
private |
Pastes the clipboard or the primary selection with its line breaks removed, as one undoable edit. Does nothing when read-only.
The validator would remove them too, but a correction it makes resets QLineEdit's undo history; removing them before the insert keeps Undo for Ctrl+V, Paste and a middle click. Drops and input methods still go through the validator alone.
| mode | Clipboard for Ctrl+V and Paste, Selection for a middle click. |
Definition at line 217 of file secretlineedit.cpp.
|
private |
Fills the X11 primary selection with the marked selection, on platforms that have one; called after a handled key or a left-button release, where QLineEdit would have copied plain text.
Definition at line 211 of file secretlineedit.cpp.
| void SecretLineEdit::setStoredText | ( | const QString & | text | ) |
Shows a value read from the entry exactly as it is stored.
setText() runs the line-break filter too (QLineEdit validates every change), which would alter a stored value with a NEL or a Unicode separator inside before the user touched it, and an unedited save would write the altered value back. The filter is for typed and pasted input, so it is set aside for this one setText().
| text | The stored value. |
Definition at line 66 of file secretlineedit.cpp.
|
staticnodiscard |
text with every line break (see isLineBreak()) removed: what a one-line field keeps of a paste.
| text | The text. |
Definition at line 61 of file secretlineedit.cpp.
|
private |
Runs a base-class event handler so that it cannot fill the primary selection with plain text: in a read-only field in Normal echo mode the handler runs under Password mode, which makes QLineEdit skip the copy without moving cursor or selection. Editable fields run the handler as is and rely on publishSelection() replacing the plain copy at once.
| handler | The base handler call, e.g. QLineEdit::keyPressEvent. |
Definition at line 192 of file secretlineedit.cpp.
|
staticconstexpr |
Most characters the line edit holds (1 MiB of them): its maxLength in place of QLineEdit's 32767.
32767 cut a key file kept as one line of base64, and the password dialog saved the cut value. Without a bound, a line of tens of megabytes (an entry may decrypt to Pass::kMaxPlaintextBytes) costs gigabytes and seconds: measured offscreen, about 75 bytes per character, and about 80 ms on every paint per 1,048,576 characters. The password dialog does not load an entry with a longer line, so nothing is cut there.
Definition at line 60 of file secretlineedit.h.