mirror of
https://github.com/keepassxreboot/keepassxc.git
synced 2025-07-22 22:40:55 -04:00
Complete refactor of TOTP integration
* Eliminate TOTP logic from GUI elements * Consolidate TOTP functionality under the Totp namespace * Eliminate guessing about state and encoders * Increased test cases * Add entry view column for TOTP [#2132] * General code cleanup, reduction of unnecessary steps, separation of concerns * Rename SetupTotpDialog to TotpSetupDialog for consistency
This commit is contained in:
parent
b74fb3e208
commit
1dc9f10c7f
21 changed files with 585 additions and 716 deletions
|
@ -22,21 +22,25 @@
|
|||
#include "core/Config.h"
|
||||
#include "gui/Clipboard.h"
|
||||
|
||||
TotpDialog::TotpDialog(DatabaseWidget* parent, Entry* entry)
|
||||
TotpDialog::TotpDialog(QWidget* parent, Entry* entry)
|
||||
: QDialog(parent)
|
||||
, m_ui(new Ui::TotpDialog())
|
||||
, m_totpUpdateTimer(new QTimer(entry))
|
||||
, m_entry(entry)
|
||||
{
|
||||
if (!m_entry->hasTotp()) {
|
||||
close();
|
||||
return;
|
||||
}
|
||||
|
||||
m_ui->setupUi(this);
|
||||
|
||||
m_step = m_entry->totpStep();
|
||||
uCounter = resetCounter();
|
||||
m_step = m_entry->totpSettings()->step;
|
||||
resetCounter();
|
||||
updateProgressBar();
|
||||
|
||||
connect(m_totpUpdateTimer, SIGNAL(timeout()), this, SLOT(updateProgressBar()));
|
||||
connect(m_totpUpdateTimer, SIGNAL(timeout()), this, SLOT(updateSeconds()));
|
||||
m_totpUpdateTimer->start(m_step * 10);
|
||||
connect(&m_totpUpdateTimer, SIGNAL(timeout()), this, SLOT(updateProgressBar()));
|
||||
connect(&m_totpUpdateTimer, SIGNAL(timeout()), this, SLOT(updateSeconds()));
|
||||
m_totpUpdateTimer.start(m_step * 10);
|
||||
updateTotp();
|
||||
|
||||
setAttribute(Qt::WA_DeleteOnClose);
|
||||
|
@ -47,6 +51,10 @@ TotpDialog::TotpDialog(DatabaseWidget* parent, Entry* entry)
|
|||
connect(m_ui->buttonBox, SIGNAL(accepted()), SLOT(copyToClipboard()));
|
||||
}
|
||||
|
||||
TotpDialog::~TotpDialog()
|
||||
{
|
||||
}
|
||||
|
||||
void TotpDialog::copyToClipboard()
|
||||
{
|
||||
clipboard()->setText(m_entry->totp());
|
||||
|
@ -57,13 +65,13 @@ void TotpDialog::copyToClipboard()
|
|||
|
||||
void TotpDialog::updateProgressBar()
|
||||
{
|
||||
if (uCounter < 100) {
|
||||
m_ui->progressBar->setValue(static_cast<int>(100 - uCounter));
|
||||
if (m_counter < 100) {
|
||||
m_ui->progressBar->setValue(100 - m_counter);
|
||||
m_ui->progressBar->update();
|
||||
uCounter++;
|
||||
++m_counter;
|
||||
} else {
|
||||
updateTotp();
|
||||
uCounter = resetCounter();
|
||||
resetCounter();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -81,16 +89,8 @@ void TotpDialog::updateTotp()
|
|||
m_ui->totpLabel->setText(firstHalf + " " + secondHalf);
|
||||
}
|
||||
|
||||
double TotpDialog::resetCounter()
|
||||
void TotpDialog::resetCounter()
|
||||
{
|
||||
uint epoch = QDateTime::currentDateTime().toTime_t();
|
||||
double counter = qRound(static_cast<double>(epoch % m_step) / m_step * 100);
|
||||
return counter;
|
||||
}
|
||||
|
||||
TotpDialog::~TotpDialog()
|
||||
{
|
||||
if (m_totpUpdateTimer) {
|
||||
delete m_totpUpdateTimer;
|
||||
}
|
||||
m_counter = static_cast<int>(static_cast<double>(epoch % m_step) / m_step * 100);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue