diff options
author | Saturn&Eric <[email protected]> | 2021-12-13 18:46:23 +0000 |
---|---|---|
committer | GitHub <[email protected]> | 2021-12-13 18:46:23 +0000 |
commit | 5d8e24b7ce4620164c3268b4f1de43a30df19a86 (patch) | |
tree | 6defd5d68468a95de980752ccf2c4ef8a0753617 /src/ui/main_window/MainWindowSlotFunction.cpp | |
parent | Create SECURITY.md (diff) | |
parent | Update Translations & README. (diff) | |
download | GpgFrontend-5d8e24b7ce4620164c3268b4f1de43a30df19a86.tar.gz GpgFrontend-5d8e24b7ce4620164c3268b4f1de43a30df19a86.zip |
Merge pull request #32 from saturneric/developv2.0.2
v2.0.2-beta.2
Diffstat (limited to 'src/ui/main_window/MainWindowSlotFunction.cpp')
-rw-r--r-- | src/ui/main_window/MainWindowSlotFunction.cpp | 76 |
1 files changed, 46 insertions, 30 deletions
diff --git a/src/ui/main_window/MainWindowSlotFunction.cpp b/src/ui/main_window/MainWindowSlotFunction.cpp index 4ad33ac3..41549182 100644 --- a/src/ui/main_window/MainWindowSlotFunction.cpp +++ b/src/ui/main_window/MainWindowSlotFunction.cpp @@ -51,40 +51,56 @@ void MainWindow::slotEncrypt() { auto key_ids = mKeyList->getChecked(); - if (key_ids->empty()) { - QMessageBox::critical(nullptr, _("No Key Selected"), _("No Key Selected")); - return; - } - - auto key_getter = GpgFrontend::GpgKeyGetter::GetInstance(); - auto keys = GpgKeyGetter::GetInstance().GetKeys(key_ids); - for (const auto& key : *keys) { - if (!key.CanEncrActual()) { - QMessageBox::information( - nullptr, _("Invalid Operation"), - QString( - _("The selected key contains a key that does not actually have a " - "encrypt usage.")) + - "<br/><br/>" + _("For example the Following Key:") + " <br/>" + - QString::fromStdString(key.uids()->front().uid())); - return; - } - } - - auto tmp = std::make_unique<ByteArray>(); - GpgEncrResult result = nullptr; GpgError error; bool if_error = false; - process_operation(this, _("Encrypting"), [&]() { - try { - auto buffer = edit->curTextPage()->toPlainText().toUtf8().toStdString(); - error = GpgFrontend::BasicOperator::GetInstance().Encrypt( - std::move(keys), buffer, tmp, result); - } catch (const std::runtime_error& e) { - if_error = true; + auto tmp = std::make_unique<ByteArray>(); + + if (key_ids->empty()) { + // Symmetric Encrypt + auto ret = + QMessageBox::warning(this, _("Warning"), + _("No Key Selected. Do you want to encrypt with a " + "symmetric cipher using a passphrase?"), + QMessageBox::Ok | QMessageBox::Cancel); + + if (ret == QMessageBox::Cancel) return; + + process_operation(this, _("Symmetrically Encrypting"), [&]() { + try { + auto buffer = edit->curTextPage()->toPlainText().toUtf8().toStdString(); + error = GpgFrontend::BasicOperator::GetInstance().EncryptSymmetric( + buffer, tmp, result); + } catch (const std::runtime_error& e) { + if_error = true; + } + }); + } else { + auto key_getter = GpgFrontend::GpgKeyGetter::GetInstance(); + auto keys = GpgKeyGetter::GetInstance().GetKeys(key_ids); + for (const auto& key : *keys) { + if (!key.CanEncrActual()) { + QMessageBox::information( + nullptr, _("Invalid Operation"), + QString(_( + "The selected key contains a key that does not actually have a " + "encrypt usage.")) + + "<br/><br/>" + _("For example the Following Key:") + " <br/>" + + QString::fromStdString(key.uids()->front().uid())); + return; + } } - }); + + process_operation(this, _("Encrypting"), [&]() { + try { + auto buffer = edit->curTextPage()->toPlainText().toUtf8().toStdString(); + error = GpgFrontend::BasicOperator::GetInstance().Encrypt( + std::move(keys), buffer, tmp, result); + } catch (const std::runtime_error& e) { + if_error = true; + } + }); + } if (!if_error) { auto resultAnalyse = EncryptResultAnalyse(error, std::move(result)); |