diff options
-rw-r--r-- | dialog.ui | 4 | ||||
-rw-r--r-- | mainwindow.cpp | 2 | ||||
-rw-r--r-- | passworddialog.cpp | 46 | ||||
-rw-r--r-- | passworddialog.h | 1 | ||||
-rw-r--r-- | passworddialog.ui | 30 |
5 files changed, 57 insertions, 26 deletions
@@ -6,7 +6,7 @@ <rect> <x>0</x> <y>0</y> - <width>594</width> + <width>763</width> <height>309</height> </rect> </property> @@ -29,7 +29,7 @@ <item> <widget class="QTabWidget" name="tabWidget"> <property name="currentIndex"> - <number>1</number> + <number>3</number> </property> <widget class="QWidget" name="tab_3"> <attribute name="title"> diff --git a/mainwindow.cpp b/mainwindow.cpp index e6440d13..000ce336 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -948,8 +948,8 @@ void MainWindow::setPassword(QString file, bool overwrite, bool isNew = false) return; } PasswordDialog d(this); - d.setPassword(lastDecrypt); d.setTemplate(passTemplate); + d.setPassword(lastDecrypt); if (!d.exec()) { d.setPassword(NULL); return; diff --git a/passworddialog.cpp b/passworddialog.cpp index c3aee8b8..537628a2 100644 --- a/passworddialog.cpp +++ b/passworddialog.cpp @@ -1,5 +1,7 @@ #include "passworddialog.h" #include "ui_passworddialog.h" +#include <QLabel> +#include <QLineEdit> PasswordDialog::PasswordDialog(MainWindow *parent) : QDialog(parent), @@ -9,8 +11,6 @@ PasswordDialog::PasswordDialog(MainWindow *parent) : ui->setupUi(this); } - - PasswordDialog::~PasswordDialog() { delete ui; @@ -37,16 +37,48 @@ void PasswordDialog::setPassword(QString password) QStringList tokens = password.split("\n"); ui->lineEditPassword->setText(tokens[0]); tokens.pop_front(); + for (int i = 0; i < ui->formLayout->rowCount(); i++) { + QLayoutItem *item = ui->formLayout->itemAt(i, QFormLayout::FieldRole); + if (item == NULL) { + continue; + } + QWidget *widget = item->widget(); + for (int j = 0; j < tokens.length(); j++) { + QString token = tokens.at(j); + if (token.startsWith(widget->objectName()+':')) { + tokens.removeAt(j); + QString value = token.remove(0, widget->objectName().length()+1); + ((QLineEdit*)widget)->setText(value); + } + } + } ui->plainTextEdit->insertPlainText(tokens.join("\n")); } QString PasswordDialog::getPassword() { - return ui->lineEditPassword->text() + "\n" + ui->plainTextEdit->toPlainText(); + QString passFile = ui->lineEditPassword->text() + "\n"; + for (int i = 0; i < ui->formLayout->rowCount(); i++) { + QLayoutItem *item = ui->formLayout->itemAt(i, QFormLayout::FieldRole); + if (item == NULL) { + continue; + } + QWidget *widget = item->widget(); + QString text = ((QLineEdit*)widget)->text(); + if (text.isEmpty()) { + continue; + } + passFile += widget->objectName() + ":" + text + "\n"; + } + passFile += ui->plainTextEdit->toPlainText(); + return passFile; } -void PasswordDialog::setTemplate(QString fields) { - - //ui->templateHolderWidget->addWidget(); - return; +void PasswordDialog::setTemplate(QString rawFields) { + fields = rawFields.split('\n'); + foreach (QString field, fields) { + QLineEdit *line = new QLineEdit(); + line->setObjectName(field); + ui->formLayout->addRow(new QLabel(field), line); + } } diff --git a/passworddialog.h b/passworddialog.h index 64499665..b53c5917 100644 --- a/passworddialog.h +++ b/passworddialog.h @@ -28,6 +28,7 @@ private: MainWindow *mainWindow; QString passTemplate; void addFields(); + QStringList fields; }; diff --git a/passworddialog.ui b/passworddialog.ui index ec7de3b1..c38dc105 100644 --- a/passworddialog.ui +++ b/passworddialog.ui @@ -70,22 +70,20 @@ </widget> </item> <item> - <widget class="QWidget" name="templateHolderWidget" native="true"> - <layout class="QHBoxLayout" name="horizontalLayout_2"> - <property name="leftMargin"> - <number>0</number> - </property> - <property name="topMargin"> - <number>0</number> - </property> - <property name="rightMargin"> - <number>0</number> - </property> - <property name="bottomMargin"> - <number>0</number> - </property> - </layout> - </widget> + <layout class="QFormLayout" name="formLayout"> + <property name="sizeConstraint"> + <enum>QLayout::SetDefaultConstraint</enum> + </property> + <property name="fieldGrowthPolicy"> + <enum>QFormLayout::AllNonFixedFieldsGrow</enum> + </property> + <property name="labelAlignment"> + <set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter</set> + </property> + <property name="formAlignment"> + <set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop</set> + </property> + </layout> </item> <item> <widget class="QPlainTextEdit" name="plainTextEdit"/> |