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 /src/ui/widgets/FilePage.cpp | |
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
Diffstat (limited to 'src/ui/widgets/FilePage.cpp')
-rw-r--r-- | src/ui/widgets/FilePage.cpp | 99 |
1 files changed, 49 insertions, 50 deletions
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 |