diff options
author | Saturneric <[email protected]> | 2023-07-13 06:51:32 +0000 |
---|---|---|
committer | Saturneric <[email protected]> | 2023-07-13 06:51:32 +0000 |
commit | 7c96f052da1f73cbcd2f0671640d1019eaaa906a (patch) | |
tree | 814d98407a0a3bc8adb32f4b8065d8428f016eb9 /src/ui/widgets/KeyList.cpp | |
parent | feat: add CacheManager to deal with cache (diff) | |
download | GpgFrontend-7c96f052da1f73cbcd2f0671640d1019eaaa906a.tar.gz GpgFrontend-7c96f052da1f73cbcd2f0671640d1019eaaa906a.zip |
feat: support marking a key as favourite
Diffstat (limited to 'src/ui/widgets/KeyList.cpp')
-rw-r--r-- | src/ui/widgets/KeyList.cpp | 35 |
1 files changed, 34 insertions, 1 deletions
diff --git a/src/ui/widgets/KeyList.cpp b/src/ui/widgets/KeyList.cpp index 670644a8..51a2936a 100644 --- a/src/ui/widgets/KeyList.cpp +++ b/src/ui/widgets/KeyList.cpp @@ -35,6 +35,7 @@ #include "core/GpgCoreInit.h" #include "core/function/GlobalSettingStation.h" #include "core/function/gpg/GpgKeyGetter.h" +#include "spdlog/spdlog.h" #include "ui/SignalStation.h" #include "ui/UserInterfaceUtils.h" #include "ui_KeyList.h" @@ -73,6 +74,8 @@ void KeyList::init() { connect(SignalStation::GetInstance(), &SignalStation::SignalKeyDatabaseRefreshDone, this, &KeyList::SlotRefresh); + connect(SignalStation::GetInstance(), &SignalStation::SignalUIRefresh, this, + &KeyList::SlotRefreshUI); // register key database sync signal for refresh button connect(ui_->refreshKeyListButton, &QPushButton::clicked, this, @@ -104,7 +107,7 @@ void KeyList::init() { } void KeyList::AddListGroupTab( - const QString& name, KeyListRow::KeyType selectType, + const QString& name, const QString& id, KeyListRow::KeyType selectType, KeyListColumn::InfoType infoType, const std::function<bool(const GpgKey&)>& filter) { SPDLOG_DEBUG("add tab: {}", name.toStdString()); @@ -113,6 +116,7 @@ void KeyList::AddListGroupTab( if (m_key_list_ == nullptr) { m_key_list_ = key_list; } + key_list->setObjectName(id); ui_->keyGroupTab->addTab(key_list, name); m_key_tables_.emplace_back(key_list, selectType, infoType, filter); @@ -175,6 +179,11 @@ void KeyList::SlotRefresh() { this->slot_refresh_ui(); } +void KeyList::SlotRefreshUI() { + SPDLOG_DEBUG("refresh, address: {}", static_cast<void*>(this)); + this->slot_refresh_ui(); +} + KeyIdArgsListPtr KeyList::GetChecked(const KeyTable& key_table) { auto ret = std::make_unique<KeyIdArgsList>(); for (int i = 0; i < key_table.key_list_->rowCount(); i++) { @@ -297,6 +306,30 @@ void KeyList::contextMenuEvent(QContextMenuEvent* event) { if (ui_->keyGroupTab->size().isEmpty()) return; m_key_list_ = qobject_cast<QTableWidget*>(ui_->keyGroupTab->currentWidget()); + QString current_tab_widget_obj_name = + ui_->keyGroupTab->widget(ui_->keyGroupTab->currentIndex())->objectName(); + SPDLOG_DEBUG("current tab widget object name: {}", + current_tab_widget_obj_name.toStdString()); + if (current_tab_widget_obj_name == "favourite") { + QList<QAction*> actions = popup_menu_->actions(); + for (QAction* action : actions) { + if (action->data().toString() == "remove_key_from_favourtie_action") { + action->setVisible(true); + } else if (action->data().toString() == "add_key_2_favourite_action") { + action->setVisible(false); + } + } + } else { + QList<QAction*> actions = popup_menu_->actions(); + for (QAction* action : actions) { + if (action->data().toString() == "remove_key_from_favourtie_action") { + action->setVisible(false); + } else if (action->data().toString() == "add_key_2_favourite_action") { + action->setVisible(true); + } + } + } + if (m_key_list_->selectedItems().length() > 0) { popup_menu_->exec(event->globalPos()); } |