QtPass 2.0.0
Developer documentation
Loading...
Searching...
No Matches
otpcodewidget.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: 2026 Anne Jan Brouwer
2// SPDX-License-Identifier: GPL-3.0-or-later
8#ifndef SRC_OTPCODEWIDGET_H_
9#define SRC_OTPCODEWIDGET_H_
10
11#include "totp.h"
12
13#include <QWidget>
14
15class QLabel;
16class QProgressBar;
18
34class OtpCodeWidget : public QWidget {
35 Q_OBJECT
36
37public:
46 OtpCodeWidget(Totp::Settings settings, bool withCopyButton, bool monospace,
47 QWidget *parent = nullptr);
48
56 void refresh(quint64 unixTime);
57
62 [[nodiscard]] auto code() const -> QString;
63
68 [[nodiscard]] auto secondsRemaining() const -> uint;
69
70signals:
75 void copyRequested(const QString &text);
76
77private:
84 QLabel *m_codeLabel{nullptr};
86 QProgressBar *m_progress{nullptr};
88 QString m_code;
91 quint64 m_counter{0};
96 bool m_hasCode{false};
97};
98
99#endif // SRC_OTPCODEWIDGET_H_
QString m_code
The code last rendered, ungrouped.
quint64 m_counter
Time-step counter m_code was generated for; a tick only regenerates when the counter changes.
QPushButtonWithClipboard * m_copyButton
Copy button, or nullptr when built without one; child widget whose text is kept equal to m_code.
void refresh(quint64 unixTime)
Recompute the code and countdown for an explicit point in time.
QProgressBar * m_progress
Countdown bar from step down to 1 second; child widget.
OtpCodeWidget(Totp::Settings settings, bool withCopyButton, bool monospace, QWidget *parent=nullptr)
Build a live OTP code display and start its refresh timer.
QLabel * m_codeLabel
Shows the current code; child widget.
uint m_secondsRemaining
Seconds left on m_code as of the last refresh().
void copyRequested(const QString &text)
Emitted when the copy button is activated.
auto code() const -> QString
The current code, ungrouped, exactly as it is copied.
bool m_hasCode
False until the first refresh(), which must generate a code regardless of m_counter.
auto secondsRemaining() const -> uint
Seconds left on the current code, as last rendered.
Totp::Settings m_settings
Validated TOTP parameters for the entry; fixed at construction.
QPushButton that stores a text payload and emits it when activated.
Validated TOTP parameters. Only Totp::parse() produces one.
Definition totp.h:59
RFC 6238 TOTP: otpauth URI parsing, code generation and canonical re-serialisation.