aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSaturneric <[email protected]>2023-03-31 08:26:24 +0000
committerSaturneric <[email protected]>2023-03-31 08:26:24 +0000
commit2b63789d1030d1ecd7effcb8836b298827a60a77 (patch)
treebc4735be6905d16e5b444f9fffd346004866d0c6
parentfix: improve general dialog position representation (diff)
downloadGpgFrontend-2b63789d1030d1ecd7effcb8836b298827a60a77.tar.gz
GpgFrontend-2b63789d1030d1ecd7effcb8836b298827a60a77.zip
feat: improve ui logic and menu operas in main window
-rw-r--r--src/ui/main_window/MainWindow.cpp6
-rw-r--r--src/ui/main_window/MainWindow.h37
-rw-r--r--src/ui/main_window/MainWindowSlotFunction.cpp108
-rw-r--r--src/ui/main_window/MainWindowUI.cpp58
4 files changed, 201 insertions, 8 deletions
diff --git a/src/ui/main_window/MainWindow.cpp b/src/ui/main_window/MainWindow.cpp
index fff3ab63..b38646cf 100644
--- a/src/ui/main_window/MainWindow.cpp
+++ b/src/ui/main_window/MainWindow.cpp
@@ -84,7 +84,13 @@ void MainWindow::Init() noexcept {
});
m_key_list_->AddMenuAction(append_selected_keys_act_);
+ m_key_list_->AddMenuAction(append_key_create_date_to_editor_act_);
+ m_key_list_->AddMenuAction(append_key_expire_date_to_editor_act_);
+ m_key_list_->AddMenuAction(append_key_fingerprint_to_editor_act_);
+ m_key_list_->AddSeparator();
m_key_list_->AddMenuAction(copy_mail_address_to_clipboard_act_);
+ m_key_list_->AddMenuAction(copy_key_default_uid_to_clipboard_act_);
+ m_key_list_->AddMenuAction(copy_key_id_to_clipboard_act_);
m_key_list_->AddSeparator();
m_key_list_->AddMenuAction(show_key_details_act_);
diff --git a/src/ui/main_window/MainWindow.h b/src/ui/main_window/MainWindow.h
index e32a02ff..04a82759 100644
--- a/src/ui/main_window/MainWindow.h
+++ b/src/ui/main_window/MainWindow.h
@@ -225,12 +225,42 @@ class MainWindow : public GeneralMainWindow {
void slot_append_selected_keys();
/**
+ * @brief
+ *
+ */
+ void slot_append_keys_create_datetime();
+
+ /**
+ * @brief
+ *
+ */
+ void slot_append_keys_expire_datetime();
+
+ /**
+ * @brief
+ *
+ */
+ void slot_append_keys_fingerprint();
+
+ /**
* @details Copy the mailaddress of selected key to clipboard.
* Method for keylists contextmenu.
*/
void slot_copy_mail_address_to_clipboard();
/**
+ * @details Copy the mailaddress of selected key to clipboard.
+ * Method for keylists contextmenu.
+ */
+ void slot_copy_default_uid_to_clipboard();
+
+ /**
+ * @details Copy the mailaddress of selected key to clipboard.
+ * Method for keylists contextmenu.
+ */
+ void slot_copy_key_id_to_clipboard();
+
+ /**
* @details Open key management dialog.
*/
void slot_open_key_management();
@@ -376,8 +406,15 @@ class MainWindow : public GeneralMainWindow {
QAction*
append_selected_keys_act_{}; ///< Action to append selected keys to edit
+ QAction* append_key_fingerprint_to_editor_act_{}; ///<
+ QAction* append_key_create_date_to_editor_act_{}; ///<
+ QAction* append_key_expire_date_to_editor_act_{}; ///<
+
QAction* copy_mail_address_to_clipboard_act_{}; ///< Action to copy mail to
///< clipboard
+ QAction* copy_key_id_to_clipboard_act_{}; ///<
+ QAction* copy_key_default_uid_to_clipboard_act_{}; ///<
+
QAction* open_key_management_act_{}; ///< Action to open key management
QAction* copy_act_{}; ///< Action to copy text
QAction* quote_act_{}; ///< Action to quote text
diff --git a/src/ui/main_window/MainWindowSlotFunction.cpp b/src/ui/main_window/MainWindowSlotFunction.cpp
index 6f702e34..841c8680 100644
--- a/src/ui/main_window/MainWindowSlotFunction.cpp
+++ b/src/ui/main_window/MainWindowSlotFunction.cpp
@@ -26,12 +26,15 @@
*
*/
+#include <boost/date_time/posix_time/posix_time.hpp>
+#include <boost/date_time/posix_time/posix_time_io.hpp>
#include <memory>
#include <string>
#include <utility>
#include "MainWindow.h"
#include "core/GpgConstants.h"
+#include "core/GpgContext.h"
#include "core/GpgModel.h"
#include "core/function/gpg/GpgBasicOperator.h"
#include "core/function/gpg/GpgKeyGetter.h"
@@ -611,11 +614,88 @@ void MainWindow::slot_append_selected_keys() {
auto exported = std::make_unique<ByteArray>();
auto key_ids = m_key_list_->GetSelected();
- GpgKeyImportExporter::GetInstance().ExportKeys(key_ids, exported);
+ if (key_ids->empty()) {
+ SPDLOG_ERROR("no key is selected");
+ return;
+ }
+
+ if (!GpgKeyImportExporter::GetInstance().ExportKeys(key_ids, exported)) {
+ QMessageBox::critical(this, _("Error"), _("Key Export Operation Failed."));
+ return;
+ }
edit_->CurTextPage()->GetTextPage()->appendPlainText(
QString::fromStdString(*exported));
}
+void MainWindow::slot_append_keys_create_datetime() {
+ if (edit_->TabCount() == 0 || edit_->SlotCurPageTextEdit() == nullptr) {
+ return;
+ }
+
+ auto key_ids = m_key_list_->GetSelected();
+
+ if (key_ids->empty()) {
+ SPDLOG_ERROR("no key is selected");
+ return;
+ }
+
+ auto key = GpgKeyGetter::GetInstance().GetKey(key_ids->front());
+ if (!key.IsGood()) {
+ QMessageBox::critical(this, _("Error"), _("Key Not Found."));
+ return;
+ }
+
+ auto create_datetime_format_str =
+ boost::posix_time::to_iso_extended_string(key.GetCreateTime()) +
+ " (UTC) " + "\n";
+
+ edit_->CurTextPage()->GetTextPage()->appendPlainText(
+ QString::fromStdString(create_datetime_format_str));
+}
+
+void MainWindow::slot_append_keys_expire_datetime() {
+ if (edit_->TabCount() == 0 || edit_->SlotCurPageTextEdit() == nullptr) {
+ return;
+ }
+
+ auto key_ids = m_key_list_->GetSelected();
+
+ if (key_ids->empty()) {
+ SPDLOG_ERROR("no key is selected");
+ return;
+ }
+
+ auto key = GpgKeyGetter::GetInstance().GetKey(key_ids->front());
+ if (!key.IsGood()) {
+ QMessageBox::critical(this, _("Error"), _("Key Not Found."));
+ return;
+ }
+
+ auto create_datetime_format_str =
+ boost::posix_time::to_iso_extended_string(key.GetCreateTime()) +
+ " (UTC) " + "\n";
+
+ edit_->CurTextPage()->GetTextPage()->appendPlainText(
+ QString::fromStdString(create_datetime_format_str));
+}
+
+void MainWindow::slot_append_keys_fingerprint() {
+ auto key_ids = m_key_list_->GetSelected();
+ if (key_ids->empty()) return;
+
+ auto key = GpgKeyGetter::GetInstance().GetKey(key_ids->front());
+ if (!key.IsGood()) {
+ QMessageBox::critical(this, _("Error"), _("Key Not Found."));
+ return;
+ }
+
+ auto fingerprint_format_str =
+ beautify_fingerprint(key.GetFingerprint()) + "\n";
+
+ edit_->CurTextPage()->GetTextPage()->appendPlainText(
+ QString::fromStdString(fingerprint_format_str));
+}
+
void MainWindow::slot_copy_mail_address_to_clipboard() {
auto key_ids = m_key_list_->GetSelected();
if (key_ids->empty()) return;
@@ -629,6 +709,32 @@ void MainWindow::slot_copy_mail_address_to_clipboard() {
cb->setText(QString::fromStdString(key.GetEmail()));
}
+void MainWindow::slot_copy_default_uid_to_clipboard() {
+ auto key_ids = m_key_list_->GetSelected();
+ if (key_ids->empty()) return;
+
+ auto key = GpgKeyGetter::GetInstance().GetKey(key_ids->front());
+ if (!key.IsGood()) {
+ QMessageBox::critical(this, _("Error"), _("Key Not Found."));
+ return;
+ }
+ QClipboard* cb = QApplication::clipboard();
+ cb->setText(QString::fromStdString(key.GetUIDs()->front().GetUID()));
+}
+
+void MainWindow::slot_copy_key_id_to_clipboard() {
+ auto key_ids = m_key_list_->GetSelected();
+ if (key_ids->empty()) return;
+
+ auto key = GpgKeyGetter::GetInstance().GetKey(key_ids->front());
+ if (!key.IsGood()) {
+ QMessageBox::critical(this, _("Error"), _("Key Not Found."));
+ return;
+ }
+ QClipboard* cb = QApplication::clipboard();
+ cb->setText(QString::fromStdString(key.GetId()));
+}
+
void MainWindow::slot_show_key_details() {
auto key_ids = m_key_list_->GetSelected();
if (key_ids->empty()) return;
diff --git a/src/ui/main_window/MainWindowUI.cpp b/src/ui/main_window/MainWindowUI.cpp
index d598f3ab..1034df52 100644
--- a/src/ui/main_window/MainWindowUI.cpp
+++ b/src/ui/main_window/MainWindowUI.cpp
@@ -27,6 +27,7 @@
*/
#include "MainWindow.h"
+#include "core/function/GlobalSettingStation.h"
#include "core/function/gpg/GpgAdvancedOperator.h"
#include "ui/UserInterfaceUtils.h"
@@ -251,11 +252,23 @@ void MainWindow::create_actions() {
CommonUtils::GetInstance()->SlotImportKeyFromClipboard(this);
});
+ // get settings
+ auto& settings = GlobalSettingStation::GetInstance().GetUISettings();
+ // read settings
+ bool forbid_all_gnupg_connection = false;
+ try {
+ forbid_all_gnupg_connection =
+ settings.lookup("network.forbid_all_gnupg_connection");
+ } catch (...) {
+ SPDLOG_ERROR("setting operation error: forbid_all_gnupg_connection");
+ }
+
import_key_from_key_server_act_ = new QAction(_("Keyserver"), this);
import_key_from_key_server_act_->setIcon(
QIcon(":import_key_from_server.png"));
import_key_from_key_server_act_->setToolTip(
_("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, [&]() {
CommonUtils::GetInstance()->SlotImportKeyFromKeyServer(this);
});
@@ -353,22 +366,53 @@ void MainWindow::create_actions() {
connect(start_wizard_act_, &QAction::triggered, this,
&MainWindow::slot_start_wizard);
- /* Popup-Menu-Action for KeyList
- */
- append_selected_keys_act_ = new QAction(_("Append To Text Editor"), this);
+ append_selected_keys_act_ =
+ new QAction(_("Append Public Key to Editor"), this);
append_selected_keys_act_->setToolTip(
- _("Append The Selected Public Key To Text in Editor"));
+ _("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(_("Append Create DateTime to Editor"), this);
+ append_key_create_date_to_editor_act_->setToolTip(
+ _("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(_("Append Expire DateTime to Editor"), this);
+ append_key_expire_date_to_editor_act_->setToolTip(
+ _("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(_("Append Fingerprint to Editor"), this);
+ append_key_expire_date_to_editor_act_->setToolTip(
+ _("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(_("Copy Email"), this);
copy_mail_address_to_clipboard_act_->setToolTip(
- _("Copy selected Email to clipboard"));
+ _("Copy selected Keypair's to clipboard"));
connect(copy_mail_address_to_clipboard_act_, &QAction::triggered, this,
&MainWindow::slot_copy_mail_address_to_clipboard);
- // TODO: find central place for shared actions, to avoid code-duplication with
- // keymgmt.cpp
+ copy_key_default_uid_to_clipboard_act_ =
+ new QAction(_("Copy Default UID"), this);
+ copy_key_default_uid_to_clipboard_act_->setToolTip(
+ _("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(_("Copy Key ID"), this);
+ copy_key_id_to_clipboard_act_->setToolTip(
+ _("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(_("Show Key Details"), this);
show_key_details_act_->setToolTip(_("Show Details for this Key"));
connect(show_key_details_act_, &QAction::triggered, this,