Improved PasswordPromptDialog
- can now also set caption - can set initial state of save option - improved size and spacing
This commit is contained in:
parent
634345b38f
commit
24751f81dd
3 changed files with 59 additions and 19 deletions
|
|
@ -138,6 +138,7 @@ bool MasterController::retrieveConnectionPassword(ConnectionConfig &cc)
|
||||||
// ook aan de gebruiker vragen zoals hier gebeurd.
|
// ook aan de gebruiker vragen zoals hier gebeurd.
|
||||||
QString str = ConnectionListModel::makeLongDescription(cc);
|
QString str = ConnectionListModel::makeLongDescription(cc);
|
||||||
auto dlg = std::make_unique<PasswordPromptDialog>(PasswordPromptDialog::SaveOption, nullptr);
|
auto dlg = std::make_unique<PasswordPromptDialog>(PasswordPromptDialog::SaveOption, nullptr);
|
||||||
|
dlg->setCaption(tr("Connection password prompt"));
|
||||||
dlg->setDescription(QString(tr("Please provide password for connection %1")).arg(str));
|
dlg->setDescription(QString(tr("Please provide password for connection %1")).arg(str));
|
||||||
int exec_result = dlg->exec();
|
int exec_result = dlg->exec();
|
||||||
|
|
||||||
|
|
@ -181,7 +182,8 @@ bool MasterController::UnlockPasswordManagerIfNeeded()
|
||||||
while (true) {
|
while (true) {
|
||||||
// ask user for passphrase
|
// ask user for passphrase
|
||||||
auto dlg = std::make_unique<PasswordPromptDialog>(nullptr, nullptr);
|
auto dlg = std::make_unique<PasswordPromptDialog>(nullptr, nullptr);
|
||||||
dlg->setDescription(tr("Enter passphrase for password manager"));
|
dlg->setCaption(tr("Unlock password manager"));
|
||||||
|
dlg->setDescription(tr("Enter password for password manager"));
|
||||||
int exec_result = dlg->exec();
|
int exec_result = dlg->exec();
|
||||||
bool ok = (exec_result == QDialog::Accepted);
|
bool ok = (exec_result == QDialog::Accepted);
|
||||||
|
|
||||||
|
|
@ -200,7 +202,10 @@ bool MasterController::UnlockPasswordManagerIfNeeded()
|
||||||
// Ask user for passphrase + confirmation, clearly instruct this is first setup
|
// Ask user for passphrase + confirmation, clearly instruct this is first setup
|
||||||
// create
|
// create
|
||||||
auto dlg = std::make_unique<PasswordPromptDialog>(PasswordPromptDialog::ConfirmPassword, nullptr);
|
auto dlg = std::make_unique<PasswordPromptDialog>(PasswordPromptDialog::ConfirmPassword, nullptr);
|
||||||
dlg->setDescription(tr("Enter passphrase for password manager initialization"));
|
dlg->setCaption(tr("Password manager setup"));
|
||||||
|
dlg->setDescription(tr("Enter a strong password for password manager initialization. A strong key will be "
|
||||||
|
"derived from your password and it will be impossible to recover anything from the "
|
||||||
|
"password manager without the password you enter here."));
|
||||||
int exec_result = dlg->exec();
|
int exec_result = dlg->exec();
|
||||||
if (exec_result == QDialog::Accepted) {
|
if (exec_result == QDialog::Accepted) {
|
||||||
QString passphrase = dlg->password();
|
QString passphrase = dlg->password();
|
||||||
|
|
|
||||||
|
|
@ -9,18 +9,24 @@
|
||||||
|
|
||||||
Q_DECLARE_OPERATORS_FOR_FLAGS(PasswordPromptDialog::Flags)
|
Q_DECLARE_OPERATORS_FOR_FLAGS(PasswordPromptDialog::Flags)
|
||||||
|
|
||||||
|
const char* PasswordPromptDialog::translateContext = "PasswordPromptDialog";
|
||||||
|
|
||||||
PasswordPromptDialog::PasswordPromptDialog(Flags flags, QWidget *parent)
|
PasswordPromptDialog::PasswordPromptDialog(Flags flags, QWidget *parent)
|
||||||
: QDialog(parent)
|
: QDialog(parent)
|
||||||
, m_Flags(flags)
|
, m_Flags(flags)
|
||||||
{
|
{
|
||||||
m_connectionLabel = new QLabel(this);
|
m_descriptionLabel = new QLabel(this);
|
||||||
m_DialogButtons = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, Qt::Horizontal, this);
|
m_DialogButtons = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, Qt::Horizontal, this);
|
||||||
|
|
||||||
const size_t inputFieldCount = flags.testFlag(ConfirmPassword) ? 2 : 1;
|
const size_t inputFieldCount = flags.testFlag(ConfirmPassword) ? 2 : 1;
|
||||||
|
|
||||||
|
setMinimumWidth(400);
|
||||||
auto mainLayout = new QGridLayout;
|
auto mainLayout = new QGridLayout;
|
||||||
|
mainLayout->setHorizontalSpacing(12);
|
||||||
|
mainLayout->setVerticalSpacing(18);
|
||||||
|
|
||||||
int row = 0;
|
int row = 0;
|
||||||
mainLayout->addWidget(m_connectionLabel, row, 0, 1, 2);
|
mainLayout->addWidget(m_descriptionLabel, row, 0, 1, 2);
|
||||||
++row;
|
++row;
|
||||||
for (size_t idx = 0; idx < inputFieldCount; ++idx) {
|
for (size_t idx = 0; idx < inputFieldCount; ++idx) {
|
||||||
auto lbl = new QLabel(this);
|
auto lbl = new QLabel(this);
|
||||||
|
|
@ -51,18 +57,43 @@ PasswordPromptDialog::PasswordPromptDialog(Flags flags, QWidget *parent)
|
||||||
connect(m_passwordInput[1], &QLineEdit::textChanged, this, &PasswordPromptDialog::passwordChanged);
|
connect(m_passwordInput[1], &QLineEdit::textChanged, this, &PasswordPromptDialog::passwordChanged);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
PasswordPromptDialog& PasswordPromptDialog::setDescription(const QString &description)
|
||||||
|
{
|
||||||
|
m_descriptionLabel->setText(QString("%1").arg(description));
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
PasswordPromptDialog& PasswordPromptDialog::setCaption(const std::optional<QString> &caption)
|
||||||
|
{
|
||||||
|
m_customCaption = caption;
|
||||||
|
UpdateCaption();
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
PasswordPromptDialog& PasswordPromptDialog::setSaveChecked(bool save)
|
||||||
|
{
|
||||||
|
if (m_saveCheck)
|
||||||
|
m_saveCheck->setCheckState(save ? Qt::CheckState::Checked : Qt::CheckState::Unchecked);
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
void PasswordPromptDialog::UpdateCaption()
|
||||||
|
{
|
||||||
|
QString cap = m_customCaption.value_or(QApplication::translate(translateContext, "Password dialog", nullptr));
|
||||||
|
setWindowTitle(cap);
|
||||||
|
}
|
||||||
|
|
||||||
void PasswordPromptDialog::retranslateUi()
|
void PasswordPromptDialog::retranslateUi()
|
||||||
{
|
{
|
||||||
const char * context = "PasswordPromptDialog";
|
UpdateCaption();
|
||||||
setWindowTitle(QApplication::translate(context, "Connection password", nullptr));
|
m_passwordLabel[0]->setText(QApplication::translate(translateContext, "Password", nullptr));
|
||||||
m_passwordLabel[0]->setText(QApplication::translate(context, "Password", nullptr));
|
m_passwordInput[0]->setPlaceholderText(QApplication::translate(translateContext, "Enter password", nullptr));
|
||||||
m_passwordInput[0]->setPlaceholderText(QApplication::translate(context, "Enter password", nullptr));
|
|
||||||
if (m_passwordLabel[1])
|
if (m_passwordLabel[1])
|
||||||
m_passwordLabel[1]->setText(QApplication::translate(context, "Confirm password", nullptr));
|
m_passwordLabel[1]->setText(QApplication::translate(translateContext, "Confirm password", nullptr));
|
||||||
if (m_passwordInput[1])
|
if (m_passwordInput[1])
|
||||||
m_passwordInput[1]->setPlaceholderText(QApplication::translate(context, "Reenter same password for confirmation", nullptr));
|
m_passwordInput[1]->setPlaceholderText(QApplication::translate(translateContext, "Reenter same password for confirmation", nullptr));
|
||||||
if (m_saveCheck)
|
if (m_saveCheck)
|
||||||
m_saveCheck->setText(QApplication::translate(context, "Save password", nullptr));
|
m_saveCheck->setText(QApplication::translate(translateContext, "Save password", nullptr));
|
||||||
}
|
}
|
||||||
|
|
||||||
void PasswordPromptDialog::updateOkEnabled()
|
void PasswordPromptDialog::updateOkEnabled()
|
||||||
|
|
@ -80,12 +111,6 @@ void PasswordPromptDialog::passwordChanged(const QString &)
|
||||||
updateOkEnabled();
|
updateOkEnabled();
|
||||||
}
|
}
|
||||||
|
|
||||||
void PasswordPromptDialog::setDescription(const QString &description)
|
|
||||||
{
|
|
||||||
m_connectionLabel->setText(QString("%1").arg(description));
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
QString PasswordPromptDialog::password() const
|
QString PasswordPromptDialog::password() const
|
||||||
{
|
{
|
||||||
return m_passwordInput[0]->text();
|
return m_passwordInput[0]->text();
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@
|
||||||
#define PASSWORDPROMPTDIALOG_H
|
#define PASSWORDPROMPTDIALOG_H
|
||||||
|
|
||||||
#include <QDialog>
|
#include <QDialog>
|
||||||
|
#include <optional>
|
||||||
|
|
||||||
class QCheckBox;
|
class QCheckBox;
|
||||||
class QDialogButtonBox;
|
class QDialogButtonBox;
|
||||||
|
|
@ -22,20 +23,29 @@ public:
|
||||||
|
|
||||||
explicit PasswordPromptDialog(Flags flags, QWidget *parent = nullptr);
|
explicit PasswordPromptDialog(Flags flags, QWidget *parent = nullptr);
|
||||||
|
|
||||||
void setDescription(const QString &description);
|
|
||||||
|
PasswordPromptDialog& setCaption(const std::optional<QString> &caption);
|
||||||
|
PasswordPromptDialog& setDescription(const QString &description);
|
||||||
|
/// Checks the save checkbox when save is true, this call is ignored when the checkbox does not exist
|
||||||
|
PasswordPromptDialog& setSaveChecked(bool save);
|
||||||
|
|
||||||
QString password() const;
|
QString password() const;
|
||||||
bool saveChecked() const;
|
bool saveChecked() const;
|
||||||
private:
|
private:
|
||||||
|
static const char* translateContext;
|
||||||
|
|
||||||
Flags m_Flags;
|
Flags m_Flags;
|
||||||
QLabel *m_connectionLabel = nullptr;
|
QLabel *m_descriptionLabel = nullptr;
|
||||||
QLabel *m_passwordLabel[2] = { nullptr, nullptr };
|
QLabel *m_passwordLabel[2] = { nullptr, nullptr };
|
||||||
QLineEdit *m_passwordInput[2] = { nullptr, nullptr };
|
QLineEdit *m_passwordInput[2] = { nullptr, nullptr };
|
||||||
QCheckBox *m_saveCheck = nullptr;
|
QCheckBox *m_saveCheck = nullptr;
|
||||||
QDialogButtonBox *m_DialogButtons = nullptr;
|
QDialogButtonBox *m_DialogButtons = nullptr;
|
||||||
|
|
||||||
|
std::optional<QString> m_customCaption;
|
||||||
|
|
||||||
void retranslateUi();
|
void retranslateUi();
|
||||||
void updateOkEnabled();
|
void updateOkEnabled();
|
||||||
|
void UpdateCaption();
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void passwordChanged(const QString &text);
|
void passwordChanged(const QString &text);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue