diff --git a/src/passworddialog.h b/src/passworddialog.h --- a/src/passworddialog.h +++ b/src/passworddialog.h @@ -63,10 +63,10 @@ void setPass(const QString &output); private Q_SLOTS: - void showPasswordChanged(int arg1); void createPassword(); void dialogAccepted(); void dialogCancelled(); + void togglePasswordGenerationOption(bool checked); private: std::unique_ptr ui; diff --git a/src/passworddialog.cpp b/src/passworddialog.cpp --- a/src/passworddialog.cpp +++ b/src/passworddialog.cpp @@ -38,6 +38,8 @@ setPasswordCharTemplate(m_passConfig.selected); connect(&m_pass, &Pass::finishedShow, this, &PasswordDialog::setPass); + connect(ui->createPasswordOptionsButton, &QAbstractButton::toggled, this, &PasswordDialog::togglePasswordGenerationOption); + togglePasswordGenerationOption(false); } /** @@ -71,7 +73,8 @@ connect(this, &PasswordDialog::accepted, this, &PasswordDialog::dialogAccepted); connect(this, &PasswordDialog::rejected, this, &PasswordDialog::dialogCancelled); connect(ui->createPasswordButton, &QAbstractButton::clicked, this, &PasswordDialog::createPassword); - connect(ui->checkBoxShow, &QCheckBox::stateChanged, this, &PasswordDialog::showPasswordChanged); + connect(ui->createPasswordOptionsButton, &QAbstractButton::toggled, this, &PasswordDialog::togglePasswordGenerationOption); + togglePasswordGenerationOption(false); } /** @@ -79,18 +82,6 @@ */ PasswordDialog::~PasswordDialog() = default; -/** - * @brief PasswordDialog::on_checkBoxShow_stateChanged hide or show passwords. - * @param arg1 - */ -void PasswordDialog::showPasswordChanged(int arg1) -{ - if (arg1) - ui->lineEditPassword->setEchoMode(QLineEdit::Normal); - else - ui->lineEditPassword->setEchoMode(QLineEdit::Password); -} - /** * @brief PasswordDialog::on_createPasswordButton_clicked generate a random * passwords. @@ -98,12 +89,12 @@ */ void PasswordDialog::createPassword() { - ui->widget->setEnabled(false); + setEnabled(false); QString newPass = m_pass.Generate_b(static_cast(ui->spinBox_pwdLength->value()), m_passConfig.Characters[static_cast(ui->passwordTemplateSwitch->currentIndex())]); if (newPass.length() > 0) - ui->lineEditPassword->setText(newPass); - ui->widget->setEnabled(true); + ui->lineEditPassword->setPassword(newPass); + setEnabled(true); } /** @@ -136,9 +127,9 @@ void PasswordDialog::setPassword(const QString& password) { FileContent fileContent = FileContent::parse(password, m_templating ? m_fields : QStringList(), m_allFields); - ui->lineEditPassword->setText(fileContent.getPassword()); + ui->lineEditPassword->setPassword(fileContent.getPassword()); - QWidget *previous = ui->checkBoxShow; + QWidget *previous = ui->createPasswordButton; // first set templated values NamedValues namedValues = fileContent.getNamedValues(); for (QLineEdit *line : std::as_const(templateLines)) { @@ -167,7 +158,7 @@ */ QString PasswordDialog::getPassword() { - QString passFile = ui->lineEditPassword->text() + QLatin1Char('\n'); + QString passFile = ui->lineEditPassword->password() + QLatin1Char('\n'); QList allLines(templateLines); allLines.append(otherLines); for (QLineEdit *line : allLines) { @@ -191,13 +182,13 @@ templateLines.clear(); if (m_templating) { - QWidget *previous = ui->checkBoxShow; + QWidget *previous = ui->createPasswordButton; for (const QString &field : std::as_const(m_fields)) { if (field.isEmpty()) continue; auto *line = new QLineEdit(); line->setObjectName(field); - ui->formLayout->addRow(new QLabel(field), line); + ui->formLayout->addRow(new QLabel(i18nc("Field name", "%1:", field)), line); setTabOrder(previous, line); templateLines.append(line); previous = line; @@ -240,3 +231,24 @@ setPassword(output); // TODO(bezet): enable ui } + +void PasswordDialog::togglePasswordGenerationOption(bool checked) +{ + if (checked) { + ui->createPasswordOptionsButton->setIcon(QIcon::fromTheme(QStringLiteral("collapse-symbolic"))); + ui->createPasswordOptionsButton->setToolTip(i18nc("@info:tooltip", "Collapse password options")); + ui->createPasswordOptionsButton->setAccessibleName(i18nc("@info:tooltip", "Collapse password options")); + ui->label_characterset->setVisible(true); + ui->passwordTemplateSwitch->setVisible(true); + ui->label_length->setVisible(true); + ui->spinBox_pwdLength->setVisible(true); + } else { + ui->createPasswordOptionsButton->setIcon(QIcon::fromTheme(QStringLiteral("expand-symbolic"))); + ui->createPasswordOptionsButton->setToolTip(i18nc("@info:tooltip", "Toggle password options")); + ui->createPasswordOptionsButton->setAccessibleName(i18nc("@info:tooltip", "Toggle password options")); + ui->label_characterset->setVisible(false); + ui->passwordTemplateSwitch->setVisible(false); + ui->label_length->setVisible(false); + ui->spinBox_pwdLength->setVisible(false); + } +} diff --git a/src/passworddialog.ui b/src/passworddialog.ui --- a/src/passworddialog.ui +++ b/src/passworddialog.ui @@ -27,153 +27,141 @@ 6 - - - - 0 - 0 - + + + 0 - - - 0 - - - 0 - - - 0 - - - 0 - - - - - - - - - - QLineEdit::Password - - - Password - - - - - - - true - - - Generate - - - - - - - - - - - Show password - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - Character Set: - - - - - - - - All Characters - - - - - Alphabetical - - - - - Alphanumerical - - - - - - - - - 0 - 0 - - - - Length: - - - - - - - 8 - - - 255 - - - - - - - - - QFormLayout::AllNonFixedFieldsGrow - - - Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter - - - Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop + + 0 + + + 0 + + + 0 + + + + + Password: + + + lineEditPassword + + + + + + + + + KPassword::RevealMode::Always + + + + + + + Generate + + + + + + + true + + + + + + + + + + + + Character Set: + + + passwordTemplateSwitch + + + + + + + + 0 + 0 + + + + + All Characters - - - - - - - - - Qt::Horizontal + + + + Alphabetical - - QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + Alphanumerical - - - + + + + + + + Length: + + + spinBox_pwdLength + + + + + + + + 0 + 0 + + + + 8 + + + 255 + + + + + + + + + Additional Notes: + + + plainTextEdit + + + + + + + + + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + @@ -181,7 +169,6 @@ lineEditPassword createPasswordButton - checkBoxShow passwordTemplateSwitch spinBox_pwdLength plainTextEdit