Refactor Key Component Widgets for translations

* Ensure full labels are applied to buttons instead of splitting the Add/Change/Remove from the component name.
This commit is contained in:
Jonathan White 2021-02-14 16:59:22 -05:00
parent 75e4329c80
commit 4f7460afbd
8 changed files with 64 additions and 99 deletions

View File

@ -22,11 +22,6 @@
#include <QTimer>
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<Page>(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) {

View File

@ -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<Ui::KeyComponentWidget> 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<QWidget> m_componentWidget;
const QScopedPointer<Ui::KeyComponentWidget> m_ui;
Q_DISABLE_COPY(KeyComponentWidget);
};
#endif // KEEPASSXC_KEYCOMPONENTWIDGET_H

View File

@ -16,13 +16,13 @@
*/
#include "KeyFileEditWidget.h"
#include "ui_KeyComponentWidget.h"
#include "ui_KeyFileEditWidget.h"
#include <gui/dbsettings/DatabaseSettingsWidget.h>
#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("<p>You can add a key file containing random bytes for additional security.</p>"
"<p>You must keep it secret and never lose it or you will be locked out!</p>"));
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("<p>You can add a key file containing random bytes for additional security.</p>"
"<p>You must keep it secret and never lose it or you will be locked out.</p>"));
}
void KeyFileEditWidget::createKeyFile()
{
Q_ASSERT(m_compEditWidget);

View File

@ -43,6 +43,7 @@ public:
protected:
QWidget* componentEditWidget() override;
void initComponentEditWidget(QWidget* widget) override;
void initComponent() override;
private slots:
void createKeyFile();

View File

@ -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 <QDialog>
PasswordEditWidget::PasswordEditWidget(QWidget* parent)
: KeyComponentWidget(parent)
, m_compUi(new Ui::PasswordEditWidget())
{
setComponentName(tr("Password"));
setComponentDescription(tr("<p>A password is the primary method for securing your database.</p>"
"<p>Good passwords are long and unique. KeePassXC can generate one for you.</p>"));
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("<p>A password is the primary method for securing your database.</p>"
"<p>Good passwords are long and unique. KeePassXC can generate one for you.</p>"));
}
void PasswordEditWidget::hideEvent(QHideEvent* event)
{
if (!isVisible() && m_compUi->enterPasswordEdit) {

View File

@ -44,6 +44,7 @@ public:
protected:
QWidget* componentEditWidget() override;
void initComponentEditWidget(QWidget* widget) override;
void initComponent() override;
void hideEvent(QHideEvent* event) override;
private slots:

View File

@ -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("<p>If you own a <a href=\"https://www.yubico.com/\">YubiKey</a>, you can use it "
"for additional security.</p><p>The YubiKey requires one of its slots to be programmed as "
"<a href=\"https://www.yubico.com/products/services-software/personalization-tools/challenge-response/\">"
"HMAC-SHA1 Challenge-Response</a>.</p>"));
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("<p>If you own a <a href=\"https://www.yubico.com/\">YubiKey</a> or "
"<a href=\"https://onlykey.io\">OnlyKey</a>, you can use it for additional security.</p>"
"<p>The key requires one of its slots to be programmed as "
"<a href=\"https://www.yubico.com/products/services-software/challenge-response/\">"
"HMAC-SHA1 Challenge-Response</a>.</p>"));
}
void YubiKeyEditWidget::pollYubikey()
{
#ifdef WITH_XC_YUBIKEY

View File

@ -43,6 +43,7 @@ public:
protected:
QWidget* componentEditWidget() override;
void initComponentEditWidget(QWidget* widget) override;
void initComponent() override;
private slots:
void hardwareKeyResponse(bool found);