diff options
author | saturneric <[email protected]> | 2024-01-17 11:39:47 +0000 |
---|---|---|
committer | saturneric <[email protected]> | 2024-01-17 11:39:47 +0000 |
commit | e352e8e6b8d03a24ef5d52eef3e4d370807b5bbd (patch) | |
tree | 9a59f0b573a845644afe4b8857a89c4b28bdcc0d | |
parent | fix: solve the gnupg tab options info not shown issue (diff) | |
download | GpgFrontend-e352e8e6b8d03a24ef5d52eef3e4d370807b5bbd.tar.gz GpgFrontend-e352e8e6b8d03a24ef5d52eef3e4d370807b5bbd.zip |
fix: find and slove some bugs
41 files changed, 342 insertions, 333 deletions
diff --git a/.clang-tidy b/.clang-tidy index 3b460e5e..681e8f5b 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -33,10 +33,10 @@ Checks: > -readability-named-parameter, -readability-braces-around-statements, -readability-magic-numbers, - -readability-named-parameter - -readability-identifier-length - -bugprone-easily-swappable-parameters - -readability-redundant-access-specifiers + -readability-named-parameter, + -readability-identifier-length, + -bugprone-easily-swappable-parameters, + -readability-redundant-access-specifiers, -readability-identifier-length CheckOptions: diff --git a/CMakeLists.txt b/CMakeLists.txt index ae549d9e..0d8683aa 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -59,9 +59,6 @@ option(GPGFRONTEND_BUILD_TYPE_TEST_ALL option(GPGFRONTEND_BUILD_TYPE_STABLE "Generate release version" ON) option(GPGFRONTEND_GENERATE_LINUX_INSTALL_SOFTWARE "Generate an installable version" OFF) -option(GPGFRONTEND_GENERATE_APP_PACKAGE_DEB "Generate DEB package" OFF) -option(GPGFRONTEND_GENERATE_APP_PACKAGE_RPM "Generate RPM package" OFF) -option(GPGFRONTEND_GENERATE_APP_PACKAGE_FREEBSD "Generate PKG package" OFF) option(GPGFRONTEND_CONFIGURE_FOR_XCODE_BUILD "Generate a version that can be successfully compiled and packaged in Xcode" OFF) option(GPGFRONTEND_XCODE_TEAM_ID "GpgFrontend Apple Team ID" "NONE") option(GPGFRONTEND_XOCDE_CODE_SIGN_IDENTITY "GpgFrontend Signing Certificate" "NONE") @@ -112,30 +109,12 @@ if (GPGFRONTEND_GENERATE_LINUX_INSTALL_SOFTWARE) unset(GPGFRONTEND_BUILD_CONFIG) set(LINUX_INSTALL_SOFTWARE 1) - set(GPGFRONTEND_GENERATE_APP_PACKAGE_DEB 1) -endif () - -# linux package build deb -if (GPGFRONTEND_GENERATE_LINUX_INSTALL_SOFTWARE AND GPGFRONTEND_GENERATE_APP_PACKAGE_DEB) - set(APP_PACKAGE_DEB 1) -endif () - -# linux package build rpm -if (GPGFRONTEND_GENERATE_LINUX_INSTALL_SOFTWARE AND GPGFRONTEND_GENERATE_APP_PACKAGE_RPM) - set(APP_PACKAGE_RPM 1) -endif () - -# linux package build pkg -if (GPGFRONTEND_GENERATE_LINUX_INSTALL_SOFTWARE AND GPGFRONTEND_GENERATE_APP_PACKAGE_FREEBSD) - set(APP_PACKAGE_FREEBSD 1) endif () # xcode archive build if (GPGFRONTEND_CONFIGURE_FOR_XCODE_BUILD) set(GPGFRONTEND_GENERATE_LINUX_INSTALL_SOFTWARE 0) - set(GPGFRONTEND_GENERATE_APP_PACKAGE_DEB 0) set(LINUX_INSTALL_SOFTWARE 0) - set(APP_PACKAGE_DEB 0) set(XCODE_BUILD 1) set(GPGFRONTEND_BUILD_TYPE_TEST_CORE 0) @@ -216,16 +216,6 @@ $ ./configure --enable-maintainer-mode --enable-languages=cpp && make -j$(nproc) $ sudo make install ``` -Build the code and make the deb package(Please use Ubuntu 20.04 or later). - -```shell -$ cd GpgFrontend -$ mkdir build && cd build -$ cmake -G Ninja -DCMAKE_BUILD_TYPE="Release" -DGPGFRONTEND_GENERATE_LINUX_INSTALL_SOFTWARE=ON .. -$ ninja -$ ninja package -``` - Build the code separately for debug(Please use ubuntu 18.04 or later). ```shell diff --git a/resource/lfs/locale/ts/GpgFrontend.zh_CN.ts b/resource/lfs/locale/ts/GpgFrontend.zh_CN.ts index 9653182c..14dfd180 100644 --- a/resource/lfs/locale/ts/GpgFrontend.zh_CN.ts +++ b/resource/lfs/locale/ts/GpgFrontend.zh_CN.ts @@ -1966,7 +1966,7 @@ This will result in loss of all cached form positions, statuses, key servers, et <message> <location filename="../../../../src/ui/main_window/KeyMgmt.cpp" line="215"/> <source>Export Checked Key(s) To a Key Package</source> - <translation type="unfinished">将检查的密钥导出到密钥包</translation> + <translation type="unfinished">将勾选的密钥导出到密钥包</translation> </message> <message> <location filename="../../../../src/ui/main_window/KeyMgmt.cpp" line="219"/> @@ -2088,7 +2088,7 @@ This will result in loss of all cached form positions, statuses, key servers, et <location filename="../../../../src/ui/main_window/KeyMgmt.cpp" line="366"/> <location filename="../../../../src/ui/main_window/KeyMgmt.cpp" line="379"/> <source>Please check some keys before doing this operation.</source> - <translation type="unfinished">请在执行此操作之前检查一些密钥。</translation> + <translation type="unfinished">请在执行此操作之前勾选一些密钥。</translation> </message> <message> <location filename="../../../../src/ui/main_window/KeyMgmt.cpp" line="371"/> @@ -3505,7 +3505,7 @@ This will result in loss of all cached form positions, statuses, key servers, et <location filename="../../../../src/ui/main_window/MainWindowGpgOperaFunction.cpp" line="140"/> <location filename="../../../../src/ui/main_window/MainWindowGpgOperaFunction.cpp" line="253"/> <source>No Key Checked</source> - <translation type="unfinished">未检查密钥</translation> + <translation type="unfinished">未勾选任何密钥</translation> </message> <message> <location filename="../../../../src/ui/main_window/MainWindowFileSlotFunction.cpp" line="369"/> @@ -3513,7 +3513,7 @@ This will result in loss of all cached form positions, statuses, key servers, et <location filename="../../../../src/ui/main_window/MainWindowFileSlotFunction.cpp" line="618"/> <location filename="../../../../src/ui/main_window/MainWindowGpgOperaFunction.cpp" line="141"/> <source>Please check the key in the key toolbox on the right.</source> - <translation type="unfinished">请检查右侧密钥工具箱中的密钥。</translation> + <translation type="unfinished">请勾选右侧密钥工具箱中的密钥。</translation> </message> <message> <location filename="../../../../src/ui/main_window/MainWindowFileSlotFunction.cpp" line="376"/> @@ -3611,7 +3611,7 @@ If Data And Signature is COMBINED within a single file, KEEP THIS EMPTY: </sourc <message> <location filename="../../../../src/ui/main_window/MainWindowGpgOperaFunction.cpp" line="254"/> <source>Please check some key in the key toolbox on the right.</source> - <translation type="unfinished">请检查右侧密钥工具箱中的一些密钥。</translation> + <translation type="unfinished">请勾选右侧密钥工具箱中的一些密钥。</translation> </message> <message> <location filename="../../../../src/ui/main_window/MainWindowSlotFunction.cpp" line="96"/> diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 1b06ec33..96334dd1 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -421,6 +421,9 @@ if (BUILD_APPLICATION) # Make app build with resources add_dependencies(${AppName} resources) + + # using c++ standard 17 + target_compile_features(${AppName} PUBLIC cxx_std_17) endif () @@ -435,30 +438,24 @@ if (BUILD_APPLICATION) else () message(STATUS "Link Application Library For Linux") target_link_libraries(${AppName} crypto pthread) - # issue on filesystem support of gcc - if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU" AND ${CMAKE_CXX_COMPILER_VERSION} VERSION_LESS 9.0) - target_link_libraries(${AppName} stdc++fs) - endif () endif () endif () -# using c++ standard 17 -target_compile_features(${AppName} PUBLIC cxx_std_17) - -# build i18n support -set(LOCALE_TS_PATH ${CMAKE_SOURCE_DIR}/resource/lfs/locale/ts) -set(LOCALE_OUTPUT_PATH ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/locales) -set(TS_FILES "${LOCALE_TS_PATH}/GpgFrontend.de_DE.ts" - "${LOCALE_TS_PATH}/GpgFrontend.fr_FR.ts" - "${LOCALE_TS_PATH}/GpgFrontend.zh_CN.ts" - "${LOCALE_TS_PATH}/GpgFrontend.zh_TW.ts" - "${LOCALE_TS_PATH}/GpgFrontend.it_IT.ts") -file(GLOB_RECURSE ALL_SOURCE_FILES RELACTIVE ${CMAKE_SOURCE_DIR}/src/*.cpp) -qt_add_translations(${AppName} - RESOURCE_PREFIX "/i18n" - TS_FILES ${TS_FILES} - SOURCES ${ALL_SOURCE_FILES} - INCLUDE_DIRECTORIES ${CMAKE_SOURCE_DIR}/src) +# add i18n support +if (BUILD_APPLICATION) + set(LOCALE_TS_PATH ${CMAKE_SOURCE_DIR}/resource/lfs/locale/ts) + set(TS_FILES "${LOCALE_TS_PATH}/GpgFrontend.de_DE.ts" + "${LOCALE_TS_PATH}/GpgFrontend.fr_FR.ts" + "${LOCALE_TS_PATH}/GpgFrontend.zh_CN.ts" + "${LOCALE_TS_PATH}/GpgFrontend.zh_TW.ts" + "${LOCALE_TS_PATH}/GpgFrontend.it_IT.ts") + file(GLOB_RECURSE ALL_SOURCE_FILES RELACTIVE ${CMAKE_SOURCE_DIR}/src/*.cpp) + qt_add_translations(${AppName} + RESOURCE_PREFIX "/i18n" + TS_FILES ${TS_FILES} + SOURCES ${ALL_SOURCE_FILES} + INCLUDE_DIRECTORIES ${CMAKE_SOURCE_DIR}/src) +endif() # if building linux package if (LINUX AND LINUX_INSTALL_SOFTWARE) @@ -492,10 +489,7 @@ if (LINUX AND LINUX_INSTALL_SOFTWARE) install(DIRECTORY ${CMAKE_SOURCE_DIR}/resource/lfs/hicolor/ DESTINATION ${CMAKE_INSTALL_FULL_DATAROOTDIR}/icons/hicolor/) endif () - install(DIRECTORY ${LOCALE_OUTPUT_PATH}/ - DESTINATION ${CMAKE_INSTALL_FULL_LOCALEDIR}) endif () message(STATUS "Resource Files: ${RESOURCE_OUTPUT_DIRECTORY}") -message(STATUS "Locale Files: ${LOCALE_OUTPUT_PATH}") message(STATUS "Runtime Files: ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}") diff --git a/src/core/function/ArchiveFileOperator.cpp b/src/core/function/ArchiveFileOperator.cpp index 60b8b004..a4b90698 100644 --- a/src/core/function/ArchiveFileOperator.cpp +++ b/src/core/function/ArchiveFileOperator.cpp @@ -32,8 +32,6 @@ #include <archive_entry.h> #include <sys/fcntl.h> -#include <fstream> - #include "core/utils/AsyncUtils.h" namespace GpgFrontend { diff --git a/src/core/function/CacheManager.cpp b/src/core/function/CacheManager.cpp index 58adede4..719c962d 100644 --- a/src/core/function/CacheManager.cpp +++ b/src/core/function/CacheManager.cpp @@ -30,6 +30,7 @@ #include <algorithm> #include <shared_mutex> +#include <utility> #include "core/function/DataObjectOperator.h" #include "core/utils/MemoryUtils.h" @@ -101,9 +102,9 @@ class CacheManager::Impl : public QObject { load_all_cache_storage(); } - void SaveCache(QString key, const QJsonDocument& value, bool flush) { + void SaveDurableCache(QString key, const QJsonDocument& value, bool flush) { auto data_object_key = get_data_object_key(key); - cache_storage_.insert(key, value); + durable_cache_storage_.insert(key, value); if (!key_storage_.contains(key)) { GF_CORE_LOG_DEBUG("register new key of cache", key); @@ -113,36 +114,50 @@ class CacheManager::Impl : public QObject { if (flush) slot_flush_cache_storage(); } - auto LoadCache(const QString& key) -> QJsonDocument { + auto LoadDurableCache(const QString& key) -> QJsonDocument { auto data_object_key = get_data_object_key(key); - if (!cache_storage_.exists(key)) { - cache_storage_.insert(key, load_cache_storage(key, {})); + if (!durable_cache_storage_.exists(key)) { + durable_cache_storage_.insert(key, load_cache_storage(key, {})); } - auto cache = cache_storage_.get(key); + auto cache = durable_cache_storage_.get(key); if (cache.has_value()) return cache.value(); return {}; } - auto LoadCache(const QString& key, QJsonDocument default_value) + auto LoadDurableCache(const QString& key, QJsonDocument default_value) -> QJsonDocument { auto data_object_key = get_data_object_key(key); - if (!cache_storage_.exists(key)) { - cache_storage_.insert(key, - load_cache_storage(key, std::move(default_value))); + if (!durable_cache_storage_.exists(key)) { + durable_cache_storage_.insert( + key, load_cache_storage(key, std::move(default_value))); } - auto cache = cache_storage_.get(key); + auto cache = durable_cache_storage_.get(key); if (cache.has_value()) return cache.value(); return {}; } - auto ResetCache(const QString& key) -> bool { + auto ResetDurableCache(const QString& key) -> bool { auto data_object_key = get_data_object_key(key); - return cache_storage_.remove(key); + return durable_cache_storage_.remove(key); } + void FlushCacheStorage() { this->slot_flush_cache_storage(); } + + void SaveCache(const QString& key, QString value) { + runtime_cache_storage_.insert(key, new QString(std::move(value))); + } + + auto LoadCache(const QString& key) -> QString { + auto* value = runtime_cache_storage_.object(key); + if (value == nullptr) return {}; + return *value; + } + + void ResetCache(const QString& key) { runtime_cache_storage_.remove(key); } + private slots: /** @@ -150,7 +165,7 @@ class CacheManager::Impl : public QObject { * */ void slot_flush_cache_storage() { - for (const auto& cache : cache_storage_.mirror()) { + for (const auto& cache : durable_cache_storage_.mirror()) { auto key = get_data_object_key(cache.first); GF_CORE_LOG_TRACE("save cache into filesystem, key {}", key); GpgFrontend::DataObjectOperator::GetInstance().SaveDataObj( @@ -161,7 +176,8 @@ class CacheManager::Impl : public QObject { } private: - ThreadSafeMap<QString, QJsonDocument> cache_storage_; + QCache<QString, QString> runtime_cache_storage_; + ThreadSafeMap<QString, QJsonDocument> durable_cache_storage_; QJsonArray key_storage_; QTimer* flush_timer_; const QString drk_key_ = "__cache_manage_data_register_key_list"; @@ -172,7 +188,7 @@ class CacheManager::Impl : public QObject { * @param key * @return QString */ - static auto get_data_object_key(QString key) -> QString { + static auto get_data_object_key(const QString& key) -> QString { return QString("__cache_data_%1").arg(key); } @@ -183,9 +199,9 @@ class CacheManager::Impl : public QObject { * @param default_value * @return QJsonObject */ - static auto load_cache_storage(QString key, QJsonDocument default_value) - -> QJsonDocument { - auto data_object_key = get_data_object_key(std::move(key)); + static auto load_cache_storage(const QString& key, + QJsonDocument default_value) -> QJsonDocument { + auto data_object_key = get_data_object_key(key); auto stored_data = GpgFrontend::DataObjectOperator::GetInstance().GetDataObject( data_object_key); @@ -231,26 +247,38 @@ CacheManager::CacheManager(int channel) : SingletonFunctionObject<CacheManager>(channel), p_(SecureCreateUniqueObject<Impl>()) {} -CacheManager::~CacheManager() = default; +CacheManager::~CacheManager() { p_->FlushCacheStorage(); } -void CacheManager::SaveCache(QString key, const QJsonDocument& value, - bool flush) { - p_->SaveCache(std::move(key), value, flush); +void CacheManager::SaveDurableCache(const QString& key, + const QJsonDocument& value, bool flush) { + p_->SaveDurableCache(key, value, flush); } -auto CacheManager::LoadCache(QString key) -> QJsonDocument { - return p_->LoadCache(key); +auto CacheManager::LoadDurableCache(const QString& key) -> QJsonDocument { + return p_->LoadDurableCache(key); } -auto CacheManager::LoadCache(QString key, QJsonDocument default_value) +auto CacheManager::LoadDurableCache(const QString& key, + QJsonDocument default_value) -> QJsonDocument { - return p_->LoadCache(key, std::move(default_value)); + return p_->LoadDurableCache(key, std::move(default_value)); } -auto CacheManager::ResetCache(QString key) -> bool { - return p_->ResetCache(key); +auto CacheManager::ResetDurableCache(const QString& key) -> bool { + return p_->ResetDurableCache(key); +} + +void CacheManager::SaveCache(const QString& key, QString value) { + p_->SaveCache(key, std::move(value)); +} + +auto CacheManager::LoadCache(const QString& key) -> QString { + return p_->LoadCache(key); } +void CacheManager::ResetCache(const QString& key) { + return p_->ResetCache(key); +} } // namespace GpgFrontend #include "CacheManager.moc"
\ No newline at end of file diff --git a/src/core/function/CacheManager.h b/src/core/function/CacheManager.h index 96496648..67e7fd75 100644 --- a/src/core/function/CacheManager.h +++ b/src/core/function/CacheManager.h @@ -35,18 +35,80 @@ namespace GpgFrontend { class GPGFRONTEND_CORE_EXPORT CacheManager : public SingletonFunctionObject<CacheManager> { public: + /** + * @brief Construct a new Cache Manager object + * + * @param channel + */ explicit CacheManager( int channel = SingletonFunctionObject::GetDefaultChannel()); + /** + * @brief Destroy the Cache Manager object + * + */ ~CacheManager() override; - void SaveCache(QString key, const QJsonDocument& value, bool flush = false); + /** + * @brief + * + * @param key + * @param value + */ + void SaveCache(const QString& key, QString value); - auto LoadCache(QString key) -> QJsonDocument; + /** + * @brief + * + * @param key + * @param value + * @param flush + */ + void SaveDurableCache(const QString& key, const QJsonDocument& value, + bool flush = false); - auto LoadCache(QString key, QJsonDocument default_value) -> QJsonDocument; + /** + * @brief + * + * @param key + * @param value + */ + auto LoadCache(const QString& key) -> QString; - auto ResetCache(QString key) -> bool; + /** + * @brief + * + * @param key + * @return QJsonDocument + */ + auto LoadDurableCache(const QString& key) -> QJsonDocument; + + /** + * @brief + * + * @param key + * @param default_value + * @return QJsonDocument + */ + auto LoadDurableCache(const QString& key, QJsonDocument default_value) + -> QJsonDocument; + + /** + * @brief + * + * @param key + * @return auto + */ + void ResetCache(const QString& key); + + /** + * @brief + * + * @param key + * @return true + * @return false + */ + auto ResetDurableCache(const QString& key) -> bool; private: class Impl; diff --git a/src/core/function/GlobalSettingStation.cpp b/src/core/function/GlobalSettingStation.cpp index 04129186..0158e8b3 100644 --- a/src/core/function/GlobalSettingStation.cpp +++ b/src/core/function/GlobalSettingStation.cpp @@ -70,7 +70,6 @@ class GlobalSettingStation::Impl { GF_CORE_LOG_INFO("app data path: {}", app_data_path_); GF_CORE_LOG_INFO("app log path: {}", app_log_path_); - GF_CORE_LOG_INFO("app locale path: {}", app_locale_path_); GF_CORE_LOG_INFO("app log files total size: {}", GetLogFilesSize()); GF_CORE_LOG_INFO("app data objects files total size: {}", @@ -127,33 +126,6 @@ class GlobalSettingStation::Impl { */ [[nodiscard]] auto GetLogDir() const -> QString { return app_log_path_; } - /** - * @brief Get the Locale Dir object - * - * @return QString - */ - [[nodiscard]] auto GetLocaleDir() const -> QString { - return app_locale_path_; - } - - /** - * @brief Get the Resource Dir object - * - * @return QString - */ - [[nodiscard]] auto GetResourceDir() const -> QString { - return app_resource_path_; - } - - /** - * @brief Get the Certs Dir object - * - * @return QString - */ - [[nodiscard]] auto GetCertsDir() const -> QString { - return app_resource_path_ + "/certs"; - } - private: QString working_path_ = QDir::currentPath(); @@ -165,22 +137,6 @@ class GlobalSettingStation::Impl { QString app_data_objs_path_ = app_data_path_ + "/data_objs"; ///< Object storage path -#ifdef LINUX_INSTALL_BUILD - QString app_resource_path_ = - QString(APP_LOCALSTATE_PATH) / "gpgfrontend"; ///< Program Data Location -#else - QString app_resource_path_ = - RESOURCE_DIR_PATH(GetAppDir()); ///< Program Data Location -#endif - -#ifdef LINUX_INSTALL_BUILD - QString app_locale_path_ = - QString(APP_LOCALE_PATH); ///< Program Data Location -#else - QString app_locale_path_ = - app_resource_path_ + "/locales"; ///< Program Data Location -#endif - bool portable_mode_ = false; ///< QString app_portable_config_path_ = working_path_ + "/config.ini"; ///< take effect only in portable mode @@ -214,18 +170,6 @@ auto GlobalSettingStation::GetAppDataPath() const -> QString { return p_->GetLogDir(); } -auto GlobalSettingStation::GetLocaleDir() const -> QString { - return p_->GetLocaleDir(); -} - -auto GlobalSettingStation::GetResourceDir() const -> QString { - return p_->GetResourceDir(); -} - -auto GlobalSettingStation::GetCertsDir() const -> QString { - return p_->GetCertsDir(); -} - auto GlobalSettingStation::GetLogFilesSize() const -> QString { return p_->GetLogFilesSize(); } diff --git a/src/core/function/GlobalSettingStation.h b/src/core/function/GlobalSettingStation.h index f8d3068e..85ac57b4 100644 --- a/src/core/function/GlobalSettingStation.h +++ b/src/core/function/GlobalSettingStation.h @@ -83,27 +83,6 @@ class GPGFRONTEND_CORE_EXPORT GlobalSettingStation [[nodiscard]] auto GetLogDir() const -> QString; /** - * @brief Get the Locale Dir object - * - * @return QString - */ - [[nodiscard]] auto GetLocaleDir() const -> QString; - - /** - * @brief Get the Resource Dir object - * - * @return QString - */ - [[nodiscard]] auto GetResourceDir() const -> QString; - - /** - * @brief Get the Certs Dir object - * - * @return QString - */ - [[nodiscard]] auto GetCertsDir() const -> QString; - - /** * @brief Get the Log Files Size object * * @return QString diff --git a/src/core/function/KeyPackageOperator.cpp b/src/core/function/KeyPackageOperator.cpp index d15859a3..abb84512 100644 --- a/src/core/function/KeyPackageOperator.cpp +++ b/src/core/function/KeyPackageOperator.cpp @@ -64,8 +64,10 @@ void KeyPackageOperator::GenerateKeyPackage(const QString& key_package_path, return; } - if (data_obj == nullptr || !data_obj->Check<GFBuffer>()) { - throw std::runtime_error("data object doesn't pass checking"); + if (CheckGpgError(err) == GPG_ERR_USER_1 || data_obj == nullptr || + !data_obj->Check<GFBuffer>()) { + cb(-1, data_obj); + return; } auto gf_buffer = ExtractParams<GFBuffer>(data_obj, 0); diff --git a/src/core/function/gpg/GpgAdvancedOperator.h b/src/core/function/gpg/GpgAdvancedOperator.h index 4f6ba8bb..d6b57095 100644 --- a/src/core/function/gpg/GpgAdvancedOperator.h +++ b/src/core/function/gpg/GpgAdvancedOperator.h @@ -52,7 +52,7 @@ class GPGFRONTEND_CORE_EXPORT GpgAdvancedOperator { * @return true * @return false */ - static void ReloadGpgComponents(OperationCallback cb); + static void ReloadGpgComponents(OperationCallback); /** * @brief @@ -68,7 +68,7 @@ class GPGFRONTEND_CORE_EXPORT GpgAdvancedOperator { * @return true * @return false */ - static void ResetConfigures(OperationCallback cb); + static void ResetConfigures(OperationCallback); /** * @brief @@ -76,7 +76,7 @@ class GPGFRONTEND_CORE_EXPORT GpgAdvancedOperator { * @return true * @return false */ - static void StartGpgAgent(OperationCallback cb); + static void StartGpgAgent(OperationCallback); /** * @brief @@ -84,7 +84,7 @@ class GPGFRONTEND_CORE_EXPORT GpgAdvancedOperator { * @return true * @return false */ - static void StartDirmngr(OperationCallback cb); + static void StartDirmngr(OperationCallback); /** * @brief @@ -92,7 +92,7 @@ class GPGFRONTEND_CORE_EXPORT GpgAdvancedOperator { * @return true * @return false */ - static void StartKeyBoxd(OperationCallback cb); + static void StartKeyBoxd(OperationCallback); }; } // namespace GpgFrontend diff --git a/src/core/function/gpg/GpgCommandExecutor.cpp b/src/core/function/gpg/GpgCommandExecutor.cpp index 886c70db..8c994515 100644 --- a/src/core/function/gpg/GpgCommandExecutor.cpp +++ b/src/core/function/gpg/GpgCommandExecutor.cpp @@ -27,7 +27,6 @@ */ #include "GpgCommandExecutor.h" -#include "core/function/basic/GpgFunctionObject.h" #include "core/model/DataObject.h" #include "core/module/Module.h" #include "core/thread/Task.h" @@ -53,7 +52,8 @@ auto BuildTaskFromExecCtx(const GpgCommandExecutor::ExecuteContext &context) "data object args count of cmd executor result callback: {}", data_object->GetObjectSize()); if (!data_object->Check<int, QString, GpgCommandExecutorCallback>()) { - throw std::runtime_error("invalid data object size"); + GF_CORE_LOG_ERROR("data object checking failed"); + return; } auto exit_code = ExtractParams<int>(data_object, 0); @@ -76,7 +76,8 @@ auto BuildTaskFromExecCtx(const GpgCommandExecutor::ExecuteContext &context) if (!data_object->Check<QString, QStringList, GpgCommandExecutorInteractor, GpgCommandExecutorCallback>()) { - throw std::runtime_error("invalid data object size"); + GF_CORE_LOG_ERROR("data object checking failed"); + return -1; } // get arguments diff --git a/src/core/function/gpg/GpgContext.cpp b/src/core/function/gpg/GpgContext.cpp index 0849f240..104e254f 100644 --- a/src/core/function/gpg/GpgContext.cpp +++ b/src/core/function/gpg/GpgContext.cpp @@ -38,8 +38,9 @@ #include "core/function/basic/GpgFunctionObject.h" #include "core/model/GpgPassphraseContext.h" #include "core/module/ModuleManager.h" +#include "core/utils/CacheUtils.h" #include "core/utils/GpgUtils.h" -#include "utils/MemoryUtils.h" +#include "core/utils/MemoryUtils.h" #ifdef _WIN32 #include <windows.h> @@ -108,11 +109,13 @@ class GpgContext::Impl { static auto CustomPassphraseCb(void *hook, const char *uid_hint, const char *passphrase_info, int prev_was_bad, int fd) -> gpgme_error_t { + auto context_cache = GetCacheValue("PinentryContext"); + bool ask_for_new = context_cache == "NEW_PASSPHRASE"; auto context = QSharedPointer<GpgPassphraseContext>(new GpgPassphraseContext( uid_hint != nullptr ? uid_hint : "", passphrase_info != nullptr ? passphrase_info : "", - prev_was_bad != 0)); + prev_was_bad != 0, ask_for_new)); GF_CORE_LOG_DEBUG( "custom passphrase cb called, uid: {}, info: {}, last_was_bad: {}", @@ -129,6 +132,7 @@ class GpgContext::Impl { context); looper.exec(); + ResetCacheValue("PinentryContext"); auto passphrase = context->GetPassphrase().toStdString(); auto passpahrase_size = passphrase.size(); GF_CORE_LOG_DEBUG("get passphrase from pinentry size: {}", diff --git a/src/core/function/gpg/GpgFileOpera.cpp b/src/core/function/gpg/GpgFileOpera.cpp index a4663150..e3d47cf6 100644 --- a/src/core/function/gpg/GpgFileOpera.cpp +++ b/src/core/function/gpg/GpgFileOpera.cpp @@ -100,7 +100,8 @@ void GpgFileOpera::EncryptDirectory(std::vector<GpgKey> keys, ArchiveFileOperator::NewArchive2DataExchanger( in_path, ex, [=](GFError err, const DataObjectPtr&) { - GF_CORE_LOG_DEBUG("new archive 2 fd operation, err: {}", err); + GF_CORE_LOG_DEBUG("new archive 2 data exchanger operation, err: {}", + err); }); } @@ -128,7 +129,8 @@ void GpgFileOpera::DecryptArchive(const QString& in_path, ArchiveFileOperator::ExtractArchiveFromDataExchanger( ex, out_path, [](GFError err, const DataObjectPtr&) { - GF_CORE_LOG_DEBUG("extract archive from fd operation, err: {}", err); + GF_CORE_LOG_DEBUG( + "extract archive from data exchanger operation, err: {}", err); }); RunGpgOperaAsync( diff --git a/src/core/model/GpgPassphraseContext.cpp b/src/core/model/GpgPassphraseContext.cpp index 45aab442..5df3f5a8 100644 --- a/src/core/model/GpgPassphraseContext.cpp +++ b/src/core/model/GpgPassphraseContext.cpp @@ -32,10 +32,11 @@ namespace GpgFrontend { GpgPassphraseContext::GpgPassphraseContext(const QString& uids_info, const QString& passphrase_info, - bool prev_was_bad) + bool prev_was_bad, bool ask_for_new) : passphrase_info_(passphrase_info), uids_info_(uids_info), - prev_was_bad_(prev_was_bad) {} + prev_was_bad_(prev_was_bad), + ask_for_new_(ask_for_new) {} GpgPassphraseContext::GpgPassphraseContext() = default; @@ -54,4 +55,6 @@ auto GpgPassphraseContext::GetPassphraseInfo() const -> QString { } auto GpgPassphraseContext::IsPreWasBad() const -> bool { return prev_was_bad_; } + +auto GpgPassphraseContext::IsAskForNew() const -> bool { return ask_for_new_; } } // namespace GpgFrontend diff --git a/src/core/model/GpgPassphraseContext.h b/src/core/model/GpgPassphraseContext.h index 3e6ce4d0..2bc1ac75 100644 --- a/src/core/model/GpgPassphraseContext.h +++ b/src/core/model/GpgPassphraseContext.h @@ -36,7 +36,7 @@ class GPGFRONTEND_CORE_EXPORT GpgPassphraseContext : public QObject { Q_OBJECT public: GpgPassphraseContext(const QString& uids_info, const QString& passphrase_info, - bool prev_was_bad); + bool prev_was_bad, bool ask_for_new); GpgPassphraseContext(); @@ -50,11 +50,14 @@ class GPGFRONTEND_CORE_EXPORT GpgPassphraseContext : public QObject { [[nodiscard]] auto IsPreWasBad() const -> bool; + [[nodiscard]] auto IsAskForNew() const -> bool; + private: QString passphrase_info_; QString uids_info_; QString passphrase_; bool prev_was_bad_; + bool ask_for_new_; }; } // namespace GpgFrontend
\ No newline at end of file diff --git a/src/core/module/ModuleManager.cpp b/src/core/module/ModuleManager.cpp index fd65a0ab..83e7c1ff 100644 --- a/src/core/module/ModuleManager.cpp +++ b/src/core/module/ModuleManager.cpp @@ -35,7 +35,6 @@ #include "core/module/GlobalRegisterTable.h" #include "core/module/Module.h" #include "core/thread/Task.h" -#include "core/thread/TaskRunner.h" #include "function/SecureMemoryAllocator.h" #include "function/basic/GpgFunctionObject.h" #include "thread/TaskRunnerGetter.h" diff --git a/src/core/utils/AsyncUtils.cpp b/src/core/utils/AsyncUtils.cpp index 15979f2b..6100b83d 100644 --- a/src/core/utils/AsyncUtils.cpp +++ b/src/core/utils/AsyncUtils.cpp @@ -56,14 +56,18 @@ auto RunGpgOperaAsync(GpgOperaRunnable runnable, GpgOperationCallback callback, operation, [=](const DataObjectPtr& data_object) -> int { auto custom_data_object = TransferParams(); - GpgError err = runnable(custom_data_object); - + auto err = runnable(custom_data_object); data_object->Swap({err, custom_data_object}); return 0; }, - [=](int, const DataObjectPtr& data_object) { - callback(ExtractParams<GpgError>(data_object, 0), - ExtractParams<DataObjectPtr>(data_object, 1)); + [=](int rtn, const DataObjectPtr& data_object) { + if (rtn < 0) { + callback(GPG_ERR_USER_1, + ExtractParams<DataObjectPtr>(data_object, 1)); + } else { + callback(ExtractParams<GpgError>(data_object, 0), + ExtractParams<DataObjectPtr>(data_object, 1)); + } }, TransferParams()); handler.Start(); @@ -84,9 +88,13 @@ auto RunIOOperaAsync(OperaRunnable runnable, OperationCallback callback, data_object->Swap({err, custom_data_object}); return 0; }, - [=](int, const DataObjectPtr& data_object) { - callback(ExtractParams<GFError>(data_object, 0), - ExtractParams<DataObjectPtr>(data_object, 1)); + [=](int rtn, const DataObjectPtr& data_object) { + if (rtn < 0) { + callback(-1, ExtractParams<DataObjectPtr>(data_object, 1)); + } else { + callback(ExtractParams<GFError>(data_object, 0), + ExtractParams<DataObjectPtr>(data_object, 1)); + } }, TransferParams()); handler.Start(); diff --git a/src/core/utils/CacheUtils.cpp b/src/core/utils/CacheUtils.cpp index 5e8657fa..e521870c 100644 --- a/src/core/utils/CacheUtils.cpp +++ b/src/core/utils/CacheUtils.cpp @@ -32,21 +32,15 @@ namespace GpgFrontend { -void SetTempCacheValue(const QString& key, const QString& value) { - QJsonDocument json; - json.setObject(QJsonObject({{key, value}})); - CacheManager::GetInstance().SaveCache(key, json); +void SetCacheValue(const QString& key, QString value) { + CacheManager::GetInstance().SaveCache(key, std::move(value)); } -auto GetTempCacheValue(const QString& key) -> QString { - QJsonDocument json = CacheManager::GetInstance().LoadCache(key); - if (!json.isObject()) return {}; - auto json_object = json.object(); - if (!json_object.contains(key) && json_object[key].isString()) return {}; - return json_object[key].toString(); +auto GetCacheValue(const QString& key) -> QString { + return CacheManager::GetInstance().LoadCache(key); } -void ResetTempCacheValue(const QString& key) { +void ResetCacheValue(const QString& key) { CacheManager::GetInstance().ResetCache(key); } diff --git a/src/core/utils/CacheUtils.h b/src/core/utils/CacheUtils.h index 67a41335..48b9ac4b 100644 --- a/src/core/utils/CacheUtils.h +++ b/src/core/utils/CacheUtils.h @@ -34,8 +34,7 @@ namespace GpgFrontend { * @brief set a temp cache under a certain key * */ -void GPGFRONTEND_CORE_EXPORT SetTempCacheValue(const QString &, - const QString &); +void GPGFRONTEND_CORE_EXPORT SetCacheValue(const QString &key, QString value); /** * @brief after get the temp cache, its value will be imediately ease in @@ -43,13 +42,13 @@ void GPGFRONTEND_CORE_EXPORT SetTempCacheValue(const QString &, * * @return QString */ -auto GPGFRONTEND_CORE_EXPORT GetTempCacheValue(const QString &) -> QString; +auto GPGFRONTEND_CORE_EXPORT GetCacheValue(const QString &key) -> QString; /** * @brief imediately ease temp cache in storage * * @return QString */ -void GPGFRONTEND_CORE_EXPORT ResetTempCacheValue(const QString &); +void GPGFRONTEND_CORE_EXPORT ResetCacheValue(const QString &); } // namespace GpgFrontend diff --git a/src/init.cpp b/src/init.cpp index 5eebcb47..4f9cf821 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -28,11 +28,6 @@ #include "init.h" -#include <qcoreapplication.h> - -#include <filesystem> -#include <string> - #include "core/GpgCoreInit.h" #include "core/function/GlobalSettingStation.h" #include "core/thread/TaskRunnerGetter.h" @@ -95,7 +90,7 @@ void InitGlobalPathEnv() { (QDir(custom_gnupg_install_path).absolutePath() + ":" + path_value) .toUtf8(), 1); - std::string modified_path_value = getenv("PATH"); + QString modified_path_value = getenv("PATH"); GF_MAIN_LOG_DEBUG("Modified System PATH: {}", modified_path_value); } } diff --git a/src/ui/GpgFrontendUIInit.cpp b/src/ui/GpgFrontendUIInit.cpp index 64c316b9..c7f54286 100644 --- a/src/ui/GpgFrontendUIInit.cpp +++ b/src/ui/GpgFrontendUIInit.cpp @@ -106,18 +106,6 @@ void InitGpgFrontendUI(QApplication* /*app*/) { // init locale InitLocale(); -#if !defined(RELEASE) && defined(WINDOWS) - // css - std::filesystem::path css_path = - GpgFrontend::GlobalSettingStation::GetInstance().GetResourceDir() / - "css" / "default.qss"; - QFile file(css_path.u8string().c_str()); - file.open(QFile::ReadOnly); - QString styleSheet = QLatin1String(file.readAll()); - qApp->setStyleSheet(styleSheet); - file.close(); -#endif - // init signal station UISignalStation::GetInstance(); @@ -221,14 +209,10 @@ void InitLocale() { auto settings = GpgFrontend::GlobalSettingStation::GetInstance().GetSettings(); - GF_UI_LOG_INFO("current system locale: {}", QLocale().name()); - // read from settings file auto lang = settings.value("basic/lang").toString(); + GF_UI_LOG_INFO("current system locale: {}", QLocale().name()); GF_UI_LOG_INFO("current custom locale settings: {}", lang); - GF_UI_LOG_INFO( - "current locales path: {}", - GpgFrontend::GlobalSettingStation::GetInstance().GetLocaleDir()); auto target_locale = lang.isEmpty() ? QLocale() : QLocale(lang); auto* translator = new QTranslator(QCoreApplication::instance()); diff --git a/src/ui/UserInterfaceUtils.cpp b/src/ui/UserInterfaceUtils.cpp index 8c928f30..751b1f03 100644 --- a/src/ui/UserInterfaceUtils.cpp +++ b/src/ui/UserInterfaceUtils.cpp @@ -42,7 +42,6 @@ #include "core/thread/Task.h" #include "core/thread/TaskRunnerGetter.h" #include "core/typedef/GpgTypedef.h" -#include "core/utils/CacheUtils.h" #include "core/utils/GpgUtils.h" #include "core/utils/IOUtils.h" #include "ui/UISignalStation.h" @@ -477,22 +476,6 @@ void CommonUtils::slot_update_key_status() { refresh_task); } -void CommonUtils::slot_popup_passphrase_input_dialog() { - auto *dialog = new QInputDialog(QApplication::activeWindow(), Qt::Dialog); - dialog->setModal(true); - dialog->setWindowTitle(tr("Password Input Dialog")); - dialog->setInputMode(QInputDialog::TextInput); - dialog->setTextEchoMode(QLineEdit::Password); - dialog->setLabelText(tr("Please Input The Password")); - dialog->resize(500, 80); - dialog->exec(); - - SetTempCacheValue("__key_passphrase", dialog->textValue()); - - // send signal - // emit SignalUserInputPassphraseDone(); -} - void CommonUtils::SlotRestartApplication(int code) { GF_UI_LOG_DEBUG("application need restart, code: {}", code); @@ -507,7 +490,7 @@ bool CommonUtils::isApplicationNeedRestart() { return application_need_to_restart_at_once_; } -bool CommonUtils::KeyExistsinFavouriteList(const GpgKey &key) { +auto CommonUtils::KeyExistsinFavouriteList(const GpgKey &key) -> bool { // load cache auto json_data = CacheObject("favourite_key_pair"); if (!json_data.isArray()) json_data.setArray(QJsonArray()); diff --git a/src/ui/UserInterfaceUtils.h b/src/ui/UserInterfaceUtils.h index 365b5ff1..39a4633e 100644 --- a/src/ui/UserInterfaceUtils.h +++ b/src/ui/UserInterfaceUtils.h @@ -134,8 +134,8 @@ class CommonUtils : public QWidget { * @brief * */ - using ImportCallbackFunctiopn = std::function<void( - const QString&, const QString&, size_t, size_t)>; + using ImportCallbackFunctiopn = + std::function<void(const QString&, const QString&, size_t, size_t)>; /** * @brief Construct a new Common Utils object @@ -295,12 +295,6 @@ class CommonUtils : public QWidget { */ void slot_update_key_status(); - /** - * @brief - * - */ - void slot_popup_passphrase_input_dialog(); - private: static std::unique_ptr<CommonUtils> instance_; ///< bool application_need_to_restart_at_once_ = false; diff --git a/src/ui/dialog/gnupg/GnuPGControllerDialog.h b/src/ui/dialog/gnupg/GnuPGControllerDialog.h index 9da25728..201801dc 100644 --- a/src/ui/dialog/gnupg/GnuPGControllerDialog.h +++ b/src/ui/dialog/gnupg/GnuPGControllerDialog.h @@ -28,9 +28,6 @@ #pragma once -#include <string> - -#include "ui/GpgFrontendUI.h" #include "ui/dialog/GeneralDialog.h" class Ui_GnuPGControllerDialog; @@ -94,14 +91,34 @@ class GnuPGControllerDialog : public GeneralDialog { * @return true * @return false */ - int get_restart_needed() const; + [[nodiscard]] auto get_restart_needed() const -> int; + /** + * @brief Set the settings object + * + */ void set_settings(); + /** + * @brief + * + */ void apply_settings(); - bool check_custom_gnupg_path(QString); + /** + * @brief + * + * @return true + * @return false + */ + auto check_custom_gnupg_path(QString) -> bool; - bool check_custom_gnupg_key_database_path(QString); + /** + * @brief + * + * @return true + * @return false + */ + auto check_custom_gnupg_key_database_path(QString) -> bool; }; } // namespace GpgFrontend::UI diff --git a/src/ui/dialog/import_export/KeyServerImportDialog.h b/src/ui/dialog/import_export/KeyServerImportDialog.h index 564b0878..6a7ddfdd 100644 --- a/src/ui/dialog/import_export/KeyServerImportDialog.h +++ b/src/ui/dialog/import_export/KeyServerImportDialog.h @@ -29,13 +29,10 @@ #pragma once #include <QtNetwork> -#include <string> #include "KeyImportDetailDialog.h" -#include "core/function/gpg/GpgContext.h" -#include "ui/GpgFrontendUI.h" +#include "core/typedef/CoreTypedef.h" #include "ui/dialog/GeneralDialog.h" -#include "ui/widgets/KeyList.h" namespace GpgFrontend::UI { @@ -53,7 +50,7 @@ class KeyServerImportDialog : public GeneralDialog { * @param automatic * @param parent */ - KeyServerImportDialog(QWidget* parent); + explicit KeyServerImportDialog(QWidget* parent); public slots: diff --git a/src/ui/dialog/import_export/KeyUploadDialog.cpp b/src/ui/dialog/import_export/KeyUploadDialog.cpp index da0ea9f4..903b2e14 100644 --- a/src/ui/dialog/import_export/KeyUploadDialog.cpp +++ b/src/ui/dialog/import_export/KeyUploadDialog.cpp @@ -29,7 +29,6 @@ #include "KeyUploadDialog.h" #include <QtNetwork> -#include <algorithm> #include "core/GpgModel.h" #include "core/function/gpg/GpgKeyGetter.h" @@ -59,7 +58,8 @@ KeyUploadDialog::KeyUploadDialog(const KeyIdArgsListPtr& keys_ids, this->setModal(true); this->setWindowTitle(tr("Uploading Public Key")); this->setFixedSize(240, 42); - this->setPosCenterOfScreen(); + this->movePosition2CenterOfParent(); + this->setAttribute(Qt::WA_DeleteOnClose); } void KeyUploadDialog::SlotUpload() { @@ -71,8 +71,15 @@ void KeyUploadDialog::SlotUpload() { return; } - if (data_obj == nullptr || !data_obj->Check<GFBuffer>()) { - throw std::runtime_error("data object doesn't pass checking"); + if (CheckGpgError(err) == GPG_ERR_USER_1 || data_obj == nullptr || + !data_obj->Check<GFBuffer>()) { + GF_CORE_LOG_ERROR("data object checking failed"); + QMessageBox::critical(this, tr("Error"), + tr("Unknown error occurred")); + // Done + this->hide(); + this->close(); + return; } auto gf_buffer = ExtractParams<GFBuffer>(data_obj, 0); @@ -127,6 +134,7 @@ void KeyUploadDialog::slot_upload_key_to_server( void KeyUploadDialog::slot_upload_finished() { auto* reply = qobject_cast<QNetworkReply*>(sender()); + this->close(); QByteArray response = reply->readAll(); GF_UI_LOG_DEBUG("response: {}", response.toStdString()); @@ -147,14 +155,12 @@ void KeyUploadDialog::slot_upload_finished() { default: message = tr("Connection Error"); } - QMessageBox::critical(this, "Upload Failed", message); + QMessageBox::critical(this->parentWidget(), tr("Upload Failed"), message); return; } - QMessageBox::information(this, tr("Upload Success"), - tr("Upload Public Key Successfully")); - GF_UI_LOG_DEBUG("success while contacting keyserver!"); - reply->deleteLater(); + QMessageBox::information(this->parentWidget(), tr("Upload Success"), + tr("Upload Public Key Successfully")); } } // namespace GpgFrontend::UI diff --git a/src/ui/dialog/key_generate/KeygenDialog.cpp b/src/ui/dialog/key_generate/KeygenDialog.cpp index ad9c7a54..0f6c19d8 100644 --- a/src/ui/dialog/key_generate/KeygenDialog.cpp +++ b/src/ui/dialog/key_generate/KeygenDialog.cpp @@ -28,15 +28,12 @@ #include "KeygenDialog.h" -#include <qdialog.h> -#include <qeventloop.h> -#include <qobject.h> - #include "core/GpgModel.h" #include "core/function/GlobalSettingStation.h" #include "core/function/gpg/GpgKeyOpera.h" #include "core/model/DataObject.h" #include "core/typedef/GpgTypedef.h" +#include "core/utils/CacheUtils.h" #include "core/utils/GpgUtils.h" #include "ui/UISignalStation.h" #include "ui/UserInterfaceUtils.h" @@ -142,6 +139,14 @@ void KeyGenDialog::slot_key_gen_accept() { } } + if (!GlobalSettingStation::GetInstance() + .GetSettings() + .value("basic/use_pinentry_as_password_input_dialog", false) + .toBool() && + !no_pass_phrase_check_box_->isChecked()) { + SetCacheValue("PinentryContext", "NEW_PASSPHRASE"); + } + CommonUtils::WaitForOpera( this, tr("Generating"), [this, gen_key_info = this->gen_key_info_](const OperaWaitingHd& hd) { @@ -151,6 +156,12 @@ void KeyGenDialog::slot_key_gen_accept() { // stop showing waiting dialog hd(); + if (CheckGpgError(err) == GPG_ERR_USER_1) { + QMessageBox::critical(this, tr("Error"), + tr("Unknown error occurred")); + return; + } + CommonUtils::RaiseMessageBox(this->parentWidget() != nullptr ? this->parentWidget() : this, @@ -253,6 +264,8 @@ void KeyGenDialog::slot_activated_key_type(int index) { const auto [name, key_algo, subkey_algo] = gen_key_info_->GetSupportedKeyAlgo()[index]; + GF_UI_LOG_DEBUG("target key algo changed, name: {}, key: {}, subkey: {}", + name, key_algo, subkey_algo); assert(!key_algo.isEmpty()); gen_key_info_->SetAlgo(key_algo); @@ -261,7 +274,6 @@ void KeyGenDialog::slot_activated_key_type(int index) { if (gen_subkey_info_ == nullptr) { gen_subkey_info_ = SecureCreateSharedObject<GenKeyInfo>(true); } - gen_subkey_info_->SetAlgo(subkey_algo); } else { gen_subkey_info_ = nullptr; diff --git a/src/ui/dialog/key_generate/KeygenDialog.h b/src/ui/dialog/key_generate/KeygenDialog.h index 8e424094..ceab3d46 100644 --- a/src/ui/dialog/key_generate/KeygenDialog.h +++ b/src/ui/dialog/key_generate/KeygenDialog.h @@ -91,9 +91,8 @@ class KeyGenDialog : public GeneralDialog { ///< entries of line edits std::shared_ptr<GenKeyInfo> gen_key_info_ = - SecureCreateSharedObject<GenKeyInfo>(); ///< - std::shared_ptr<GenKeyInfo> gen_subkey_info_ = - SecureCreateSharedObject<GenKeyInfo>(); ///< + SecureCreateSharedObject<GenKeyInfo>(); ///< + std::shared_ptr<GenKeyInfo> gen_subkey_info_ = nullptr; ///< QDialogButtonBox* button_box_; ///< Box for standard buttons QLabel* error_label_{}; ///< Label containing error message diff --git a/src/ui/dialog/key_generate/SubkeyGenerateDialog.cpp b/src/ui/dialog/key_generate/SubkeyGenerateDialog.cpp index 0867354b..eecf2a1d 100644 --- a/src/ui/dialog/key_generate/SubkeyGenerateDialog.cpp +++ b/src/ui/dialog/key_generate/SubkeyGenerateDialog.cpp @@ -34,6 +34,7 @@ #include "core/function/GlobalSettingStation.h" #include "core/function/gpg/GpgKeyGetter.h" #include "core/function/gpg/GpgKeyOpera.h" +#include "core/utils/CacheUtils.h" #include "core/utils/GpgUtils.h" #include "ui/UISignalStation.h" #include "ui/UserInterfaceUtils.h" @@ -295,6 +296,12 @@ void SubkeyGenerateDialog::slot_key_gen_accept() { // stop showing waiting dialog hd(); + if (CheckGpgError(err) == GPG_ERR_USER_1) { + QMessageBox::critical(this, tr("Error"), + tr("Unknown error occurred")); + return; + } + CommonUtils::RaiseMessageBox(this, err); if (CheckGpgError(err) == GPG_ERR_NO_ERROR) { emit UISignalStation::GetInstance() diff --git a/src/ui/dialog/keypair_details/KeySetExpireDateDialog.cpp b/src/ui/dialog/keypair_details/KeySetExpireDateDialog.cpp index a2870965..22d1db2a 100644 --- a/src/ui/dialog/keypair_details/KeySetExpireDateDialog.cpp +++ b/src/ui/dialog/keypair_details/KeySetExpireDateDialog.cpp @@ -126,6 +126,13 @@ void KeySetExpireDateDialog::init() { UISignalStation::GetInstance(), &UISignalStation::SignalKeyDatabaseRefresh); + if (m_key_.GetExpireTime().toSecsSinceEpoch() == 0) { + ui_->noExpirationCheckBox->setCheckState(Qt::Checked); + } else { + ui_->dateEdit->setDateTime(m_key_.GetExpireTime()); + ui_->timeEdit->setDateTime(m_key_.GetExpireTime()); + } + ui_->titleLabel->setText(tr("Modified Expiration Date (Local Time)")); ui_->label->setText(tr( "Tips: For the sake of security, the key is valid for up to two years. " @@ -133,6 +140,8 @@ void KeySetExpireDateDialog::init() { "settings.")); ui_->noExpirationCheckBox->setText(tr("No Expiration")); this->setWindowTitle(tr("Modified Expiration Date")); + this->setAttribute(Qt::WA_DeleteOnClose); + this->setModal(true); } void KeySetExpireDateDialog::slot_non_expired_checked(int state) { diff --git a/src/ui/function/RaisePinentry.cpp b/src/ui/function/RaisePinentry.cpp index 762977b7..64e10c48 100644 --- a/src/ui/function/RaisePinentry.cpp +++ b/src/ui/function/RaisePinentry.cpp @@ -30,6 +30,7 @@ #include "core/function/CoreSignalStation.h" #include "core/model/GpgPassphraseContext.h" +#include "core/utils/CacheUtils.h" #include "pinentry/pinentrydialog.h" namespace GpgFrontend::UI { @@ -57,7 +58,8 @@ auto RaisePinentry::Exec() -> int { context_->GetUidsInfo().toStdString(), context_->GetPassphraseInfo().toStdString(), context_->IsPreWasBad()); - bool ask_for_new = context_->GetPassphraseInfo().isEmpty() && + bool ask_for_new = context_->IsAskForNew() && + context_->GetPassphraseInfo().isEmpty() && context_->GetUidsInfo().isEmpty(); auto* pinentry = @@ -80,8 +82,8 @@ auto RaisePinentry::Exec() -> int { pinentry->setPinentryInfo(pinentry_info); pinentry->setRepeatErrorText(tr("Passphrases do not match")); - pinentry->setGenpinLabel(QString("BBBBBBBBB")); - pinentry->setGenpinTT(QString("AAAAAAAA")); + pinentry->setGenpinLabel(QString("")); + pinentry->setGenpinTT(QString("")); pinentry->setCapsLockHint(tr("Caps Lock is on")); pinentry->setFormattedPassphrase({false, QString()}); pinentry->setConstraintsOptions({false, QString(), QString(), QString()}); diff --git a/src/ui/main_window/KeyMgmt.cpp b/src/ui/main_window/KeyMgmt.cpp index 25c32335..3f22265e 100644 --- a/src/ui/main_window/KeyMgmt.cpp +++ b/src/ui/main_window/KeyMgmt.cpp @@ -117,6 +117,7 @@ KeyMgmt::KeyMgmt(QWidget* parent) this->statusBar()->show(); setWindowTitle(tr("KeyPair Management")); + setMinimumSize(QSize(600, 400)); key_list_->AddMenuAction(generate_subkey_act_); key_list_->AddMenuAction(delete_selected_keys_act_); @@ -399,13 +400,22 @@ void KeyMgmt::SlotExportKeyToClipboard() { // stop waiting op_hd(); + if (CheckGpgError(err) == GPG_ERR_USER_1) { + QMessageBox::critical(this, tr("Error"), + tr("Unknown error occurred")); + return; + } + if (CheckGpgError(err) != GPG_ERR_NO_ERROR) { CommonUtils::RaiseMessageBox(this, err); return; } if (data_obj == nullptr || !data_obj->Check<GFBuffer>()) { - throw std::runtime_error("data object doesn't pass checking"); + GF_CORE_LOG_ERROR("data object checking failed"); + QMessageBox::critical(this, tr("Error"), + tr("Unknown error occurred")); + return; } auto gf_buffer = ExtractParams<GFBuffer>(data_obj, 0); @@ -469,13 +479,21 @@ void KeyMgmt::SlotExportAsOpenSSHFormat() { // stop waiting op_hd(); + if (CheckGpgError(err) == GPG_ERR_USER_1) { + QMessageBox::critical(this, tr("Error"), + tr("Unknown error occurred")); + return; + } + if (CheckGpgError(err) != GPG_ERR_NO_ERROR) { CommonUtils::RaiseMessageBox(this, err); return; } if (data_obj == nullptr || !data_obj->Check<GFBuffer>()) { - throw std::runtime_error("data object doesn't pass checking"); + QMessageBox::critical(this, tr("Error"), + tr("Unknown error occurred")); + return; } auto gf_buffer = ExtractParams<GFBuffer>(data_obj, 0); diff --git a/src/ui/main_window/MainWindow.cpp b/src/ui/main_window/MainWindow.cpp index 7f75574e..f0a2be29 100644 --- a/src/ui/main_window/MainWindow.cpp +++ b/src/ui/main_window/MainWindow.cpp @@ -193,7 +193,7 @@ void MainWindow::restore_settings() { void MainWindow::recover_editor_unsaved_pages_from_cache() { auto json_data = - CacheManager::GetInstance().LoadCache("editor_unsaved_pages"); + CacheManager::GetInstance().LoadDurableCache("editor_unsaved_pages"); if (json_data.isEmpty() || !json_data.isArray()) { return; @@ -252,8 +252,8 @@ void MainWindow::closeEvent(QCloseEvent *event) { if (event->isAccepted()) { // clear cache of unsaved page - CacheManager::GetInstance().SaveCache("editor_unsaved_pages", - QJsonDocument(QJsonArray()), true); + CacheManager::GetInstance().SaveDurableCache( + "editor_unsaved_pages", QJsonDocument(QJsonArray()), true); // clear password from memory // GpgContext::GetInstance().clearPasswordCache(); diff --git a/src/ui/main_window/MainWindowFileSlotFunction.cpp b/src/ui/main_window/MainWindowFileSlotFunction.cpp index ffc9909c..76fd4a9d 100644 --- a/src/ui/main_window/MainWindowFileSlotFunction.cpp +++ b/src/ui/main_window/MainWindowFileSlotFunction.cpp @@ -94,7 +94,8 @@ void MainWindow::SlotFileEncrypt(const QString& path) { // stop waiting op_hd(); - if (data_obj == nullptr || + if (CheckGpgError(err) == GPG_ERR_USER_1 || + data_obj == nullptr || !data_obj->Check<GpgEncryptResult>()) { QMessageBox::critical(this, tr("Error"), tr("Unknown error occurred")); @@ -137,7 +138,8 @@ void MainWindow::SlotFileEncrypt(const QString& path) { // stop waiting op_hd(); - if (data_obj == nullptr || !data_obj->Check<GpgEncryptResult>()) { + if (CheckGpgError(err) == GPG_ERR_USER_1 || data_obj == nullptr || + !data_obj->Check<GpgEncryptResult>()) { QMessageBox::critical(this, tr("Error"), tr("Unknown error occurred")); return; @@ -250,7 +252,8 @@ void MainWindow::SlotDirectoryEncrypt(const QString& path) { // stop waiting op_hd(); - if (data_obj == nullptr || !data_obj->Check<GpgEncryptResult>()) { + if (CheckGpgError(err) == GPG_ERR_USER_1 || data_obj == nullptr || + !data_obj->Check<GpgEncryptResult>()) { QMessageBox::critical(this, tr("Error"), tr("Unknown error occurred")); return; @@ -299,7 +302,8 @@ void MainWindow::SlotFileDecrypt(const QString& path) { // stop waiting op_hd(); - if (data_obj == nullptr || !data_obj->Check<GpgDecryptResult>()) { + if (CheckGpgError(err) == GPG_ERR_USER_1 || data_obj == nullptr || + !data_obj->Check<GpgDecryptResult>()) { QMessageBox::critical(this, tr("Error"), tr("Unknown error occurred")); return; @@ -347,7 +351,8 @@ void MainWindow::SlotArchiveDecrypt(const QString& path) { // stop waiting op_hd(); - if (data_obj == nullptr || !data_obj->Check<GpgDecryptResult>()) { + if (CheckGpgError(err) == GPG_ERR_USER_1 || data_obj == nullptr || + !data_obj->Check<GpgDecryptResult>()) { QMessageBox::critical(this, tr("Error"), tr("Unknown error occurred")); return; @@ -420,7 +425,8 @@ void MainWindow::SlotFileSign(const QString& path) { // stop waiting op_hd(); - if (data_obj == nullptr || !data_obj->Check<GpgSignResult>()) { + if (CheckGpgError(err) == GPG_ERR_USER_1 || data_obj == nullptr || + !data_obj->Check<GpgSignResult>()) { QMessageBox::critical(this, tr("Error"), tr("Unknown error occurred")); return; @@ -492,7 +498,8 @@ void MainWindow::SlotFileVerify(const QString& path) { // stop waiting op_hd(); - if (data_obj == nullptr || !data_obj->Check<GpgVerifyResult>()) { + if (CheckGpgError(err) == GPG_ERR_USER_1 || data_obj == nullptr || + !data_obj->Check<GpgVerifyResult>()) { QMessageBox::critical(this, tr("Error"), tr("Unknown error occurred")); return; @@ -593,7 +600,7 @@ void MainWindow::SlotFileEncryptSign(const QString& path) { // stop waiting op_hd(); - if (data_obj == nullptr || + if (CheckGpgError(err) == GPG_ERR_USER_1 || data_obj == nullptr || !data_obj->Check<GpgEncryptResult, GpgSignResult>()) { QMessageBox::critical(this, tr("Error"), tr("Unknown error occurred")); @@ -697,7 +704,7 @@ void MainWindow::SlotDirectoryEncryptSign(const QString& path) { // stop waiting op_hd(); - if (data_obj == nullptr || + if (CheckGpgError(err) == GPG_ERR_USER_1 || data_obj == nullptr || !data_obj->Check<GpgEncryptResult, GpgSignResult>()) { QMessageBox::critical(this, tr("Error"), tr("Unknown error occurred")); @@ -756,7 +763,7 @@ void MainWindow::SlotFileDecryptVerify(const QString& path) { // stop waiting op_hd(); - if (data_obj == nullptr || + if (CheckGpgError(err) == GPG_ERR_USER_1 || data_obj == nullptr || !data_obj->Check<GpgDecryptResult, GpgVerifyResult>()) { QMessageBox::critical(this, tr("Error"), tr("Unknown error occurred")); @@ -824,7 +831,7 @@ void MainWindow::SlotArchiveDecryptVerify(const QString& path) { // stop waiting op_hd(); - if (data_obj == nullptr || + if (CheckGpgError(err) == GPG_ERR_USER_1 || data_obj == nullptr || !data_obj->Check<GpgDecryptResult, GpgVerifyResult>()) { QMessageBox::critical(this, tr("Error"), tr("Unknown error occurred")); diff --git a/src/ui/main_window/MainWindowGpgOperaFunction.cpp b/src/ui/main_window/MainWindowGpgOperaFunction.cpp index e6e6e016..ea9540bb 100644 --- a/src/ui/main_window/MainWindowGpgOperaFunction.cpp +++ b/src/ui/main_window/MainWindowGpgOperaFunction.cpp @@ -66,7 +66,8 @@ void MainWindow::SlotEncrypt() { // stop waiting op_hd(); - if (data_obj == nullptr || + if (CheckGpgError(err) == GPG_ERR_USER_1 || + data_obj == nullptr || !data_obj->Check<GpgEncryptResult, GFBuffer>()) { QMessageBox::critical(this, tr("Error"), tr("Unknown error occurred")); @@ -169,7 +170,7 @@ void MainWindow::SlotSign() { // stop waiting hd(); - if (data_obj == nullptr || + if (CheckGpgError(err) == GPG_ERR_USER_1 || data_obj == nullptr || !data_obj->Check<GpgSignResult, GFBuffer>()) { QMessageBox::critical(this, tr("Error"), tr("Unknown error occurred")); @@ -202,7 +203,7 @@ void MainWindow::SlotDecrypt() { // stop waiting hd(); - if (data_obj == nullptr || + if (CheckGpgError(err) == GPG_ERR_USER_1 || data_obj == nullptr || !data_obj->Check<GpgDecryptResult, GFBuffer>()) { QMessageBox::critical(this, tr("Error"), tr("Unknown error occurred")); @@ -238,7 +239,8 @@ void MainWindow::SlotVerify() { // stop waiting hd(); - if (data_obj == nullptr || !data_obj->Check<GpgVerifyResult>()) { + if (CheckGpgError(err) == GPG_ERR_USER_1 || data_obj == nullptr || + !data_obj->Check<GpgVerifyResult>()) { QMessageBox::critical(this, tr("Error"), tr("Unknown error occurred")); return; @@ -312,7 +314,7 @@ void MainWindow::SlotEncryptSign() { // stop waiting hd(); - if (data_obj == nullptr || + if (CheckGpgError(err) == GPG_ERR_USER_1 || data_obj == nullptr || !data_obj ->Check<GpgEncryptResult, GpgSignResult, GFBuffer>()) { QMessageBox::critical(this, tr("Error"), @@ -358,7 +360,7 @@ void MainWindow::SlotDecryptVerify() { // stop waiting hd(); - if (data_obj == nullptr || + if (CheckGpgError(err) == GPG_ERR_USER_1 || data_obj == nullptr || !data_obj ->Check<GpgDecryptResult, GpgVerifyResult, GFBuffer>()) { QMessageBox::critical(this, tr("Error"), diff --git a/src/ui/struct/CacheObject.cpp b/src/ui/struct/CacheObject.cpp index 16c793fc..bd3b9818 100644 --- a/src/ui/struct/CacheObject.cpp +++ b/src/ui/struct/CacheObject.cpp @@ -34,13 +34,12 @@ namespace GpgFrontend::UI { CacheObject::CacheObject(QString cache_name) : cache_name_(std::move(cache_name)) { - GF_UI_LOG_DEBUG("loading cache from: {}", this->cache_name_); this->QJsonDocument::operator=( - CacheManager::GetInstance().LoadCache(cache_name_)); + CacheManager::GetInstance().LoadDurableCache(cache_name_)); } CacheObject::~CacheObject() { - CacheManager::GetInstance().SaveCache(cache_name_, *this); + CacheManager::GetInstance().SaveDurableCache(cache_name_, *this); } } // namespace GpgFrontend::UI
\ No newline at end of file diff --git a/src/ui/widgets/FilePage.cpp b/src/ui/widgets/FilePage.cpp index b32cb175..27f4205f 100644 --- a/src/ui/widgets/FilePage.cpp +++ b/src/ui/widgets/FilePage.cpp @@ -28,11 +28,7 @@ #include "ui/widgets/FilePage.h" -#include <string> - #include "core/GpgModel.h" -#include "core/function/ArchiveFileOperator.h" -#include "core/function/gpg/GpgFileOpera.h" #include "ui/UISignalStation.h" #include "ui/main_window/MainWindow.h" #include "ui_FilePage.h" diff --git a/src/ui/widgets/KeyList.h b/src/ui/widgets/KeyList.h index 4ab9def9..f709aa9e 100644 --- a/src/ui/widgets/KeyList.h +++ b/src/ui/widgets/KeyList.h @@ -28,8 +28,6 @@ #pragma once -#include <string> - #include "core/GpgModel.h" class Ui_KeyList; diff --git a/src/ui/widgets/PlainTextEditorPage.h b/src/ui/widgets/PlainTextEditorPage.h index 702dec1d..4981b24c 100644 --- a/src/ui/widgets/PlainTextEditorPage.h +++ b/src/ui/widgets/PlainTextEditorPage.h @@ -28,11 +28,6 @@ #pragma once -#include <string> - -#include "core/GpgConstants.h" -#include "ui/GpgFrontendUI.h" - class Ui_PlainTextEditor; namespace GpgFrontend::UI { |