Page Menu
Home
GnuPG
Search
Configure Global Search
Log In
Files
F34621348
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Size
9 KB
Subscribers
None
View Options
diff --git a/src/passworddialog.cpp b/src/passworddialog.cpp
index f20de1f..77d7fe6 100644
--- a/src/passworddialog.cpp
+++ b/src/passworddialog.cpp
@@ -1,221 +1,223 @@
#include "passworddialog.h"
#include "filecontent.h"
#include "pass.h"
#include "passwordconfiguration.h"
#include "qtpasssettings.h"
#include "ui_passworddialog.h"
#include <QLabel>
#include <QLineEdit>
#ifdef QT_DEBUG
#include "debughelper.h"
#endif
/**
* @brief PasswordDialog::PasswordDialog basic constructor.
* @param passConfig configuration constant
* @param parent
*/
PasswordDialog::PasswordDialog(const PasswordConfiguration &passConfig,
QWidget *parent)
: QDialog(parent), ui(new Ui::PasswordDialog), m_passConfig(passConfig) {
m_templating = false;
m_allFields = false;
m_isNew = false;
ui->setupUi(this);
setLength(m_passConfig.length);
setPasswordCharTemplate(m_passConfig.selected);
connect(QtPassSettings::getPass(), &Pass::finishedShow, this,
&PasswordDialog::setPass);
}
/**
* @brief PasswordDialog::PasswordDialog complete constructor.
* @param file
* @param isNew
* @param parent pointer
*/
PasswordDialog::PasswordDialog(const QString &file, const bool &isNew,
QWidget *parent)
: QDialog(parent), ui(new Ui::PasswordDialog), m_file(file),
m_isNew(isNew) {
if (!isNew)
QtPassSettings::getPass()->Show(m_file);
ui->setupUi(this);
setWindowTitle(this->windowTitle() + QStringLiteral(" ") + m_file);
m_passConfig = QtPassSettings::getPasswordConfiguration();
setTemplate(QtPassSettings::getPassTemplate(),
QtPassSettings::isUseTemplate());
templateAll(QtPassSettings::isTemplateAllFields());
setLength(m_passConfig.length);
setPasswordCharTemplate(m_passConfig.selected);
connect(QtPassSettings::getPass(), &Pass::finishedShow, this,
&PasswordDialog::setPass);
connect(QtPassSettings::getPass(), &Pass::processErrorExit, this,
&PasswordDialog::close);
connect(this, &PasswordDialog::accepted, this, &PasswordDialog::on_accepted);
connect(this, &PasswordDialog::rejected, this, &PasswordDialog::on_rejected);
+ connect(ui->createPasswordButton, &QAbstractButton::clicked, this, &PasswordDialog::createPassword);
+ connect(ui->checkBoxShow, &QCheckBox::stateChanged, this, &PasswordDialog::showPasswordChanged);
}
/**
* @brief Pass{}{}wordDialog::~PasswordDialog basic destructor.
*/
PasswordDialog::~PasswordDialog() { delete ui; }
/**
* @brief PasswordDialog::on_checkBoxShow_stateChanged hide or show passwords.
* @param arg1
*/
-void PasswordDialog::on_checkBoxShow_stateChanged(int 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.
* @todo refactor when process is untangled from MainWindow class.
*/
-void PasswordDialog::on_createPasswordButton_clicked() {
+void PasswordDialog::createPassword() {
ui->widget->setEnabled(false);
QString newPass = QtPassSettings::getPass()->Generate_b(
static_cast<unsigned int>(ui->spinBox_pwdLength->value()),
m_passConfig.Characters[static_cast<PasswordConfiguration::characterSet>(
ui->passwordTemplateSwitch->currentIndex())]);
if (newPass.length() > 0)
ui->lineEditPassword->setText(newPass);
ui->widget->setEnabled(true);
}
/**
* @brief PasswordDialog::on_accepted handle Ok click for QDialog
*/
void PasswordDialog::on_accepted() {
QString newValue = getPassword();
if (newValue.isEmpty())
return;
if (newValue.right(1) != QLatin1Char('\n'))
newValue += QLatin1Char('\n');
QtPassSettings::getPass()->Insert(m_file, newValue, !m_isNew);
}
/**
* @brief PasswordDialog::on_rejected handle Cancel click for QDialog
*/
void PasswordDialog::on_rejected() { setPassword(QString()); }
/**
* @brief PasswordDialog::setPassword populate the (templated) fields.
* @param password
*/
void PasswordDialog::setPassword(QString password) {
FileContent fileContent = FileContent::parse(
password, m_templating ? m_fields : QStringList(), m_allFields);
ui->lineEditPassword->setText(fileContent.getPassword());
QWidget *previous = ui->checkBoxShow;
// first set templated values
NamedValues namedValues = fileContent.getNamedValues();
for (QLineEdit *line : qAsConst(templateLines)) {
line->setText(namedValues.takeValue(line->objectName()));
previous = line;
}
// show remaining values (if there are)
otherLines.clear();
for (const NamedValue &nv : qAsConst(namedValues)) {
auto *line = new QLineEdit();
line->setObjectName(nv.name);
line->setText(nv.value);
ui->formLayout->addRow(new QLabel(nv.name), line);
setTabOrder(previous, line);
otherLines.append(line);
previous = line;
}
ui->plainTextEdit->insertPlainText(fileContent.getRemainingData());
}
/**
* @brief PasswordDialog::getPassword join the (templated) fields to a QString
* for writing back.
* @return collappsed password.
*/
QString PasswordDialog::getPassword() {
QString passFile = ui->lineEditPassword->text() + QLatin1Char('\n');
QList<QLineEdit *> allLines(templateLines);
allLines.append(otherLines);
for (QLineEdit *line : allLines) {
QString text = line->text();
if (text.isEmpty())
continue;
passFile += line->objectName() + QStringLiteral(": ") + text + QLatin1Char('\n');
}
passFile += ui->plainTextEdit->toPlainText();
return passFile;
}
/**
* @brief PasswordDialog::setTemplate set the template and create the fields.
* @param rawFields
*/
void PasswordDialog::setTemplate(QString rawFields, bool useTemplate) {
m_fields = rawFields.split(QLatin1Char('\n'));
m_templating = useTemplate;
templateLines.clear();
if (m_templating) {
QWidget *previous = ui->checkBoxShow;
Q_FOREACH (QString field, m_fields) {
if (field.isEmpty())
continue;
auto *line = new QLineEdit();
line->setObjectName(field);
ui->formLayout->addRow(new QLabel(field), line);
setTabOrder(previous, line);
templateLines.append(line);
previous = line;
}
}
}
/**
* @brief PasswordDialog::templateAll basic setter for use in
* PasswordDialog::setPassword templating all tokenisable lines.
* @param templateAll
*/
void PasswordDialog::templateAll(bool templateAll) {
m_allFields = templateAll;
}
/**
* @brief PasswordDialog::setLength
* PasswordDialog::setLength password length.
* @param l
*/
void PasswordDialog::setLength(int l) { ui->spinBox_pwdLength->setValue(l); }
/**
* @brief PasswordDialog::setPasswordCharTemplate
* PasswordDialog::setPasswordCharTemplate chose the template style.
* @param t
*/
void PasswordDialog::setPasswordCharTemplate(int t) {
ui->passwordTemplateSwitch->setCurrentIndex(t);
}
void PasswordDialog::setPass(const QString &output) {
setPassword(output);
// TODO(bezet): enable ui
}
diff --git a/src/passworddialog.h b/src/passworddialog.h
index 6640f6d..15b0f6c 100644
--- a/src/passworddialog.h
+++ b/src/passworddialog.h
@@ -1,73 +1,73 @@
#ifndef PASSWORDDIALOG_H_
#define PASSWORDDIALOG_H_
#include "passwordconfiguration.h"
#include <QDialog>
namespace Ui {
class PasswordDialog;
}
class QLineEdit;
class QWidget;
/*!
\class PasswordDialog
\brief PasswordDialog Handles the inserting and editing of passwords.
Includes templated views.
*/
class PasswordDialog : public QDialog {
Q_OBJECT
public:
explicit PasswordDialog(const PasswordConfiguration &passConfig,
QWidget *parent = nullptr);
PasswordDialog(const QString &file, const bool &isNew,
QWidget *parent = nullptr);
~PasswordDialog();
/*! Sets content in the password field in the interface.
\param password the password as a QString
\sa getPassword
*/
void setPassword(QString password);
/*! Returns the password as set in the password field in the interface.
\return password as a QString
\sa setPassword
*/
QString getPassword();
/*! Sets content in the template for the interface.
\param rawFields is the template as a QString
\param useTemplate whether the template is used
*/
void setTemplate(QString rawFields, bool useTemplate);
void templateAll(bool templateAll);
void setLength(int l);
void setPasswordCharTemplate(int t);
public Q_SLOTS:
void setPass(const QString &output);
private Q_SLOTS:
- void on_checkBoxShow_stateChanged(int arg1);
- void on_createPasswordButton_clicked();
+ void showPasswordChanged(int arg1);
+ void createPassword();
void on_accepted();
void on_rejected();
private:
Ui::PasswordDialog *ui;
PasswordConfiguration m_passConfig;
QStringList m_fields;
QString m_file;
bool m_templating;
bool m_allFields;
bool m_isNew;
QList<QLineEdit *> templateLines;
QList<QLineEdit *> otherLines;
};
#endif // PASSWORDDIALOG_H_
File Metadata
Details
Attached
Mime Type
text/x-diff
Expires
Tue, Jan 20, 1:14 AM (6 h, 19 m)
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
09/c0/a3875b4bffa7d19af16b125c2918
Attached To
rGPGPASS GnuPG Password Manager
Event Timeline
Log In to Comment