diff options
author | Saturneric <[email protected]> | 2021-07-20 19:01:06 +0000 |
---|---|---|
committer | Saturneric <[email protected]> | 2021-07-20 19:01:06 +0000 |
commit | 69e33d6eeef7d77385d21c5b969df76cb0fbc0e7 (patch) | |
tree | 333861b3e1691dd720c410388639a429458c5eb5 /src/ui/keygen/KeygenDialog.cpp | |
parent | Fix problem that macos cannot use multi-languages. (diff) | |
download | GpgFrontend-69e33d6eeef7d77385d21c5b969df76cb0fbc0e7.tar.gz GpgFrontend-69e33d6eeef7d77385d21c5b969df76cb0fbc0e7.zip |
Fix Keygen Problem
Diffstat (limited to 'src/ui/keygen/KeygenDialog.cpp')
-rw-r--r-- | src/ui/keygen/KeygenDialog.cpp | 42 |
1 files changed, 15 insertions, 27 deletions
diff --git a/src/ui/keygen/KeygenDialog.cpp b/src/ui/keygen/KeygenDialog.cpp index 7991ddd1..98216dc6 100644 --- a/src/ui/keygen/KeygenDialog.cpp +++ b/src/ui/keygen/KeygenDialog.cpp @@ -23,6 +23,7 @@ */ #include "ui/keygen/KeygenDialog.h" +#include "ui/WaitingDialog.h" KeyGenDialog::KeyGenDialog(GpgME::GpgContext *ctx, QWidget *parent) : QDialog(parent), mCtx(ctx) { @@ -92,34 +93,28 @@ void KeyGenDialog::slotKeyGenAccept() { genKeyInfo.setExpired(dateEdit->dateTime()); } - kg = new KeyGenThread(&genKeyInfo, mCtx); - connect(kg, SIGNAL(signalKeyGenerated(bool)), this, SLOT(slotKeyGenResult(bool))); - kg->start(); - - this->accept(); - - auto *dialog = new QDialog(this, Qt::CustomizeWindowHint | Qt::WindowTitleHint); - dialog->setModal(true); - dialog->setWindowTitle(tr("Generating Key...")); - - auto *waitMessage = new QLabel( - tr("Collecting random data for key generation.\n This may take a while.\n To speed up the process use your computer\n (e.g. browse the net, listen to music,...)")); - auto *pb = new QProgressBar(); - pb->setRange(0, 0); - - auto *layout = new QVBoxLayout(dialog); - layout->addWidget(waitMessage); - layout->addWidget(pb); - dialog->setLayout(layout); + gpgme_error_t error = false; + auto thread = QThread::create([&]() { + error = mCtx->generateKey(&genKeyInfo); + }); + thread->start(); + auto *dialog = new WaitingDialog("Generating", this); dialog->show(); - while (kg->isRunning()) { + while (thread->isRunning()) { QCoreApplication::processEvents(); } dialog->close(); + if(gpgme_err_code(error) == GPG_ERR_NO_ERROR) { + QMessageBox::information(this, tr("Success"), tr("The new key pair has been generated.")); + this->close(); + } + else + QMessageBox::critical(this, tr("Failure"), tr(gpgme_strerror(error))); + } else { /** * create error message @@ -307,13 +302,6 @@ bool KeyGenDialog::check_email_address(const QString &str) { return re_email.match(str).hasMatch(); } -void KeyGenDialog::slotKeyGenResult(bool success) { - if(success) - QMessageBox::information(nullptr, tr("Success"), tr("The new key pair has been generated.")); - else - QMessageBox::critical(nullptr, tr("Failure"), tr("An error occurred during key generation.")); -} - QGroupBox *KeyGenDialog::create_basic_info_group_box() { errorLabel = new QLabel(tr("")); |