QtPass 2.0.0
Developer documentation
Loading...
Searching...
No Matches
OtpCodeWidget Class Reference

Live one-time password display: code, copy button and countdown. More...

#include <otpcodewidget.h>

Inheritance diagram for OtpCodeWidget:
Collaboration diagram for OtpCodeWidget:

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.

Detailed Description

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.

Constructor & Destructor Documentation

◆ OtpCodeWidget()

OtpCodeWidget::OtpCodeWidget ( Totp::Settings settings,
bool withCopyButton,
bool monospace,
QWidget * parent = nullptr )

Build a live OTP code display and start its refresh timer.

Parameters
settingsValidated TOTP settings for the selected entry.
withCopyButtonAdd the clipboard button. Pass false when the clipboard type is Enums::CLIPBOARD_NEVER.
monospaceRender the code in a monospace font.
parentParent widget.

Definition at line 32 of file otpcodewidget.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

Member Function Documentation

◆ code()

auto OtpCodeWidget::code ( ) const -> QString
nodiscard

The current code, ungrouped, exactly as it is copied.

Returns
The current OTP code.

Definition at line 98 of file otpcodewidget.cpp.

◆ copyRequested

void OtpCodeWidget::copyRequested ( const QString & text)
signal

Emitted when the copy button is activated.

Parameters
textThe current code.
Here is the caller graph for this function:

◆ refresh()

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.

Parameters
unixTimeSeconds since the Unix epoch (UTC).

Definition at line 82 of file otpcodewidget.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ secondsRemaining()

auto OtpCodeWidget::secondsRemaining ( ) const -> uint
nodiscard

Seconds left on the current code, as last rendered.

Returns
A value in 1..Totp::Settings::step.

Definition at line 100 of file otpcodewidget.cpp.

Member Data Documentation

◆ m_code

QString OtpCodeWidget::m_code
private

The code last rendered, ungrouped.

Definition at line 88 of file otpcodewidget.h.

◆ m_codeLabel

QLabel* OtpCodeWidget::m_codeLabel {nullptr}
private

Shows the current code; child widget.

Definition at line 84 of file otpcodewidget.h.

◆ m_copyButton

QPushButtonWithClipboard* OtpCodeWidget::m_copyButton {nullptr}
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.

◆ m_counter

quint64 OtpCodeWidget::m_counter {0}
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.

◆ m_hasCode

bool OtpCodeWidget::m_hasCode {false}
private

False until the first refresh(), which must generate a code regardless of m_counter.

Definition at line 96 of file otpcodewidget.h.

◆ m_progress

QProgressBar* OtpCodeWidget::m_progress {nullptr}
private

Countdown bar from step down to 1 second; child widget.

Definition at line 86 of file otpcodewidget.h.

◆ m_secondsRemaining

uint OtpCodeWidget::m_secondsRemaining {0}
private

Seconds left on m_code as of the last refresh().

Definition at line 93 of file otpcodewidget.h.

◆ m_settings

Totp::Settings OtpCodeWidget::m_settings
private

Validated TOTP parameters for the entry; fixed at construction.

Definition at line 79 of file otpcodewidget.h.


The documentation for this class was generated from the following files: