aboutsummaryrefslogtreecommitdiffstats
path: root/src/ui/main_window/MainWindowSlotFunction.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/ui/main_window/MainWindowSlotFunction.cpp')
-rw-r--r--src/ui/main_window/MainWindowSlotFunction.cpp209
1 files changed, 115 insertions, 94 deletions
diff --git a/src/ui/main_window/MainWindowSlotFunction.cpp b/src/ui/main_window/MainWindowSlotFunction.cpp
index fe0408e0..9a05cdc6 100644
--- a/src/ui/main_window/MainWindowSlotFunction.cpp
+++ b/src/ui/main_window/MainWindowSlotFunction.cpp
@@ -1,4 +1,6 @@
/**
+ * Copyright (C) 2021 Saturneric
+ *
* This file is part of GpgFrontend.
*
* GpgFrontend is free software: you can redistribute it and/or modify
@@ -6,19 +8,21 @@
* 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,
+ * GpgFrontend 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/>.
+ * along with GpgFrontend. If not, see <https://www.gnu.org/licenses/>.
+ *
+ * The initial version of the source code is inherited from
+ * the gpg4usb project, which is under GPL-3.0-or-later.
*
- * The initial version of the source code is inherited from gpg4usb-team.
- * Their source code version also complies with GNU General Public License.
+ * All the source code of GpgFrontend was modified and released by
+ * Saturneric<[email protected]> starting on May 12, 2021.
*
- * The source code version of this software was modified and released
- * by Saturneric<[email protected]> starting on May 12, 2021.
+ * SPDX-License-Identifier: GPL-3.0-or-later
*
*/
@@ -32,25 +36,28 @@
#endif
#ifdef SMTP_SUPPORT
-#include "ui/smtp/SendMailDialog.h"
+#include "ui/mail/SendMailDialog.h"
#endif
-#include "gpg/function/BasicOperator.h"
-#include "gpg/function/GpgKeyGetter.h"
-#include "gpg/function/GpgKeyImportExporter.h"
+#include "core/function/GlobalSettingStation.h"
+#include "core/function/gpg/GpgBasicOperator.h"
+#include "core/function/gpg/GpgKeyGetter.h"
+#include "core/function/gpg/GpgKeyImportExporter.h"
#include "ui/UserInterfaceUtils.h"
#include "ui/help/AboutDialog.h"
-#include "ui/settings/GlobalSettingStation.h"
#include "ui/widgets/SignersPicker.h"
namespace GpgFrontend::UI {
/**
* Encrypt Entry(Text & File)
*/
-void MainWindow::slotEncrypt() {
- if (edit->tabCount() == 0 || edit->slotCurPageTextEdit() == nullptr) return;
+void MainWindow::slot_encrypt() {
+ if (edit_->TabCount() == 0 || edit_->SlotCurPageTextEdit() == nullptr) {
+ if (edit_->SlotCurPageFileTreeView() != nullptr) this->SlotFileEncrypt();
+ return;
+ }
- auto key_ids = mKeyList->getChecked();
+ auto key_ids = m_key_list_->GetChecked();
GpgEncrResult result = nullptr;
GpgError error;
@@ -70,8 +77,8 @@ void MainWindow::slotEncrypt() {
process_operation(this, _("Symmetrically Encrypting"), [&]() {
try {
auto buffer =
- edit->curTextPage()->getTextPage()->toPlainText().toStdString();
- error = GpgFrontend::BasicOperator::GetInstance().EncryptSymmetric(
+ edit_->CurTextPage()->GetTextPage()->toPlainText().toStdString();
+ error = GpgFrontend::GpgBasicOperator::GetInstance().EncryptSymmetric(
buffer, tmp, result);
} catch (const std::runtime_error& e) {
if_error = true;
@@ -96,8 +103,8 @@ void MainWindow::slotEncrypt() {
process_operation(this, _("Encrypting"), [&]() {
try {
auto buffer =
- edit->curTextPage()->getTextPage()->toPlainText().toStdString();
- error = GpgFrontend::BasicOperator::GetInstance().Encrypt(
+ edit_->CurTextPage()->GetTextPage()->toPlainText().toStdString();
+ error = GpgFrontend::GpgBasicOperator::GetInstance().Encrypt(
std::move(keys), buffer, tmp, result);
} catch (const std::runtime_error& e) {
if_error = true;
@@ -107,17 +114,17 @@ void MainWindow::slotEncrypt() {
if (!if_error) {
LOG(INFO) << "result" << result.get();
- auto resultAnalyse = EncryptResultAnalyse(error, std::move(result));
+ auto resultAnalyse = GpgEncryptResultAnalyse(error, std::move(result));
resultAnalyse.Analyse();
- process_result_analyse(edit, infoBoard, resultAnalyse);
+ process_result_analyse(edit_, info_board_, resultAnalyse);
if (check_gpg_error_2_err_code(error) == GPG_ERR_NO_ERROR)
- edit->slotFillTextEditWithText(QString::fromStdString(*tmp));
- infoBoard->resetOptionActionsMenu();
+ edit_->SlotFillTextEditWithText(QString::fromStdString(*tmp));
+ info_board_->ResetOptionActionsMenu();
#ifdef SMTP_SUPPORT
if (check_gpg_error_2_err_code(error) == GPG_ERR_NO_ERROR)
- send_an_email(this, infoBoard,
- edit->curTextPage()->getTextPage()->toPlainText());
+ send_an_email(this, info_board_,
+ edit_->CurTextPage()->GetTextPage()->toPlainText());
#endif
} else {
QMessageBox::critical(this, _("Error"),
@@ -126,10 +133,10 @@ void MainWindow::slotEncrypt() {
}
}
-void MainWindow::slotSign() {
- if (edit->tabCount() == 0 || edit->slotCurPageTextEdit() == nullptr) return;
+void MainWindow::slot_sign() {
+ if (edit_->TabCount() == 0 || edit_->SlotCurPageTextEdit() == nullptr) return;
- auto key_ids = mKeyList->getPrivateChecked();
+ auto key_ids = m_key_list_->GetPrivateChecked();
if (key_ids->empty()) {
QMessageBox::critical(
@@ -160,12 +167,12 @@ void MainWindow::slotSign() {
process_operation(this, _("Signing"), [&]() {
try {
- auto buffer = edit->curTextPage()
- ->getTextPage()
+ auto buffer = edit_->CurTextPage()
+ ->GetTextPage()
->toPlainText()
.toUtf8()
.toStdString();
- error = GpgFrontend::BasicOperator::GetInstance().Sign(
+ error = GpgFrontend::GpgBasicOperator::GetInstance().Sign(
std::move(keys), buffer, tmp, GPGME_SIG_MODE_CLEAR, result);
} catch (const std::runtime_error& e) {
if_error = true;
@@ -173,12 +180,12 @@ void MainWindow::slotSign() {
});
if (!if_error) {
- auto resultAnalyse = SignResultAnalyse(error, std::move(result));
+ auto resultAnalyse = GpgSignResultAnalyse(error, std::move(result));
resultAnalyse.Analyse();
- process_result_analyse(edit, infoBoard, resultAnalyse);
+ process_result_analyse(edit_, info_board_, resultAnalyse);
if (check_gpg_error_2_err_code(error) == GPG_ERR_NO_ERROR)
- edit->slotFillTextEditWithText(QString::fromStdString(*tmp));
+ edit_->SlotFillTextEditWithText(QString::fromStdString(*tmp));
} else {
QMessageBox::critical(this, _("Error"),
_("An error occurred during operation."));
@@ -186,11 +193,14 @@ void MainWindow::slotSign() {
}
}
-void MainWindow::slotDecrypt() {
- if (edit->tabCount() == 0 || edit->slotCurPageTextEdit() == nullptr) return;
+void MainWindow::slot_decrypt() {
+ if (edit_->TabCount() == 0 || edit_->SlotCurPageTextEdit() == nullptr) {
+ if (edit_->SlotCurPageFileTreeView() != nullptr) this->SlotFileDecrypt();
+ return;
+ }
auto decrypted = std::make_unique<ByteArray>();
- QByteArray text = edit->curTextPage()->getTextPage()->toPlainText().toUtf8();
+ QByteArray text = edit_->CurTextPage()->GetTextPage()->toPlainText().toUtf8();
if (text.trimmed().startsWith(GpgConstants::GPG_FRONTEND_SHORT_CRYPTO_HEAD)) {
QMessageBox::critical(
@@ -205,7 +215,7 @@ void MainWindow::slotDecrypt() {
process_operation(this, _("Decrypting"), [&]() {
try {
auto buffer = text.toStdString();
- error = GpgFrontend::BasicOperator::GetInstance().Decrypt(
+ error = GpgFrontend::GpgBasicOperator::GetInstance().Decrypt(
buffer, decrypted, result);
} catch (const std::runtime_error& e) {
if_error = true;
@@ -213,12 +223,12 @@ void MainWindow::slotDecrypt() {
});
if (!if_error) {
- auto resultAnalyse = DecryptResultAnalyse(error, std::move(result));
+ auto resultAnalyse = GpgDecryptResultAnalyse(error, std::move(result));
resultAnalyse.Analyse();
- process_result_analyse(edit, infoBoard, resultAnalyse);
+ process_result_analyse(edit_, info_board_, resultAnalyse);
if (check_gpg_error_2_err_code(error) == GPG_ERR_NO_ERROR)
- edit->slotFillTextEditWithText(QString::fromStdString(*decrypted));
+ edit_->SlotFillTextEditWithText(QString::fromStdString(*decrypted));
} else {
QMessageBox::critical(this, _("Error"),
_("An error occurred during operation."));
@@ -226,22 +236,25 @@ void MainWindow::slotDecrypt() {
}
}
-void MainWindow::slotFind() {
- if (edit->tabCount() == 0 || edit->curTextPage() == nullptr) {
+void MainWindow::slot_find() {
+ if (edit_->TabCount() == 0 || edit_->CurTextPage() == nullptr) {
return;
}
// At first close verifynotification, if existing
- edit->slotCurPageTextEdit()->closeNoteByClass("findwidget");
+ edit_->SlotCurPageTextEdit()->CloseNoteByClass("findwidget");
- auto* fw = new FindWidget(this, edit->curTextPage());
- edit->slotCurPageTextEdit()->showNotificationWidget(fw, "findWidget");
+ auto* fw = new FindWidget(this, edit_->CurTextPage());
+ edit_->SlotCurPageTextEdit()->ShowNotificationWidget(fw, "findWidget");
}
-void MainWindow::slotVerify() {
- if (edit->tabCount() == 0 || edit->slotCurPageTextEdit() == nullptr) return;
+void MainWindow::slot_verify() {
+ if (edit_->TabCount() == 0 || edit_->SlotCurPageTextEdit() == nullptr) {
+ if (edit_->SlotCurPageFileTreeView() != nullptr) this->SlotFileVerify();
+ return;
+ }
- auto text = edit->curTextPage()->getTextPage()->toPlainText().toUtf8();
+ auto text = edit_->CurTextPage()->GetTextPage()->toPlainText().toUtf8();
// TODO(Saturneric) PreventNoDataErr
auto sig_buffer = std::make_unique<ByteArray>();
@@ -253,7 +266,7 @@ void MainWindow::slotVerify() {
process_operation(this, _("Verifying"), [&]() {
try {
auto buffer = text.toStdString();
- error = GpgFrontend::BasicOperator::GetInstance().Verify(
+ error = GpgFrontend::GpgBasicOperator::GetInstance().Verify(
buffer, sig_buffer, result);
} catch (const std::runtime_error& e) {
if_error = true;
@@ -261,22 +274,26 @@ void MainWindow::slotVerify() {
});
if (!if_error) {
- auto result_analyse = VerifyResultAnalyse(error, result);
+ auto result_analyse = GpgVerifyResultAnalyse(error, result);
result_analyse.Analyse();
- process_result_analyse(edit, infoBoard, result_analyse);
+ process_result_analyse(edit_, info_board_, result_analyse);
if (result_analyse.GetStatus() == -2)
import_unknown_key_from_keyserver(this, result_analyse);
if (result_analyse.GetStatus() >= 0)
- show_verify_details(this, infoBoard, error, result);
+ show_verify_details(this, info_board_, error, result);
}
}
-void MainWindow::slotEncryptSign() {
- if (edit->tabCount() == 0 || edit->slotCurPageTextEdit() == nullptr) return;
+void MainWindow::slot_encrypt_sign() {
+ if (edit_->TabCount() == 0 || edit_->SlotCurPageTextEdit() == nullptr) {
+ if (edit_->SlotCurPageFileTreeView() != nullptr)
+ this->SlotFileEncryptSign();
+ return;
+ }
- auto key_ids = mKeyList->getChecked();
+ auto key_ids = m_key_list_->GetChecked();
if (key_ids->empty()) {
QMessageBox::critical(
@@ -302,10 +319,10 @@ void MainWindow::slotEncryptSign() {
auto signersPicker = new SignersPicker(this);
QEventLoop loop;
- connect(signersPicker, SIGNAL(finished(int)), &loop, SLOT(quit()));
+ connect(signersPicker, &SignersPicker::finished, &loop, &QEventLoop::quit);
loop.exec();
- auto signer_key_ids = signersPicker->getCheckedSigners();
+ auto signer_key_ids = signersPicker->GetCheckedSigners();
auto signer_keys = GpgKeyGetter::GetInstance().GetKeys(signer_key_ids);
for (const auto& key : *keys) {
@@ -324,12 +341,12 @@ void MainWindow::slotEncryptSign() {
auto tmp = std::make_unique<ByteArray>();
process_operation(this, _("Encrypting and Signing"), [&]() {
try {
- auto buffer = edit->curTextPage()
- ->getTextPage()
+ auto buffer = edit_->CurTextPage()
+ ->GetTextPage()
->toPlainText()
.toUtf8()
.toStdString();
- error = GpgFrontend::BasicOperator::GetInstance().EncryptSign(
+ error = GpgFrontend::GpgBasicOperator::GetInstance().EncryptSign(
std::move(keys), std::move(signer_keys), buffer, tmp, encr_result,
sign_result);
} catch (const std::runtime_error& e) {
@@ -351,20 +368,20 @@ void MainWindow::slotEncryptSign() {
}
}
#endif
- LOG(INFO) << "ResultAnalyse Started";
- auto encrypt_res = EncryptResultAnalyse(error, std::move(encr_result));
- auto sign_res = SignResultAnalyse(error, std::move(sign_result));
+ LOG(INFO) << "GpgResultAnalyse Started";
+ auto encrypt_res = GpgEncryptResultAnalyse(error, std::move(encr_result));
+ auto sign_res = GpgSignResultAnalyse(error, std::move(sign_result));
encrypt_res.Analyse();
sign_res.Analyse();
- process_result_analyse(edit, infoBoard, encrypt_res, sign_res);
+ process_result_analyse(edit_, info_board_, encrypt_res, sign_res);
if (check_gpg_error_2_err_code(error) == GPG_ERR_NO_ERROR)
- edit->slotFillTextEditWithText(QString::fromStdString(*tmp));
+ edit_->SlotFillTextEditWithText(QString::fromStdString(*tmp));
- infoBoard->resetOptionActionsMenu();
+ info_board_->ResetOptionActionsMenu();
#ifdef SMTP_SUPPORT
if (check_gpg_error_2_err_code(error) == GPG_ERR_NO_ERROR)
- send_an_email(this, infoBoard,
- edit->curTextPage()->getTextPage()->toPlainText(), false);
+ send_an_email(this, info_board_,
+ edit_->CurTextPage()->GetTextPage()->toPlainText(), false);
#endif
#ifdef ADVANCE_SUPPORT
@@ -385,10 +402,14 @@ void MainWindow::slotEncryptSign() {
}
}
-void MainWindow::slotDecryptVerify() {
- if (edit->tabCount() == 0 || edit->slotCurPageTextEdit() == nullptr) return;
+void MainWindow::slot_decrypt_verify() {
+ if (edit_->TabCount() == 0 || edit_->SlotCurPageTextEdit() == nullptr) {
+ if (edit_->SlotCurPageFileTreeView() != nullptr)
+ this->SlotFileDecryptVerify();
+ return;
+ }
- QString plainText = edit->curTextPage()->getTextPage()->toPlainText();
+ QString plainText = edit_->CurTextPage()->GetTextPage()->toPlainText();
#ifdef ADVANCE_SUPPORT
if (plainText.trimmed().startsWith(
@@ -424,27 +445,27 @@ void MainWindow::slotDecryptVerify() {
process_operation(this, _("Decrypting and Verifying"), [&]() {
try {
auto buffer = text.toStdString();
- error = BasicOperator::GetInstance().DecryptVerify(buffer, decrypted,
- d_result, v_result);
+ error = GpgBasicOperator::GetInstance().DecryptVerify(buffer, decrypted,
+ d_result, v_result);
} catch (const std::runtime_error& e) {
if_error = true;
}
});
if (!if_error) {
- auto decrypt_res = DecryptResultAnalyse(error, std::move(d_result));
- auto verify_res = VerifyResultAnalyse(error, v_result);
+ auto decrypt_res = GpgDecryptResultAnalyse(error, std::move(d_result));
+ auto verify_res = GpgVerifyResultAnalyse(error, v_result);
decrypt_res.Analyse();
verify_res.Analyse();
- process_result_analyse(edit, infoBoard, decrypt_res, verify_res);
+ process_result_analyse(edit_, info_board_, decrypt_res, verify_res);
if (check_gpg_error_2_err_code(error) == GPG_ERR_NO_ERROR)
- edit->slotFillTextEditWithText(QString::fromStdString(*decrypted));
+ edit_->SlotFillTextEditWithText(QString::fromStdString(*decrypted));
if (verify_res.GetStatus() == -2)
import_unknown_key_from_keyserver(this, verify_res);
if (verify_res.GetStatus() >= 0)
- show_verify_details(this, infoBoard, error, v_result);
+ show_verify_details(this, info_board_, error, v_result);
} else {
QMessageBox::critical(this, _("Error"),
@@ -456,21 +477,21 @@ void MainWindow::slotDecryptVerify() {
/*
* Append the selected (not checked!) Key(s) To Textedit
*/
-void MainWindow::slotAppendSelectedKeys() {
- if (edit->tabCount() == 0 || edit->slotCurPageTextEdit() == nullptr) {
+void MainWindow::slot_append_selected_keys() {
+ if (edit_->TabCount() == 0 || edit_->SlotCurPageTextEdit() == nullptr) {
return;
}
auto exported = std::make_unique<ByteArray>();
- auto key_ids = mKeyList->getSelected();
+ auto key_ids = m_key_list_->GetSelected();
GpgKeyImportExporter::GetInstance().ExportKeys(key_ids, exported);
- edit->curTextPage()->getTextPage()->appendPlainText(
+ edit_->CurTextPage()->GetTextPage()->appendPlainText(
QString::fromStdString(*exported));
}
-void MainWindow::slotCopyMailAddressToClipboard() {
- auto key_ids = mKeyList->getSelected();
+void MainWindow::slot_copy_mail_address_to_clipboard() {
+ auto key_ids = m_key_list_->GetSelected();
if (key_ids->empty()) return;
auto key = GpgKeyGetter::GetInstance().GetKey(key_ids->front());
@@ -482,8 +503,8 @@ void MainWindow::slotCopyMailAddressToClipboard() {
cb->setText(QString::fromStdString(key.GetEmail()));
}
-void MainWindow::slotShowKeyDetails() {
- auto key_ids = mKeyList->getSelected();
+void MainWindow::slot_show_key_details() {
+ auto key_ids = m_key_list_->GetSelected();
if (key_ids->empty()) return;
auto key = GpgKeyGetter::GetInstance().GetKey(key_ids->front());
@@ -494,25 +515,25 @@ void MainWindow::slotShowKeyDetails() {
}
}
-void MainWindow::refreshKeysFromKeyserver() {
- auto key_ids = mKeyList->getSelected();
+void MainWindow::refresh_keys_from_key_server() {
+ auto key_ids = m_key_list_->GetSelected();
if (key_ids->empty()) return;
auto* dialog = new KeyServerImportDialog(this);
dialog->show();
- dialog->slotImport(key_ids);
+ dialog->SlotImport(key_ids);
}
-void MainWindow::uploadKeyToServer() {
- auto key_ids = mKeyList->getSelected();
+void MainWindow::upload_key_to_server() {
+ auto key_ids = m_key_list_->GetSelected();
auto* dialog = new KeyUploadDialog(key_ids, this);
dialog->show();
- dialog->slotUpload();
+ dialog->SlotUpload();
}
-void MainWindow::slotOpenFile(QString& path) { edit->slotOpenFile(path); }
+void MainWindow::SlotOpenFile(QString& path) { edit_->SlotOpenFile(path); }
-void MainWindow::slotVersionUpgrade(const SoftwareVersion& version) {
+void MainWindow::slot_version_upgrade(const SoftwareVersion& version) {
LOG(INFO) << _("called");
if (version.NeedUpgrade()) {
statusBar()->showMessage(