diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/gpg/GpgContext.cpp | 18 | ||||
-rw-r--r-- | src/ui/keygen/KeygenDialog.cpp | 42 | ||||
-rw-r--r-- | src/ui/keygen/KeygenThread.cpp | 36 | ||||
-rw-r--r-- | src/ui/keygen/SubkeyGenerateDialog.cpp | 41 | ||||
-rw-r--r-- | src/ui/keygen/SubkeyGenerateThread.cpp | 36 |
5 files changed, 38 insertions, 135 deletions
diff --git a/src/gpg/GpgContext.cpp b/src/gpg/GpgContext.cpp index 0462433d..72c04ac9 100644 --- a/src/gpg/GpgContext.cpp +++ b/src/gpg/GpgContext.cpp @@ -197,7 +197,7 @@ namespace GpgME { /** Generate New Key with values params * */ - bool GpgContext::generateKey(GenKeyInfo *params) { + gpgme_error_t GpgContext::generateKey(GenKeyInfo *params) { auto userid_utf8 = params->getUserid().toUtf8(); const char *userid = userid_utf8.constData(); @@ -232,12 +232,12 @@ namespace GpgME { err = gpgme_op_createkey(mCtx, userid, algo, 0, expires, nullptr, flags); - if (err != GPG_ERR_NO_ERROR) { + if (gpgme_err_code(err) != GPG_ERR_NO_ERROR) { checkErr(err); - return false; + return err; } else { emit signalKeyDBChanged(); - return true; + return err; } } @@ -986,10 +986,10 @@ namespace GpgME { } } - bool GpgContext::generateSubkey(const GpgKey &key, GenKeyInfo *params) { + gpgme_error_t GpgContext::generateSubkey(const GpgKey &key, GenKeyInfo *params) { if (!params->isSubKey()) { - return false; + return GPG_ERR_CANCELED; } auto algo_utf8 = (params->getAlgo() + params->getKeySizeStr()).toUtf8(); @@ -1022,12 +1022,12 @@ namespace GpgME { auto gpgmeError = gpgme_op_createsubkey(mCtx, key.key_refer, algo, 0, expires, flags); - if (gpgmeError == GPG_ERR_NO_ERROR) { + if (gpgme_err_code(gpgmeError) == GPG_ERR_NO_ERROR) { emit signalKeyUpdated(key.id); - return true; + return gpgmeError; } else { checkErr(gpgmeError); - return false; + return gpgmeError; } } 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("")); diff --git a/src/ui/keygen/KeygenThread.cpp b/src/ui/keygen/KeygenThread.cpp deleted file mode 100644 index d7b9d840..00000000 --- a/src/ui/keygen/KeygenThread.cpp +++ /dev/null @@ -1,36 +0,0 @@ -/** - * This file is part of GPGFrontend. - * - * GPGFrontend is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Foobar is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with Foobar. If not, see <https://www.gnu.org/licenses/>. - * - * The initial version of the source code is inherited from gpg4usb-team. - * Their source code version also complies with GNU General Public License. - * - * The source code version of this software was modified and released - * by Saturneric<[email protected]> starting on May 12, 2021. - * - */ - -#include "ui/keygen/KeygenThread.h" - -KeyGenThread::KeyGenThread(GenKeyInfo* keyGenParams, GpgME::GpgContext *ctx) -: mCtx(ctx), keyGenParams(keyGenParams), QThread(nullptr) { - connect(this, &KeyGenThread::finished, this, &KeyGenThread::deleteLater); -} - -void KeyGenThread::run() { - bool success = mCtx->generateKey(keyGenParams); - emit signalKeyGenerated(success); - emit finished({}); -} diff --git a/src/ui/keygen/SubkeyGenerateDialog.cpp b/src/ui/keygen/SubkeyGenerateDialog.cpp index c545381f..3d709d81 100644 --- a/src/ui/keygen/SubkeyGenerateDialog.cpp +++ b/src/ui/keygen/SubkeyGenerateDialog.cpp @@ -23,6 +23,7 @@ */ #include "ui/keygen/SubkeyGenerateDialog.h" +#include "ui/WaitingDialog.h" SubkeyGenerateDialog::SubkeyGenerateDialog(GpgME::GpgContext *ctx, const GpgKey &key, QWidget *parent) : genKeyInfo(true), mCtx(ctx), mKey(key), QDialog(parent) { @@ -224,34 +225,27 @@ void SubkeyGenerateDialog::slotKeyGenAccept() { genKeyInfo.setExpired(dateEdit->dateTime()); } - kg = new SubkeyGenerateThread(mKey ,&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 Subkey...")); - - auto *waitMessage = new QLabel( - tr("Collecting random data for subkey 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->generateSubkey(mKey, &genKeyInfo); + }); + thread->start(); + auto *dialog = new WaitingDialog("Generating", this); dialog->show(); - while (!kg->isFinished() && kg->isRunning()) { + while (thread->isRunning()) { QCoreApplication::processEvents(); } dialog->close(); + if (gpgme_err_code(error) == GPG_ERR_NO_ERROR) { + QMessageBox::information(nullptr, tr("Success"), tr("The new subkey has been generated.")); + this->close(); + } else + QMessageBox::critical(this, tr("Failure"), tr(gpgme_strerror(error))); + } else { /** * create error message @@ -303,10 +297,3 @@ void SubkeyGenerateDialog::slotActivatedKeyType(int index) { genKeyInfo.setAlgo(this->keyTypeComboBox->itemText(index)); refresh_widgets_state(); } - -void SubkeyGenerateDialog::slotKeyGenResult(bool success) { - if(success) - QMessageBox::information(nullptr, tr("Success"), tr("The new subkey has been generated.")); - else - QMessageBox::critical(nullptr, tr("Failure"), tr("An error occurred during subkey generation.")); -} diff --git a/src/ui/keygen/SubkeyGenerateThread.cpp b/src/ui/keygen/SubkeyGenerateThread.cpp deleted file mode 100644 index 125f35f8..00000000 --- a/src/ui/keygen/SubkeyGenerateThread.cpp +++ /dev/null @@ -1,36 +0,0 @@ -/** - * This file is part of GPGFrontend. - * - * GPGFrontend is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Foobar is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with Foobar. If not, see <https://www.gnu.org/licenses/>. - * - * The initial version of the source code is inherited from gpg4usb-team. - * Their source code version also complies with GNU General Public License. - * - * The source code version of this software was modified and released - * by Saturneric<[email protected]><[email protected]> starting on May 12, 2021. - * - */ - -#include "ui/keygen/SubkeyGenerateThread.h" - -SubkeyGenerateThread::SubkeyGenerateThread(GpgKey key, GenKeyInfo *keyGenParams, GpgME::GpgContext *ctx) - : mKey(std::move(key)), keyGenParams(keyGenParams) , mCtx(ctx) { - connect(this, &SubkeyGenerateThread::finished, this, &SubkeyGenerateThread::deleteLater); -} - -void SubkeyGenerateThread::run() { - bool success = mCtx->generateSubkey(mKey, keyGenParams); - emit signalKeyGenerated(success); - emit finished({}); -} |