1
0

fix: solve an issue that switch tab but crypto menu won't update

This commit is contained in:
saturneric 2024-01-24 12:50:42 +08:00
parent bab198aa13
commit 9fa19d9dae
10 changed files with 125 additions and 76 deletions

View File

@ -71,6 +71,18 @@ class UISignalStation : public QObject {
*/ */
void SignalUIRefresh(); void SignalUIRefresh();
/**
* @brief
*
*/
void SignalMainWindowlUpdateBasicalOperaMenu(unsigned int);
/**
* @brief
*
*/
void SignalMainWindowOpenFile(QString);
/** /**
* @brief * @brief
* *

View File

@ -99,7 +99,7 @@ void KeySetExpireDateDialog::init() {
auto settings = auto settings =
GpgFrontend::GlobalSettingStation::GetInstance().GetSettings(); GpgFrontend::GlobalSettingStation::GetInstance().GetSettings();
bool longer_expiration_date = longer_expiration_date = bool longer_expiration_date =
settings.value("basic/longer_expiration_date").toBool(); settings.value("basic/longer_expiration_date").toBool();
auto max_date_time = auto max_date_time =

View File

@ -103,6 +103,12 @@ void MainWindow::Init() noexcept {
[=](const QString &message, int timeout) { [=](const QString &message, int timeout) {
statusBar()->showMessage(message, 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_selected_keys_act_);
m_key_list_->AddMenuAction(append_key_create_date_to_editor_act_); m_key_list_->AddMenuAction(append_key_create_date_to_editor_act_);

View File

@ -74,11 +74,6 @@ class MainWindow : public GeneralMainWindow {
*/ */
void Init() noexcept; void Init() noexcept;
/**
* @details refresh and enable specify crypto-menu actions.
*/
void SetCryptoMenuStatus(CryptoMenu::OperationType type);
signals: signals:
/** /**
@ -118,6 +113,11 @@ class MainWindow : public GeneralMainWindow {
public slots: public slots:
/**
* @details refresh and enable specify crypto-menu actions.
*/
void SlotUpdateCryptoMenuStatus(unsigned int type);
/** /**
* @details Open a new tab for path * @details Open a new tab for path
*/ */

View File

@ -65,13 +65,8 @@ void MainWindow::slot_open_key_management() {
void MainWindow::slot_open_file_tab() { edit_->SlotNewFileTab(); } void MainWindow::slot_open_file_tab() { edit_->SlotNewFileTab(); }
void MainWindow::slot_disable_tab_actions(int number) { void MainWindow::slot_disable_tab_actions(int number) {
bool disable; auto disable = number == -1;
if (edit_->CurFilePage() != nullptr) disable = true;
disable = number == -1;
if (edit_->CurFilePage() != nullptr) {
disable = true;
}
print_act_->setDisabled(disable); print_act_->setDisabled(disable);
save_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); cut_pgp_header_act_->setDisabled(disable);
add_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() { 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_; } int MainWindow::get_restart_needed() const { return this->restart_needed_; }
void MainWindow::SetCryptoMenuStatus( void MainWindow::SlotUpdateCryptoMenuStatus(unsigned int type) {
MainWindow::CryptoMenu::OperationType type) { MainWindow::CryptoMenu::OperationType opera_type = type;
GF_UI_LOG_DEBUG("type: {}", type); GF_UI_LOG_DEBUG("update crypto menu status, type: {}", opera_type);
// refresh status to disable all // refresh status to disable all
verify_act_->setDisabled(true); verify_act_->setDisabled(true);
@ -197,22 +198,22 @@ void MainWindow::SetCryptoMenuStatus(
decrypt_verify_act_->setDisabled(true); decrypt_verify_act_->setDisabled(true);
// enable according to type // enable according to type
if (type & MainWindow::CryptoMenu::Verify) { if ((opera_type & MainWindow::CryptoMenu::Verify) != 0U) {
verify_act_->setDisabled(false); verify_act_->setDisabled(false);
} }
if (type & MainWindow::CryptoMenu::Sign) { if ((opera_type & MainWindow::CryptoMenu::Sign) != 0U) {
sign_act_->setDisabled(false); sign_act_->setDisabled(false);
} }
if (type & MainWindow::CryptoMenu::Encrypt) { if ((opera_type & MainWindow::CryptoMenu::Encrypt) != 0U) {
encrypt_act_->setDisabled(false); encrypt_act_->setDisabled(false);
} }
if (type & MainWindow::CryptoMenu::EncryptAndSign) { if ((opera_type & MainWindow::CryptoMenu::EncryptAndSign) != 0U) {
encrypt_sign_act_->setDisabled(false); encrypt_sign_act_->setDisabled(false);
} }
if (type & MainWindow::CryptoMenu::Decrypt) { if ((opera_type & MainWindow::CryptoMenu::Decrypt) != 0U) {
decrypt_act_->setDisabled(false); decrypt_act_->setDisabled(false);
} }
if (type & MainWindow::CryptoMenu::DecryptAndVerify) { if ((opera_type & MainWindow::CryptoMenu::DecryptAndVerify) != 0U) {
decrypt_verify_act_->setDisabled(false); decrypt_verify_act_->setDisabled(false);
} }
} }

View File

@ -96,14 +96,35 @@ FilePage::FilePage(QWidget* parent, const QString& target_path)
[this](const QString& path) { this->ui_->pathEdit->setText(path); }); [this](const QString& path) { this->ui_->pathEdit->setText(path); });
connect(file_tree_view_, &FileTreeView::SignalPathChanged, this, connect(file_tree_view_, &FileTreeView::SignalPathChanged, this,
&FilePage::SignalPathChanged); &FilePage::SignalPathChanged);
connect(file_tree_view_, &FileTreeView::SignalOpenFile,
auto* main_window = qobject_cast<MainWindow*>(this->parent()); UISignalStation::GetInstance(),
if (main_window != nullptr) { &UISignalStation::SignalMainWindowOpenFile);
connect(file_tree_view_, &FileTreeView::SignalOpenFile, main_window,
&MainWindow::SlotOpenFile);
connect(file_tree_view_, &FileTreeView::SignalSelectedChanged, this, connect(file_tree_view_, &FileTreeView::SignalSelectedChanged, this,
[main_window](const QString& selected_path) { &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 {
return file_tree_view_->GetSelectedPath();
}
void FilePage::SlotGoPath() {
file_tree_view_->SlotGoPath(ui_->pathEdit->text());
}
void FilePage::keyPressEvent(QKeyEvent* event) {
GF_UI_LOG_DEBUG("file page notices key press by user: {}", event->key());
if (ui_->pathEdit->hasFocus() &&
(event->key() == Qt::Key_Return || event->key() == Qt::Key_Enter)) {
SlotGoPath();
}
}
void FilePage::update_main_basical_opera_menu(const QString& selected_path) {
MainWindow::CryptoMenu::OperationType operation_type = MainWindow::CryptoMenu::OperationType operation_type =
MainWindow::CryptoMenu::None; MainWindow::CryptoMenu::None;
@ -124,44 +145,22 @@ FilePage::FilePage(QWidget* parent, const QString& target_path)
operation_type |= MainWindow::CryptoMenu::EncryptAndSign; operation_type |= MainWindow::CryptoMenu::EncryptAndSign;
} }
if (info.isFile() && if (info.isFile() && (info.suffix() == "gpg" || info.suffix() == "pgp" ||
(info.suffix() == "gpg" || info.suffix() == "pgp" ||
info.suffix() == "asc")) { info.suffix() == "asc")) {
operation_type |= MainWindow::CryptoMenu::Decrypt; operation_type |= MainWindow::CryptoMenu::Decrypt;
operation_type |= MainWindow::CryptoMenu::DecryptAndVerify; operation_type |= MainWindow::CryptoMenu::DecryptAndVerify;
} }
if (info.isFile() && if (info.isFile() && (info.suffix() != "gpg" && info.suffix() != "pgp" &&
(info.suffix() != "gpg" && info.suffix() != "pgp" &&
info.suffix() != "sig" && info.suffix() != "asc")) { info.suffix() != "sig" && info.suffix() != "asc")) {
operation_type |= MainWindow::CryptoMenu::Sign; operation_type |= MainWindow::CryptoMenu::Sign;
} }
if (info.isFile() && if (info.isFile() && (info.suffix() == "sig" || info.suffix() == "gpg" ||
(info.suffix() == "sig" || info.suffix() == "gpg" ||
info.suffix() == "pgp" || info.suffix() == "asc")) { info.suffix() == "pgp" || info.suffix() == "asc")) {
operation_type |= MainWindow::CryptoMenu::Verify; operation_type |= MainWindow::CryptoMenu::Verify;
} }
main_window->SetCryptoMenuStatus(operation_type); emit SignalMainWindowlUpdateBasicalOperaMenu(operation_type);
});
} }
}
auto FilePage::GetSelected() const -> QString {
return file_tree_view_->GetSelectedPath();
}
void FilePage::SlotGoPath() {
file_tree_view_->SlotGoPath(ui_->pathEdit->text());
}
void FilePage::keyPressEvent(QKeyEvent* event) {
GF_UI_LOG_DEBUG("file page notices key press by user: {}", event->key());
if (ui_->pathEdit->hasFocus() &&
(event->key() == Qt::Key_Return || event->key() == Qt::Key_Enter)) {
SlotGoPath();
}
}
} // namespace GpgFrontend::UI } // namespace GpgFrontend::UI

View File

@ -71,7 +71,7 @@ class FilePage : public QWidget {
* *
* @param path * @param path
*/ */
void SignalPathChanged(const QString& path); void SignalPathChanged(const QString&);
/** /**
* @brief * @brief
@ -79,8 +79,20 @@ class FilePage : public QWidget {
* @param text * @param text
* @param verify_label_status * @param verify_label_status
*/ */
void SignalRefreshInfoBoard(const QString& text, void SignalRefreshInfoBoard(const QString&, InfoBoardStatus);
InfoBoardStatus verify_label_status);
/**
* @brief
*
*/
void SignalCurrentTabChanged();
/**
* @brief
*
* @param int
*/
void SignalMainWindowlUpdateBasicalOperaMenu(unsigned int);
protected: protected:
/** /**
@ -99,6 +111,14 @@ class FilePage : public QWidget {
QMenu* popup_menu_{}; ///< QMenu* popup_menu_{}; ///<
QMenu* option_popup_menu_{}; ///< QMenu* option_popup_menu_{}; ///<
FileTreeView* file_tree_view_; FileTreeView* file_tree_view_;
private slots:
/**
* @brief
*
*/
void update_main_basical_opera_menu(const QString&);
}; };
} // namespace GpgFrontend::UI } // namespace GpgFrontend::UI

View File

@ -394,4 +394,8 @@ void FileTreeView::paintEvent(QPaintEvent* event) {
this->resizeColumnToContents(i); this->resizeColumnToContents(i);
} }
} }
void FileTreeView::mousePressEvent(QMouseEvent* event) {
QTreeView::mousePressEvent(event);
}
} // namespace GpgFrontend::UI } // namespace GpgFrontend::UI

View File

@ -88,6 +88,13 @@ class FileTreeView : public QTreeView {
*/ */
void paintEvent(QPaintEvent* event) override; void paintEvent(QPaintEvent* event) override;
/**
* @brief
*
* @param event
*/
void mousePressEvent(QMouseEvent* event) override;
signals: signals:
/** /**

View File

@ -429,7 +429,7 @@ void KeyList::SetDoubleClickedAction(
this->m_action_ = std::move(action); this->m_action_ = std::move(action);
} }
QString KeyList::GetSelectedKey() { auto KeyList::GetSelectedKey() -> QString {
if (ui_->keyGroupTab->size().isEmpty()) return {}; if (ui_->keyGroupTab->size().isEmpty()) return {};
const auto& buffered_keys = const auto& buffered_keys =
m_key_tables_[ui_->keyGroupTab->currentIndex()].buffered_keys_; m_key_tables_[ui_->keyGroupTab->currentIndex()].buffered_keys_;