diff options
author | Saturneric <[email protected]> | 2021-07-06 02:56:19 +0000 |
---|---|---|
committer | Saturneric <[email protected]> | 2021-07-06 02:56:19 +0000 |
commit | cdaee767e93430a3495a2140ad6f81698d3458ba (patch) | |
tree | d1c1fc6a55daff71b66c80e99a96909d2c16c45a /src/ui/main_window/MainWindowSlotFunction.cpp | |
parent | Edit Project Configuration (diff) | |
download | GpgFrontend-cdaee767e93430a3495a2140ad6f81698d3458ba.tar.gz GpgFrontend-cdaee767e93430a3495a2140ad6f81698d3458ba.zip |
Fix issues.
Improve UI.
Diffstat (limited to '')
-rw-r--r-- | src/ui/main_window/MainWindowSlotFunction.cpp | 265 |
1 files changed, 152 insertions, 113 deletions
diff --git a/src/ui/main_window/MainWindowSlotFunction.cpp b/src/ui/main_window/MainWindowSlotFunction.cpp index 36d8f363..21d0af0d 100644 --- a/src/ui/main_window/MainWindowSlotFunction.cpp +++ b/src/ui/main_window/MainWindowSlotFunction.cpp @@ -61,9 +61,9 @@ void MainWindow::slotEncrypt() { thread->start(); - WaitingDialog *dialog = new WaitingDialog(this); + auto *dialog = new WaitingDialog(tr("Encrypting"), this); - while(thread->isRunning()) { + while (thread->isRunning()) { QApplication::processEvents(); } @@ -118,7 +118,18 @@ void MainWindow::slotSign() { gpgme_sign_result_t result = nullptr; - auto error = mCtx->sign(keys, edit->curTextPage()->toPlainText().toUtf8(), tmp, false, &result); + gpgme_error_t error; + auto thread = QThread::create([&]() { + error = mCtx->sign(keys, edit->curTextPage()->toPlainText().toUtf8(), tmp, false, &result); + }); + thread->start(); + + auto *dialog = new WaitingDialog(tr("Signing"), this); + while (thread->isRunning()) { + QApplication::processEvents(); + } + dialog->close(); + infoBoard->associateTextEdit(edit->curTextPage()); edit->slotFillTextEditWithText(QString::fromUtf8(*tmp)); @@ -156,8 +167,8 @@ void MainWindow::slotDecrypt() { }); thread->start(); - WaitingDialog *dialog = new WaitingDialog(this); - while(thread->isRunning()) { + auto *dialog = new WaitingDialog(tr("Decrypting"), this); + while (thread->isRunning()) { QApplication::processEvents(); } @@ -215,11 +226,10 @@ void MainWindow::slotVerify() { }); thread->start(); - WaitingDialog *dialog = new WaitingDialog(this); - while(thread->isRunning()) { + auto *dialog = new WaitingDialog(tr("Verifying"), this); + while (thread->isRunning()) { QApplication::processEvents(); } - dialog->close(); auto resultAnalyse = new VerifyResultAnalyse(mCtx, error, result); @@ -268,27 +278,27 @@ void MainWindow::slotEncryptSign() { if (!key_can_sign && !key_can_encr) { QMessageBox::critical(nullptr, - tr("Invalid KeyPair"), - tr("The selected keypair cannot be used for signing and encryption at the same time.<br/>") - + tr("<br/>For example the Following Key: <br/>") + key.uids.first().uid); + tr("Invalid KeyPair"), + tr("The selected keypair cannot be used for signing and encryption at the same time.<br/>") + + tr("<br/>For example the Following Key: <br/>") + key.uids.first().uid); return; } - if(key_can_sign) can_sign = true; - if(key_can_encr) can_encr = true; + if (key_can_sign) can_sign = true; + if (key_can_encr) can_encr = true; } - if(!can_encr) { - QMessageBox::critical(nullptr, - tr("Incomplete Operation"), - tr("None of the selected key pairs can provide the encryption function.")); - return; + if (!can_encr) { + QMessageBox::critical(nullptr, + tr("Incomplete Operation"), + tr("None of the selected key pairs can provide the encryption function.")); + return; } - if(!can_sign) { - QMessageBox::warning(nullptr, - tr("Incomplete Operation"), - tr("None of the selected key pairs can provide the signature function.")); + if (!can_sign) { + QMessageBox::warning(nullptr, + tr("Incomplete Operation"), + tr("None of the selected key pairs can provide the signature function.")); } auto *tmp = new QByteArray(); @@ -300,18 +310,18 @@ void MainWindow::slotEncryptSign() { gpgme_error_t error; auto thread = QThread::create([&]() { error = mCtx->encryptSign(keys, edit->curTextPage()->toPlainText().toUtf8(), tmp, &encr_result, - &sign_result); + &sign_result); }); thread->start(); - WaitingDialog *dialog = new WaitingDialog(this); - while(thread->isRunning()) { + auto *dialog = new WaitingDialog(tr("Encrypting and Signing"), this); + while (thread->isRunning()) { QApplication::processEvents(); } dialog->close(); - if(gpgme_err_code(error) == GPG_ERR_NO_ERROR) { + if (gpgme_err_code(error) == GPG_ERR_NO_ERROR) { auto *tmp2 = new QString(*tmp); edit->slotFillTextEditWithText(*tmp2); } @@ -356,8 +366,8 @@ void MainWindow::slotDecryptVerify() { }); thread->start(); - WaitingDialog *dialog = new WaitingDialog(this); - while(thread->isRunning()) { + WaitingDialog *dialog = new WaitingDialog(tr("Decrypting and Verifying"), this); + while (thread->isRunning()) { QApplication::processEvents(); } @@ -495,22 +505,26 @@ void MainWindow::slotFileEncrypt() { } } - try { - gpgme_encrypt_result_t result; + gpgme_encrypt_result_t result; - gpgme_error_t error; - auto thread = QThread::create([&]() { + gpgme_error_t error; + bool if_error = false; + auto thread = QThread::create([&]() { + try { error = GpgFileOpera::encryptFile(mCtx, keys, path, &result); - }); - thread->start(); - - WaitingDialog *dialog = new WaitingDialog(this); - while(thread->isRunning()) { - QApplication::processEvents(); + } catch (const std::runtime_error &e) { + if_error = true; } + }); + thread->start(); - dialog->close(); + auto *dialog = new WaitingDialog(tr("Encrypting"), this); + while (thread->isRunning()) { + QApplication::processEvents(); + } + dialog->close(); + if(!if_error) { auto resultAnalyse = new EncryptResultAnalyse(error, result); auto &reportText = resultAnalyse->getResultReport(); infoBoard->associateTabWidget(edit->tabWidget); @@ -526,11 +540,10 @@ void MainWindow::slotFileEncrypt() { delete resultAnalyse; fileTreeView->update(); - - } catch (const std::runtime_error &e) { + } else { QMessageBox::critical(this, tr("Error"), tr("An error occurred during operation.")); + return; } - } void MainWindow::slotFileDecrypt() { @@ -572,21 +585,27 @@ void MainWindow::slotFileDecrypt() { return; } - try { - gpgme_decrypt_result_t result; - gpgme_error_t error; - auto thread = QThread::create([&]() { - error = GpgFileOpera::decryptFile(mCtx, path, &result); - }); - thread->start(); + gpgme_decrypt_result_t result; + gpgme_error_t error; + bool if_error = false; - WaitingDialog *dialog = new WaitingDialog(this); - while(thread->isRunning()) { - QApplication::processEvents(); + auto thread = QThread::create([&]() { + try { + error = GpgFileOpera::decryptFile(mCtx, path, &result); + } catch (const std::runtime_error &e) { + if_error = true; } + }); + thread->start(); - dialog->close(); + auto *dialog = new WaitingDialog("Decrypting", this); + while (thread->isRunning()) { + QApplication::processEvents(); + } + dialog->close(); + + if(!if_error) { auto resultAnalyse = new DecryptResultAnalyse(mCtx, error, result); auto &reportText = resultAnalyse->getResultReport(); infoBoard->associateTabWidget(edit->tabWidget); @@ -602,7 +621,7 @@ void MainWindow::slotFileDecrypt() { delete resultAnalyse; fileTreeView->update(); - } catch (const std::runtime_error &e) { + } else { QMessageBox::critical(this, tr("Error"), tr("An error occurred during operation.")); return; } @@ -661,20 +680,27 @@ void MainWindow::slotFileSign() { } } - try { - gpgme_sign_result_t result; - gpgme_error_t error; - auto thread = QThread::create([&]() { - error = GpgFileOpera::signFile(mCtx, keys, path, &result); - }); - thread->start(); + gpgme_sign_result_t result; + gpgme_error_t error; + bool if_error = false; - WaitingDialog *dialog = new WaitingDialog(this); - while(thread->isRunning()) { - QApplication::processEvents(); + auto thread = QThread::create([&]() { + try { + error = GpgFileOpera::signFile(mCtx, keys, path, &result); + } catch (const std::runtime_error &e) { + if_error = true; } + }); + thread->start(); - dialog->close(); + auto *dialog = new WaitingDialog(tr("Signing"), this); + while (thread->isRunning()) { + QApplication::processEvents(); + } + + dialog->close(); + + if(!if_error) { auto resultAnalyse = new SignResultAnalyse(error, result); auto &reportText = resultAnalyse->getResultReport(); @@ -692,8 +718,9 @@ void MainWindow::slotFileSign() { fileTreeView->update(); - } catch (const std::runtime_error &e) { + } else { QMessageBox::critical(this, tr("Error"), tr("An error occurred during operation.")); + return; } fileTreeView->update(); @@ -709,11 +736,10 @@ void MainWindow::slotFileVerify() { QString signFilePath, dataFilePath; - if(fileInfo.suffix() == "gpg") { + if (fileInfo.suffix() == "gpg") { dataFilePath = path; signFilePath = path; - } - else if (fileInfo.suffix() == "sig") { + } else if (fileInfo.suffix() == "sig") { int pos = path.lastIndexOf(QChar('.')); dataFilePath = path.left(pos); signFilePath = path; @@ -743,7 +769,7 @@ void MainWindow::slotFileVerify() { gpgme_error_t error; bool if_error = false; auto thread = QThread::create([&]() { - try{ + try { error = GpgFileOpera::verifyFile(mCtx, dataFilePath, &result); } catch (const std::runtime_error &e) { if_error = true; @@ -751,13 +777,13 @@ void MainWindow::slotFileVerify() { }); thread->start(); - WaitingDialog *dialog = new WaitingDialog(this); - while(thread->isRunning()) { + auto *dialog = new WaitingDialog(tr("Verifying"), this); + while (thread->isRunning()) { QApplication::processEvents(); } dialog->close(); - if(!if_error) { + if (!if_error) { auto resultAnalyse = new VerifyResultAnalyse(mCtx, error, result); auto &reportText = resultAnalyse->getResultReport(); infoBoard->associateTabWidget(edit->tabWidget); @@ -832,45 +858,51 @@ void MainWindow::slotFileEncryptSign() { if (!key_can_sign && !key_can_encr) { QMessageBox::critical(nullptr, - tr("Invalid KeyPair"), - tr("The selected keypair cannot be used for signing and encryption at the same time.<br/>") - + tr("<br/>For example the Following Key: <br/>") + key.uids.first().uid); + tr("Invalid KeyPair"), + tr("The selected keypair cannot be used for signing and encryption at the same time.<br/>") + + tr("<br/>For example the Following Key: <br/>") + key.uids.first().uid); return; } - if(key_can_sign) can_sign = true; - if(key_can_encr) can_encr = true; + if (key_can_sign) can_sign = true; + if (key_can_encr) can_encr = true; } - if(!can_encr) { - QMessageBox::critical(nullptr, - tr("Incomplete Operation"), - tr("None of the selected key pairs can provide the encryption function.")); - return; + if (!can_encr) { + QMessageBox::critical(nullptr, + tr("Incomplete Operation"), + tr("None of the selected key pairs can provide the encryption function.")); + return; } - if(!can_sign) { - QMessageBox::warning(nullptr, - tr("Incomplete Operation"), - tr("None of the selected key pairs can provide the signature function.")); + if (!can_sign) { + QMessageBox::warning(nullptr, + tr("Incomplete Operation"), + tr("None of the selected key pairs can provide the signature function.")); } - try { + gpgme_encrypt_result_t encr_result = nullptr; + gpgme_sign_result_t sign_result = nullptr; - gpgme_encrypt_result_t encr_result = nullptr; - gpgme_sign_result_t sign_result = nullptr; + gpgme_error_t error; + bool if_error = false; - gpgme_error_t error; - auto thread = QThread::create([&]() { + auto thread = QThread::create([&]() { + try { error = GpgFileOpera::encryptSignFile(mCtx, keys, path, &encr_result, &sign_result); - }); - thread->start(); - - WaitingDialog *dialog = new WaitingDialog(this); - while(thread->isRunning()) { - QApplication::processEvents(); + } catch (const std::runtime_error &e) { + if_error = true; } - dialog->close(); + }); + thread->start(); + + WaitingDialog *dialog = new WaitingDialog(tr("Encrypting and Signing"), this); + while (thread->isRunning()) { + QApplication::processEvents(); + } + dialog->close(); + + if(!if_error) { auto resultAnalyseEncr = new EncryptResultAnalyse(error, encr_result); auto resultAnalyseSign = new SignResultAnalyse(error, sign_result); @@ -891,8 +923,9 @@ void MainWindow::slotFileEncryptSign() { fileTreeView->update(); - } catch (std::runtime_error &e) { + } else { QMessageBox::critical(this, tr("Error"), tr("An error occurred during operation.")); + return; } } @@ -924,22 +957,28 @@ void MainWindow::slotFileDecryptVerify() { outFileName = path + ".out"; } - try { + gpgme_decrypt_result_t d_result = nullptr; + gpgme_verify_result_t v_result = nullptr; - gpgme_decrypt_result_t d_result = nullptr; - gpgme_verify_result_t v_result = nullptr; + gpgme_error_t error; + bool if_error = false; - gpgme_error_t error; - auto thread = QThread::create([&]() { + auto thread = QThread::create([&]() { + try { error = GpgFileOpera::decryptVerifyFile(mCtx, path, &d_result, &v_result); - }); - thread->start(); - - WaitingDialog *dialog = new WaitingDialog(this); - while(thread->isRunning()) { - QApplication::processEvents(); + } catch (const std::runtime_error &e) { + if_error = true; } - dialog->close(); + }); + thread->start(); + + auto *dialog = new WaitingDialog(tr("Decrypting and Verifying"), this); + while (thread->isRunning()) { + QApplication::processEvents(); + } + dialog->close(); + + if(!if_error) { infoBoard->associateFileTreeView(edit->curFilePage()); auto resultAnalyseDecrypt = new DecryptResultAnalyse(mCtx, error, d_result); @@ -964,7 +1003,7 @@ void MainWindow::slotFileDecryptVerify() { delete resultAnalyseVerify; fileTreeView->update(); - } catch (std::runtime_error &e) { + } else { QMessageBox::critical(this, tr("Error"), tr("An error occurred during operation.")); return; } |