Skip to content

Commit

Permalink
Fix key component widget initialization and password field echo mode …
Browse files Browse the repository at this point in the history
…on database open
  • Loading branch information
phoerious committed Apr 1, 2019
1 parent cb2900f commit f49a8a7
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 11 deletions.
6 changes: 2 additions & 4 deletions src/gui/DatabaseOpenWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -185,9 +185,7 @@ void DatabaseOpenWidget::openDatabase()
return;
}

if (!m_ui->editPassword->isPasswordVisible()) {
m_ui->editPassword->setShowPassword(false);
}
m_ui->editPassword->setShowPassword(false);
QCoreApplication::processEvents();

m_db.reset(new Database());
Expand Down Expand Up @@ -369,7 +367,7 @@ void DatabaseOpenWidget::pollYubikey()
m_ui->checkChallengeResponse->setChecked(false);
m_ui->comboChallengeResponse->setEnabled(false);
m_ui->comboChallengeResponse->clear();
m_ui->comboChallengeResponse->addItem(tr("-- SELECT --"), -1);
m_ui->comboChallengeResponse->addItem(tr("Select slot..."), -1);
m_ui->yubikeyProgress->setVisible(true);

// YubiKey init is slow, detect asynchronously to not block the UI
Expand Down
20 changes: 14 additions & 6 deletions src/gui/masterkey/KeyComponentWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ KeyComponentWidget::KeyComponentWidget(const QString& name, QWidget* parent)
connect(m_ui->removeButton, SIGNAL(clicked(bool)), SIGNAL(componentRemovalRequested()));
connect(m_ui->cancelButton, SIGNAL(clicked(bool)), SLOT(cancelEdit()));

connect(m_ui->stackedWidget, SIGNAL(currentChanged(int)), SLOT(reset()));
connect(m_ui->stackedWidget, SIGNAL(currentChanged(int)), SLOT(resetComponentEditWidget()));

connect(this, SIGNAL(nameChanged(QString)), SLOT(updateComponentName(QString)));
connect(this, SIGNAL(descriptionChanged(QString)), SLOT(updateComponentDescription(QString)));
Expand All @@ -46,11 +46,13 @@ KeyComponentWidget::KeyComponentWidget(const QString& name, QWidget* parent)
connect(this, SIGNAL(componentRemovalRequested()), SLOT(doRemove()));
connect(this, SIGNAL(componentAddChanged(bool)), SLOT(updateAddStatus(bool)));

blockSignals(true);
bool prev = blockSignals(true);
setComponentName(name);
blockSignals(prev);

prev = m_ui->stackedWidget->blockSignals(true);
m_ui->stackedWidget->setCurrentIndex(Page::AddNew);
updateSize();
blockSignals(false);
m_ui->stackedWidget->blockSignals(prev);
}

KeyComponentWidget::~KeyComponentWidget()
Expand Down Expand Up @@ -164,9 +166,15 @@ void KeyComponentWidget::cancelEdit()
emit editCanceled();
}

void KeyComponentWidget::reset()
void KeyComponentWidget::showEvent(QShowEvent* event)
{
QWidget::showEvent(event);
resetComponentEditWidget();
}

void KeyComponentWidget::resetComponentEditWidget()
{
if (static_cast<Page>(m_ui->stackedWidget->currentIndex()) == Page::Edit) {
if (m_ui->componentWidgetLayout->isEmpty() || static_cast<Page>(m_ui->stackedWidget->currentIndex()) == Page::Edit) {
if (!m_ui->componentWidgetLayout->isEmpty()) {
auto* item = m_ui->componentWidgetLayout->takeAt(0);
if (item->widget()) {
Expand Down
5 changes: 4 additions & 1 deletion src/gui/masterkey/KeyComponentWidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,9 @@ class KeyComponentWidget : public QWidget
void editCanceled();
void componentRemovalRequested();

protected:
void showEvent(QShowEvent* event) override ;

private slots:
void updateComponentName(const QString& name);
void updateComponentDescription(const QString& decription);
Expand All @@ -117,7 +120,7 @@ private slots:
void doEdit();
void doRemove();
void cancelEdit();
void reset();
void resetComponentEditWidget();
void updateSize();

private:
Expand Down
3 changes: 3 additions & 0 deletions src/gui/masterkey/PasswordEditWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,11 @@ void PasswordEditWidget::initComponentEditWidget(QWidget* widget)

void PasswordEditWidget::hideEvent(QHideEvent* event)
{
Q_ASSERT(m_compUi->enterPasswordEdit);

if (!isVisible() && m_compUi->enterPasswordEdit) {
m_compUi->enterPasswordEdit->setText("");
m_compUi->repeatPasswordEdit->setText("");
}

QWidget::hideEvent(event);
Expand Down

0 comments on commit f49a8a7

Please sign in to comment.