diff --git a/src/gui/databasekey/KeyComponentWidget.cpp b/src/gui/databasekey/KeyComponentWidget.cpp index 769cbab9..7fa23662 100644 --- a/src/gui/databasekey/KeyComponentWidget.cpp +++ b/src/gui/databasekey/KeyComponentWidget.cpp @@ -22,11 +22,6 @@ #include KeyComponentWidget::KeyComponentWidget(QWidget* parent) - : KeyComponentWidget({}, parent) -{ -} - -KeyComponentWidget::KeyComponentWidget(const QString& name, QWidget* parent) : QWidget(parent) , m_ui(new Ui::KeyComponentWidget()) { @@ -39,18 +34,12 @@ KeyComponentWidget::KeyComponentWidget(const QString& name, QWidget* parent) 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))); connect(this, SIGNAL(componentAddRequested()), SLOT(doAdd())); connect(this, SIGNAL(componentEditRequested()), SLOT(doEdit())); connect(this, SIGNAL(componentRemovalRequested()), SLOT(doRemove())); connect(this, SIGNAL(componentAddChanged(bool)), SLOT(updateAddStatus(bool))); - bool prev = blockSignals(true); - setComponentName(name); - blockSignals(prev); - - prev = m_ui->stackedWidget->blockSignals(true); + bool prev = m_ui->stackedWidget->blockSignals(true); m_ui->stackedWidget->setCurrentIndex(Page::AddNew); m_ui->stackedWidget->blockSignals(prev); } @@ -59,42 +48,6 @@ KeyComponentWidget::~KeyComponentWidget() { } -/** - * @param name display name for the key component - */ -void KeyComponentWidget::setComponentName(const QString& name) -{ - if (name == m_componentName) { - return; - } - - m_componentName = name; - emit nameChanged(name); -} - -/** - * @return The key component's display name - */ -QString KeyComponentWidget::componentName() const -{ - return m_componentName; -} - -void KeyComponentWidget::setComponentDescription(const QString& description) -{ - if (description == m_componentDescription) { - return; - } - - m_componentDescription = description; - emit descriptionChanged(description); -} - -QString KeyComponentWidget::componentDescription() const -{ - return m_componentDescription; -} - void KeyComponentWidget::setComponentAdded(bool added) { if (m_isComponentAdded == added) { @@ -121,21 +74,6 @@ KeyComponentWidget::Page KeyComponentWidget::visiblePage() const return static_cast(m_ui->stackedWidget->currentIndex()); } -void KeyComponentWidget::updateComponentName(const QString& name) -{ - m_ui->groupBox->setTitle(name); - m_ui->addButton->setText(tr("Add %1", "Add a key component").arg(name)); - m_ui->changeButton->setText(tr("Change %1", "Change a key component").arg(name)); - m_ui->removeButton->setText(tr("Remove %1", "Remove a key component").arg(name)); - m_ui->changeOrRemoveLabel->setText( - tr("%1 set, click to change or remove", "Change or remove a key component").arg(name)); -} - -void KeyComponentWidget::updateComponentDescription(const QString& description) -{ - m_ui->componentDescription->setText(description); -} - void KeyComponentWidget::updateAddStatus(bool added) { if (added) { diff --git a/src/gui/databasekey/KeyComponentWidget.h b/src/gui/databasekey/KeyComponentWidget.h index b73f881f..225aacda 100644 --- a/src/gui/databasekey/KeyComponentWidget.h +++ b/src/gui/databasekey/KeyComponentWidget.h @@ -33,10 +33,6 @@ class KeyComponentWidget : public QWidget { Q_OBJECT // clang-format off - Q_PROPERTY(QString componentName READ m_componentName READ componentName - WRITE setComponentName NOTIFY nameChanged) - Q_PROPERTY(QString componentDescription READ m_componentDescription READ componentDescription - WRITE setComponentDescription NOTIFY descriptionChanged) Q_PROPERTY(bool componentAdded READ m_isComponentAdded READ componentAdded WRITE setComponentAdded NOTIFY componentAddChanged) // clang-format on @@ -50,8 +46,6 @@ public: }; explicit KeyComponentWidget(QWidget* parent = nullptr); - explicit KeyComponentWidget(const QString& name, QWidget* parent = nullptr); - Q_DISABLE_COPY(KeyComponentWidget); ~KeyComponentWidget() override; /** @@ -73,10 +67,6 @@ public: */ virtual bool validate(QString& errorMessage) const = 0; - void setComponentName(const QString& name); - QString componentName() const; - void setComponentDescription(const QString& name); - QString componentDescription() const; void setComponentAdded(bool added); bool componentAdded() const; void changeVisiblePage(Page page); @@ -101,9 +91,14 @@ protected: */ virtual void initComponentEditWidget(QWidget* widget) = 0; + /** + * Initialize component-specific labels, buttons, and description + */ + virtual void initComponent() = 0; + + const QScopedPointer m_ui; + signals: - void nameChanged(const QString& newName); - void descriptionChanged(const QString& newDescription); void componentAddChanged(bool added); void componentAddRequested(); void componentEditRequested(); @@ -114,8 +109,6 @@ protected: void showEvent(QShowEvent* event) override; private slots: - void updateComponentName(const QString& name); - void updateComponentDescription(const QString& decription); void updateAddStatus(bool added); void doAdd(); void doEdit(); @@ -127,11 +120,9 @@ private slots: private: bool m_isComponentAdded = false; Page m_previousPage = Page::AddNew; - QString m_componentName; - QString m_componentDescription; QPointer m_componentWidget; - const QScopedPointer m_ui; + Q_DISABLE_COPY(KeyComponentWidget); }; #endif // KEEPASSXC_KEYCOMPONENTWIDGET_H diff --git a/src/gui/databasekey/KeyFileEditWidget.cpp b/src/gui/databasekey/KeyFileEditWidget.cpp index 2fb0b3de..4265662c 100644 --- a/src/gui/databasekey/KeyFileEditWidget.cpp +++ b/src/gui/databasekey/KeyFileEditWidget.cpp @@ -16,13 +16,13 @@ */ #include "KeyFileEditWidget.h" +#include "ui_KeyComponentWidget.h" #include "ui_KeyFileEditWidget.h" -#include #include "gui/FileDialog.h" #include "gui/MainWindow.h" #include "gui/MessageBox.h" -#include "keys/CompositeKey.h" +#include "gui/dbsettings/DatabaseSettingsWidget.h" #include "keys/FileKey.h" KeyFileEditWidget::KeyFileEditWidget(DatabaseSettingsWidget* parent) @@ -30,9 +30,7 @@ KeyFileEditWidget::KeyFileEditWidget(DatabaseSettingsWidget* parent) , m_compUi(new Ui::KeyFileEditWidget()) , m_parent(parent) { - setComponentName(tr("Key File")); - setComponentDescription(tr("

You can add a key file containing random bytes for additional security.

" - "

You must keep it secret and never lose it or you will be locked out!

")); + initComponent(); } KeyFileEditWidget::~KeyFileEditWidget() @@ -90,6 +88,20 @@ void KeyFileEditWidget::initComponentEditWidget(QWidget* widget) m_compUi->keyFileCombo->setFocus(); } +void KeyFileEditWidget::initComponent() +{ + // These need to be set in total for each credential type for translation purposes + m_ui->groupBox->setTitle(tr("Key File")); + m_ui->addButton->setText(tr("Add Key File")); + m_ui->changeButton->setText(tr("Change Key File")); + m_ui->removeButton->setText(tr("Remove Key File")); + m_ui->changeOrRemoveLabel->setText(tr("Key File set, click to change or remove")); + + m_ui->componentDescription->setText( + tr("

You can add a key file containing random bytes for additional security.

" + "

You must keep it secret and never lose it or you will be locked out.

")); +} + void KeyFileEditWidget::createKeyFile() { Q_ASSERT(m_compEditWidget); diff --git a/src/gui/databasekey/KeyFileEditWidget.h b/src/gui/databasekey/KeyFileEditWidget.h index dd414e13..fc2f91e1 100644 --- a/src/gui/databasekey/KeyFileEditWidget.h +++ b/src/gui/databasekey/KeyFileEditWidget.h @@ -43,6 +43,7 @@ public: protected: QWidget* componentEditWidget() override; void initComponentEditWidget(QWidget* widget) override; + void initComponent() override; private slots: void createKeyFile(); diff --git a/src/gui/databasekey/PasswordEditWidget.cpp b/src/gui/databasekey/PasswordEditWidget.cpp index 2d355cc1..4f468c12 100644 --- a/src/gui/databasekey/PasswordEditWidget.cpp +++ b/src/gui/databasekey/PasswordEditWidget.cpp @@ -16,22 +16,18 @@ */ #include "PasswordEditWidget.h" +#include "ui_KeyComponentWidget.h" #include "ui_PasswordEditWidget.h" -#include "core/Resources.h" #include "gui/PasswordGeneratorWidget.h" #include "keys/CompositeKey.h" #include "keys/PasswordKey.h" -#include - PasswordEditWidget::PasswordEditWidget(QWidget* parent) : KeyComponentWidget(parent) , m_compUi(new Ui::PasswordEditWidget()) { - setComponentName(tr("Password")); - setComponentDescription(tr("

A password is the primary method for securing your database.

" - "

Good passwords are long and unique. KeePassXC can generate one for you.

")); + initComponent(); } PasswordEditWidget::~PasswordEditWidget() @@ -85,6 +81,20 @@ void PasswordEditWidget::initComponentEditWidget(QWidget* widget) m_compUi->enterPasswordEdit->setFocus(); } +void PasswordEditWidget::initComponent() +{ + // These need to be set in total for each credential type for translation purposes + m_ui->groupBox->setTitle(tr("Password")); + m_ui->addButton->setText(tr("Add Password")); + m_ui->changeButton->setText(tr("Change Password")); + m_ui->removeButton->setText(tr("Remove Password")); + m_ui->changeOrRemoveLabel->setText(tr("Password set, click to change or remove")); + + m_ui->componentDescription->setText( + tr("

A password is the primary method for securing your database.

" + "

Good passwords are long and unique. KeePassXC can generate one for you.

")); +} + void PasswordEditWidget::hideEvent(QHideEvent* event) { if (!isVisible() && m_compUi->enterPasswordEdit) { diff --git a/src/gui/databasekey/PasswordEditWidget.h b/src/gui/databasekey/PasswordEditWidget.h index 80221945..be6c3f93 100644 --- a/src/gui/databasekey/PasswordEditWidget.h +++ b/src/gui/databasekey/PasswordEditWidget.h @@ -44,6 +44,7 @@ public: protected: QWidget* componentEditWidget() override; void initComponentEditWidget(QWidget* widget) override; + void initComponent() override; void hideEvent(QHideEvent* event) override; private slots: diff --git a/src/gui/databasekey/YubiKeyEditWidget.cpp b/src/gui/databasekey/YubiKeyEditWidget.cpp index 855bd709..c8182120 100644 --- a/src/gui/databasekey/YubiKeyEditWidget.cpp +++ b/src/gui/databasekey/YubiKeyEditWidget.cpp @@ -16,12 +16,11 @@ */ #include "YubiKeyEditWidget.h" +#include "ui_KeyComponentWidget.h" #include "ui_YubiKeyEditWidget.h" #include "config-keepassx.h" #include "core/AsyncTask.h" -#include "gui/MainWindow.h" -#include "gui/MessageBox.h" #include "keys/CompositeKey.h" #include "keys/YkChallengeResponseKey.h" @@ -29,12 +28,7 @@ YubiKeyEditWidget::YubiKeyEditWidget(QWidget* parent) : KeyComponentWidget(parent) , m_compUi(new Ui::YubiKeyEditWidget()) { - setComponentName(tr("YubiKey Challenge-Response")); - setComponentDescription( - tr("

If you own a YubiKey, you can use it " - "for additional security.

The YubiKey requires one of its slots to be programmed as " - "" - "HMAC-SHA1 Challenge-Response.

")); + initComponent(); connect(YubiKey::instance(), SIGNAL(detectComplete(bool)), SLOT(hardwareKeyResponse(bool)), Qt::QueuedConnection); } @@ -97,6 +91,23 @@ void YubiKeyEditWidget::initComponentEditWidget(QWidget* widget) m_compUi->comboChallengeResponse->setFocus(); } +void YubiKeyEditWidget::initComponent() +{ + // These need to be set in total for each credential type for translation purposes + m_ui->groupBox->setTitle(tr("Challenge-Response")); + m_ui->addButton->setText(tr("Add Challenge-Response")); + m_ui->changeButton->setText(tr("Change Challenge-Response")); + m_ui->removeButton->setText(tr("Remove Challenge-Response")); + m_ui->changeOrRemoveLabel->setText(tr("Challenge-Response set, click to change or remove")); + + m_ui->componentDescription->setText( + tr("

If you own a YubiKey or " + "OnlyKey, you can use it for additional security.

" + "

The key requires one of its slots to be programmed as " + "" + "HMAC-SHA1 Challenge-Response.

")); +} + void YubiKeyEditWidget::pollYubikey() { #ifdef WITH_XC_YUBIKEY diff --git a/src/gui/databasekey/YubiKeyEditWidget.h b/src/gui/databasekey/YubiKeyEditWidget.h index d5be0a68..b673ebaa 100644 --- a/src/gui/databasekey/YubiKeyEditWidget.h +++ b/src/gui/databasekey/YubiKeyEditWidget.h @@ -43,6 +43,7 @@ public: protected: QWidget* componentEditWidget() override; void initComponentEditWidget(QWidget* widget) override; + void initComponent() override; private slots: void hardwareKeyResponse(bool found);