aboutsummaryrefslogtreecommitdiffstats
path: root/src/ui/UserInterfaceUtils.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/ui/UserInterfaceUtils.cpp')
-rw-r--r--src/ui/UserInterfaceUtils.cpp38
1 files changed, 38 insertions, 0 deletions
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