|
QtPass 2.0.0
Developer documentation
|
Live one-time password display: code, copy button and countdown. More...
#include <otpcodewidget.h>
Signals | |
| void | copyRequested (const QString &text) |
| Emitted when the copy button is activated. | |
Public Member Functions | |
| OtpCodeWidget (Totp::Settings settings, bool withCopyButton, bool monospace, QWidget *parent=nullptr) | |
| Build a live OTP code display and start its refresh timer. | |
| void | refresh (quint64 unixTime) |
| Recompute the code and countdown for an explicit point in time. | |
| auto | code () const -> QString |
| The current code, ungrouped, exactly as it is copied. | |
| auto | secondsRemaining () const -> uint |
| Seconds left on the current code, as last rendered. | |
Private Attributes | |
| Totp::Settings | m_settings |
| Validated TOTP parameters for the entry; fixed at construction. | |
| QPushButtonWithClipboard * | m_copyButton {nullptr} |
| Copy button, or nullptr when built without one; child widget whose text is kept equal to m_code. | |
| QLabel * | m_codeLabel {nullptr} |
| Shows the current code; child widget. | |
| QProgressBar * | m_progress {nullptr} |
| Countdown bar from step down to 1 second; child widget. | |
| QString | m_code |
| The code last rendered, ungrouped. | |
| quint64 | m_counter {0} |
| Time-step counter m_code was generated for; a tick only regenerates when the counter changes. | |
| uint | m_secondsRemaining {0} |
| Seconds left on m_code as of the last refresh(). | |
| bool | m_hasCode {false} |
| False until the first refresh(), which must generate a code regardless of m_counter. | |
Live one-time password display: code, copy button and countdown.
Rendered by PasswordDisplayPanel as the value side of the "OTP code" row. It is a widget rather than a set of loose children so that its refresh timer is a child of the thing it updates: PasswordDisplayPanel::clear() deletes the row's widgets, which destroys this widget and therefore the timer. A timer owned by the panel instead could fire after its label had been deleted.
The code is recomputed from the wall clock on every tick rather than from an internal counter, so a machine that suspends across a period boundary self-corrects on the first tick after resume.
Definition at line 34 of file otpcodewidget.h.
| OtpCodeWidget::OtpCodeWidget | ( | Totp::Settings | settings, |
| bool | withCopyButton, | ||
| bool | monospace, | ||
| QWidget * | parent = nullptr ) |
Build a live OTP code display and start its refresh timer.
| settings | Validated TOTP settings for the selected entry. |
| withCopyButton | Add the clipboard button. Pass false when the clipboard type is Enums::CLIPBOARD_NEVER. |
| monospace | Render the code in a monospace font. |
| parent | Parent widget. |
Definition at line 32 of file otpcodewidget.cpp.
|
nodiscard |
The current code, ungrouped, exactly as it is copied.
Definition at line 98 of file otpcodewidget.cpp.
|
signal |
Emitted when the copy button is activated.
| text | The current code. |
| void OtpCodeWidget::refresh | ( | quint64 | unixTime | ) |
Recompute the code and countdown for an explicit point in time.
Called once per second by the internal timer; exposed so tests can pin the clock instead of racing it.
| unixTime | Seconds since the Unix epoch (UTC). |
Definition at line 82 of file otpcodewidget.cpp.
|
nodiscard |
Seconds left on the current code, as last rendered.
Definition at line 100 of file otpcodewidget.cpp.
|
private |
The code last rendered, ungrouped.
Definition at line 88 of file otpcodewidget.h.
|
private |
Shows the current code; child widget.
Definition at line 84 of file otpcodewidget.h.
|
private |
Copy button, or nullptr when built without one; child widget whose text is kept equal to m_code.
Definition at line 82 of file otpcodewidget.h.
|
private |
Time-step counter m_code was generated for; a tick only regenerates when the counter changes.
Definition at line 91 of file otpcodewidget.h.
|
private |
False until the first refresh(), which must generate a code regardless of m_counter.
Definition at line 96 of file otpcodewidget.h.
|
private |
Countdown bar from step down to 1 second; child widget.
Definition at line 86 of file otpcodewidget.h.
|
private |
Seconds left on m_code as of the last refresh().
Definition at line 93 of file otpcodewidget.h.
|
private |
Validated TOTP parameters for the entry; fixed at construction.
Definition at line 79 of file otpcodewidget.h.