diff options
author | Anne Jan Brouwer <brouwer@annejan.com> | 2015-05-24 15:18:31 +0200 |
---|---|---|
committer | Anne Jan Brouwer <brouwer@annejan.com> | 2015-05-24 15:18:31 +0200 |
commit | 8a1120e93bbb60dd3e49024c414bd676060c8ee9 (patch) | |
tree | 7a05201b06b60e9bd3634a9a662e7c5457c0fe3a | |
parent | a6240506da4182c5a82b5931ac93a0fa89dbc336 (diff) |
gen-key code
-rw-r--r-- | dialog.cpp | 18 | ||||
-rw-r--r-- | dialog.h | 1 | ||||
-rw-r--r-- | keygendialog.cpp | 62 | ||||
-rw-r--r-- | keygendialog.h | 10 | ||||
-rw-r--r-- | keygendialog.ui | 3 | ||||
-rw-r--r-- | mainwindow.cpp | 21 | ||||
-rw-r--r-- | mainwindow.h | 1 |
7 files changed, 96 insertions, 20 deletions
@@ -356,7 +356,9 @@ void Dialog::addGPGId(bool addGPGId) { ui->checkBoxAddGPGId->setChecked(addGPGId); } - +/** + * @brief Dialog::wizard + */ void Dialog::wizard() { //mainWindow->checkConfig(); @@ -373,8 +375,6 @@ void Dialog::wizard() QStringList names = mainWindow->getSecretKeys(); //qDebug() << names; if (QFile(gpg).exists() && names.empty()) { - QMessageBox::critical(this, tr("Secret key not found"), - tr("You can not encrypt :(")); // TODO have usable gpg id wizrd :P KeygenDialog d(this); d.exec(); @@ -391,4 +391,14 @@ void Dialog::wizard() //ui->gpgPath->setText(gpg); - } +} + +/** + * @brief Dialog::genKey + * @param QString batch + * @return status + */ +bool Dialog::genKey(QString batch) +{ + return mainWindow->genKey(batch); +} @@ -42,6 +42,7 @@ public: bool hideContent(); bool addGPGId(); void wizard(); + bool genKey(QString); private slots: void on_radioButtonNative_clicked(); diff --git a/keygendialog.cpp b/keygendialog.cpp index 6ecbb2b4..744b80b9 100644 --- a/keygendialog.cpp +++ b/keygendialog.cpp @@ -1,12 +1,14 @@ #include "keygendialog.h" #include "ui_keygendialog.h" #include <QDebug> +#include <QMessageBox> -KeygenDialog::KeygenDialog(QWidget *parent) : +KeygenDialog::KeygenDialog(Dialog *parent) : QDialog(parent), ui(new Ui::KeygenDialog) { ui->setupUi(this); + dialog = parent; } KeygenDialog::~KeygenDialog() @@ -19,6 +21,11 @@ void KeygenDialog::on_passphrase1_textChanged(const QString &arg1) if (ui->passphrase1->text() == ui->passphrase2->text()) { ui->buttonBox->setEnabled(true); replace("Passphrase", arg1); + if (arg1 == "") { + no_protection(true); + } else { + no_protection(false); + } } else { ui->buttonBox->setEnabled(false); } @@ -67,22 +74,63 @@ void KeygenDialog::replace(QString key, QString value) ui->plainTextEdit->setPlainText(clear.join("\n")); } +/** + * @brief KeygenDialog::no_protection + * @param enable + */\ +void KeygenDialog::no_protection(bool enable) +{ + QStringList clear; + QString expert = ui->plainTextEdit->toPlainText(); + QStringList lines = expert.split(QRegExp("[\r\n]"),QString::SkipEmptyParts); + foreach (QString line, lines) { + bool remove = false; + if (!enable) { + if (line.indexOf("%no-protection") == 0) { + remove = true; + } + } else { + if (line.indexOf("Passphrase") == 0) { + clear.append(line); + line = "%no-protection"; + } + } + if (!remove) { + clear.append(line); + } + } + ui->plainTextEdit->setPlainText(clear.join("\n")); +} + +/** + * @brief KeygenDialog::done + * @param r + */ void KeygenDialog::done(int r) { if(QDialog::Accepted == r) // ok was pressed { - bool status = false; - - // TODO call for keygen - - if(status) // validate the data somehow + ui->widget->setEnabled(false); + ui->buttonBox->setEnabled(false); + ui->checkBox->setEnabled(false); + ui->plainTextEdit->setEnabled(false); + // some kind of animation or at-least explanation needed here + // people don't like wating :D + bool status = dialog->genKey(ui->plainTextEdit->toPlainText()); + if(status) { QDialog::done(r); return; } else { - // something went wrong? + QMessageBox::critical(this, tr("GPG gen-key error"), + tr("Something went wrong, I guess")); + ui->widget->setEnabled(true); + ui->buttonBox->setEnabled(true); + ui->checkBox->setEnabled(true); + on_checkBox_stateChanged(ui->checkBox->isChecked()); + // something went wrong, explain things? return; } } diff --git a/keygendialog.h b/keygendialog.h index f0f277c7..d808816a 100644 --- a/keygendialog.h +++ b/keygendialog.h @@ -2,6 +2,7 @@ #define KEYGENDIALOG_H #include <QDialog> +#include "dialog.h" namespace Ui { class KeygenDialog; @@ -12,24 +13,23 @@ class KeygenDialog : public QDialog Q_OBJECT public: - explicit KeygenDialog(QWidget *parent = 0); + explicit KeygenDialog(Dialog *parent = 0); ~KeygenDialog(); private slots: void on_passphrase1_textChanged(const QString &arg1); - void on_passphrase2_textChanged(const QString &arg1); - void on_checkBox_stateChanged(int arg1); - void on_email_textChanged(const QString &arg1); - void on_name_textChanged(const QString &arg1); private: Ui::KeygenDialog *ui; void replace(QString, QString); void done(int r); + void no_protection(bool enable); + Dialog *dialog; + }; #endif // KEYGENDIALOG_H diff --git a/keygendialog.ui b/keygendialog.ui index aea2ee71..e6e4be04 100644 --- a/keygendialog.ui +++ b/keygendialog.ui @@ -112,8 +112,7 @@ Name-Comment: QtPass Name-Email: Expire-Date: 0 Passphrase: -%pubring foo.pub -%secring foo.sec +%no-protection # Do a commit here, so that we can later print "done" :-) %commit %echo done</string> diff --git a/mainwindow.cpp b/mainwindow.cpp index 27bcd6e4..e042b7e8 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -32,7 +32,7 @@ MainWindow::MainWindow(QWidget *parent) : enableUiElements(true); wrapperRunning = false; execQueue = new QQueue<execQueueItem>; - ui->statusBar->showMessage(tr("Welcome to QtPass ") + VERSION, 2000); + ui->statusBar->showMessage(tr("Welcome to QtPass %1").arg(VERSION), 2000); firstRun = true; } @@ -566,7 +566,7 @@ void MainWindow::on_configButton_clicked() void MainWindow::on_lineEdit_textChanged(const QString &arg1) { ui->treeView->expandAll(); - ui->statusBar->showMessage(tr("Looking for: ") + arg1, 1000); + ui->statusBar->showMessage(tr("Looking for: %1").arg(arg1), 1000); QString query = arg1; query.replace(QRegExp(" "), ".*"); QRegExp regExp(query, Qt::CaseInsensitive); @@ -978,3 +978,20 @@ QStringList MainWindow::getSecretKeys() return names; } + +/** + * @brief Dialog::genKey + * @param QString batch + * @return status + */ +bool MainWindow::genKey(QString batch) +{ + ui->statusBar->showMessage(tr("Generating GPG key pair"), 60000); + currentAction = GPG_INTERNAL; + executeWrapper(gpgExecutable , "--gen-key --no-tty --batch", batch); + process->waitForFinished(600000); // ten minutes enough ? + if (process->exitStatus() != QProcess::NormalExit) { + return true; + } + return false; +} diff --git a/mainwindow.h b/mainwindow.h index ef57b6a0..4a2f6ebe 100644 --- a/mainwindow.h +++ b/mainwindow.h @@ -43,6 +43,7 @@ public: void setApp(SingleApplication* app); void setText(QString); QStringList getSecretKeys(); + bool genKey(QString); private slots: void on_updateButton_clicked(); |