diff options
author | saturneric <[email protected]> | 2025-04-16 18:05:00 +0000 |
---|---|---|
committer | saturneric <[email protected]> | 2025-04-16 18:05:00 +0000 |
commit | 272cf34f21ab1741d24673a7e3b7c95567a74cec (patch) | |
tree | 4497435e41a8bbdd7560cee57b2c8c4171099951 /src/ui/main_window | |
parent | fix: found bugs (diff) | |
download | GpgFrontend-272cf34f21ab1741d24673a7e3b7c95567a74cec.tar.gz GpgFrontend-272cf34f21ab1741d24673a7e3b7c95567a74cec.zip |
fix: testing and solve bugs found
Diffstat (limited to 'src/ui/main_window')
-rw-r--r-- | src/ui/main_window/KeyMgmt.cpp | 50 | ||||
-rw-r--r-- | src/ui/main_window/KeyMgmt.h | 9 | ||||
-rw-r--r-- | src/ui/main_window/MainWindow.cpp | 61 | ||||
-rw-r--r-- | src/ui/main_window/MainWindow.h | 23 | ||||
-rw-r--r-- | src/ui/main_window/MainWindowSlotUI.cpp | 17 | ||||
-rw-r--r-- | src/ui/main_window/MainWindowUI.cpp | 2 |
6 files changed, 117 insertions, 45 deletions
diff --git a/src/ui/main_window/KeyMgmt.cpp b/src/ui/main_window/KeyMgmt.cpp index cd5a9f05..e3128231 100644 --- a/src/ui/main_window/KeyMgmt.cpp +++ b/src/ui/main_window/KeyMgmt.cpp @@ -121,12 +121,17 @@ KeyMgmt::KeyMgmt(QWidget* parent) setWindowTitle(tr("KeyPair Management")); setMinimumSize(QSize(640, 480)); - key_list_->AddMenuAction(generate_subkey_act_); - key_list_->AddMenuAction(delete_selected_keys_act_); - key_list_->AddSeparator(); - key_list_->AddMenuAction(set_owner_trust_of_key_act_); - key_list_->AddSeparator(); - key_list_->AddMenuAction(show_key_details_act_); + popup_menu_ = new QMenu(this); + + popup_menu_->addAction(generate_subkey_act_); + popup_menu_->addAction(delete_selected_keys_act_); + popup_menu_->addSeparator(); + popup_menu_->addAction(set_owner_trust_of_key_act_); + popup_menu_->addSeparator(); + popup_menu_->addAction(show_key_details_act_); + + connect(key_list_, &KeyList::SignalRequestContextMenu, this, + &KeyMgmt::slot_popup_menu_by_key_list); connect(this, &KeyMgmt::SignalKeyStatusUpdated, UISignalStation::GetInstance(), @@ -292,7 +297,7 @@ void KeyMgmt::create_tool_bars() { QToolBar* key_tool_bar = addToolBar(tr("Key")); key_tool_bar->setObjectName("keytoolbar"); - // genrate key pair + // generate key pair key_tool_bar->addAction(generate_key_pair_act_); key_tool_bar->addSeparator(); @@ -587,13 +592,36 @@ void KeyMgmt::SlotImportKeyPackage() { emit SignalStatusBarChanged(tr("key(s) imported")); emit SignalKeyStatusUpdated(); - auto* dialog = new KeyImportDetailDialog( - key_list_->GetCurrentGpgContextChannel(), - SecureCreateSharedObject<GpgImportInformation>(info), this); - dialog->exec(); + auto* connection = new QMetaObject::Connection; + *connection = connect( + UISignalStation::GetInstance(), + &UISignalStation::SignalKeyDatabaseRefreshDone, this, + [=]() { + (new KeyImportDetailDialog( + key_list_->GetCurrentGpgContextChannel(), + SecureCreateSharedObject<GpgImportInformation>(info), + this)); + QObject::disconnect(*connection); + delete connection; + }); } }); }); } +void KeyMgmt::slot_popup_menu_by_key_list(QContextMenuEvent* event, + KeyTable* key_table) { + if (event == nullptr || key_table == nullptr) return; + + auto keys = key_table->GetSelectedKeys(); + if (keys.isEmpty()) return; + + auto key = keys.front(); + generate_subkey_act_->setDisabled(key->KeyType() != + GpgAbstractKeyType::kGPG_KEY); + set_owner_trust_of_key_act_->setDisabled(key->KeyType() != + GpgAbstractKeyType::kGPG_KEY); + + popup_menu_->exec(event->globalPos()); +} } // namespace GpgFrontend::UI diff --git a/src/ui/main_window/KeyMgmt.h b/src/ui/main_window/KeyMgmt.h index b25cfaaa..c0a8502a 100644 --- a/src/ui/main_window/KeyMgmt.h +++ b/src/ui/main_window/KeyMgmt.h @@ -34,6 +34,7 @@ namespace GpgFrontend::UI { class KeyList; +struct KeyTable; /** * @brief @@ -120,6 +121,10 @@ class KeyMgmt : public GeneralMainWindow { */ void SignalKeyStatusUpdated(); + private slots: + + void slot_popup_menu_by_key_list(QContextMenuEvent* event, KeyTable*); + private: KeyList* key_list_; ///< QMenu* file_menu_{}; ///< @@ -128,6 +133,8 @@ class KeyMgmt : public GeneralMainWindow { QMenu* import_key_menu_{}; ///< QMenu* export_key_menu_{}; /// < + QMenu* popup_menu_; + QAction* open_key_file_act_{}; ///< QAction* export_key_to_file_act_{}; ///< QAction* export_key_as_open_ssh_format_{}; ///< @@ -143,7 +150,7 @@ class KeyMgmt : public GeneralMainWindow { QAction* import_keys_from_key_package_act_{}; ///< QAction* close_act_{}; ///< QAction* show_key_details_act_{}; ///< - QAction* set_owner_trust_of_key_act_{}; + QAction* set_owner_trust_of_key_act_{}; ///< /** * @brief Create a menus object diff --git a/src/ui/main_window/MainWindow.cpp b/src/ui/main_window/MainWindow.cpp index 5ebfbb00..e17dacca 100644 --- a/src/ui/main_window/MainWindow.cpp +++ b/src/ui/main_window/MainWindow.cpp @@ -105,27 +105,36 @@ void MainWindow::Init() noexcept { [=](const QString& message, int timeout) { statusBar()->showMessage(message, timeout); }); - connect(UISignalStation::GetInstance(), - &UISignalStation::SignalMainWindowUpdateBasicOperaMenu, this, - &MainWindow::SlotUpdateCryptoMenuStatus); + connect( + UISignalStation::GetInstance(), + &UISignalStation::SignalMainWindowUpdateBasicOperaMenu, this, + [=](unsigned int mask) { + operations_menu_mask_ = mask; + slot_update_operations_menu_by_checked_keys(operations_menu_mask_); + }); connect(UISignalStation::GetInstance(), &UISignalStation::SignalMainWindowOpenFile, this, &MainWindow::SlotOpenFile); - 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_->AddMenuAction(set_owner_trust_of_key_act_); - m_key_list_->AddMenuAction(add_key_2_favourite_act_); - m_key_list_->AddMenuAction(remove_key_from_favourtie_act_); - - m_key_list_->AddSeparator(); - m_key_list_->AddMenuAction(show_key_details_act_); + popup_menu_ = new QMenu(this); + + popup_menu_->addAction(append_selected_keys_act_); + popup_menu_->addAction(append_key_create_date_to_editor_act_); + popup_menu_->addAction(append_key_expire_date_to_editor_act_); + popup_menu_->addAction(append_key_fingerprint_to_editor_act_); + popup_menu_->addSeparator(); + popup_menu_->addAction(copy_mail_address_to_clipboard_act_); + popup_menu_->addAction(copy_key_default_uid_to_clipboard_act_); + popup_menu_->addAction(copy_key_id_to_clipboard_act_); + popup_menu_->addAction(set_owner_trust_of_key_act_); + popup_menu_->addAction(add_key_2_favourite_act_); + popup_menu_->addAction(remove_key_from_favourtie_act_); + + popup_menu_->addSeparator(); + popup_menu_->addAction(show_key_details_act_); + + connect(m_key_list_, &KeyList::SignalRequestContextMenu, this, + &MainWindow::slot_popup_menu_by_key_list); restore_settings(); @@ -139,7 +148,7 @@ void MainWindow::Init() noexcept { // recover unsaved page from cache if it exists recover_editor_unsaved_pages_from_cache(); - slot_update_operations_menu_by_checked_keys(); + slot_update_operations_menu_by_checked_keys(~0); // check if need to open wizard window if (GetSettings().value("wizard/show_wizard", true).toBool()) { @@ -307,4 +316,20 @@ void MainWindow::check_update_at_startup() { Module::TriggerEvent("CHECK_APPLICATION_VERSION"); } } + +void MainWindow::slot_popup_menu_by_key_list(QContextMenuEvent* event, + KeyTable* key_table) { + if (event == nullptr || key_table == nullptr) return; + + const auto key_table_name = key_table->objectName(); + if (key_table_name == "favourite") { + remove_key_from_favourtie_act_->setDisabled(true); + add_key_2_favourite_act_->setDisabled(false); + } else { + remove_key_from_favourtie_act_->setDisabled(false); + add_key_2_favourite_act_->setDisabled(true); + } + + popup_menu_->popup(event->globalPos()); +} } // namespace GpgFrontend::UI diff --git a/src/ui/main_window/MainWindow.h b/src/ui/main_window/MainWindow.h index 6eb4da65..d89356aa 100644 --- a/src/ui/main_window/MainWindow.h +++ b/src/ui/main_window/MainWindow.h @@ -46,6 +46,7 @@ class TextEdit; class InfoBoardWidget; struct GpgOperaContext; struct GpgOperaContextBasement; +struct KeyTable; /** * @brief @@ -121,11 +122,6 @@ class MainWindow : public GeneralMainWindow { public slots: /** - * @details refresh and enable specify crypto-menu actions. - */ - void SlotUpdateCryptoMenuStatus(unsigned int type); - - /** * @details Open a new tab for path */ void SlotOpenFile(const QString& path); @@ -523,11 +519,23 @@ class MainWindow : public GeneralMainWindow { const QContainer<GpgOperaResult>& results); /** + * @details refresh and enable specify crypto-menu actions. + */ + void slot_update_crypto_operations_menu(unsigned int mask); + + /** * @brief * * @param results */ - void slot_update_operations_menu_by_checked_keys(); + void slot_update_operations_menu_by_checked_keys(unsigned int type); + + /** + * @brief + * + * @param event + */ + void slot_popup_menu_by_key_list(QContextMenuEvent* event, KeyTable*); private: /** @@ -771,9 +779,12 @@ class MainWindow : public GeneralMainWindow { InfoBoardWidget* info_board_{}; ///< QMap<QString, QPointer<QAction>> buffered_actions_; + QMenu* popup_menu_; + bool attachment_dock_created_{}; ///< int restart_mode_{0}; ///< bool prohibit_update_checking_ = false; ///< + unsigned int operations_menu_mask_ = ~0; }; } // namespace GpgFrontend::UI diff --git a/src/ui/main_window/MainWindowSlotUI.cpp b/src/ui/main_window/MainWindowSlotUI.cpp index 51de7d23..49958c9f 100644 --- a/src/ui/main_window/MainWindowSlotUI.cpp +++ b/src/ui/main_window/MainWindowSlotUI.cpp @@ -167,8 +167,8 @@ void MainWindow::slot_cut_pgp_header() { void MainWindow::SlotSetRestartNeeded(int mode) { this->restart_mode_ = mode; } -void MainWindow::SlotUpdateCryptoMenuStatus(unsigned int type) { - OperationMenu::OperationType opera_type = type; +void MainWindow::slot_update_crypto_operations_menu(unsigned int mask) { + OperationMenu::OperationType opera_type = mask; // refresh status to disable all verify_act_->setDisabled(true); @@ -346,13 +346,14 @@ void MainWindow::slot_restart_gpg_components(bool) { }); } -void MainWindow::slot_update_operations_menu_by_checked_keys() { +void MainWindow::slot_update_operations_menu_by_checked_keys( + unsigned int mask) { auto keys = m_key_list_->GetCheckedKeys(); - OperationMenu::OperationType type = ~0; + unsigned int temp = ~0; if (keys.isEmpty()) { - type &= ~(OperationMenu::kEncrypt | OperationMenu::kEncryptAndSign | + temp &= ~(OperationMenu::kEncrypt | OperationMenu::kEncryptAndSign | OperationMenu::kSign); } else { @@ -360,15 +361,15 @@ void MainWindow::slot_update_operations_menu_by_checked_keys() { if (key == nullptr || key->IsDisabled()) continue; if (!key->IsHasEncrCap()) { - type &= ~(OperationMenu::kEncrypt | OperationMenu::kEncryptAndSign); + temp &= ~(OperationMenu::kEncrypt | OperationMenu::kEncryptAndSign); } if (!key->IsHasSignCap()) { - type &= ~(OperationMenu::kSign); + temp &= ~(OperationMenu::kSign); } } } - SlotUpdateCryptoMenuStatus(type); + slot_update_crypto_operations_menu(operations_menu_mask_ & mask & temp); } } // namespace GpgFrontend::UI diff --git a/src/ui/main_window/MainWindowUI.cpp b/src/ui/main_window/MainWindowUI.cpp index 26c3a8ad..41463b7a 100644 --- a/src/ui/main_window/MainWindowUI.cpp +++ b/src/ui/main_window/MainWindowUI.cpp @@ -611,7 +611,7 @@ void MainWindow::create_dock_windows() { view_menu_->addAction(info_board_dock_->toggleViewAction()); connect(m_key_list_, &KeyList::SignalKeyChecked, this, - &MainWindow::slot_update_operations_menu_by_checked_keys); + [=]() { slot_update_operations_menu_by_checked_keys(~0); }); } } // namespace GpgFrontend::UI |