- Fix multiple activations of updateTotp by different QTimer instance timeouts.
- Fix call to updateTotp with invalid, uninitialized state
- Fix tooltip description
This commit is contained in:
Adolfo E. García 2017-11-11 16:25:20 -06:00
parent 35136090cb
commit 3427a1aff4
3 changed files with 25 additions and 21 deletions

View File

@ -20,6 +20,7 @@
#include "ui_DetailsWidget.h" #include "ui_DetailsWidget.h"
#include <QDebug> #include <QDebug>
#include <QTimer>
#include "core/Config.h" #include "core/Config.h"
#include "core/FilePath.h" #include "core/FilePath.h"
@ -33,6 +34,7 @@ DetailsWidget::DetailsWidget(QWidget* parent)
, m_locked(false) , m_locked(false)
, m_currentEntry(nullptr) , m_currentEntry(nullptr)
, m_currentGroup(nullptr) , m_currentGroup(nullptr)
, m_timer(nullptr)
, m_attributesWidget(nullptr) , m_attributesWidget(nullptr)
, m_autotypeWidget(nullptr) , m_autotypeWidget(nullptr)
, m_selectedTabEntry(0) , m_selectedTabEntry(0)
@ -108,7 +110,8 @@ void DetailsWidget::getSelectedEntry(Entry* selectedEntry)
m_ui->usernameLabel->setText(m_currentEntry->resolveMultiplePlaceholders(m_currentEntry->username())); m_ui->usernameLabel->setText(m_currentEntry->resolveMultiplePlaceholders(m_currentEntry->username()));
if (!config()->get("security/hidepassworddetails").toBool()) { if (!config()->get("security/hidepassworddetails").toBool()) {
m_ui->passwordLabel->setText(shortPassword(m_currentEntry->resolveMultiplePlaceholders(m_currentEntry->password()))); m_ui->passwordLabel->setText(
shortPassword(m_currentEntry->resolveMultiplePlaceholders(m_currentEntry->password())));
m_ui->passwordLabel->setToolTip(m_currentEntry->resolveMultiplePlaceholders(m_currentEntry->password())); m_ui->passwordLabel->setToolTip(m_currentEntry->resolveMultiplePlaceholders(m_currentEntry->password()));
} else { } else {
m_ui->passwordLabel->setText("****"); m_ui->passwordLabel->setText("****");
@ -136,14 +139,16 @@ void DetailsWidget::getSelectedEntry(Entry* selectedEntry)
} }
if (m_currentEntry->hasTotp()) { if (m_currentEntry->hasTotp()) {
m_ui->totpButton->show();
updateTotp();
m_step = m_currentEntry->totpStep(); m_step = m_currentEntry->totpStep();
if (nullptr != m_timer) {
m_timer->stop();
}
m_timer = new QTimer(this); m_timer = new QTimer(this);
connect(m_timer, SIGNAL(timeout()), this, SLOT(updateTotp())); connect(m_timer, SIGNAL(timeout()), this, SLOT(updateTotp()));
updateTotp();
m_timer->start(m_step * 10); m_timer->start(m_step * 10);
m_ui->totpButton->show();
} }
QString notes = m_currentEntry->notes(); QString notes = m_currentEntry->notes();
@ -212,7 +217,6 @@ void DetailsWidget::getSelectedGroup(Group* selectedGroup)
m_ui->tabWidget->setTabEnabled(GroupNotesTab, false); m_ui->tabWidget->setTabEnabled(GroupNotesTab, false);
m_ui->totpButton->hide(); m_ui->totpButton->hide();
m_ui->totpWidget->hide(); m_ui->totpWidget->hide();
@ -263,14 +267,14 @@ void DetailsWidget::getSelectedGroup(Group* selectedGroup)
void DetailsWidget::updateTotp() void DetailsWidget::updateTotp()
{ {
if (m_locked) { if (!m_locked) {
m_timer->stop();
return;
}
QString totpCode = m_currentEntry->totp(); QString totpCode = m_currentEntry->totp();
QString firstHalf = totpCode.left(totpCode.size() / 2); QString firstHalf = totpCode.left(totpCode.size() / 2);
QString secondHalf = totpCode.right(totpCode.size() / 2); QString secondHalf = totpCode.right(totpCode.size() / 2);
m_ui->totpLabel->setText(firstHalf + " " + secondHalf); m_ui->totpLabel->setText(firstHalf + " " + secondHalf);
} else if (nullptr != m_timer) {
m_timer->stop();
}
} }
void DetailsWidget::showTotp(bool visible) void DetailsWidget::showTotp(bool visible)
@ -326,7 +330,8 @@ void DetailsWidget::setDatabaseMode(DatabaseWidget::Mode mode)
} }
} }
void DetailsWidget::updateTabIndex(int index) { void DetailsWidget::updateTabIndex(int index)
{
if (m_ui->stackedWidget->currentIndex() == GroupPreview) { if (m_ui->stackedWidget->currentIndex() == GroupPreview) {
m_selectedTabGroup = index; m_selectedTabGroup = index;
} else { } else {

View File

@ -18,9 +18,8 @@
#ifndef KEEPASSX_DETAILSWIDGET_H #ifndef KEEPASSX_DETAILSWIDGET_H
#define KEEPASSX_DETAILSWIDGET_H #define KEEPASSX_DETAILSWIDGET_H
#include <QWidget>
#include "gui/DatabaseWidget.h" #include "gui/DatabaseWidget.h"
#include <QWidget>
namespace Ui { namespace Ui {
class DetailsWidget; class DetailsWidget;

View File

@ -105,7 +105,7 @@
<item> <item>
<widget class="QToolButton" name="closeButton"> <widget class="QToolButton" name="closeButton">
<property name="toolTip"> <property name="toolTip">
<string>Generate TOTP Token</string> <string>Close</string>
</property> </property>
<property name="text"> <property name="text">
<string/> <string/>