summaryrefslogtreecommitdiffstats
path: root/src/passworddialog.cpp
diff options
context:
space:
mode:
authorLukas Vogel <lukedirtwalker@gmail.com>2018-03-15 09:11:36 +0100
committerLukas Vogel <lukedirtwalker@gmail.com>2018-03-15 10:04:59 +0100
commit5e07132b9e89ed7c0f9f3b07e7fdc0de42525f1d (patch)
tree15ecc2da7cf6c1241d8c448e4ee62f8918b3c478 /src/passworddialog.cpp
parent5eb8d771b94dce458e7761131b8c0b85e3e127f4 (diff)
Use FileContent parsing in PasswordDialog
Diffstat (limited to 'src/passworddialog.cpp')
-rw-r--r--src/passworddialog.cpp62
1 files changed, 23 insertions, 39 deletions
diff --git a/src/passworddialog.cpp b/src/passworddialog.cpp
index 56718b2e..e1c72f6b 100644
--- a/src/passworddialog.cpp
+++ b/src/passworddialog.cpp
@@ -1,6 +1,7 @@
#include "passworddialog.h"
#include "debughelper.h"
#include "qtpasssettings.h"
+#include "filecontent.h"
#include "ui_passworddialog.h"
#include <QDebug>
#include <QLabel>
@@ -58,46 +59,29 @@ void PasswordDialog::on_createPasswordButton_clicked() {
* @param password
*/
void PasswordDialog::setPassword(QString password) {
- QStringList tokens = password.split("\n");
- ui->lineEditPassword->setText(tokens[0]);
- tokens.pop_front();
- if (templating) {
- QWidget *previous = ui->checkBoxShow;
- for (QLineEdit *line : templateLines) {
- for (int j = 0; j < tokens.length(); ++j) {
- QString token = tokens.at(j);
- if (token.startsWith(line->objectName() + ':')) {
- tokens.removeAt(j);
- QString value = token.remove(0, line->objectName().length() + 1);
- line->setText(value.trimmed());
- }
- }
- previous = line;
- }
- if (allFields) {
- otherLines.clear();
- for (int j = 0; j < tokens.length(); ++j) {
- QString token = tokens.at(j);
- if (token.contains(':')) {
- int colon = token.indexOf(':');
- QString field = token.left(colon);
- QString value = token.right(token.length() - colon - 1);
- if (!fields.contains(field) && value.startsWith("//"))
- continue; // colon is probably from a url
- QLineEdit *line = new QLineEdit();
- line->setObjectName(field.trimmed());
- line->setText(value.trimmed());
- ui->formLayout->addRow(new QLabel(field), line);
- setTabOrder(previous, line);
- otherLines.append(line);
- previous = line;
- tokens.removeAt(j);
- --j; // tokens.length() also got shortened by the remove..
- }
- }
- }
+ FileContent fileContent = FileContent::parse(password, templating ? fields : QStringList(), allFields);
+ ui->lineEditPassword->setText(fileContent.getPassword());
+
+ QWidget *previous = ui->checkBoxShow;
+ // first set templated values
+ NamedValues namedValues = fileContent.getNamedValues();
+ for (QLineEdit *line : templateLines) {
+ line->setText(namedValues.takeValue(line->objectName()));
+ previous = line;
}
- ui->plainTextEdit->insertPlainText(tokens.join("\n"));
+ // show remaining values (if there are)
+ otherLines.clear();
+ for (const NamedValue &nv : namedValues) {
+ QLineEdit *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());
}
/**