aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/ui/SignalStation.h6
-rw-r--r--src/ui/UserInterfaceUtils.cpp38
-rw-r--r--src/ui/UserInterfaceUtils.h19
-rw-r--r--src/ui/dialog/SignersPicker.cpp2
-rw-r--r--src/ui/dialog/keypair_details/KeyUIDSignDialog.cpp2
-rw-r--r--src/ui/main_window/KeyMgmt.cpp12
-rw-r--r--src/ui/main_window/MainWindow.cpp5
-rw-r--r--src/ui/main_window/MainWindow.h18
-rw-r--r--src/ui/main_window/MainWindowSlotFunction.cpp20
-rw-r--r--src/ui/main_window/MainWindowUI.cpp29
-rw-r--r--src/ui/widgets/KeyList.cpp35
-rw-r--r--src/ui/widgets/KeyList.h8
12 files changed, 181 insertions, 13 deletions
diff --git a/src/ui/SignalStation.h b/src/ui/SignalStation.h
index 5037ef4f..17e866f5 100644
--- a/src/ui/SignalStation.h
+++ b/src/ui/SignalStation.h
@@ -66,6 +66,12 @@ class SignalStation : public QObject {
/**
* @brief
*
+ */
+ void SignalUIRefresh();
+
+ /**
+ * @brief
+ *
* @param text
* @param verify_label_status
*/
diff --git a/src/ui/UserInterfaceUtils.cpp b/src/ui/UserInterfaceUtils.cpp
index 614d5bc9..3154aa2b 100644
--- a/src/ui/UserInterfaceUtils.cpp
+++ b/src/ui/UserInterfaceUtils.cpp
@@ -34,6 +34,7 @@
#include "core/GpgConstants.h"
#include "core/common/CoreCommonUtil.h"
+#include "core/function/CacheManager.h"
#include "core/function/CoreSignalStation.h"
#include "core/function/FileOperator.h"
#include "core/function/GlobalSettingStation.h"
@@ -481,4 +482,41 @@ bool CommonUtils::isApplicationNeedRestart() {
return application_need_to_restart_at_once_;
}
+bool CommonUtils::KeyExistsinFavouriteList(const GpgKey &key) {
+ // load cache
+ auto key_array = CacheManager::GetInstance().LoadCache("favourite_key_pair");
+ if (!key_array.is_array()) {
+ CacheManager::GetInstance().SaveCache("favourite_key_pair",
+ nlohmann::json::array());
+ }
+ return std::find(key_array.begin(), key_array.end(), key.GetFingerprint()) !=
+ key_array.end();
+}
+
+void CommonUtils::AddKey2Favourtie(const GpgKey &key) {
+ auto key_array = CacheManager::GetInstance().LoadCache("favourite_key_pair");
+ if (!key_array.is_array()) {
+ CacheManager::GetInstance().SaveCache("favourite_key_pair",
+ nlohmann::json::array());
+ }
+ key_array.push_back(key.GetFingerprint());
+ CacheManager::GetInstance().SaveCache("favourite_key_pair", key_array);
+}
+
+void CommonUtils::RemoveKeyFromFavourite(const GpgKey &key) {
+ auto key_array = CacheManager::GetInstance().LoadCache("favourite_key_pair");
+ if (!key_array.is_array()) {
+ CacheManager::GetInstance().SaveCache("favourite_key_pair",
+ nlohmann::json::array());
+ return;
+ }
+ auto it = std::find(key_array.begin(), key_array.end(), key.GetFingerprint());
+ if (it != key_array.end()) {
+ auto rm_it =
+ std::remove(key_array.begin(), key_array.end(), key.GetFingerprint());
+ key_array.erase(rm_it, key_array.end());
+ CacheManager::GetInstance().SaveCache("favourite_key_pair", key_array);
+ }
+}
+
} // namespace GpgFrontend::UI \ No newline at end of file
diff --git a/src/ui/UserInterfaceUtils.h b/src/ui/UserInterfaceUtils.h
index 7dd7bb1e..59c803b9 100644
--- a/src/ui/UserInterfaceUtils.h
+++ b/src/ui/UserInterfaceUtils.h
@@ -31,6 +31,7 @@
#include "core/GpgModel.h"
#include "core/function/result_analyse/GpgVerifyResultAnalyse.h"
+#include "core/model/GpgKey.h"
#include "ui/GpgFrontendUI.h"
namespace GpgFrontend {
@@ -150,6 +151,24 @@ class CommonUtils : public QWidget {
*/
bool isApplicationNeedRestart();
+ /**
+ * @brief
+ *
+ */
+ bool KeyExistsinFavouriteList(const GpgKey& key);
+
+ /**
+ * @brief
+ *
+ */
+ void AddKey2Favourtie(const GpgKey& key);
+
+ /**
+ * @brief
+ *
+ */
+ void RemoveKeyFromFavourite(const GpgKey& key);
+
signals:
/**
* @brief
diff --git a/src/ui/dialog/SignersPicker.cpp b/src/ui/dialog/SignersPicker.cpp
index a670e514..7e26de09 100644
--- a/src/ui/dialog/SignersPicker.cpp
+++ b/src/ui/dialog/SignersPicker.cpp
@@ -45,7 +45,7 @@ SignersPicker::SignersPicker(QWidget* parent)
/*Setup KeyList*/
key_list_ = new KeyList(false, this);
key_list_->AddListGroupTab(
- _("Signers"), KeyListRow::ONLY_SECRET_KEY,
+ _("Signers"), "signers", KeyListRow::ONLY_SECRET_KEY,
KeyListColumn::NAME | KeyListColumn::EmailAddress | KeyListColumn::Usage,
[](const GpgKey& key) -> bool {
return key.IsHasActualSigningCapability();
diff --git a/src/ui/dialog/keypair_details/KeyUIDSignDialog.cpp b/src/ui/dialog/keypair_details/KeyUIDSignDialog.cpp
index ca83dbfd..f0ab0a6e 100644
--- a/src/ui/dialog/keypair_details/KeyUIDSignDialog.cpp
+++ b/src/ui/dialog/keypair_details/KeyUIDSignDialog.cpp
@@ -40,7 +40,7 @@ KeyUIDSignDialog::KeyUIDSignDialog(const GpgKey& key, UIDArgsListPtr uid,
const auto key_id = m_key_.GetId();
m_key_list_ = new KeyList(KeyMenuAbility::NONE, this);
m_key_list_->AddListGroupTab(
- _("Signers"), KeyListRow::ONLY_SECRET_KEY,
+ _("Signers"), "signers", KeyListRow::ONLY_SECRET_KEY,
KeyListColumn::NAME | KeyListColumn::EmailAddress,
[key_id](const GpgKey& key) -> bool {
if (key.IsDisabled() || !key.IsHasCertificationCapability() ||
diff --git a/src/ui/main_window/KeyMgmt.cpp b/src/ui/main_window/KeyMgmt.cpp
index 758a7af1..9cd93985 100644
--- a/src/ui/main_window/KeyMgmt.cpp
+++ b/src/ui/main_window/KeyMgmt.cpp
@@ -48,10 +48,10 @@ KeyMgmt::KeyMgmt(QWidget* parent)
/* the list of Keys available*/
key_list_ = new KeyList(KeyMenuAbility::ALL, this);
- key_list_->AddListGroupTab(_("All"), KeyListRow::SECRET_OR_PUBLIC_KEY);
+ key_list_->AddListGroupTab(_("All"), "all", KeyListRow::SECRET_OR_PUBLIC_KEY);
key_list_->AddListGroupTab(
- _("Only Public Key"), KeyListRow::SECRET_OR_PUBLIC_KEY,
+ _("Only Public Key"), "only_public_key", KeyListRow::SECRET_OR_PUBLIC_KEY,
KeyListColumn::TYPE | KeyListColumn::NAME | KeyListColumn::EmailAddress |
KeyListColumn::Usage | KeyListColumn::Validity,
[](const GpgKey& key) -> bool {
@@ -60,7 +60,7 @@ KeyMgmt::KeyMgmt(QWidget* parent)
});
key_list_->AddListGroupTab(
- _("Has Private Key"), KeyListRow::SECRET_OR_PUBLIC_KEY,
+ _("Has Private Key"), "has_private_key", KeyListRow::SECRET_OR_PUBLIC_KEY,
KeyListColumn::TYPE | KeyListColumn::NAME | KeyListColumn::EmailAddress |
KeyListColumn::Usage | KeyListColumn::Validity,
[](const GpgKey& key) -> bool {
@@ -69,7 +69,7 @@ KeyMgmt::KeyMgmt(QWidget* parent)
});
key_list_->AddListGroupTab(
- _("No Primary Key"), KeyListRow::SECRET_OR_PUBLIC_KEY,
+ _("No Primary Key"), "no_primary_key", KeyListRow::SECRET_OR_PUBLIC_KEY,
KeyListColumn::TYPE | KeyListColumn::NAME | KeyListColumn::EmailAddress |
KeyListColumn::Usage | KeyListColumn::Validity,
[](const GpgKey& key) -> bool {
@@ -78,13 +78,13 @@ KeyMgmt::KeyMgmt(QWidget* parent)
});
key_list_->AddListGroupTab(
- _("Revoked"), KeyListRow::SECRET_OR_PUBLIC_KEY,
+ _("Revoked"), "revoked", KeyListRow::SECRET_OR_PUBLIC_KEY,
KeyListColumn::TYPE | KeyListColumn::NAME | KeyListColumn::EmailAddress |
KeyListColumn::Usage | KeyListColumn::Validity,
[](const GpgKey& key) -> bool { return key.IsRevoked(); });
key_list_->AddListGroupTab(
- _("Expired"), KeyListRow::SECRET_OR_PUBLIC_KEY,
+ _("Expired"), "expired", KeyListRow::SECRET_OR_PUBLIC_KEY,
KeyListColumn::TYPE | KeyListColumn::NAME | KeyListColumn::EmailAddress |
KeyListColumn::Usage | KeyListColumn::Validity,
[](const GpgKey& key) -> bool { return key.IsExpired(); });
diff --git a/src/ui/main_window/MainWindow.cpp b/src/ui/main_window/MainWindow.cpp
index 9e02c095..486cb47a 100644
--- a/src/ui/main_window/MainWindow.cpp
+++ b/src/ui/main_window/MainWindow.cpp
@@ -80,6 +80,9 @@ void MainWindow::Init() noexcept {
SignalStation::GetInstance(),
&SignalStation::SignalRestartApplication);
+ connect(this, &MainWindow::SignalUIRefresh, SignalStation::GetInstance(),
+ &SignalStation::SignalUIRefresh);
+
connect(edit_->tab_widget_, &QTabWidget::currentChanged, this,
&MainWindow::slot_disable_tab_actions);
connect(SignalStation::GetInstance(),
@@ -96,6 +99,8 @@ void MainWindow::Init() noexcept {
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(add_key_2_favourtie_act_);
+ m_key_list_->AddMenuAction(remove_key_from_favourtie_act_);
m_key_list_->AddSeparator();
m_key_list_->AddMenuAction(show_key_details_act_);
diff --git a/src/ui/main_window/MainWindow.h b/src/ui/main_window/MainWindow.h
index 8f0b2e4d..670db23a 100644
--- a/src/ui/main_window/MainWindow.h
+++ b/src/ui/main_window/MainWindow.h
@@ -97,6 +97,11 @@ class MainWindow : public GeneralMainWindow {
*/
void SignalRestartApplication(int);
+ /**
+ * @brief
+ */
+ void SignalUIRefresh();
+
public slots:
/**
@@ -307,6 +312,16 @@ class MainWindow : public GeneralMainWindow {
*/
void slot_version_upgrade(const SoftwareVersion& version);
+ /**
+ * @details
+ */
+ void slot_add_key_2_favourite();
+
+ /**
+ * @details
+ */
+ void slot_remove_key_from_favourite();
+
private:
/**
* @details Create actions for the main-menu and the context-menu of the
@@ -421,6 +436,9 @@ class MainWindow : public GeneralMainWindow {
QAction* copy_key_id_to_clipboard_act_{}; ///<
QAction* copy_key_default_uid_to_clipboard_act_{}; ///<
+ QAction* add_key_2_favourtie_act_{}; ///<
+ QAction* remove_key_from_favourtie_act_{}; ///<
+
QAction* open_key_management_act_{}; ///< Action to open key management
QAction* copy_act_{}; ///< Action to copy text
QAction* quote_act_{}; ///< Action to quote text
diff --git a/src/ui/main_window/MainWindowSlotFunction.cpp b/src/ui/main_window/MainWindowSlotFunction.cpp
index 841c8680..fc0218b9 100644
--- a/src/ui/main_window/MainWindowSlotFunction.cpp
+++ b/src/ui/main_window/MainWindowSlotFunction.cpp
@@ -747,6 +747,26 @@ void MainWindow::slot_show_key_details() {
}
}
+void MainWindow::slot_add_key_2_favourite() {
+ auto key_ids = m_key_list_->GetSelected();
+ if (key_ids->empty()) return;
+
+ auto key = GpgKeyGetter::GetInstance().GetKey(key_ids->front());
+ CommonUtils::GetInstance()->AddKey2Favourtie(key);
+
+ emit SignalUIRefresh();
+}
+
+void MainWindow::slot_remove_key_from_favourite() {
+ auto key_ids = m_key_list_->GetSelected();
+ if (key_ids->empty()) return;
+
+ auto key = GpgKeyGetter::GetInstance().GetKey(key_ids->front());
+ CommonUtils::GetInstance()->RemoveKeyFromFavourite(key);
+
+ emit SignalUIRefresh();
+}
+
void MainWindow::refresh_keys_from_key_server() {
auto key_ids = m_key_list_->GetSelected();
if (key_ids->empty()) return;
diff --git a/src/ui/main_window/MainWindowUI.cpp b/src/ui/main_window/MainWindowUI.cpp
index 6e664988..77128ece 100644
--- a/src/ui/main_window/MainWindowUI.cpp
+++ b/src/ui/main_window/MainWindowUI.cpp
@@ -418,6 +418,21 @@ void MainWindow::create_actions() {
connect(show_key_details_act_, &QAction::triggered, this,
&MainWindow::slot_show_key_details);
+ add_key_2_favourtie_act_ = new QAction(_("Add To Favourite"), this);
+ add_key_2_favourtie_act_->setToolTip(_("Add this key to Favourite Table"));
+ add_key_2_favourtie_act_->setData(QVariant("add_key_2_favourite_action"));
+ connect(add_key_2_favourtie_act_, &QAction::triggered, this,
+ &MainWindow::slot_add_key_2_favourite);
+
+ remove_key_from_favourtie_act_ =
+ new QAction(_("Remove From Favourite"), this);
+ remove_key_from_favourtie_act_->setToolTip(
+ _("Remove this key from Favourite Table"));
+ remove_key_from_favourtie_act_->setData(
+ QVariant("remove_key_from_favourtie_action"));
+ connect(remove_key_from_favourtie_act_, &QAction::triggered, this,
+ &MainWindow::slot_remove_key_from_favourite);
+
/* Key-Shortcuts for Tab-Switchung-Action
*/
switch_tab_up_act_ = new QAction(this);
@@ -591,7 +606,7 @@ void MainWindow::create_dock_windows() {
addDockWidget(Qt::RightDockWidgetArea, key_list_dock_);
m_key_list_->AddListGroupTab(
- _("Default"), KeyListRow::SECRET_OR_PUBLIC_KEY,
+ _("Default"), "default", KeyListRow::SECRET_OR_PUBLIC_KEY,
KeyListColumn::TYPE | KeyListColumn::NAME | KeyListColumn::EmailAddress |
KeyListColumn::Usage | KeyListColumn::Validity,
[](const GpgKey& key) -> bool {
@@ -599,7 +614,15 @@ void MainWindow::create_dock_windows() {
});
m_key_list_->AddListGroupTab(
- _("Only Public Key"), KeyListRow::SECRET_OR_PUBLIC_KEY,
+ _("Favourite"), "favourite", KeyListRow::SECRET_OR_PUBLIC_KEY,
+ KeyListColumn::TYPE | KeyListColumn::NAME | KeyListColumn::EmailAddress |
+ KeyListColumn::Usage | KeyListColumn::Validity,
+ [](const GpgKey& key) -> bool {
+ return CommonUtils::GetInstance()->KeyExistsinFavouriteList(key);
+ });
+
+ m_key_list_->AddListGroupTab(
+ _("Only Public Key"), "only_public_key", KeyListRow::SECRET_OR_PUBLIC_KEY,
KeyListColumn::TYPE | KeyListColumn::NAME | KeyListColumn::EmailAddress |
KeyListColumn::Usage | KeyListColumn::Validity,
[](const GpgKey& key) -> bool {
@@ -608,7 +631,7 @@ void MainWindow::create_dock_windows() {
});
m_key_list_->AddListGroupTab(
- _("Has Private Key"), KeyListRow::SECRET_OR_PUBLIC_KEY,
+ _("Has Private Key"), "has_private_key", KeyListRow::SECRET_OR_PUBLIC_KEY,
KeyListColumn::TYPE | KeyListColumn::NAME | KeyListColumn::EmailAddress |
KeyListColumn::Usage | KeyListColumn::Validity,
[](const GpgKey& key) -> bool {
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());
}
diff --git a/src/ui/widgets/KeyList.h b/src/ui/widgets/KeyList.h
index f1c88cc6..63b5f7af 100644
--- a/src/ui/widgets/KeyList.h
+++ b/src/ui/widgets/KeyList.h
@@ -171,7 +171,7 @@ class KeyList : public QWidget {
* @param filter
*/
void AddListGroupTab(
- const QString& name,
+ const QString& name, const QString& id,
KeyListRow::KeyType selectType = KeyListRow::SECRET_OR_PUBLIC_KEY,
KeyListColumn::InfoType infoType = KeyListColumn::ALL,
const std::function<bool(const GpgKey&)>& filter =
@@ -303,6 +303,12 @@ class KeyList : public QWidget {
*/
void SlotRefresh();
+ /**
+ * @brief
+ *
+ */
+ void SlotRefreshUI();
+
private:
/**
* @brief