diff --git a/share/translations/keepassxc_en.ts b/share/translations/keepassxc_en.ts index 050b50ed5f..6c65c66e74 100644 --- a/share/translations/keepassxc_en.ts +++ b/share/translations/keepassxc_en.ts @@ -1525,14 +1525,6 @@ Backup database located at %2 Browse… - - Refresh hardware tokens - - - - Refresh - - Unlock Database @@ -1627,10 +1619,6 @@ If you do not have a key file, please leave the field empty. Detecting hardware keys… - - No hardware keys detected - - Select hardware key… diff --git a/src/gui/DatabaseOpenWidget.cpp b/src/gui/DatabaseOpenWidget.cpp index 2280f24dbc..4f9d4f8415 100644 --- a/src/gui/DatabaseOpenWidget.cpp +++ b/src/gui/DatabaseOpenWidget.cpp @@ -99,13 +99,13 @@ DatabaseOpenWidget::DatabaseOpenWidget(QWidget* parent) m_ui->keyFileLabelHelp->setIcon(icons()->icon("system-help").pixmap(QSize(12, 12))); connect(m_ui->keyFileLabelHelp, SIGNAL(clicked(bool)), SLOT(openKeyFileHelp())); + toggleHardwareKeyWidgets(false); + #ifdef WITH_XC_YUBIKEY - m_ui->hardwareKeyProgress->setVisible(false); QSizePolicy sp = m_ui->hardwareKeyProgress->sizePolicy(); sp.setRetainSizeWhenHidden(true); m_ui->hardwareKeyProgress->setSizePolicy(sp); - connect(m_ui->buttonRedetectYubikey, SIGNAL(clicked()), SLOT(pollHardwareKey())); connect(YubiKey::instance(), SIGNAL(detectComplete(bool)), SLOT(hardwareKeyResponse(bool)), Qt::QueuedConnection); connect(YubiKey::instance(), &YubiKey::userInteractionRequest, this, [this] { @@ -117,12 +117,6 @@ DatabaseOpenWidget::DatabaseOpenWidget(QWidget* parent) } }); connect(YubiKey::instance(), &YubiKey::challengeCompleted, this, [this] { m_ui->messageWidget->hide(); }); -#else - m_ui->hardwareKeyLabel->setVisible(false); - m_ui->hardwareKeyLabelHelp->setVisible(false); - m_ui->buttonRedetectYubikey->setVisible(false); - m_ui->challengeResponseCombo->setVisible(false); - m_ui->hardwareKeyProgress->setVisible(false); #endif // QuickUnlock actions @@ -133,6 +127,14 @@ DatabaseOpenWidget::DatabaseOpenWidget(QWidget* parent) DatabaseOpenWidget::~DatabaseOpenWidget() = default; +void DatabaseOpenWidget::toggleHardwareKeyWidgets(bool state) +{ + m_ui->hardwareKeyCombo->setVisible(state); + m_ui->hardwareKeyProgress->setVisible(false); + m_ui->hardwareKeyLabel->setVisible(state); + m_ui->hardwareKeyLabelHelp->setVisible(state); +} + void DatabaseOpenWidget::showEvent(QShowEvent* event) { DialogyWidget::showEvent(event); @@ -217,7 +219,7 @@ void DatabaseOpenWidget::clearForms() m_ui->keyFileLineEdit->clear(); m_ui->keyFileLineEdit->setShowPassword(false); m_ui->keyFileLineEdit->setClearButtonEnabled(true); - m_ui->challengeResponseCombo->clear(); + m_ui->hardwareKeyCombo->clear(); m_ui->centralStack->setCurrentIndex(0); QString error; @@ -396,9 +398,9 @@ QSharedPointer DatabaseOpenWidget::buildDatabaseKey() auto lastChallengeResponse = config()->get(Config::LastChallengeResponse).toHash(); lastChallengeResponse.remove(m_filename); - int selectionIndex = m_ui->challengeResponseCombo->currentIndex(); + int selectionIndex = m_ui->hardwareKeyCombo->currentIndex(); if (selectionIndex > 0) { - auto slot = m_ui->challengeResponseCombo->itemData(selectionIndex).value(); + auto slot = m_ui->hardwareKeyCombo->itemData(selectionIndex).value(); auto crKey = QSharedPointer(new ChallengeResponseKey(slot)); databaseKey->addChallengeResponseKey(crKey); @@ -444,11 +446,10 @@ void DatabaseOpenWidget::pollHardwareKey() return; } - m_ui->challengeResponseCombo->clear(); - m_ui->challengeResponseCombo->addItem(tr("Detecting hardware keys…")); + m_ui->hardwareKeyCombo->clear(); + m_ui->hardwareKeyCombo->addItem(tr("Detecting hardware keys…")); + m_ui->hardwareKeyCombo->setEnabled(false); - m_ui->buttonRedetectYubikey->setEnabled(false); - m_ui->challengeResponseCombo->setEnabled(false); m_ui->hardwareKeyProgress->setVisible(true); m_pollingHardwareKey = true; @@ -457,19 +458,15 @@ void DatabaseOpenWidget::pollHardwareKey() void DatabaseOpenWidget::hardwareKeyResponse(bool found) { - m_ui->challengeResponseCombo->clear(); - m_ui->buttonRedetectYubikey->setEnabled(true); m_ui->hardwareKeyProgress->setVisible(false); + m_ui->hardwareKeyCombo->clear(); m_pollingHardwareKey = false; if (!found) { - m_ui->challengeResponseCombo->addItem(tr("No hardware keys detected")); - m_ui->challengeResponseCombo->setEnabled(false); + toggleHardwareKeyWidgets(false); return; - } else { - m_ui->challengeResponseCombo->addItem(tr("Select hardware key…")); } - + m_ui->hardwareKeyCombo->addItem(tr("Select hardware key…")); YubiKeySlot lastUsedSlot; if (config()->get(Config::RememberLastKeyFiles).toBool()) { auto lastChallengeResponse = config()->get(Config::LastChallengeResponse).toHash(); @@ -485,15 +482,16 @@ void DatabaseOpenWidget::hardwareKeyResponse(bool found) int selectedIndex = 0; for (auto& slot : YubiKey::instance()->foundKeys()) { // add detected YubiKey to combo box - m_ui->challengeResponseCombo->addItem(YubiKey::instance()->getDisplayName(slot), QVariant::fromValue(slot)); + m_ui->hardwareKeyCombo->addItem(YubiKey::instance()->getDisplayName(slot), QVariant::fromValue(slot)); // Select this YubiKey + Slot if we used it in the past if (lastUsedSlot == slot) { - selectedIndex = m_ui->challengeResponseCombo->count() - 1; + selectedIndex = m_ui->hardwareKeyCombo->count() - 1; } } - m_ui->challengeResponseCombo->setCurrentIndex(selectedIndex); - m_ui->challengeResponseCombo->setEnabled(true); + toggleHardwareKeyWidgets(true); + m_ui->hardwareKeyCombo->setEnabled(true); + m_ui->hardwareKeyCombo->setCurrentIndex(selectedIndex); } void DatabaseOpenWidget::openHardwareKeyHelp() diff --git a/src/gui/DatabaseOpenWidget.h b/src/gui/DatabaseOpenWidget.h index ad16ede2ac..7eda04060c 100644 --- a/src/gui/DatabaseOpenWidget.h +++ b/src/gui/DatabaseOpenWidget.h @@ -83,6 +83,7 @@ private slots: void openKeyFileHelp(); private: + void toggleHardwareKeyWidgets(bool state); #ifdef WITH_XC_YUBIKEY QPointer m_deviceListener; #endif diff --git a/src/gui/DatabaseOpenWidget.ui b/src/gui/DatabaseOpenWidget.ui index ad4d4af7a9..dae3b1c80d 100644 --- a/src/gui/DatabaseOpenWidget.ui +++ b/src/gui/DatabaseOpenWidget.ui @@ -71,7 +71,6 @@ 12 - 75 true @@ -200,6 +199,54 @@ 3 + + + + 0 + + + + + + 16777215 + 2 + + + + 0 + + + 0 + + + -1 + + + false + + + + + + + false + + + + 0 + 0 + + + + Hardware key slot selection + + + false + + + + + @@ -251,54 +298,6 @@ - - - - 0 - - - - - - 16777215 - 2 - - - - 0 - - - 0 - - - -1 - - - false - - - - - - - false - - - - 0 - 0 - - - - Hardware key slot selection - - - false - - - - - @@ -315,7 +314,7 @@ Hardware Key: - challengeResponseCombo + hardwareKeyCombo @@ -357,7 +356,7 @@ - + Qt::Vertical @@ -375,11 +374,8 @@ - - - 0 - - + + @@ -395,58 +391,19 @@ - - - - - - Browse for key file - - - Browse for key file - - - Browse… - - - - - - - 0 - - - - true - + - Refresh hardware tokens + Browse for key file - Refresh hardware tokens + Browse for key file - Refresh + Browse… - - - - Qt::Vertical - - - QSizePolicy::Fixed - - - - 0 - 2 - - - - @@ -525,7 +482,6 @@ 10 - 75 true @@ -635,13 +591,13 @@ + quickUnlockButton + resetQuickUnlockButton editPassword keyFileLineEdit buttonBrowseFile - challengeResponseCombo - buttonRedetectYubikey - quickUnlockButton - resetQuickUnlockButton + hardwareKeyCombo + buttonBox