aboutsummaryrefslogtreecommitdiffstats
path: root/src/ui/main_window/MainWindowSlotFunction.cpp
diff options
context:
space:
mode:
authorsaturneric <[email protected]>2023-12-31 06:10:31 +0000
committersaturneric <[email protected]>2023-12-31 06:10:31 +0000
commit5030380bc5e155252655e2ad71e63c15271054c4 (patch)
tree80a4592451267c83da6f8569b3999539884d08e9 /src/ui/main_window/MainWindowSlotFunction.cpp
parentfeat: do not load entire data to memory in libarchive operations (diff)
downloadGpgFrontend-5030380bc5e155252655e2ad71e63c15271054c4.tar.gz
GpgFrontend-5030380bc5e155252655e2ad71e63c15271054c4.zip
feat: fully test basical operations of archive and file
Diffstat (limited to 'src/ui/main_window/MainWindowSlotFunction.cpp')
-rw-r--r--src/ui/main_window/MainWindowSlotFunction.cpp374
1 files changed, 6 insertions, 368 deletions
diff --git a/src/ui/main_window/MainWindowSlotFunction.cpp b/src/ui/main_window/MainWindowSlotFunction.cpp
index 444fe54a..e4038f66 100644
--- a/src/ui/main_window/MainWindowSlotFunction.cpp
+++ b/src/ui/main_window/MainWindowSlotFunction.cpp
@@ -32,22 +32,14 @@
#include "MainWindow.h"
#include "core/GpgConstants.h"
#include "core/GpgModel.h"
-#include "core/function/gpg/GpgBasicOperator.h"
#include "core/function/gpg/GpgKeyGetter.h"
#include "core/function/gpg/GpgKeyImportExporter.h"
#include "core/function/gpg/GpgKeyManager.h"
-#include "core/function/result_analyse/GpgDecryptResultAnalyse.h"
-#include "core/function/result_analyse/GpgEncryptResultAnalyse.h"
-#include "core/function/result_analyse/GpgSignResultAnalyse.h"
-#include "core/function/result_analyse/GpgVerifyResultAnalyse.h"
-#include "core/model/DataObject.h"
-#include "core/model/GpgEncryptResult.h"
#include "core/module/ModuleManager.h"
#include "core/typedef/GpgTypedef.h"
#include "core/utils/CommonUtils.h"
#include "core/utils/GpgUtils.h"
#include "ui/UserInterfaceUtils.h"
-#include "ui/dialog/SignersPicker.h"
#include "ui/dialog/help/AboutDialog.h"
#include "ui/dialog/import_export/KeyUploadDialog.h"
#include "ui/dialog/keypair_details/KeyDetailsDialog.h"
@@ -56,366 +48,6 @@
namespace GpgFrontend::UI {
-/**
- * Encrypt Entry(Text & File)
- */
-void MainWindow::SlotEncrypt() {
- if (edit_->SlotCurPageTextEdit() == nullptr) {
- // ignore
- return;
- }
-
- auto key_ids = m_key_list_->GetChecked();
-
- if (key_ids->empty()) {
- // Symmetric Encrypt
- auto ret = QMessageBox::information(
- this, _("Symmetric Encryption"),
- _("No Key Checked. Do you want to encrypt with a "
- "symmetric cipher using a passphrase?"),
- QMessageBox::Ok | QMessageBox::Cancel);
-
- if (ret == QMessageBox::Cancel) return;
-
- auto buffer = GFBuffer(edit_->CurTextPage()->GetTextPage()->toPlainText());
- CommonUtils::WaitForOpera(
- this, _("Symmetrically Encrypting"),
- [this, buffer](const OperaWaitingHd& op_hd) {
- GpgFrontend::GpgBasicOperator::GetInstance().EncryptSymmetric(
- buffer, true,
- [this, op_hd](GpgError err, const DataObjectPtr& data_obj) {
- // stop waiting
- op_hd();
-
- if (data_obj == nullptr ||
- !data_obj->Check<GpgEncryptResult, GFBuffer>()) {
- throw std::runtime_error("data object doesn't pass checking");
- }
-
- auto result = ExtractParams<GpgEncryptResult>(data_obj, 0);
- auto buffer = ExtractParams<GFBuffer>(data_obj, 1);
-
- auto result_analyse = GpgEncryptResultAnalyse(err, result);
- result_analyse.Analyse();
- process_result_analyse(edit_, info_board_, result_analyse);
-
- if (CheckGpgError(err) == GPG_ERR_NO_ERROR) {
- edit_->SlotFillTextEditWithText(buffer.ConvertToQByteArray());
- }
- info_board_->ResetOptionActionsMenu();
- });
- });
-
- return;
- }
-
- auto keys = GpgKeyGetter::GetInstance().GetKeys(key_ids);
- for (const auto& key : *keys) {
- if (!key.IsHasActualEncryptionCapability()) {
- QMessageBox::information(
- this, _("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.GetUIDs()->front().GetUID()));
- return;
- }
- }
-
- auto buffer = GFBuffer(edit_->CurTextPage()->GetTextPage()->toPlainText());
- CommonUtils::WaitForOpera(
- this, _("Encrypting"), [this, keys, buffer](const OperaWaitingHd& op_hd) {
- GpgFrontend::GpgBasicOperator::GetInstance().Encrypt(
- {keys->begin(), keys->end()}, buffer, true,
- [this, op_hd](GpgError err, const DataObjectPtr& data_obj) {
- // stop waiting
- op_hd();
-
- if (data_obj == nullptr ||
- !data_obj->Check<GpgEncryptResult, GFBuffer>()) {
- throw std::runtime_error("data object doesn't pass checking");
- }
-
- auto result = ExtractParams<GpgEncryptResult>(data_obj, 0);
- auto buffer = ExtractParams<GFBuffer>(data_obj, 1);
-
- auto result_analyse = GpgEncryptResultAnalyse(err, result);
- result_analyse.Analyse();
- process_result_analyse(edit_, info_board_, result_analyse);
-
- if (CheckGpgError(err) == GPG_ERR_NO_ERROR) {
- edit_->SlotFillTextEditWithText(buffer.ConvertToQByteArray());
- }
- info_board_->ResetOptionActionsMenu();
- });
- });
-}
-
-void MainWindow::slot_sign() {
- if (edit_->TabCount() == 0 || edit_->SlotCurPageTextEdit() == nullptr) {
- if (edit_->SlotCurPageFileTreeView() != nullptr) this->SlotFileSign();
- return;
- }
-
- auto key_ids = m_key_list_->GetPrivateChecked();
-
- if (key_ids->empty()) {
- QMessageBox::critical(
- this, _("No Key Checked"),
- _("Please check the key in the key toolbox on the right."));
- return;
- }
-
- auto keys = GpgKeyGetter::GetInstance().GetKeys(key_ids);
- for (const auto& key : *keys) {
- if (!key.IsHasActualSigningCapability()) {
- QMessageBox::information(
- this, _("Invalid Operation"),
- QString(
- _("The selected key contains a key that does not actually have a "
- "signature usage.")) +
- "<br/><br/>" + _("For example the Following Key:") + "<br/>" +
- key.GetUIDs()->front().GetUID().c_str());
- return;
- }
- }
-
- // set input buffer
- auto buffer = GFBuffer(edit_->CurTextPage()->GetTextPage()->toPlainText());
- CommonUtils::WaitForOpera(
- this, _("Signing"), [this, keys, buffer](const OperaWaitingHd& hd) {
- GpgFrontend::GpgBasicOperator::GetInstance().Sign(
- {keys->begin(), keys->end()}, buffer, GPGME_SIG_MODE_CLEAR, true,
- [this, hd](GpgError err, const DataObjectPtr& data_obj) {
- // stop waiting
- hd();
-
- if (data_obj == nullptr ||
- !data_obj->Check<GpgSignResult, GFBuffer>()) {
- throw std::runtime_error("data object doesn't pass checking");
- }
- auto sign_result = ExtractParams<GpgSignResult>(data_obj, 0);
- auto sign_out_buffer = ExtractParams<GFBuffer>(data_obj, 1);
- auto result_analyse = GpgSignResultAnalyse(err, sign_result);
- result_analyse.Analyse();
- process_result_analyse(edit_, info_board_, result_analyse);
-
- if (CheckGpgError(err) == GPG_ERR_NO_ERROR) {
- edit_->SlotFillTextEditWithText(
- sign_out_buffer.ConvertToQByteArray());
- }
- });
- });
-}
-
-void MainWindow::SlotDecrypt() {
- if (edit_->SlotCurPageTextEdit() == nullptr) {
- return;
- }
-
- // data to transfer into task
- auto buffer = GFBuffer(edit_->CurTextPage()->GetTextPage()->toPlainText());
-
- CommonUtils::WaitForOpera(
- this, _("Decrypting"), [this, buffer](const OperaWaitingHd& hd) {
- GpgFrontend::GpgBasicOperator::GetInstance().Decrypt(
- buffer, [this, hd](GpgError err, const DataObjectPtr& data_obj) {
- // stop waiting
- hd();
-
- if (data_obj == nullptr ||
- !data_obj->Check<GpgDecryptResult, GFBuffer>()) {
- throw std::runtime_error("data object doesn't pass checking");
- }
- auto decrypt_result =
- ExtractParams<GpgDecryptResult>(data_obj, 0);
- auto out_buffer = ExtractParams<GFBuffer>(data_obj, 1);
- auto result_analyse =
- GpgDecryptResultAnalyse(err, decrypt_result);
- result_analyse.Analyse();
- process_result_analyse(edit_, info_board_, result_analyse);
-
- if (CheckGpgError(err) == GPG_ERR_NO_ERROR) {
- edit_->SlotFillTextEditWithText(
- out_buffer.ConvertToQByteArray());
- }
- });
- });
-}
-
-void MainWindow::slot_verify() {
- if (edit_->TabCount() == 0 || edit_->SlotCurPageTextEdit() == nullptr) {
- if (edit_->SlotCurPageFileTreeView() != nullptr) this->SlotFileVerify();
- return;
- }
-
- // set input buffer
- auto buffer = GFBuffer(edit_->CurTextPage()->GetTextPage()->toPlainText());
-
- CommonUtils::WaitForOpera(
- this, _("Verifying"), [this, buffer](const OperaWaitingHd& hd) {
- GpgFrontend::GpgBasicOperator::GetInstance().Verify(
- buffer, GFBuffer(),
- [this, hd](GpgError err, const DataObjectPtr& data_obj) {
- // stop waiting
- hd();
-
- if (data_obj == nullptr || !data_obj->Check<GpgVerifyResult>()) {
- throw std::runtime_error("data object doesn't pass checking");
- }
- auto verify_result = ExtractParams<GpgVerifyResult>(data_obj, 0);
-
- // analyse result
- auto result_analyse = GpgVerifyResultAnalyse(err, verify_result);
- result_analyse.Analyse();
- process_result_analyse(edit_, info_board_, result_analyse);
- });
- });
-}
-
-void MainWindow::slot_encrypt_sign() {
- if (edit_->TabCount() == 0 || edit_->SlotCurPageTextEdit() == nullptr) {
- if (edit_->SlotCurPageFileTreeView() != nullptr)
- this->SlotFileEncryptSign();
- return;
- }
-
- auto key_ids = m_key_list_->GetChecked();
-
- if (key_ids->empty()) {
- QMessageBox::critical(
- this, _("No Key Checked"),
- _("Please check some key in the key toolbox on the right."));
- return;
- }
-
- auto keys = GpgKeyGetter::GetInstance().GetKeys(key_ids);
-
- for (const auto& key : *keys) {
- bool key_can_encrypt = key.IsHasActualEncryptionCapability();
-
- if (!key_can_encrypt) {
- QMessageBox::critical(
- this, _("Invalid KeyPair"),
- QString(_("The selected keypair cannot be used for encryption.")) +
- "<br/><br/>" + _("For example the Following Key:") + " <br/>" +
- QString::fromStdString(key.GetUIDs()->front().GetUID()));
- return;
- }
- }
-
- auto* signers_picker = new SignersPicker(this);
- QEventLoop loop;
- connect(signers_picker, &SignersPicker::finished, &loop, &QEventLoop::quit);
- loop.exec();
-
- // return when canceled
- if (!signers_picker->GetStatus()) return;
-
- auto signer_key_ids = signers_picker->GetCheckedSigners();
- auto signer_keys = GpgKeyGetter::GetInstance().GetKeys(signer_key_ids);
-
- for (const auto& key : *keys) {
- SPDLOG_DEBUG("keys {}", key.GetEmail());
- }
-
- for (const auto& signer : *signer_keys) {
- SPDLOG_DEBUG("signers {}", signer.GetEmail());
- }
-
- // data to transfer into task
- auto buffer = GFBuffer(edit_->CurTextPage()->GetTextPage()->toPlainText());
-
- CommonUtils::WaitForOpera(
- this, _("Encrypting and Signing"),
- [this, keys, signer_keys, buffer](const OperaWaitingHd& hd) {
- GpgFrontend::GpgBasicOperator::GetInstance().EncryptSign(
- {keys->begin(), keys->end()},
- {signer_keys->begin(), signer_keys->end()}, buffer, true,
- [this, hd](GpgError err, const DataObjectPtr& data_obj) {
- // stop waiting
- hd();
-
- if (data_obj == nullptr ||
- !data_obj
- ->Check<GpgEncryptResult, GpgSignResult, GFBuffer>()) {
- throw std::runtime_error("data object doesn't pass checking");
- }
- auto encrypt_result =
- ExtractParams<GpgEncryptResult>(data_obj, 0);
- auto sign_result = ExtractParams<GpgSignResult>(data_obj, 1);
- auto out_buffer = ExtractParams<GFBuffer>(data_obj, 2);
-
- // analyse result
- auto encrypt_result_analyse =
- GpgEncryptResultAnalyse(err, encrypt_result);
- encrypt_result_analyse.Analyse();
-
- auto sign_result_analyse = GpgSignResultAnalyse(err, sign_result);
- sign_result_analyse.Analyse();
-
- // show analyse result
- process_result_analyse(edit_, info_board_, encrypt_result_analyse,
- sign_result_analyse);
-
- if (CheckGpgError(err) == GPG_ERR_NO_ERROR) {
- edit_->SlotFillTextEditWithText(
- out_buffer.ConvertToQByteArray());
- }
- });
- });
-}
-
-void MainWindow::slot_decrypt_verify() {
- if (edit_->TabCount() == 0 || edit_->SlotCurPageTextEdit() == nullptr) {
- if (edit_->SlotCurPageFileTreeView() != nullptr)
- this->SlotFileDecryptVerify();
- return;
- }
-
- // data to transfer into task
- auto buffer = GFBuffer(edit_->CurTextPage()->GetTextPage()->toPlainText());
-
- CommonUtils::WaitForOpera(
- this, _("Decrypting and Verifying"),
- [this, buffer](const OperaWaitingHd& hd) {
- GpgFrontend::GpgBasicOperator::GetInstance().DecryptVerify(
- buffer, [this, hd](GpgError err, const DataObjectPtr& data_obj) {
- // stop waiting
- hd();
-
- if (data_obj == nullptr ||
- !data_obj
- ->Check<GpgDecryptResult, GpgVerifyResult, GFBuffer>()) {
- throw std::runtime_error("data object doesn't pass checking");
- }
- auto decrypt_result =
- ExtractParams<GpgDecryptResult>(data_obj, 0);
- auto verify_result = ExtractParams<GpgVerifyResult>(data_obj, 1);
- auto out_buffer = ExtractParams<GFBuffer>(data_obj, 2);
-
- // analyse result
- auto decrypt_result_analyse =
- GpgDecryptResultAnalyse(err, decrypt_result);
- decrypt_result_analyse.Analyse();
-
- auto verify_result_analyse =
- GpgVerifyResultAnalyse(err, verify_result);
- verify_result_analyse.Analyse();
-
- // show analyse result
- process_result_analyse(edit_, info_board_, decrypt_result_analyse,
- verify_result_analyse);
-
- if (CheckGpgError(err) == GPG_ERR_NO_ERROR) {
- edit_->SlotFillTextEditWithText(
- out_buffer.ConvertToQByteArray());
- }
- });
- });
-}
-
void MainWindow::slot_find() {
if (edit_->TabCount() == 0 || edit_->CurTextPage() == nullptr) {
return;
@@ -688,4 +320,10 @@ void MainWindow::slot_version_upgrade_nofity() {
}
}
+void MainWindow::slot_refresh_current_file_view() {
+ if (edit_->CurFilePage() != nullptr) {
+ edit_->CurFilePage()->update();
+ }
+}
+
} // namespace GpgFrontend::UI