diff options
author | saturneric <[email protected]> | 2024-01-24 04:50:42 +0000 |
---|---|---|
committer | saturneric <[email protected]> | 2024-01-24 04:50:42 +0000 |
commit | 9fa19d9dae8153ae360e666887fbd079620c5022 (patch) | |
tree | 5d1d3cabd54b1fadb0e7dec75b25aa3e446aa8a0 | |
parent | feat: improve key list and find widget (diff) | |
download | GpgFrontend-9fa19d9dae8153ae360e666887fbd079620c5022.tar.gz GpgFrontend-9fa19d9dae8153ae360e666887fbd079620c5022.zip |
fix: solve an issue that switch tab but crypto menu won't update
-rw-r--r-- | src/ui/UISignalStation.h | 12 | ||||
-rw-r--r-- | src/ui/dialog/keypair_details/KeySetExpireDateDialog.cpp | 2 | ||||
-rw-r--r-- | src/ui/main_window/MainWindow.cpp | 6 | ||||
-rw-r--r-- | src/ui/main_window/MainWindow.h | 10 | ||||
-rw-r--r-- | src/ui/main_window/MainWindowSlotUI.cpp | 33 | ||||
-rw-r--r-- | src/ui/widgets/FilePage.cpp | 99 | ||||
-rw-r--r-- | src/ui/widgets/FilePage.h | 26 | ||||
-rw-r--r-- | src/ui/widgets/FileTreeView.cpp | 4 | ||||
-rw-r--r-- | src/ui/widgets/FileTreeView.h | 7 | ||||
-rw-r--r-- | src/ui/widgets/KeyList.cpp | 2 |
10 files changed, 125 insertions, 76 deletions
diff --git a/src/ui/UISignalStation.h b/src/ui/UISignalStation.h index aee61300..9a762d16 100644 --- a/src/ui/UISignalStation.h +++ b/src/ui/UISignalStation.h @@ -74,6 +74,18 @@ class UISignalStation : public QObject { /** * @brief * + */ + void SignalMainWindowlUpdateBasicalOperaMenu(unsigned int); + + /** + * @brief + * + */ + void SignalMainWindowOpenFile(QString); + + /** + * @brief + * * @param text * @param verify_label_status */ diff --git a/src/ui/dialog/keypair_details/KeySetExpireDateDialog.cpp b/src/ui/dialog/keypair_details/KeySetExpireDateDialog.cpp index 51956379..43fb6f3b 100644 --- a/src/ui/dialog/keypair_details/KeySetExpireDateDialog.cpp +++ b/src/ui/dialog/keypair_details/KeySetExpireDateDialog.cpp @@ -99,7 +99,7 @@ void KeySetExpireDateDialog::init() { auto settings = GpgFrontend::GlobalSettingStation::GetInstance().GetSettings(); - bool longer_expiration_date = longer_expiration_date = + bool longer_expiration_date = settings.value("basic/longer_expiration_date").toBool(); auto max_date_time = diff --git a/src/ui/main_window/MainWindow.cpp b/src/ui/main_window/MainWindow.cpp index 3090bdb7..3d930d4d 100644 --- a/src/ui/main_window/MainWindow.cpp +++ b/src/ui/main_window/MainWindow.cpp @@ -103,6 +103,12 @@ void MainWindow::Init() noexcept { [=](const QString &message, int timeout) { statusBar()->showMessage(message, timeout); }); + connect(UISignalStation::GetInstance(), + &UISignalStation::SignalMainWindowlUpdateBasicalOperaMenu, this, + &MainWindow::SlotUpdateCryptoMenuStatus); + 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_); diff --git a/src/ui/main_window/MainWindow.h b/src/ui/main_window/MainWindow.h index 34166444..523c14f0 100644 --- a/src/ui/main_window/MainWindow.h +++ b/src/ui/main_window/MainWindow.h @@ -74,11 +74,6 @@ class MainWindow : public GeneralMainWindow { */ void Init() noexcept; - /** - * @details refresh and enable specify crypto-menu actions. - */ - void SetCryptoMenuStatus(CryptoMenu::OperationType type); - signals: /** @@ -119,6 +114,11 @@ 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); diff --git a/src/ui/main_window/MainWindowSlotUI.cpp b/src/ui/main_window/MainWindowSlotUI.cpp index 74091c63..99a26626 100644 --- a/src/ui/main_window/MainWindowSlotUI.cpp +++ b/src/ui/main_window/MainWindowSlotUI.cpp @@ -65,13 +65,8 @@ void MainWindow::slot_open_key_management() { void MainWindow::slot_open_file_tab() { edit_->SlotNewFileTab(); } void MainWindow::slot_disable_tab_actions(int number) { - bool disable; - - disable = number == -1; - - if (edit_->CurFilePage() != nullptr) { - disable = true; - } + auto disable = number == -1; + if (edit_->CurFilePage() != nullptr) disable = true; print_act_->setDisabled(disable); save_act_->setDisabled(disable); @@ -100,6 +95,12 @@ void MainWindow::slot_disable_tab_actions(int number) { cut_pgp_header_act_->setDisabled(disable); add_pgp_header_act_->setDisabled(disable); + + if (edit_->CurFilePage() != nullptr) { + GF_UI_LOG_DEBUG("edit current page is file page"); + auto* file_page = edit_->CurFilePage(); + emit file_page->SignalCurrentTabChanged(); + } } void MainWindow::slot_open_settings_dialog() { @@ -184,9 +185,9 @@ void MainWindow::SlotSetRestartNeeded(int mode) { int MainWindow::get_restart_needed() const { return this->restart_needed_; } -void MainWindow::SetCryptoMenuStatus( - MainWindow::CryptoMenu::OperationType type) { - GF_UI_LOG_DEBUG("type: {}", type); +void MainWindow::SlotUpdateCryptoMenuStatus(unsigned int type) { + MainWindow::CryptoMenu::OperationType opera_type = type; + GF_UI_LOG_DEBUG("update crypto menu status, type: {}", opera_type); // refresh status to disable all verify_act_->setDisabled(true); @@ -197,22 +198,22 @@ void MainWindow::SetCryptoMenuStatus( decrypt_verify_act_->setDisabled(true); // enable according to type - if (type & MainWindow::CryptoMenu::Verify) { + if ((opera_type & MainWindow::CryptoMenu::Verify) != 0U) { verify_act_->setDisabled(false); } - if (type & MainWindow::CryptoMenu::Sign) { + if ((opera_type & MainWindow::CryptoMenu::Sign) != 0U) { sign_act_->setDisabled(false); } - if (type & MainWindow::CryptoMenu::Encrypt) { + if ((opera_type & MainWindow::CryptoMenu::Encrypt) != 0U) { encrypt_act_->setDisabled(false); } - if (type & MainWindow::CryptoMenu::EncryptAndSign) { + if ((opera_type & MainWindow::CryptoMenu::EncryptAndSign) != 0U) { encrypt_sign_act_->setDisabled(false); } - if (type & MainWindow::CryptoMenu::Decrypt) { + if ((opera_type & MainWindow::CryptoMenu::Decrypt) != 0U) { decrypt_act_->setDisabled(false); } - if (type & MainWindow::CryptoMenu::DecryptAndVerify) { + if ((opera_type & MainWindow::CryptoMenu::DecryptAndVerify) != 0U) { decrypt_verify_act_->setDisabled(false); } } diff --git a/src/ui/widgets/FilePage.cpp b/src/ui/widgets/FilePage.cpp index c6260003..d99bfc53 100644 --- a/src/ui/widgets/FilePage.cpp +++ b/src/ui/widgets/FilePage.cpp @@ -96,56 +96,16 @@ FilePage::FilePage(QWidget* parent, const QString& target_path) [this](const QString& path) { this->ui_->pathEdit->setText(path); }); connect(file_tree_view_, &FileTreeView::SignalPathChanged, this, &FilePage::SignalPathChanged); - - auto* main_window = qobject_cast<MainWindow*>(this->parent()); - if (main_window != nullptr) { - connect(file_tree_view_, &FileTreeView::SignalOpenFile, main_window, - &MainWindow::SlotOpenFile); - - connect(file_tree_view_, &FileTreeView::SignalSelectedChanged, this, - [main_window](const QString& selected_path) { - MainWindow::CryptoMenu::OperationType operation_type = - MainWindow::CryptoMenu::None; - - // abort... - if (selected_path.isEmpty()) return; - - QFileInfo const info(selected_path); - - if ((info.isDir() || info.isFile()) && - (info.suffix() != "gpg" && info.suffix() != "pgp" && - info.suffix() != "sig" && info.suffix() != "asc")) { - operation_type |= MainWindow::CryptoMenu::Encrypt; - } - - if ((info.isDir() || info.isFile()) && - (info.suffix() != "gpg" && info.suffix() != "pgp" && - info.suffix() != "sig" && info.suffix() != "asc")) { - operation_type |= MainWindow::CryptoMenu::EncryptAndSign; - } - - if (info.isFile() && - (info.suffix() == "gpg" || info.suffix() == "pgp" || - info.suffix() == "asc")) { - operation_type |= MainWindow::CryptoMenu::Decrypt; - operation_type |= MainWindow::CryptoMenu::DecryptAndVerify; - } - - if (info.isFile() && - (info.suffix() != "gpg" && info.suffix() != "pgp" && - info.suffix() != "sig" && info.suffix() != "asc")) { - operation_type |= MainWindow::CryptoMenu::Sign; - } - - if (info.isFile() && - (info.suffix() == "sig" || info.suffix() == "gpg" || - info.suffix() == "pgp" || info.suffix() == "asc")) { - operation_type |= MainWindow::CryptoMenu::Verify; - } - - main_window->SetCryptoMenuStatus(operation_type); - }); - } + connect(file_tree_view_, &FileTreeView::SignalOpenFile, + UISignalStation::GetInstance(), + &UISignalStation::SignalMainWindowOpenFile); + connect(file_tree_view_, &FileTreeView::SignalSelectedChanged, this, + &FilePage::update_main_basical_opera_menu); + connect(this, &FilePage::SignalCurrentTabChanged, this, + [this]() { update_main_basical_opera_menu(GetSelected()); }); + connect(this, &FilePage::SignalMainWindowlUpdateBasicalOperaMenu, + UISignalStation::GetInstance(), + &UISignalStation::SignalMainWindowlUpdateBasicalOperaMenu); } auto FilePage::GetSelected() const -> QString { @@ -164,4 +124,43 @@ void FilePage::keyPressEvent(QKeyEvent* event) { } } +void FilePage::update_main_basical_opera_menu(const QString& selected_path) { + MainWindow::CryptoMenu::OperationType operation_type = + MainWindow::CryptoMenu::None; + + // abort... + if (selected_path.isEmpty()) return; + + QFileInfo const info(selected_path); + + if ((info.isDir() || info.isFile()) && + (info.suffix() != "gpg" && info.suffix() != "pgp" && + info.suffix() != "sig" && info.suffix() != "asc")) { + operation_type |= MainWindow::CryptoMenu::Encrypt; + } + + if ((info.isDir() || info.isFile()) && + (info.suffix() != "gpg" && info.suffix() != "pgp" && + info.suffix() != "sig" && info.suffix() != "asc")) { + operation_type |= MainWindow::CryptoMenu::EncryptAndSign; + } + + if (info.isFile() && (info.suffix() == "gpg" || info.suffix() == "pgp" || + info.suffix() == "asc")) { + operation_type |= MainWindow::CryptoMenu::Decrypt; + operation_type |= MainWindow::CryptoMenu::DecryptAndVerify; + } + + if (info.isFile() && (info.suffix() != "gpg" && info.suffix() != "pgp" && + info.suffix() != "sig" && info.suffix() != "asc")) { + operation_type |= MainWindow::CryptoMenu::Sign; + } + + if (info.isFile() && (info.suffix() == "sig" || info.suffix() == "gpg" || + info.suffix() == "pgp" || info.suffix() == "asc")) { + operation_type |= MainWindow::CryptoMenu::Verify; + } + + emit SignalMainWindowlUpdateBasicalOperaMenu(operation_type); +} } // namespace GpgFrontend::UI diff --git a/src/ui/widgets/FilePage.h b/src/ui/widgets/FilePage.h index da5370a2..7f05e405 100644 --- a/src/ui/widgets/FilePage.h +++ b/src/ui/widgets/FilePage.h @@ -71,7 +71,7 @@ class FilePage : public QWidget { * * @param path */ - void SignalPathChanged(const QString& path); + void SignalPathChanged(const QString&); /** * @brief @@ -79,8 +79,20 @@ class FilePage : public QWidget { * @param text * @param verify_label_status */ - void SignalRefreshInfoBoard(const QString& text, - InfoBoardStatus verify_label_status); + void SignalRefreshInfoBoard(const QString&, InfoBoardStatus); + + /** + * @brief + * + */ + void SignalCurrentTabChanged(); + + /** + * @brief + * + * @param int + */ + void SignalMainWindowlUpdateBasicalOperaMenu(unsigned int); protected: /** @@ -99,6 +111,14 @@ class FilePage : public QWidget { QMenu* popup_menu_{}; ///< QMenu* option_popup_menu_{}; ///< FileTreeView* file_tree_view_; + + private slots: + + /** + * @brief + * + */ + void update_main_basical_opera_menu(const QString&); }; } // namespace GpgFrontend::UI diff --git a/src/ui/widgets/FileTreeView.cpp b/src/ui/widgets/FileTreeView.cpp index 450acbad..0350bb09 100644 --- a/src/ui/widgets/FileTreeView.cpp +++ b/src/ui/widgets/FileTreeView.cpp @@ -394,4 +394,8 @@ void FileTreeView::paintEvent(QPaintEvent* event) { this->resizeColumnToContents(i); } } + +void FileTreeView::mousePressEvent(QMouseEvent* event) { + QTreeView::mousePressEvent(event); +} } // namespace GpgFrontend::UI diff --git a/src/ui/widgets/FileTreeView.h b/src/ui/widgets/FileTreeView.h index d2272f90..95bbc4cd 100644 --- a/src/ui/widgets/FileTreeView.h +++ b/src/ui/widgets/FileTreeView.h @@ -88,6 +88,13 @@ class FileTreeView : public QTreeView { */ void paintEvent(QPaintEvent* event) override; + /** + * @brief + * + * @param event + */ + void mousePressEvent(QMouseEvent* event) override; + signals: /** diff --git a/src/ui/widgets/KeyList.cpp b/src/ui/widgets/KeyList.cpp index e2152c5a..a9c8e38f 100644 --- a/src/ui/widgets/KeyList.cpp +++ b/src/ui/widgets/KeyList.cpp @@ -429,7 +429,7 @@ void KeyList::SetDoubleClickedAction( this->m_action_ = std::move(action); } -QString KeyList::GetSelectedKey() { +auto KeyList::GetSelectedKey() -> QString { if (ui_->keyGroupTab->size().isEmpty()) return {}; const auto& buffered_keys = m_key_tables_[ui_->keyGroupTab->currentIndex()].buffered_keys_; |