9#include "ui_passworddialog.h"
27 m_passConfig(std::move(passConfig)) {
56 setWindowTitle(this->windowTitle() +
" " + m_file);
69 &PasswordDialog::close);
70 connect(
this, &PasswordDialog::accepted,
this, &PasswordDialog::on_accepted);
71 connect(
this, &PasswordDialog::rejected,
this, &PasswordDialog::on_rejected);
83void PasswordDialog::on_checkBoxShow_stateChanged(
int arg1) {
85 ui->lineEditPassword->setEchoMode(QLineEdit::Normal);
87 ui->lineEditPassword->setEchoMode(QLineEdit::Password);
95void PasswordDialog::on_createPasswordButton_clicked() {
96 ui->widget->setEnabled(
false);
97 const int currentIndex = ui->passwordTemplateSwitch->currentIndex();
98 if (currentIndex < 0 ||
100 ui->widget->setEnabled(
true);
105 static_cast<unsigned int>(ui->spinBox_pwdLength->value()),
108 if (!newPass.isEmpty()) {
109 ui->lineEditPassword->setText(newPass);
111 ui->widget->setEnabled(
true);
117void PasswordDialog::on_accepted() {
119 if (newValue.isEmpty()) {
123 if (newValue.right(1) !=
"\n") {
133void PasswordDialog::on_rejected() {
setPassword(QString()); }
141 password, m_templating ? m_fields : QStringList(), m_allFields);
142 ui->lineEditPassword->setText(fileContent.
getPassword());
144 QWidget *previous = ui->checkBoxShow;
147 for (QLineEdit *line :
AS_CONST(templateLines)) {
148 line->setText(namedValues.
takeValue(line->objectName()));
154 auto *line =
new QLineEdit();
155 line->setObjectName(nv.name);
156 line->setText(nv.value);
157 ui->formLayout->addRow(
new QLabel(nv.name), line);
158 setTabOrder(previous, line);
159 otherLines.append(line);
172 QString passFile = ui->lineEditPassword->text() +
"\n";
173 QList<QLineEdit *> allLines(templateLines);
174 allLines.append(otherLines);
175 for (QLineEdit *line : allLines) {
176 QString text = line->text();
177 if (text.isEmpty()) {
180 passFile += line->objectName() +
": " + text +
"\n";
182 passFile += ui->plainTextEdit->toPlainText();
191 m_fields = rawFields.split(
'\n');
192 m_templating = useTemplate;
193 templateLines.clear();
196 QWidget *previous = ui->checkBoxShow;
197 for (
const QString &field : std::as_const(m_fields)) {
198 if (field.isEmpty()) {
201 auto *line =
new QLineEdit();
202 line->setObjectName(field);
203 ui->formLayout->addRow(
new QLabel(field), line);
204 setTabOrder(previous, line);
205 templateLines.append(line);
226 ui->spinBox_pwdLength->setValue(length);
235 ui->passwordTemplateSwitch->setCurrentIndex(templateIndex);
244 ui->passwordTemplateSwitch->setDisabled(
usePwgen);
245 ui->label_characterset->setDisabled(
usePwgen);
auto getRemainingData() const -> QString
Gets remaining data not in named values.
auto getNamedValues() const -> NamedValues
Gets named value pairs from the parsed file.
auto getPassword() const -> QString
Gets the password from the parsed file.
static auto parse(const QString &fileContent, const QStringList &templateFields, bool allFields) -> FileContent
parse parses the given fileContent in a FileContent object. The password is accessible through getPas...
The NamedValues class is mostly a list of NamedValue but also has a method to take a specific NamedVa...
auto takeValue(const QString &name) -> QString
Finds and removes a named value by name.
void finishedShow(const QString &)
Emitted when show finishes.
void processErrorExit(int exitCode, const QString &err)
Emitted on process error exit.
void setPassword(const QString &password)
Sets content in the password field in the interface.
PasswordDialog(PasswordConfiguration passConfig, QWidget *parent=nullptr)
PasswordDialog::PasswordDialog basic constructor.
void setLength(int length)
PasswordDialog::setLength PasswordDialog::setLength password length.
~PasswordDialog() override
PasswordDialog::~PasswordDialog basic destructor.
void usePwgen(bool usePwgen)
PasswordDialog::usePwgen PasswordDialog::usePwgen don't use own password generator.
void setPasswordCharTemplate(int templateIndex)
PasswordDialog::setPasswordCharTemplate PasswordDialog::setPasswordCharTemplate chose the template st...
void setTemplate(const QString &rawFields, bool useTemplate)
Sets content in the template for the interface.
void templateAll(bool templateAll)
PasswordDialog::templateAll basic setter for use in PasswordDialog::setPassword templating all tokeni...
void setPass(const QString &output)
Sets the password from pass show output.
auto getPassword() -> QString
Returns the password as set in the password field in the interface.
static auto getPass() -> Pass *
Get currently active pass backend instance.
static auto getPasswordConfiguration() -> PasswordConfiguration
Get complete password generation configuration.
static auto isTemplateAllFields(const bool &defaultValue=QVariant().toBool()) -> bool
Check whether template applies to all fields.
static auto isUseTemplate(const bool &defaultValue=QVariant().toBool()) -> bool
Check whether template usage is enabled.
static auto getPassTemplate(const QString &defaultValue=QVariant().toString()) -> QString
Get pass entry template.
static auto isUsePwgen(const bool &defaultValue=QVariant().toBool()) -> bool
Check whether pwgen support is enabled.
Debug utilities for QtPass.
Utility macros for QtPass.
#define AS_CONST(x)
Cross-platform const_cast for range-based for loops.
Holds the Password configuration settings.
characterSet
The selected character set.