diff options
author | Anne Jan Brouwer <brouwer@annejan.com> | 2015-08-07 02:03:18 +0200 |
---|---|---|
committer | Anne Jan Brouwer <brouwer@annejan.com> | 2015-08-07 02:03:18 +0200 |
commit | 20ea88682281317a0fabf4facd69f369d8c9031c (patch) | |
tree | f08a246bd539d61e6545b981251e35b4eca750ca | |
parent | 03921586a8dae45c28508d5b8c74ed54b32b462c (diff) |
magic fields
-rw-r--r-- | dialog.cpp | 8 | ||||
-rw-r--r-- | dialog.h | 2 | ||||
-rw-r--r-- | dialog.ui | 33 | ||||
-rw-r--r-- | mainwindow.cpp | 6 | ||||
-rw-r--r-- | mainwindow.h | 1 | ||||
-rw-r--r-- | passworddialog.cpp | 48 | ||||
-rw-r--r-- | passworddialog.h | 6 |
7 files changed, 74 insertions, 30 deletions
@@ -847,3 +847,11 @@ bool Dialog::autoPull() { bool Dialog::autoPush() { return ui->checkBoxAutoPush->isChecked(); } + +bool Dialog::templateAllFields() { + return ui->checkBoxTemplateAllFields->isChecked(); +} + +void Dialog::templateAllFields(bool templateAll) { + ui->checkBoxTemplateAllFields->setChecked(templateAll); +} @@ -73,6 +73,8 @@ public: void useTemplate(bool); QString getTemplate(); void setTemplate(QString); + void templateAllFields(bool); + bool templateAllFields(); bool autoPull(); void autoPull(bool); bool autoPush(); @@ -496,24 +496,23 @@ <string>Template</string> </attribute> <layout class="QVBoxLayout" name="verticalLayout_6"> - <property name="leftMargin"> - <number>6</number> - </property> - <property name="topMargin"> - <number>6</number> - </property> - <property name="rightMargin"> - <number>6</number> - </property> - <property name="bottomMargin"> - <number>6</number> - </property> <item> - <widget class="QCheckBox" name="checkBoxUseTemplate"> - <property name="text"> - <string>Use template</string> - </property> - </widget> + <layout class="QHBoxLayout" name="horizontalLayout_8"> + <item> + <widget class="QCheckBox" name="checkBoxUseTemplate"> + <property name="text"> + <string>Use template</string> + </property> + </widget> + </item> + <item> + <widget class="QCheckBox" name="checkBoxTemplateAllFields"> + <property name="text"> + <string>Show all fields templated</string> + </property> + </widget> + </item> + </layout> </item> <item> <widget class="QPlainTextEdit" name="plainTextEditTemplate"> diff --git a/mainwindow.cpp b/mainwindow.cpp index 6d9a759c..d0493bf0 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -239,6 +239,7 @@ bool MainWindow::checkConfig() { passTemplate = settings.value("passTemplate").toString(); useTemplate = settings.value("useTemplate").toBool(); + templateAllFields = settings.value("templateAllFields").toBool(); //qDebug() << version; @@ -377,6 +378,7 @@ void MainWindow::config() { d->setPasswordChars(passwordChars); d->useTemplate(useTemplate); d->setTemplate(passTemplate); + d->templateAllFields(templateAllFields); d->autoPull(autoPull); d->autoPush(autoPush); if (startupPhase) { @@ -409,6 +411,7 @@ void MainWindow::config() { passwordChars = d->getPasswordChars(); useTemplate = d->useTemplate(); passTemplate = d->getTemplate(); + templateAllFields = d->templateAllFields(); autoPush = d->autoPush(); autoPull = d->autoPull(); @@ -439,6 +442,7 @@ void MainWindow::config() { settings.setValue("passwordChars", passwordChars); settings.setValue("useTemplate", useTemplate); settings.setValue("passTemplate", passTemplate); + settings.setValue("templateAllFields", templateAllFields); settings.setValue("autoPull", autoPull ? "true" : "false"); settings.setValue("autoPush", autoPush ? "true" : "false"); @@ -950,6 +954,8 @@ void MainWindow::setPassword(QString file, bool overwrite, bool isNew = false) PasswordDialog d(this); d.setFile(file); d.setTemplate(passTemplate); + d.useTemplate(useTemplate); + d.templateAll(templateAllFields); d.setPassword(lastDecrypt); if (!d.exec()) { d.setPassword(NULL); diff --git a/mainwindow.h b/mainwindow.h index d48b8c94..5ff48ea6 100644 --- a/mainwindow.h +++ b/mainwindow.h @@ -127,6 +127,7 @@ private: QString passwordChars; bool useTemplate; QString passTemplate; + bool templateAllFields; bool autoPull; bool autoPush; void updateText(); diff --git a/passworddialog.cpp b/passworddialog.cpp index c7b3673a..08f91ff1 100644 --- a/passworddialog.cpp +++ b/passworddialog.cpp @@ -2,6 +2,7 @@ #include "ui_passworddialog.h" #include <QLabel> #include <QLineEdit> +#include <QDebug> PasswordDialog::PasswordDialog(MainWindow *parent) : QDialog(parent), @@ -37,18 +38,35 @@ 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; + if (templating) { + 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); + } + } } - 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); + if (allFields) { + for (int j = 0; j < tokens.length(); j++) { + QString token = tokens.at(j); + if (token.contains(':')) { + tokens.removeAt(j); + int colon = token.indexOf(':'); + QString field = token.left(colon); + QString value = token.right(token.length()-colon-1); + QLineEdit *line = new QLineEdit(); + line->setObjectName(field); + line->setText(value); + ui->formLayout->addRow(new QLabel(field), line); + } } } } @@ -89,3 +107,11 @@ void PasswordDialog::setTemplate(QString rawFields) { void PasswordDialog::setFile(QString file) { this->setWindowTitle(this->windowTitle()+" "+file); } + +void PasswordDialog::templateAll(bool templateAll) { + allFields = templateAll; +} + +void PasswordDialog::useTemplate(bool useTemplate) { + templating = useTemplate; +} diff --git a/passworddialog.h b/passworddialog.h index 4ba57a50..2ab2e5f8 100644 --- a/passworddialog.h +++ b/passworddialog.h @@ -19,6 +19,8 @@ public: QString getPassword(); void setTemplate(QString); void setFile(QString); + void useTemplate(bool); + void templateAll(bool); private slots: void on_checkBoxShow_stateChanged(int arg1); @@ -28,9 +30,9 @@ private: Ui::PasswordDialog *ui; MainWindow *mainWindow; QString passTemplate; - void addFields(); QStringList fields; - + bool templating; + bool allFields; }; #endif // PASSWORDDIALOG_H |