aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/ui/main_window/MainWindow.cpp27
-rw-r--r--src/ui/main_window/MainWindow.h76
-rw-r--r--src/ui/main_window/MainWindowFileSlotFunction.cpp32
-rw-r--r--src/ui/main_window/MainWindowGpgOperaFunction.cpp99
-rw-r--r--src/ui/main_window/MainWindowSlotFunction.cpp16
-rw-r--r--src/ui/main_window/MainWindowSlotUI.cpp174
-rw-r--r--src/ui/main_window/MainWindowUI.cpp560
-rw-r--r--src/ui/widgets/InfoBoardWidget.cpp11
-rw-r--r--src/ui/widgets/InfoBoardWidget.h9
-rw-r--r--src/ui/widgets/PlainTextEditorPage.cpp10
-rw-r--r--src/ui/widgets/PlainTextEditorPage.h11
-rw-r--r--src/ui/widgets/TextEdit.cpp13
-rw-r--r--src/ui/widgets/TextEdit.h35
-rw-r--r--src/ui/widgets/TextEditTabWidget.cpp2
14 files changed, 546 insertions, 529 deletions
diff --git a/src/ui/main_window/MainWindow.cpp b/src/ui/main_window/MainWindow.cpp
index 597697f4..47e7487b 100644
--- a/src/ui/main_window/MainWindow.cpp
+++ b/src/ui/main_window/MainWindow.cpp
@@ -98,11 +98,11 @@ void MainWindow::Init() noexcept {
UISignalStation::GetInstance(),
&UISignalStation::SignalKeyDatabaseRefresh);
- connect(edit_->tab_widget_, &TextEditTabWidget::currentChanged, this,
- &MainWindow::slot_disable_tab_actions);
+ connect(edit_->TabWidget(), &TextEditTabWidget::currentChanged, this,
+ &MainWindow::slot_switch_menu_control_mode);
connect(UISignalStation::GetInstance(),
&UISignalStation::SignalRefreshStatusBar, this,
- [=](const QString &message, int timeout) {
+ [=](const QString& message, int timeout) {
statusBar()->showMessage(message, timeout);
});
connect(UISignalStation::GetInstance(),
@@ -131,6 +131,8 @@ void MainWindow::Init() noexcept {
edit_->CurTextPage()->setFocus();
+ info_board_->AssociateTabWidget(edit_->TabWidget());
+
Module::ListenRTPublishEvent(
this, kVersionCheckingModuleID, "version.loading_done",
[=](Module::Namespace, Module::Key, int, std::any) {
@@ -190,7 +192,7 @@ void MainWindow::recover_editor_unsaved_pages_from_cache() {
bool first = true;
auto unsaved_page_array = json_data.array();
- for (const auto &value_ref : unsaved_page_array) {
+ for (const auto& value_ref : unsaved_page_array) {
if (!value_ref.isObject()) continue;
auto unsaved_page_json = value_ref.toObject();
@@ -222,7 +224,7 @@ void MainWindow::close_attachment_dock() {
attachment_dock_created_ = false;
}
-void MainWindow::closeEvent(QCloseEvent *event) {
+void MainWindow::closeEvent(QCloseEvent* event) {
/*
* ask to save changes, if there are
* modified documents in any tab
@@ -243,4 +245,19 @@ void MainWindow::closeEvent(QCloseEvent *event) {
}
}
+auto MainWindow::create_action(
+ const QString& id, const QString& name, const QString& icon,
+ const QString& too_tip, const QList<QKeySequence>& shortcuts) -> QAction* {
+ auto* action = new QAction(name, this);
+ action->setIcon(QIcon(icon));
+ action->setToolTip(too_tip);
+
+ if (!shortcuts.isEmpty()) {
+ action->setShortcuts(shortcuts);
+ }
+
+ buffered_actions_.insert(id, {action});
+ return action;
+}
+
} // namespace GpgFrontend::UI
diff --git a/src/ui/main_window/MainWindow.h b/src/ui/main_window/MainWindow.h
index 884e26ed..d446bfb1 100644
--- a/src/ui/main_window/MainWindow.h
+++ b/src/ui/main_window/MainWindow.h
@@ -256,6 +256,48 @@ class MainWindow : public GeneralMainWindow {
*/
void SlotSetRestartNeeded(int);
+ /**
+ * @brief
+ *
+ */
+ void SlotGeneralEncrypt(bool);
+
+ /**
+ * @brief
+ *
+ */
+ void SlotGeneralDecrypt(bool);
+
+ /**
+ * @brief
+ *
+ */
+ void SlotGeneralSign(bool);
+
+ /**
+ * @brief
+ *
+ */
+ void SlotGeneralVerify(bool);
+
+ /**
+ * @brief
+ *
+ */
+ void SlotGeneralEncryptSign(bool);
+
+ /**
+ * @brief
+ *
+ */
+ void SlotGeneralDecryptVerify(bool);
+
+ /**
+ * @brief
+ *
+ */
+ void SlotGeneralVerifyEMail(bool);
+
private slots:
/**
@@ -370,7 +412,7 @@ class MainWindow : public GeneralMainWindow {
* @details Disable tab related actions, if number of tabs is 0.
* @param number number of the opened tabs and -1, if no tab is opened
*/
- void slot_disable_tab_actions(int number);
+ void slot_switch_menu_control_mode(int number);
/**
* @details called when need to upgrade.
@@ -445,6 +487,24 @@ class MainWindow : public GeneralMainWindow {
*/
void slot_refresh_info_board(int status, const QString& text);
+ /**
+ * @brief
+ *
+ */
+ void slot_clean_gpg_password_cache(bool);
+
+ /**
+ * @brief
+ *
+ */
+ void slot_reload_gpg_components(bool);
+
+ /**
+ * @brief
+ *
+ */
+ void slot_restart_gpg_components(bool);
+
private:
/**
* @details Create actions for the main-menu and the context-menu of the
@@ -492,6 +552,19 @@ class MainWindow : public GeneralMainWindow {
*/
void recover_editor_unsaved_pages_from_cache();
+ /**
+ * @brief Create a action object
+ *
+ * @param id
+ * @param name
+ * @param icon
+ * @param too_tip
+ * @return QAction*
+ */
+ auto create_action(const QString& id, const QString& name,
+ const QString& icon, const QString& too_tip,
+ const QList<QKeySequence>& shortcuts = {}) -> QAction*;
+
TextEdit* edit_{}; ///< Tabwidget holding the edit-windows
QMenu* file_menu_{}; ///< Submenu for file-operations
QMenu* edit_menu_{}; ///< Submenu for text-operations
@@ -586,6 +659,7 @@ class MainWindow : public GeneralMainWindow {
KeyList* m_key_list_{}; ///<
InfoBoardWidget* info_board_{}; ///<
+ QMap<QString, QPointer<QAction>> buffered_actions_;
bool attachment_dock_created_{}; ///<
int restart_mode_{0}; ///<
diff --git a/src/ui/main_window/MainWindowFileSlotFunction.cpp b/src/ui/main_window/MainWindowFileSlotFunction.cpp
index 12c06312..b94da713 100644
--- a/src/ui/main_window/MainWindowFileSlotFunction.cpp
+++ b/src/ui/main_window/MainWindowFileSlotFunction.cpp
@@ -557,37 +557,7 @@ void MainWindow::SlotFileVerify(const QString& path) {
if (!result_analyse.GetUnknownSignatures().isEmpty() &&
Module::IsModuleActivate(kKeyServerSyncModuleID)) {
- LOG_D() << "try to sync missing key info from server"
- << result_analyse.GetUnknownSignatures();
-
- QString fingerprint_list;
- for (const auto& fingerprint :
- result_analyse.GetUnknownSignatures()) {
- fingerprint_list += fingerprint + "\n";
- }
-
- // Interaction with user
- auto user_response = QMessageBox::question(
- this, tr("Missing Keys"),
- tr("Some signatures cannot be verified because the "
- "corresponding keys are missing.\n\n"
- "The following fingerprints are missing:\n%1\n\n"
- "Would you like to fetch these keys from the key "
- "server?")
- .arg(fingerprint_list),
- QMessageBox::Yes | QMessageBox::No);
-
- if (user_response == QMessageBox::Yes) {
- CommonUtils::GetInstance()
- ->ImportKeyByKeyServerSyncModule(
- this, m_key_list_->GetCurrentGpgContextChannel(),
- result_analyse.GetUnknownSignatures());
- } else {
- QMessageBox::information(
- this, tr("Verification Incomplete"),
- tr("Verification was incomplete due to missing "
- "keys. You can manually import the keys later."));
- }
+ slot_verifying_unknown_signature_helper(result_analyse);
}
this->slot_refresh_current_file_view();
diff --git a/src/ui/main_window/MainWindowGpgOperaFunction.cpp b/src/ui/main_window/MainWindowGpgOperaFunction.cpp
index 2bfb09b8..6e29f362 100644
--- a/src/ui/main_window/MainWindowGpgOperaFunction.cpp
+++ b/src/ui/main_window/MainWindowGpgOperaFunction.cpp
@@ -59,7 +59,7 @@ void MainWindow::SlotEncrypt() {
if (ret == QMessageBox::Cancel) return;
- auto buffer = GFBuffer(edit_->CurTextPage()->GetTextPage()->toPlainText());
+ auto buffer = GFBuffer(edit_->CurPlainText());
CommonUtils::WaitForOpera(
this, tr("Symmetrically Encrypting"),
[this, buffer](const OperaWaitingHd& op_hd) {
@@ -118,7 +118,7 @@ void MainWindow::SlotEncrypt() {
}
}
- auto buffer = GFBuffer(edit_->CurTextPage()->GetTextPage()->toPlainText());
+ auto buffer = GFBuffer(edit_->CurPlainText());
CommonUtils::WaitForOpera(
this, tr("Encrypting"),
[this, keys, buffer](const OperaWaitingHd& op_hd) {
@@ -185,7 +185,7 @@ void MainWindow::SlotSign() {
}
// set input buffer
- auto buffer = GFBuffer(edit_->CurTextPage()->GetTextPage()->toPlainText());
+ auto buffer = GFBuffer(edit_->CurPlainText());
CommonUtils::WaitForOpera(
this, tr("Signing"), [this, keys, buffer](const OperaWaitingHd& hd) {
GpgFrontend::GpgBasicOperator::GetInstance(
@@ -223,7 +223,7 @@ void MainWindow::SlotDecrypt() {
if (edit_->SlotCurPageTextEdit() == nullptr) return;
// data to transfer into task
- auto buffer = GFBuffer(edit_->CurTextPage()->GetTextPage()->toPlainText());
+ auto buffer = GFBuffer(edit_->CurPlainText());
CommonUtils::WaitForOpera(
this, tr("Decrypting"), [this, buffer](const OperaWaitingHd& hd) {
@@ -261,70 +261,39 @@ void MainWindow::SlotVerify() {
if (edit_->SlotCurPageTextEdit() == nullptr) return;
// set input buffer
- auto buffer = GFBuffer(edit_->CurTextPage()->GetTextPage()->toPlainText());
+ auto buffer = GFBuffer(edit_->CurPlainText());
CommonUtils::WaitForOpera(
this, tr("Verifying"), [this, buffer](const OperaWaitingHd& hd) {
GpgFrontend::GpgBasicOperator::GetInstance(
m_key_list_->GetCurrentGpgContextChannel())
- .Verify(
- buffer, GFBuffer(),
- [this, hd](GpgError err, const DataObjectPtr& data_obj) {
- // stop waiting
- hd();
-
- if (CheckGpgError(err) == GPG_ERR_USER_1 ||
- data_obj == nullptr ||
- !data_obj->Check<GpgVerifyResult>()) {
- QMessageBox::critical(this, tr("Error"),
- tr("Unknown error occurred"));
- return;
- }
- auto verify_result =
- ExtractParams<GpgVerifyResult>(data_obj, 0);
-
- // analyse result
- auto result_analyse = GpgVerifyResultAnalyse(
- m_key_list_->GetCurrentGpgContextChannel(), err,
- verify_result);
- result_analyse.Analyse();
- slot_result_analyse_show_helper(result_analyse);
-
- if (!result_analyse.GetUnknownSignatures().isEmpty() &&
- Module::IsModuleActivate(kKeyServerSyncModuleID)) {
- LOG_D() << "try to sync missing key info from server"
- << result_analyse.GetUnknownSignatures();
-
- QString fingerprint_list;
- for (const auto& fingerprint :
- result_analyse.GetUnknownSignatures()) {
- fingerprint_list += fingerprint + "\n";
- }
-
- // Interaction with user
- auto user_response = QMessageBox::question(
- this, tr("Missing Keys"),
- tr("Some signatures cannot be verified because the "
- "corresponding keys are missing.\n\n"
- "The following fingerprints are missing:\n%1\n\n"
- "Would you like to fetch these keys from the key "
- "server?")
- .arg(fingerprint_list),
- QMessageBox::Yes | QMessageBox::No);
-
- if (user_response == QMessageBox::Yes) {
- CommonUtils::GetInstance()
- ->ImportKeyByKeyServerSyncModule(
- this, m_key_list_->GetCurrentGpgContextChannel(),
- result_analyse.GetUnknownSignatures());
- } else {
- QMessageBox::information(
- this, tr("Verification Incomplete"),
- tr("Verification was incomplete due to missing "
- "keys. You can manually import the keys later."));
- }
- }
- });
+ .Verify(buffer, GFBuffer(),
+ [this, hd](GpgError err, const DataObjectPtr& data_obj) {
+ // stop waiting
+ hd();
+
+ if (CheckGpgError(err) == GPG_ERR_USER_1 ||
+ data_obj == nullptr ||
+ !data_obj->Check<GpgVerifyResult>()) {
+ QMessageBox::critical(this, tr("Error"),
+ tr("Unknown error occurred"));
+ return;
+ }
+ auto verify_result =
+ ExtractParams<GpgVerifyResult>(data_obj, 0);
+
+ // analyse result
+ auto result_analyse = GpgVerifyResultAnalyse(
+ m_key_list_->GetCurrentGpgContextChannel(), err,
+ verify_result);
+ result_analyse.Analyse();
+ slot_result_analyse_show_helper(result_analyse);
+
+ if (!result_analyse.GetUnknownSignatures().isEmpty() &&
+ Module::IsModuleActivate(kKeyServerSyncModuleID)) {
+ slot_verifying_unknown_signature_helper(result_analyse);
+ }
+ });
});
}
@@ -450,7 +419,7 @@ void MainWindow::SlotEncryptSign() {
}
// data to transfer into task
- auto buffer = GFBuffer(edit_->CurTextPage()->GetTextPage()->toPlainText());
+ auto buffer = GFBuffer(edit_->CurPlainText());
CommonUtils::WaitForOpera(
this, tr("Encrypting and Signing"),
@@ -504,7 +473,7 @@ void MainWindow::SlotDecryptVerify() {
if (edit_->SlotCurPageTextEdit() == nullptr) return;
// data to transfer into task
- auto buffer = GFBuffer(edit_->CurTextPage()->GetTextPage()->toPlainText());
+ auto buffer = GFBuffer(edit_->CurPlainText());
CommonUtils::WaitForOpera(
this, tr("Decrypting and Verifying"),
diff --git a/src/ui/main_window/MainWindowSlotFunction.cpp b/src/ui/main_window/MainWindowSlotFunction.cpp
index 66ce14e0..e70fc8fa 100644
--- a/src/ui/main_window/MainWindowSlotFunction.cpp
+++ b/src/ui/main_window/MainWindowSlotFunction.cpp
@@ -344,7 +344,7 @@ void MainWindow::slot_import_key_from_edit() {
CommonUtils::GetInstance()->SlotImportKeys(
this, m_key_list_->GetCurrentGpgContextChannel(),
- edit_->CurTextPage()->GetTextPage()->toPlainText().toLatin1());
+ edit_->CurPlainText().toLatin1());
}
void MainWindow::slot_verify_email_by_eml_data(const QByteArray& buffer) {
@@ -401,7 +401,7 @@ void MainWindow::slot_verify_email_by_eml_data(const QByteArray& buffer) {
void MainWindow::SlotVerifyEML() {
if (edit_->TabCount() == 0 || edit_->SlotCurPageTextEdit() == nullptr) return;
- auto buffer = edit_->CurTextPage()->GetTextPage()->toPlainText().toLatin1();
+ auto buffer = edit_->CurPlainText().toLatin1();
buffer = buffer.replace("\n", "\r\n");
// LOG_D() << "EML BUFFER: " << buffer;
@@ -411,7 +411,9 @@ void MainWindow::SlotVerifyEML() {
void MainWindow::slot_verifying_unknown_signature_helper(
const GpgVerifyResultAnalyse& result_analyse) {
- LOG_D() << "try to sync missing key info from server"
+ if (!Module::IsModuleActivate(kKeyServerSyncModuleID)) return;
+
+ LOG_D() << "try to sync missing key info from server: "
<< result_analyse.GetUnknownSignatures();
QString fingerprint_list;
@@ -530,9 +532,7 @@ void MainWindow::slot_result_analyse_show_helper(
}
void MainWindow::slot_refresh_info_board(int status, const QString& text) {
- if (edit_->tab_widget_ != nullptr) {
- info_board_->AssociateTabWidget(edit_->tab_widget_);
- }
+ info_board_->SlotReset();
if (status < 0) {
info_board_->SlotRefresh(text, INFO_ERROR_CRITICAL);
@@ -545,9 +545,7 @@ void MainWindow::slot_refresh_info_board(int status, const QString& text) {
void MainWindow::slot_result_analyse_show_helper(const GpgResultAnalyse& r_a,
const GpgResultAnalyse& r_b) {
- if (edit_->tab_widget_ != nullptr) {
- info_board_->AssociateTabWidget(edit_->tab_widget_);
- }
+ info_board_->SlotReset();
slot_refresh_info_board(std::min(r_a.GetStatus(), r_b.GetStatus()),
r_a.GetResultReport() + r_b.GetResultReport());
diff --git a/src/ui/main_window/MainWindowSlotUI.cpp b/src/ui/main_window/MainWindowSlotUI.cpp
index 3cf79eea..aaf075d5 100644
--- a/src/ui/main_window/MainWindowSlotUI.cpp
+++ b/src/ui/main_window/MainWindowSlotUI.cpp
@@ -29,15 +29,14 @@
#include "MainWindow.h"
#include "core/GpgConstants.h"
#include "core/function/CacheManager.h"
-#include "core/model/GpgPassphraseContext.h"
+#include "core/function/gpg/GpgAdvancedOperator.h"
#include "core/model/SettingsObject.h"
+#include "core/module/ModuleManager.h"
#include "ui/UserInterfaceUtils.h"
#include "ui/dialog/Wizard.h"
#include "ui/main_window/KeyMgmt.h"
#include "ui/struct/settings_object/AppearanceSO.h"
-#include "ui/widgets/KeyList.h"
#include "ui/widgets/TextEdit.h"
-
namespace GpgFrontend::UI {
void MainWindow::SlotSetStatusBarText(const QString& text) {
@@ -57,10 +56,11 @@ void MainWindow::slot_open_key_management() {
dialog->raise();
}
-void MainWindow::slot_open_file_tab() { edit_->SlotNewFileTab(); }
+void MainWindow::slot_open_file_tab() { edit_->SlotNewFileBrowserTab(); }
-void MainWindow::slot_disable_tab_actions(int number) {
- auto disable = number == -1;
+void MainWindow::slot_switch_menu_control_mode(int index) {
+ auto disable = false;
+ if (index == -1) disable = true;
if (edit_->CurFilePage() != nullptr) disable = true;
print_act_->setDisabled(disable);
@@ -129,7 +129,7 @@ void MainWindow::slot_clean_double_line_breaks() {
return;
}
- QString content = edit_->CurTextPage()->GetTextPage()->toPlainText();
+ QString content = edit_->CurPlainText();
content.replace("\n\n", "\n");
edit_->SlotFillTextEditWithText(content);
}
@@ -139,8 +139,7 @@ void MainWindow::slot_add_pgp_header() {
return;
}
- QString content =
- edit_->CurTextPage()->GetTextPage()->toPlainText().trimmed();
+ QString content = edit_->CurPlainText().trimmed();
content.prepend("\n\n").prepend(PGP_CRYPT_BEGIN);
content.append("\n").append(PGP_CRYPT_END);
@@ -153,7 +152,7 @@ void MainWindow::slot_cut_pgp_header() {
return;
}
- QString content = edit_->CurTextPage()->GetTextPage()->toPlainText();
+ QString content = edit_->CurPlainText();
auto start = content.indexOf(PGP_CRYPT_BEGIN);
auto end = content.indexOf(PGP_CRYPT_END);
@@ -206,4 +205,159 @@ void MainWindow::SlotUpdateCryptoMenuStatus(unsigned int type) {
}
}
+void MainWindow::SlotGeneralEncrypt(bool) {
+ if (edit_->SlotCurPageFileTreeView() != nullptr) {
+ const auto* file_tree_view = edit_->SlotCurPageFileTreeView();
+ const auto path = file_tree_view->GetSelected();
+
+ const auto file_info = QFileInfo(path);
+ if (file_info.isFile()) {
+ this->SlotFileEncrypt(path);
+ } else if (file_info.isDir()) {
+ this->SlotDirectoryEncrypt(path);
+ }
+ }
+ if (edit_->SlotCurPageTextEdit() != nullptr) {
+ this->SlotEncrypt();
+ }
+}
+
+void MainWindow::SlotGeneralDecrypt(bool) {
+ if (edit_->SlotCurPageFileTreeView() != nullptr) {
+ const auto* file_tree_view = edit_->SlotCurPageFileTreeView();
+ const auto path = file_tree_view->GetSelected();
+
+ const auto file_info = QFileInfo(path);
+ if (file_info.isFile()) {
+ const QString extension = file_info.completeSuffix();
+
+ if (extension == "tar.gpg" || extension == "tar.asc") {
+ this->SlotArchiveDecrypt(path);
+ } else {
+ this->SlotFileDecrypt(path);
+ }
+ }
+ }
+ if (edit_->SlotCurPageTextEdit() != nullptr) {
+ this->SlotDecrypt();
+ }
+}
+
+void MainWindow::SlotGeneralSign(bool) {
+ if (edit_->SlotCurPageFileTreeView() != nullptr) {
+ const auto* file_tree_view = edit_->SlotCurPageFileTreeView();
+ const auto path = file_tree_view->GetSelected();
+
+ const auto file_info = QFileInfo(path);
+ if (file_info.isFile()) this->SlotFileSign(path);
+ }
+ if (edit_->SlotCurPageTextEdit() != nullptr) this->SlotSign();
+}
+
+void MainWindow::SlotGeneralVerify(bool) {
+ if (edit_->SlotCurPageFileTreeView() != nullptr) {
+ const auto* file_tree_view = edit_->SlotCurPageFileTreeView();
+ const auto path = file_tree_view->GetSelected();
+
+ const auto file_info = QFileInfo(path);
+ if (file_info.isFile()) this->SlotFileVerify(path);
+ }
+ if (edit_->SlotCurPageTextEdit() != nullptr) this->SlotVerify();
+}
+
+void MainWindow::SlotGeneralEncryptSign(bool) {
+ if (edit_->SlotCurPageFileTreeView() != nullptr) {
+ const auto* file_tree_view = edit_->SlotCurPageFileTreeView();
+ const auto path = file_tree_view->GetSelected();
+
+ const auto file_info = QFileInfo(path);
+ if (file_info.isFile()) {
+ this->SlotFileEncryptSign(path);
+ } else if (file_info.isDir()) {
+ this->SlotDirectoryEncryptSign(path);
+ }
+ }
+ if (edit_->SlotCurPageTextEdit() != nullptr) {
+ this->SlotEncryptSign();
+ }
+}
+
+void MainWindow::SlotGeneralDecryptVerify(bool) {
+ if (edit_->SlotCurPageFileTreeView() != nullptr) {
+ const auto* file_tree_view = edit_->SlotCurPageFileTreeView();
+ const auto path = file_tree_view->GetSelected();
+
+ const auto file_info = QFileInfo(path);
+ if (file_info.isFile()) {
+ const QString extension = file_info.completeSuffix();
+
+ if (extension == "tar.gpg" || extension == "tar.asc") {
+ this->SlotArchiveDecryptVerify(path);
+ } else {
+ this->SlotFileDecryptVerify(path);
+ }
+ }
+ }
+ if (edit_->SlotCurPageTextEdit() != nullptr) {
+ this->SlotDecryptVerify();
+ }
+}
+
+void MainWindow::SlotGeneralVerifyEMail(bool) {
+ if (edit_->SlotCurPageFileTreeView() != nullptr) {
+ const auto* file_tree_view = edit_->SlotCurPageFileTreeView();
+ const auto path = file_tree_view->GetSelected();
+
+ const auto file_info = QFileInfo(path);
+ if (file_info.isFile()) this->SlotFileVerifyEML(path);
+ }
+ if (edit_->SlotCurPageTextEdit() != nullptr) this->SlotVerifyEML();
+}
+
+void MainWindow::slot_clean_gpg_password_cache(bool) {
+ GpgFrontend::GpgAdvancedOperator::ClearGpgPasswordCache(
+ [=](int err, DataObjectPtr) {
+ if (err >= 0) {
+ QMessageBox::information(this, tr("Successful Operation"),
+ tr("Clear password cache successfully"));
+ } else {
+ QMessageBox::critical(this, tr("Failed Operation"),
+ tr("Failed to clear password cache of GnuPG"));
+ }
+ });
+}
+
+void MainWindow::slot_reload_gpg_components(bool) {
+ GpgFrontend::GpgAdvancedOperator::ReloadGpgComponents(
+ [=](int err, DataObjectPtr) {
+ if (err >= 0) {
+ QMessageBox::information(
+ this, tr("Successful Operation"),
+ tr("Reload all the GnuPG's components successfully"));
+ } else {
+ QMessageBox::critical(
+ this, tr("Failed Operation"),
+ tr("Failed to reload all or one of the GnuPG's component(s)"));
+ }
+ });
+}
+
+void MainWindow::slot_restart_gpg_components(bool) {
+ GpgFrontend::GpgAdvancedOperator::RestartGpgComponents();
+ Module::ListenRTPublishEvent(
+ this, "core", "gpg_advanced_operator.restart_gpg_components",
+ [=](Module::Namespace, Module::Key, int, std::any value) {
+ bool success_state = std::any_cast<bool>(value);
+ if (success_state) {
+ QMessageBox::information(
+ this, tr("Successful Operation"),
+ tr("Restart all the GnuPG's components successfully"));
+ } else {
+ QMessageBox::critical(
+ this, tr("Failed Operation"),
+ tr("Failed to restart all or one of the GnuPG's component(s)"));
+ }
+ });
+}
+
} // namespace GpgFrontend::UI
diff --git a/src/ui/main_window/MainWindowUI.cpp b/src/ui/main_window/MainWindowUI.cpp
index 80344306..11ea3406 100644
--- a/src/ui/main_window/MainWindowUI.cpp
+++ b/src/ui/main_window/MainWindowUI.cpp
@@ -28,9 +28,7 @@
#include "MainWindow.h"
#include "core/function/GlobalSettingStation.h"
-#include "core/function/gpg/GpgAdvancedOperator.h"
#include "core/module/ModuleManager.h"
-#include "core/utils/GpgUtils.h"
#include "dialog/controller/ModuleControllerDialog.h"
#include "ui/UserInterfaceUtils.h"
#include "ui/dialog/controller/GnuPGControllerDialog.h"
@@ -41,285 +39,160 @@
namespace GpgFrontend::UI {
void MainWindow::create_actions() {
- /* Main Menu
- */
- new_tab_act_ = new QAction(tr("New"), this);
- new_tab_act_->setIcon(QIcon(":/icons/misc_doc.png"));
- QList<QKeySequence> new_tab_act_shortcut_list;
- new_tab_act_shortcut_list.append(QKeySequence(Qt::CTRL | Qt::Key_N));
- new_tab_act_shortcut_list.append(QKeySequence(Qt::CTRL | Qt::Key_T));
- new_tab_act_->setShortcuts(new_tab_act_shortcut_list);
- new_tab_act_->setToolTip(tr("Open a new file"));
+ new_tab_act_ = create_action(
+ "new_tab", tr("New"), ":/icons/misc_doc.png", tr("Open a new file"),
+ {QKeySequence(Qt::CTRL | Qt::Key_N), QKeySequence(Qt::CTRL | Qt::Key_T)});
connect(new_tab_act_, &QAction::triggered, edit_, &TextEdit::SlotNewTab);
- open_act_ = new QAction(tr("Open..."), this);
- open_act_->setIcon(QIcon(":/icons/fileopen.png"));
- open_act_->setShortcut(QKeySequence::Open);
- open_act_->setToolTip(tr("Open an existing file"));
+ open_act_ = create_action("open", tr("Open..."), ":/icons/fileopen.png",
+ tr("Open an existing file"), {QKeySequence::Open});
connect(open_act_, &QAction::triggered, edit_, &TextEdit::SlotOpen);
- browser_act_ = new QAction(tr("File Browser"), this);
- browser_act_->setIcon(QIcon(":/icons/file-browser.png"));
- browser_act_->setShortcut(QKeySequence(Qt::CTRL | Qt::Key_B));
- browser_act_->setToolTip(tr("Open a file browser"));
+ browser_act_ = create_action(
+ "file_browser", tr("File Browser"), ":/icons/file-browser.png",
+ tr("Open a file browser"), {QKeySequence(Qt::CTRL | Qt::Key_B)});
connect(browser_act_, &QAction::triggered, this,
&MainWindow::slot_open_file_tab);
- save_act_ = new QAction(tr("Save File"), this);
- save_act_->setIcon(QIcon(":/icons/filesave.png"));
- save_act_->setShortcut(QKeySequence::Save);
- save_act_->setToolTip(tr("Save the current File"));
+ save_act_ = create_action("save", tr("Save File"), ":/icons/filesave.png",
+ tr("Save the current File"), {QKeySequence::Save});
connect(save_act_, &QAction::triggered, edit_, &TextEdit::SlotSave);
- save_as_act_ = new QAction(tr("Save As") + "...", this);
- save_as_act_->setIcon(QIcon(":/icons/filesaveas.png"));
- save_as_act_->setShortcut(QKeySequence::SaveAs);
- save_as_act_->setToolTip(tr("Save the current File as..."));
+ save_as_act_ =
+ create_action("save_as", tr("Save As") + "...", ":/icons/filesaveas.png",
+ tr("Save the current File as..."), {QKeySequence::SaveAs});
connect(save_as_act_, &QAction::triggered, edit_, &TextEdit::SlotSaveAs);
- print_act_ = new QAction(tr("Print"), this);
- print_act_->setIcon(QIcon(":/icons/fileprint.png"));
- print_act_->setShortcut(QKeySequence::Print);
- print_act_->setToolTip(tr("Print Document"));
+ print_act_ = create_action("print", tr("Print"), ":/icons/fileprint.png",
+ tr("Print Document"), {QKeySequence::Print});
connect(print_act_, &QAction::triggered, edit_, &TextEdit::SlotPrint);
- close_tab_act_ = new QAction(tr("Close"), this);
- close_tab_act_->setIcon(QIcon(":/icons/close.png"));
- close_tab_act_->setShortcut(QKeySequence::Close);
- close_tab_act_->setToolTip(tr("Close file"));
+ close_tab_act_ = create_action("close_tab", tr("Close"), ":/icons/close.png",
+ tr("Close file"), {QKeySequence::Close});
connect(close_tab_act_, &QAction::triggered, edit_, &TextEdit::SlotCloseTab);
- quit_act_ = new QAction(tr("Quit"), this);
- quit_act_->setShortcut(QKeySequence::Quit);
- quit_act_->setIcon(QIcon(":/icons/exit.png"));
- quit_act_->setToolTip(tr("Quit Program"));
+ quit_act_ = create_action("quit", tr("Quit"), ":/icons/exit.png",
+ tr("Quit Program"), {QKeySequence::Quit});
connect(quit_act_, &QAction::triggered, this, &MainWindow::close);
- /* Edit Menu
- */
- undo_act_ = new QAction(tr("Undo"), this);
- undo_act_->setIcon(QIcon(":/icons/undo.png"));
- undo_act_->setShortcut(QKeySequence::Undo);
- undo_act_->setToolTip(tr("Undo Last Edit Action"));
+ /* Edit Menu */
+ undo_act_ = create_action("undo", tr("Undo"), ":/icons/undo.png",
+ tr("Undo Last Edit Action"), {QKeySequence::Undo});
connect(undo_act_, &QAction::triggered, edit_, &TextEdit::SlotUndo);
- redo_act_ = new QAction(tr("Redo"), this);
- redo_act_->setIcon(QIcon(":/icons/redo.png"));
- redo_act_->setShortcut(QKeySequence::Redo);
- redo_act_->setToolTip(tr("Redo Last Edit Action"));
+ redo_act_ = create_action("redo", tr("Redo"), ":/icons/redo.png",
+ tr("Redo Last Edit Action"), {QKeySequence::Redo});
connect(redo_act_, &QAction::triggered, edit_, &TextEdit::SlotRedo);
- zoom_in_act_ = new QAction(tr("Zoom In"), this);
- zoom_in_act_->setIcon(QIcon(":/icons/zoomin.png"));
- zoom_in_act_->setShortcut(QKeySequence::ZoomIn);
+ zoom_in_act_ = create_action("zoom_in", tr("Zoom In"), ":/icons/zoomin.png",
+ tr("Zoom in"), {QKeySequence::ZoomIn});
connect(zoom_in_act_, &QAction::triggered, edit_, &TextEdit::SlotZoomIn);
- zoom_out_act_ = new QAction(tr("Zoom Out"), this);
- zoom_out_act_->setIcon(QIcon(":/icons/zoomout.png"));
- zoom_out_act_->setShortcut(QKeySequence::ZoomOut);
+ zoom_out_act_ =
+ create_action("zoom_out", tr("Zoom Out"), ":/icons/zoomout.png",
+ tr("Zoom out"), {QKeySequence::ZoomOut});
connect(zoom_out_act_, &QAction::triggered, edit_, &TextEdit::SlotZoomOut);
- paste_act_ = new QAction(tr("Paste"), this);
- paste_act_->setIcon(QIcon(":/icons/button_paste.png"));
- paste_act_->setShortcut(QKeySequence::Paste);
- paste_act_->setToolTip(tr("Paste Text From Clipboard"));
+ paste_act_ =
+ create_action("paste", tr("Paste"), ":/icons/button_paste.png",
+ tr("Paste Text From Clipboard"), {QKeySequence::Paste});
connect(paste_act_, &QAction::triggered, edit_, &TextEdit::SlotPaste);
- cut_act_ = new QAction(tr("Cut"), this);
- cut_act_->setIcon(QIcon(":/icons/button_cut.png"));
- cut_act_->setShortcut(QKeySequence::Cut);
- cut_act_->setToolTip(
- tr("Cut the current selection's contents to the "
- "clipboard"));
+ cut_act_ =
+ create_action("cut", tr("Cut"), ":/icons/button_cut.png",
+ tr("Cut the current selection's contents to the clipboard"),
+ {QKeySequence::Cut});
connect(cut_act_, &QAction::triggered, edit_, &TextEdit::SlotCut);
- copy_act_ = new QAction(tr("Copy"), this);
- copy_act_->setIcon(QIcon(":/icons/button_copy.png"));
- copy_act_->setShortcut(QKeySequence::Copy);
- copy_act_->setToolTip(
- tr("Copy the current selection's contents to the "
- "clipboard"));
+ copy_act_ = create_action(
+ "copy", tr("Copy"), ":/icons/button_copy.png",
+ tr("Copy the current selection's contents to the clipboard"),
+ {QKeySequence::Copy});
connect(copy_act_, &QAction::triggered, edit_, &TextEdit::SlotCopy);
- quote_act_ = new QAction(tr("Quote"), this);
- quote_act_->setIcon(QIcon(":/icons/quote.png"));
- quote_act_->setToolTip(tr("Quote whole text"));
+ quote_act_ = create_action("quote", tr("Quote"), ":/icons/quote.png",
+ tr("Quote whole text"));
connect(quote_act_, &QAction::triggered, edit_, &TextEdit::SlotQuote);
- select_all_act_ = new QAction(tr("Select All"), this);
- select_all_act_->setIcon(QIcon(":/icons/edit.png"));
- select_all_act_->setShortcut(QKeySequence::SelectAll);
- select_all_act_->setToolTip(tr("Select the whole text"));
+ select_all_act_ =
+ create_action("select_all", tr("Select All"), ":/icons/edit.png",
+ tr("Select the whole text"), {QKeySequence::SelectAll});
connect(select_all_act_, &QAction::triggered, edit_,
&TextEdit::SlotSelectAll);
- find_act_ = new QAction(tr("Find"), this);
- find_act_->setIcon(QIcon(":/icons/search.png"));
- find_act_->setShortcut(QKeySequence::Find);
- find_act_->setToolTip(tr("Find a word"));
+ find_act_ = create_action("find", tr("Find"), ":/icons/search.png",
+ tr("Find a word"), {QKeySequence::Find});
connect(find_act_, &QAction::triggered, this, &MainWindow::slot_find);
- clean_double_line_breaks_act_ = new QAction(tr("Remove spacing"), this);
- clean_double_line_breaks_act_->setIcon(
- QIcon(":/icons/format-line-spacing-triple.png"));
- // cleanDoubleLineBreaksAct->setShortcut(QKeySequence::SelectAll);
- clean_double_line_breaks_act_->setToolTip(
+ clean_double_line_breaks_act_ = create_action(
+ "remove_spacing", tr("Remove spacing"),
+ ":/icons/format-line-spacing-triple.png",
tr("Remove double linebreaks, e.g. in pasted text from Web Mailer"));
connect(clean_double_line_breaks_act_, &QAction::triggered, this,
&MainWindow::slot_clean_double_line_breaks);
- open_settings_act_ = new QAction(tr("Settings"), this);
- open_settings_act_->setIcon(QIcon(":/icons/setting.png"));
- open_settings_act_->setToolTip(tr("Open settings dialog"));
+ open_settings_act_ =
+ create_action("settings", tr("Settings"), ":/icons/setting.png",
+ tr("Open settings dialog"), {QKeySequence::Preferences});
open_settings_act_->setMenuRole(QAction::PreferencesRole);
- open_settings_act_->setShortcut(QKeySequence::Preferences);
connect(open_settings_act_, &QAction::triggered, this,
&MainWindow::slot_open_settings_dialog);
- /* Crypt Menu
+ /*
+ * Crypt Menu
*/
- encrypt_act_ = new QAction(tr("Encrypt"), this);
- encrypt_act_->setIcon(QIcon(":/icons/encrypted.png"));
- encrypt_act_->setShortcut(QKeySequence(Qt::CTRL | Qt::Key_E));
-
- encrypt_act_->setToolTip(tr("Encrypt Message"));
- connect(encrypt_act_, &QAction::triggered, this, [this]() {
- if (edit_->SlotCurPageFileTreeView() != nullptr) {
- const auto* file_tree_view = edit_->SlotCurPageFileTreeView();
- const auto path = file_tree_view->GetSelected();
-
- const auto file_info = QFileInfo(path);
- if (file_info.isFile()) {
- this->SlotFileEncrypt(path);
- } else if (file_info.isDir()) {
- this->SlotDirectoryEncrypt(path);
- }
- }
- if (edit_->SlotCurPageTextEdit() != nullptr) {
- this->SlotEncrypt();
- }
- });
-
- encrypt_sign_act_ = new QAction(tr("Encrypt Sign"), this);
- encrypt_sign_act_->setIcon(QIcon(":/icons/encrypted_signed.png"));
- encrypt_sign_act_->setShortcut(
- QKeySequence(Qt::CTRL | Qt::SHIFT | Qt::Key_E));
-
- encrypt_sign_act_->setToolTip(tr("Encrypt and Sign Message"));
- connect(encrypt_sign_act_, &QAction::triggered, this, [this]() {
- if (edit_->SlotCurPageFileTreeView() != nullptr) {
- const auto* file_tree_view = edit_->SlotCurPageFileTreeView();
- const auto path = file_tree_view->GetSelected();
-
- const auto file_info = QFileInfo(path);
- if (file_info.isFile()) {
- this->SlotFileEncryptSign(path);
- } else if (file_info.isDir()) {
- this->SlotDirectoryEncryptSign(path);
- }
- }
- if (edit_->SlotCurPageTextEdit() != nullptr) {
- this->SlotEncryptSign();
- }
- });
-
- decrypt_act_ = new QAction(tr("Decrypt"), this);
- decrypt_act_->setIcon(QIcon(":/icons/decrypted.png"));
- decrypt_act_->setShortcut(QKeySequence(Qt::CTRL | Qt::Key_D));
- decrypt_act_->setToolTip(tr("Decrypt Message"));
- connect(decrypt_act_, &QAction::triggered, this, [this]() {
- if (edit_->SlotCurPageFileTreeView() != nullptr) {
- const auto* file_tree_view = edit_->SlotCurPageFileTreeView();
- const auto path = file_tree_view->GetSelected();
-
- const auto file_info = QFileInfo(path);
- if (file_info.isFile()) {
- const QString extension = file_info.completeSuffix();
-
- if (extension == "tar.gpg" || extension == "tar.asc") {
- this->SlotArchiveDecrypt(path);
- } else {
- this->SlotFileDecrypt(path);
- }
- }
- }
- if (edit_->SlotCurPageTextEdit() != nullptr) {
- this->SlotDecrypt();
- }
- });
-
- decrypt_verify_act_ = new QAction(tr("Decrypt Verify"), this);
- decrypt_verify_act_->setIcon(QIcon(":/icons/decrypted_verified.png"));
- decrypt_verify_act_->setShortcut(
- QKeySequence(Qt::CTRL | Qt::SHIFT | Qt::Key_D));
- decrypt_verify_act_->setToolTip(tr("Decrypt and Verify Message"));
- connect(decrypt_verify_act_, &QAction::triggered, this, [this]() {
- if (edit_->SlotCurPageFileTreeView() != nullptr) {
- const auto* file_tree_view = edit_->SlotCurPageFileTreeView();
- const auto path = file_tree_view->GetSelected();
-
- const auto file_info = QFileInfo(path);
- if (file_info.isFile()) {
- const QString extension = file_info.completeSuffix();
-
- if (extension == "tar.gpg" || extension == "tar.asc") {
- this->SlotArchiveDecryptVerify(path);
- } else {
- this->SlotFileDecryptVerify(path);
- }
- }
- }
- if (edit_->SlotCurPageTextEdit() != nullptr) {
- this->SlotDecryptVerify();
- }
- });
-
- sign_act_ = new QAction(tr("Sign"), this);
- sign_act_->setIcon(QIcon(":/icons/signature.png"));
- sign_act_->setShortcut(QKeySequence(Qt::CTRL | Qt::SHIFT | Qt::Key_I));
- sign_act_->setToolTip(tr("Sign Message"));
- connect(sign_act_, &QAction::triggered, this, [this]() {
- if (edit_->SlotCurPageFileTreeView() != nullptr) {
- const auto* file_tree_view = edit_->SlotCurPageFileTreeView();
- const auto path = file_tree_view->GetSelected();
-
- const auto file_info = QFileInfo(path);
- if (file_info.isFile()) this->SlotFileSign(path);
- }
- if (edit_->SlotCurPageTextEdit() != nullptr) this->SlotSign();
- });
+ encrypt_act_ = create_action("encrypt", tr("Encrypt"),
+ ":/icons/encrypted.png", tr("Encrypt Message"),
+ {QKeySequence(Qt::CTRL | Qt::Key_E)});
+ connect(encrypt_act_, &QAction::triggered, this,
+ &MainWindow::SlotGeneralEncrypt);
+
+ encrypt_sign_act_ = create_action(
+ "encrypt_sign", tr("Encrypt Sign"), ":/icons/encrypted_signed.png",
+ tr("Encrypt and Sign Message"),
+ {QKeySequence(Qt::CTRL | Qt::SHIFT | Qt::Key_E)});
+ connect(encrypt_sign_act_, &QAction::triggered, this,
+ &MainWindow::SlotGeneralEncryptSign);
+
+ decrypt_act_ = create_action("decrypt", tr("Decrypt"),
+ ":/icons/decrypted.png", tr("Decrypt Message"),
+ {QKeySequence(Qt::CTRL | Qt::Key_D)});
+ connect(decrypt_act_, &QAction::triggered, this,
+ &MainWindow::SlotGeneralDecrypt);
+
+ decrypt_verify_act_ = create_action(
+ "decrypt_verify", tr("Decrypt Verify"), ":/icons/decrypted_verified.png",
+ tr("Decrypt and Verify Message"),
+ {QKeySequence(Qt::CTRL | Qt::SHIFT | Qt::Key_D)});
+ connect(decrypt_verify_act_, &QAction::triggered, this,
+ &MainWindow::SlotGeneralDecryptVerify);
+
+ sign_act_ = create_action("sign", tr("Sign"), ":/icons/signature.png",
+ tr("Sign Message"),
+ {QKeySequence(Qt::CTRL | Qt::SHIFT | Qt::Key_I)});
+ connect(sign_act_, &QAction::triggered, this, &MainWindow::SlotGeneralSign);
+
+ verify_act_ = create_action("verify", tr("Verify"), ":/icons/verify.png",
+ tr("Verify Message"),
+ {QKeySequence(Qt::CTRL | Qt::SHIFT | Qt::Key_V)});
+ connect(verify_act_, &QAction::triggered, this,
+ &MainWindow::SlotGeneralVerify);
- verify_act_ = new QAction(tr("Verify"), this);
- verify_act_->setIcon(QIcon(":/icons/verify.png"));
- verify_act_->setShortcut(QKeySequence(Qt::CTRL | Qt::SHIFT | Qt::Key_V));
- verify_act_->setToolTip(tr("Verify Message"));
- connect(verify_act_, &QAction::triggered, this, [this]() {
- if (edit_->SlotCurPageFileTreeView() != nullptr) {
- const auto* file_tree_view = edit_->SlotCurPageFileTreeView();
- const auto path = file_tree_view->GetSelected();
-
- const auto file_info = QFileInfo(path);
- if (file_info.isFile()) this->SlotFileVerify(path);
- }
- if (edit_->SlotCurPageTextEdit() != nullptr) this->SlotVerify();
- });
-
- /* Key Menu
+ /*
+ * Key Menu
*/
-
- import_key_from_file_act_ = new QAction(tr("File"), this);
- import_key_from_file_act_->setIcon(QIcon(":/icons/import_key_from_file.png"));
- import_key_from_file_act_->setToolTip(tr("Import New Key From File"));
+ import_key_from_file_act_ = create_action("import_key_from_file", tr("File"),
+ ":/icons/import_key_from_file.png",
+ tr("Import New Key From File"));
connect(import_key_from_file_act_, &QAction::triggered, this, [=]() {
CommonUtils::GetInstance()->SlotImportKeyFromFile(
this, m_key_list_->GetCurrentGpgContextChannel());
});
- import_key_from_clipboard_act_ = new QAction(tr("Clipboard"), this);
- import_key_from_clipboard_act_->setIcon(
- QIcon(":/icons/import_key_from_clipboard.png"));
- import_key_from_clipboard_act_->setToolTip(
- tr("Import New Key From Clipboard"));
+ import_key_from_clipboard_act_ =
+ create_action("import_key_from_clipboard", tr("Clipboard"),
+ ":/icons/import_key_from_clipboard.png",
+ tr("Import New Key From Clipboard"));
connect(import_key_from_clipboard_act_, &QAction::triggered, this, [this]() {
CommonUtils::GetInstance()->SlotImportKeyFromClipboard(
this, m_key_list_->GetCurrentGpgContextChannel());
@@ -331,249 +204,196 @@ void MainWindow::create_actions() {
.value("network/forbid_all_gnupg_connection", false)
.toBool();
- import_key_from_key_server_act_ = new QAction(tr("Keyserver"), this);
- import_key_from_key_server_act_->setIcon(
- QIcon(":/icons/import_key_from_server.png"));
- import_key_from_key_server_act_->setToolTip(
- tr("Import New Key From Keyserver"));
+ import_key_from_key_server_act_ =
+ create_action("import_key_from_keyserver", tr("Keyserver"),
+ ":/icons/import_key_from_server.png",
+ tr("Import New Key From Keyserver"));
import_key_from_key_server_act_->setDisabled(forbid_all_gnupg_connection);
connect(import_key_from_key_server_act_, &QAction::triggered, this, [this]() {
CommonUtils::GetInstance()->SlotImportKeyFromKeyServer(
this, m_key_list_->GetCurrentGpgContextChannel());
});
- import_key_from_edit_act_ = new QAction(tr("Editor"), this);
- import_key_from_edit_act_->setIcon(QIcon(":/icons/editor.png"));
- import_key_from_edit_act_->setToolTip(tr("Import New Key From Editor"));
+ import_key_from_edit_act_ =
+ create_action("import_key_from_edit", tr("Editor"), ":/icons/editor.png",
+ tr("Import New Key From Editor"));
connect(import_key_from_edit_act_, &QAction::triggered, this,
&MainWindow::slot_import_key_from_edit);
- open_key_management_act_ = new QAction(tr("Manage Keys"), this);
- open_key_management_act_->setIcon(QIcon(":/icons/keymgmt.png"));
- open_key_management_act_->setToolTip(tr("Open Key Management"));
+ open_key_management_act_ =
+ create_action("open_key_management", tr("Manage Keys"),
+ ":/icons/keymgmt.png", tr("Open Key Management"));
connect(open_key_management_act_, &QAction::triggered, this,
&MainWindow::slot_open_key_management);
- clean_gpg_password_cache_act_ = new QAction(tr("Clear Password Cache"), this);
- clean_gpg_password_cache_act_->setIcon(QIcon(":/icons/clear-f.png"));
- clean_gpg_password_cache_act_->setToolTip(
- tr("Clear Password Cache of GnuPG"));
- connect(clean_gpg_password_cache_act_, &QAction::triggered, this, [=]() {
- GpgFrontend::GpgAdvancedOperator::ClearGpgPasswordCache([=](int err,
- DataObjectPtr) {
- if (err >= 0) {
- QMessageBox::information(this, tr("Successful Operation"),
- tr("Clear password cache successfully"));
- } else {
- QMessageBox::critical(this, tr("Failed Operation"),
- tr("Failed to clear password cache of GnuPG"));
- }
- });
- });
-
- reload_components_act_ = new QAction(tr("Reload All Components"), this);
- reload_components_act_->setIcon(QIcon(":/icons/restart.png"));
- reload_components_act_->setToolTip(tr("Reload All GnuPG's Components"));
- connect(reload_components_act_, &QAction::triggered, this, [=]() {
- GpgFrontend::GpgAdvancedOperator::ReloadGpgComponents(
- [=](int err, DataObjectPtr) {
- if (err >= 0) {
- QMessageBox::information(
- this, tr("Successful Operation"),
- tr("Reload all the GnuPG's components successfully"));
- } else {
- QMessageBox::critical(
- this, tr("Failed Operation"),
- tr("Failed to reload all or one of the GnuPG's component(s)"));
- }
- });
- });
-
- restart_components_act_ = new QAction(tr("Restart All Components"), this);
- restart_components_act_->setIcon(QIcon(":/icons/restart.png"));
- restart_components_act_->setToolTip(tr("Restart All GnuPG's Components"));
- connect(restart_components_act_, &QAction::triggered, this, [=]() {
- GpgFrontend::GpgAdvancedOperator::RestartGpgComponents();
- Module::ListenRTPublishEvent(
- this, "core", "gpg_advanced_operator.restart_gpg_components",
- [=](Module::Namespace, Module::Key, int, std::any value) {
- bool success_state = std::any_cast<bool>(value);
- if (success_state) {
- QMessageBox::information(
- this, tr("Successful Operation"),
- tr("Restart all the GnuPG's components successfully"));
- } else {
- QMessageBox::critical(
- this, tr("Failed Operation"),
- tr("Failed to restart all or one of the GnuPG's component(s)"));
- }
- });
- });
-
- gnupg_controller_open_act_ = new QAction(tr("Open GnuPG Controller"), this);
- gnupg_controller_open_act_->setIcon(QIcon(":/icons/configure.png"));
- gnupg_controller_open_act_->setToolTip(tr("Open GnuPG Controller Dialog"));
+ clean_gpg_password_cache_act_ =
+ create_action("clean_password_cache", tr("Clear Password Cache"),
+ ":/icons/clear-f.png", tr("Clear Password Cache of GnuPG"));
+ connect(clean_gpg_password_cache_act_, &QAction::triggered, this,
+ &MainWindow::slot_clean_gpg_password_cache);
+
+ reload_components_act_ =
+ create_action("reload_components", tr("Reload All Components"),
+ ":/icons/restart.png", tr("Reload All GnuPG's Components"));
+ connect(reload_components_act_, &QAction::triggered, this,
+ &MainWindow::slot_reload_gpg_components);
+
+ restart_components_act_ = create_action(
+ "restart_components", tr("Restart All Components"), ":/icons/restart.png",
+ tr("Restart All GnuPG's Components"));
+ connect(restart_components_act_, &QAction::triggered, this,
+ &MainWindow::slot_restart_gpg_components);
+
+ gnupg_controller_open_act_ = create_action(
+ "gnupg_controller_open", tr("Open GnuPG Controller"),
+ ":/icons/configure.png", tr("Open GnuPG Controller Dialog"));
connect(gnupg_controller_open_act_, &QAction::triggered, this,
[this]() { (new GnuPGControllerDialog(this))->exec(); });
- module_controller_open_act_ = new QAction(tr("Open Module Controller"), this);
- module_controller_open_act_->setIcon(QIcon(":/icons/module.png"));
- module_controller_open_act_->setToolTip(tr("Open Module Controller Dialog"));
+ module_controller_open_act_ =
+ create_action("module_controller_open", tr("Open Module Controller"),
+ ":/icons/module.png", tr("Open Module Controller Dialog"));
connect(module_controller_open_act_, &QAction::triggered, this,
[this]() { (new ModuleControllerDialog(this))->exec(); });
/**
- * E-Mmail Menu
+ * E-Mail Menu
*/
if (Module::IsModuleActivate(kEmailModuleID)) {
- verify_email_by_eml_data_act_ = new QAction(tr("Verify E-Mail"), this);
- verify_email_by_eml_data_act_->setIcon(QIcon(":/icons/email-check.png"));
- verify_email_by_eml_data_act_->setToolTip(
- tr("Verify RAW E-Mail Data (EML)"));
- connect(verify_email_by_eml_data_act_, &QAction::triggered, this, [this]() {
- if (edit_->SlotCurPageFileTreeView() != nullptr) {
- const auto* file_tree_view = edit_->SlotCurPageFileTreeView();
- const auto path = file_tree_view->GetSelected();
-
- const auto file_info = QFileInfo(path);
- if (file_info.isFile()) this->SlotFileVerifyEML(path);
- }
- if (edit_->SlotCurPageTextEdit() != nullptr) this->SlotVerifyEML();
- });
+ verify_email_by_eml_data_act_ = create_action(
+ "verify_email_by_eml_data", tr("Verify E-Mail"),
+ ":/icons/email-check.png", tr("Verify RAW E-Mail Data (EML)"));
+ connect(verify_email_by_eml_data_act_, &QAction::triggered, this,
+ &MainWindow::SlotGeneralVerifyEMail);
}
/*
* About Menu
*/
- about_act_ = new QAction(tr("About"), this);
- about_act_->setIcon(QIcon(":/icons/help.png"));
- about_act_->setToolTip(tr("Show the application's About box"));
+ about_act_ = create_action("about", tr("About"), ":/icons/help.png",
+ tr("Show the application's About box"));
about_act_->setMenuRole(QAction::AboutRole);
connect(about_act_, &QAction::triggered, this,
[=]() { new AboutDialog(0, this); });
if (Module::IsModuleActivate(kGnuPGInfoGatheringModuleID)) {
- gnupg_act_ = new QAction(tr("GnuPG"), this);
- gnupg_act_->setIcon(QIcon(":/icons/key.png"));
- gnupg_act_->setToolTip(tr("Information about Gnupg"));
+ gnupg_act_ = create_action("gnupg_info", tr("GnuPG"), ":/icons/key.png",
+ tr("Information about Gnupg"));
connect(gnupg_act_, &QAction::triggered, this,
[=]() { new AboutDialog(tr("GnuPG"), this); });
}
- translate_act_ = new QAction(tr("Translate"), this);
- translate_act_->setIcon(QIcon(":/icons/translate.png"));
- translate_act_->setToolTip(tr("Information about translation"));
+ translate_act_ =
+ create_action("translate", tr("Translate"), ":/icons/translate.png",
+ tr("Information about translation"));
connect(translate_act_, &QAction::triggered, this,
[=]() { new AboutDialog(tr("Translators"), this); });
if (Module::IsModuleActivate(kVersionCheckingModuleID)) {
- check_update_act_ = new QAction(tr("Check for Updates"), this);
- check_update_act_->setIcon(QIcon(":/icons/update.png"));
- check_update_act_->setToolTip(tr("Check for updates"));
+ check_update_act_ =
+ create_action("check_update", tr("Check for Updates"),
+ ":/icons/update.png", tr("Check for updates"));
connect(check_update_act_, &QAction::triggered, this,
[=]() { new AboutDialog(tr("Update"), this); });
}
- start_wizard_act_ = new QAction(tr("Open Wizard"), this);
- start_wizard_act_->setIcon(QIcon(":/icons/wizard.png"));
- start_wizard_act_->setToolTip(tr("Open the wizard"));
+ start_wizard_act_ =
+ create_action("start_wizard", tr("Open Wizard"), ":/icons/wizard.png",
+ tr("Open the wizard"));
connect(start_wizard_act_, &QAction::triggered, this,
&MainWindow::slot_start_wizard);
append_selected_keys_act_ =
- new QAction(tr("Append Public Key to Editor"), this);
- append_selected_keys_act_->setToolTip(
- tr("Append selected Keypair's Public Key to Editor"));
+ create_action("append_selected_keys", tr("Append Public Key to Editor"),
+ "", tr("Append selected Keypair's Public Key to Editor"));
connect(append_selected_keys_act_, &QAction::triggered, this,
&MainWindow::slot_append_selected_keys);
- append_key_create_date_to_editor_act_ =
- new QAction(tr("Append Create DateTime to Editor"), this);
- append_key_create_date_to_editor_act_->setToolTip(
+ append_key_create_date_to_editor_act_ = create_action(
+ "append_key_create_date", tr("Append Create DateTime to Editor"), "",
tr("Append selected Key's creation date and time to Editor"));
connect(append_key_create_date_to_editor_act_, &QAction::triggered, this,
&MainWindow::slot_append_keys_create_datetime);
- append_key_expire_date_to_editor_act_ =
- new QAction(tr("Append Expire DateTime to Editor"), this);
- append_key_expire_date_to_editor_act_->setToolTip(
+ append_key_expire_date_to_editor_act_ = create_action(
+ "append_key_expire_date", tr("Append Expire DateTime to Editor"), "",
tr("Append selected Key's expiration date and time to Editor"));
connect(append_key_expire_date_to_editor_act_, &QAction::triggered, this,
&MainWindow::slot_append_keys_expire_datetime);
- append_key_fingerprint_to_editor_act_ =
- new QAction(tr("Append Fingerprint to Editor"), this);
- append_key_expire_date_to_editor_act_->setToolTip(
+ append_key_fingerprint_to_editor_act_ = create_action(
+ "append_key_fingerprint", tr("Append Fingerprint to Editor"), "",
tr("Append selected Key's Fingerprint to Editor"));
connect(append_key_fingerprint_to_editor_act_, &QAction::triggered, this,
&MainWindow::slot_append_keys_fingerprint);
- copy_mail_address_to_clipboard_act_ = new QAction(tr("Copy Email"), this);
- copy_mail_address_to_clipboard_act_->setToolTip(
- tr("Copy selected Keypair's to clipboard"));
+ copy_mail_address_to_clipboard_act_ =
+ create_action("copy_email", tr("Copy Email"), "",
+ tr("Copy selected Keypair's to clipboard"));
connect(copy_mail_address_to_clipboard_act_, &QAction::triggered, this,
&MainWindow::slot_copy_mail_address_to_clipboard);
copy_key_default_uid_to_clipboard_act_ =
- new QAction(tr("Copy Default UID"), this);
- copy_key_default_uid_to_clipboard_act_->setToolTip(
- tr("Copy selected Keypair's default UID to clipboard"));
+ create_action("copy_default_uid", tr("Copy Default UID"), "",
+ tr("Copy selected Keypair's default UID to clipboard"));
connect(copy_key_default_uid_to_clipboard_act_, &QAction::triggered, this,
&MainWindow::slot_copy_default_uid_to_clipboard);
- copy_key_id_to_clipboard_act_ = new QAction(tr("Copy Key ID"), this);
- copy_key_id_to_clipboard_act_->setToolTip(
- tr("Copy selected Keypair's ID to clipboard"));
+ copy_key_id_to_clipboard_act_ =
+ create_action("copy_key_id", tr("Copy Key ID"), "",
+ tr("Copy selected Keypair's ID to clipboard"));
connect(copy_key_id_to_clipboard_act_, &QAction::triggered, this,
&MainWindow::slot_copy_key_id_to_clipboard);
- show_key_details_act_ = new QAction(tr("Show Key Details"), this);
- show_key_details_act_->setToolTip(tr("Show Details for this Key"));
+ show_key_details_act_ =
+ create_action("show_key_details", tr("Show Key Details"), "",
+ tr("Show Details for this Key"));
connect(show_key_details_act_, &QAction::triggered, this,
&MainWindow::slot_show_key_details);
- add_key_2_favourite_act_ = new QAction(tr("Add To Favourite"), this);
- add_key_2_favourite_act_->setToolTip(tr("Add this key to Favourite Table"));
+ add_key_2_favourite_act_ =
+ create_action("add_to_favourite", tr("Add To Favourite"), "",
+ tr("Add this key to Favourite Table"));
add_key_2_favourite_act_->setData(QVariant("add_key_2_favourite_action"));
connect(add_key_2_favourite_act_, &QAction::triggered, this,
&MainWindow::slot_add_key_2_favorite);
remove_key_from_favourtie_act_ =
- new QAction(tr("Remove From Favourite"), this);
- remove_key_from_favourtie_act_->setToolTip(
- tr("Remove this key from Favourite Table"));
+ create_action("remove_from_favourite", tr("Remove From Favourite"), "",
+ tr("Remove this key from Favourite Table"));
remove_key_from_favourtie_act_->setData(
QVariant("remove_key_from_favourtie_action"));
connect(remove_key_from_favourtie_act_, &QAction::triggered, this,
&MainWindow::slot_remove_key_from_favorite);
- set_owner_trust_of_key_act_ = new QAction(tr("Set Owner Trust Level"), this);
- set_owner_trust_of_key_act_->setToolTip(tr("Set Owner Trust Level"));
+ set_owner_trust_of_key_act_ =
+ create_action("set_owner_trust_level", tr("Set Owner Trust Level"), "",
+ tr("Set Owner Trust Level"));
set_owner_trust_of_key_act_->setData(QVariant("set_owner_trust_level"));
connect(set_owner_trust_of_key_act_, &QAction::triggered, this,
&MainWindow::slot_set_owner_trust_level_of_key);
- /* Key-Shortcuts for Tab-Switchung-Action
- */
- switch_tab_up_act_ = new QAction(this);
- switch_tab_up_act_->setShortcut(QKeySequence::NextChild);
+ /* Key-Shortcuts for Tab-Switching-Action */
+ switch_tab_up_act_ =
+ create_action("switch_tab_up", "", "", "", {QKeySequence::NextChild});
connect(switch_tab_up_act_, &QAction::triggered, edit_,
&TextEdit::SlotSwitchTabUp);
this->addAction(switch_tab_up_act_);
- switch_tab_down_act_ = new QAction(this);
- switch_tab_down_act_->setShortcut(QKeySequence::PreviousChild);
+ switch_tab_down_act_ = create_action("switch_tab_down", "", "", "",
+ {QKeySequence::PreviousChild});
connect(switch_tab_down_act_, &QAction::triggered, edit_,
&TextEdit::SlotSwitchTabDown);
this->addAction(switch_tab_down_act_);
- cut_pgp_header_act_ = new QAction(tr("Remove PGP Header"), this);
- cut_pgp_header_act_->setIcon(QIcon(":/icons/minus.png"));
+ cut_pgp_header_act_ =
+ create_action("cut_pgp_header", tr("Remove PGP Header"),
+ ":/icons/minus.png", tr("Remove PGP Header"));
connect(cut_pgp_header_act_, &QAction::triggered, this,
&MainWindow::slot_cut_pgp_header);
- add_pgp_header_act_ = new QAction(tr("Add PGP Header"), this);
- add_pgp_header_act_->setIcon(QIcon(":/icons/add.png"));
+ add_pgp_header_act_ = create_action("add_pgp_header", tr("Add PGP Header"),
+ ":/icons/add.png", tr("Add PGP Header"));
connect(add_pgp_header_act_, &QAction::triggered, this,
&MainWindow::slot_add_pgp_header);
}
diff --git a/src/ui/widgets/InfoBoardWidget.cpp b/src/ui/widgets/InfoBoardWidget.cpp
index 92b22452..57d3d87b 100644
--- a/src/ui/widgets/InfoBoardWidget.cpp
+++ b/src/ui/widgets/InfoBoardWidget.cpp
@@ -95,16 +95,7 @@ void InfoBoardWidget::SlotRefresh(const QString& text, InfoBoardStatus status) {
ui_->infoBoard->verticalScrollBar()->setValue(0);
}
-void InfoBoardWidget::AssociateTextEdit(QTextEdit* edit) {
- if (m_text_page_ != nullptr) {
- disconnect(m_text_page_, &QTextEdit::textChanged, this,
- &InfoBoardWidget::SlotReset);
- }
- this->m_text_page_ = edit;
- connect(edit, &QTextEdit::textChanged, this, &InfoBoardWidget::SlotReset);
-}
-
-void InfoBoardWidget::AssociateTabWidget(TextEditTabWidget* tab) {
+void InfoBoardWidget::AssociateTabWidget(QTabWidget* tab) {
m_text_page_ = nullptr;
m_tab_widget_ = tab;
connect(tab, &QTabWidget::tabBarClicked, this, &InfoBoardWidget::SlotReset);
diff --git a/src/ui/widgets/InfoBoardWidget.h b/src/ui/widgets/InfoBoardWidget.h
index 1dfe7a52..c0416e2d 100644
--- a/src/ui/widgets/InfoBoardWidget.h
+++ b/src/ui/widgets/InfoBoardWidget.h
@@ -65,16 +65,9 @@ class InfoBoardWidget : public QWidget {
/**
* @brief
*
- * @param edit
- */
- void AssociateTextEdit(QTextEdit* edit);
-
- /**
- * @brief
- *
* @param tab
*/
- void AssociateTabWidget(TextEditTabWidget* tab);
+ void AssociateTabWidget(QTabWidget* tab);
/**
* @brief
diff --git a/src/ui/widgets/PlainTextEditorPage.cpp b/src/ui/widgets/PlainTextEditorPage.cpp
index c1c679a6..ac41c9ab 100644
--- a/src/ui/widgets/PlainTextEditorPage.cpp
+++ b/src/ui/widgets/PlainTextEditorPage.cpp
@@ -81,7 +81,13 @@ const QString &PlainTextEditorPage::GetFilePath() const {
return full_file_path_;
}
-QPlainTextEdit *PlainTextEditorPage::GetTextPage() { return ui_->textPage; }
+auto PlainTextEditorPage::GetTextPage() -> QPlainTextEdit * {
+ return ui_->textPage;
+}
+
+auto PlainTextEditorPage::GetPlainText() -> QString {
+ return ui_->textPage->toPlainText();
+}
void PlainTextEditorPage::NotifyFileSaved() {
this->is_crlf_ = false;
@@ -212,7 +218,7 @@ void PlainTextEditorPage::slot_insert_text(QByteArray bytes_data) {
read_bytes_ += bytes_data.size();
// insert the text to the text page
- this->GetTextPage()->insertPlainText(bytes_data);
+ this->ui_->textPage->insertPlainText(bytes_data);
this->ui_->characterLabel->setText(
tr("%1 character(s)").arg(this->GetTextPage()->toPlainText().size()));
diff --git a/src/ui/widgets/PlainTextEditorPage.h b/src/ui/widgets/PlainTextEditorPage.h
index 9c2edc6e..c4423378 100644
--- a/src/ui/widgets/PlainTextEditorPage.h
+++ b/src/ui/widgets/PlainTextEditorPage.h
@@ -51,7 +51,7 @@ class PlainTextEditorPage : public QWidget {
/**
* @details Get the filepath of the currently activated tab.
*/
- [[nodiscard]] const QString& GetFilePath() const;
+ [[nodiscard]] auto GetFilePath() const -> const QString&;
/**
* @details Set filepath of currently activated tab.
@@ -63,7 +63,14 @@ class PlainTextEditorPage : public QWidget {
/**
* @details Return pointer tp the textedit of the currently activated tab.
*/
- QPlainTextEdit* GetTextPage();
+ auto GetTextPage() -> QPlainTextEdit*;
+
+ /**
+ * @brief Get the Plain Text object
+ *
+ * @return QString
+ */
+ auto GetPlainText() -> QString;
/**
* @details Show additional widget at buttom of currently active tab
diff --git a/src/ui/widgets/TextEdit.cpp b/src/ui/widgets/TextEdit.cpp
index d0cfe58e..2b1f4766 100644
--- a/src/ui/widgets/TextEdit.cpp
+++ b/src/ui/widgets/TextEdit.cpp
@@ -30,12 +30,9 @@
#include <QtPrintSupport>
#include <cstddef>
-#include <tuple>
#include <utility>
-#include <vector>
#include "core/GpgModel.h"
-#include "ui/UISignalStation.h"
#include "ui/widgets/HelpPage.h"
#include "ui/widgets/TextEditTabWidget.h"
@@ -71,7 +68,7 @@ void TextEdit::SlotNewHelpTab(const QString& title, const QString& path) const {
tab_widget_->setCurrentIndex(tab_widget_->count() - 1);
}
-void TextEdit::SlotNewFileTab() {
+void TextEdit::SlotNewFileBrowserTab() {
auto const target_directory = QFileDialog::getExistingDirectory(
this, tr("Open Directory"), QDir::home().path(),
QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks);
@@ -549,4 +546,12 @@ void TextEdit::SlotSelectAll() const {
}
CurTextPage()->GetTextPage()->selectAll();
}
+
+auto TextEdit::CurPlainText() const -> QString {
+ auto* plain_text_tab = CurTextPage();
+ if (plain_text_tab == nullptr) return {};
+ return plain_text_tab->GetPlainText();
+}
+
+auto TextEdit::TabWidget() const -> QTabWidget* { return tab_widget_; }
} // namespace GpgFrontend::UI
diff --git a/src/ui/widgets/TextEdit.h b/src/ui/widgets/TextEdit.h
index 5219196f..30540569 100644
--- a/src/ui/widgets/TextEdit.h
+++ b/src/ui/widgets/TextEdit.h
@@ -88,8 +88,19 @@ class TextEdit : public QWidget {
*/
[[nodiscard]] auto UnsavedDocuments() const -> QHash<int, QString>;
- TextEditTabWidget*
- tab_widget_; /** Widget containing the tabs of the editor */
+ /**
+ * @details textpage of the currently activated tab
+ * @return \li reference to QTextEdit if tab has one
+ * \li 0 otherwise (e.g. if helppage)
+ */
+ [[nodiscard]] auto CurPlainText() const -> QString;
+
+ /**
+ * @brief
+ *
+ * @return QTabWidget*
+ */
+ [[nodiscard]] auto TabWidget() const -> QTabWidget*;
public slots:
@@ -171,7 +182,7 @@ class TextEdit : public QWidget {
/**
* New File Tab to do file operation
*/
- void SlotNewFileTab();
+ void SlotNewFileBrowserTab();
/**
* @details put a * in front of current tabs title, if current textedit is
@@ -257,6 +268,15 @@ class TextEdit : public QWidget {
*/
auto saveFile(const QString& file_name) -> bool;
+ private slots:
+
+ /**
+ * @details Remove the tab with given index
+ *
+ * @param index Tab-number to remove
+ */
+ void slot_remove_tab(int index);
+
private:
/**
* @details return just a filename stripped of a whole path
@@ -273,14 +293,7 @@ class TextEdit : public QWidget {
*/
auto maybe_save_current_tab(bool askToSave) -> bool;
- private slots:
-
- /**
- * @details Remove the tab with given index
- *
- * @param index Tab-number to remove
- */
- void slot_remove_tab(int index);
+ TextEditTabWidget* tab_widget_; ///< widget containing the tabs of the editor
};
} // namespace GpgFrontend::UI
diff --git a/src/ui/widgets/TextEditTabWidget.cpp b/src/ui/widgets/TextEditTabWidget.cpp
index 110302be..97826f03 100644
--- a/src/ui/widgets/TextEditTabWidget.cpp
+++ b/src/ui/widgets/TextEditTabWidget.cpp
@@ -106,7 +106,7 @@ void TextEditTabWidget::SlotOpenFile(const QString& path) {
connect(page->GetTextPage()->document(),
&QTextDocument::modificationChanged, this,
&TextEditTabWidget::SlotShowModified);
- // connect to cache recovery fucntion
+ // connect to cache recovery function
connect(page->GetTextPage()->document(), &QTextDocument::contentsChanged,
this, &TextEditTabWidget::slot_save_status_to_cache_for_recovery);