diff options
author | saturneric <[email protected]> | 2024-01-12 15:08:38 +0000 |
---|---|---|
committer | saturneric <[email protected]> | 2024-01-12 15:08:38 +0000 |
commit | 6983b5c1dd82d159236ebd06cf17f071cc9c1ee9 (patch) | |
tree | fc53f790e33546320b2ecd306a1a9ade6fbdfe7a /src | |
parent | fix: slove a heap-use-after-free issue (diff) | |
download | GpgFrontend-6983b5c1dd82d159236ebd06cf17f071cc9c1ee9.tar.gz GpgFrontend-6983b5c1dd82d159236ebd06cf17f071cc9c1ee9.zip |
refactor: remove boost and use QString instead of std::filesystem::path
Diffstat (limited to 'src')
74 files changed, 470 insertions, 768 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index b4d6f68d..60829c4f 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -23,16 +23,6 @@ # # SPDX-License-Identifier: GPL-3.0-or-later - -# Introduce boost -if(NOT BOOST_ROOT) - find_package(Boost COMPONENTS date_time system program_options filesystem REQUIRED) -else() - find_package(Boost - COMPONENTS date_time system program_options filesystem REQUIRED - PATHS ${BOOST_ROOT} NO_DEFAULT_PATH) -endif() - if(APPLE) add_compile_definitions("_GNU_SOURCE") endif() diff --git a/src/GpgFrontendContext.cpp b/src/GpgFrontendContext.cpp index 461bbeaa..9d264dcd 100644 --- a/src/GpgFrontendContext.cpp +++ b/src/GpgFrontendContext.cpp @@ -34,24 +34,14 @@ #include <qthread.h> #include "core/utils/MemoryUtils.h" -#include "ui/GpgFrontendApplication.h" namespace GpgFrontend { -void GpgFrontendContext::InitApplication(bool gui_mode) { - if (!gui_mode) { - app_ = SecureCreateObject<QCoreApplication>(argc, argv); - } else { - app_ = SecureCreateObject<QApplication>(argc, argv); - } - this->load_ui_env = gui_mode; +void GpgFrontendContext::InitApplication() { + app_ = SecureCreateObject<QApplication>(argc, argv); } -auto GpgFrontendContext::GetApp() -> QCoreApplication* { return app_; } - -auto GpgFrontendContext::GetGuiApp() -> QApplication* { - return qobject_cast<QApplication*>(app_); -} +auto GpgFrontendContext::GetApp() -> QApplication* { return app_; } GpgFrontendContext::GpgFrontendContext(int argc, char** argv) : argc(argc), argv(argv) {} diff --git a/src/GpgFrontendContext.h b/src/GpgFrontendContext.h index 9bf591d4..e0d176f1 100644 --- a/src/GpgFrontendContext.h +++ b/src/GpgFrontendContext.h @@ -44,32 +44,35 @@ struct GpgFrontendContext { bool gather_external_gnupg_info; bool load_default_gpg_context; + /** + * @brief Construct a new Gpg Frontend Context object + * + * @param argc + * @param argv + */ GpgFrontendContext(int argc, char** argv); + /** + * @brief Destroy the Gpg Frontend Context object + * + */ ~GpgFrontendContext(); /** * @brief * */ - void InitApplication(bool); + void InitApplication(); /** * @brief Get the App object * * @return QCoreApplication* */ - auto GetApp() -> QCoreApplication*; - - /** - * @brief Get the Gui App object - * - * @return QApplication* - */ - auto GetGuiApp() -> QApplication*; + auto GetApp() -> QApplication*; private: - QCoreApplication* app_ = nullptr; + QApplication* app_ = nullptr; }; } // namespace GpgFrontend
\ No newline at end of file diff --git a/src/app.cpp b/src/app.cpp index 69262737..d079adb3 100644 --- a/src/app.cpp +++ b/src/app.cpp @@ -64,12 +64,7 @@ auto StartApplication(const GFCxtWPtr& p_ctx) -> int { return -1; } - if (!ctx->load_ui_env) { - GF_MAIN_LOG_ERROR("the loading of gui application is forbidden."); - return -1; - } - - auto* app = ctx->GetGuiApp(); + auto* app = ctx->GetApp(); if (app == nullptr) { GF_MAIN_LOG_ERROR("cannot get qapplication from gpgfrontend context."); return -1; diff --git a/src/cmd.cpp b/src/cmd.cpp index 29a8114d..a8a5b9d9 100644 --- a/src/cmd.cpp +++ b/src/cmd.cpp @@ -33,16 +33,11 @@ // std #include <iostream> -// boost -#include <boost/program_options.hpp> - // GpgFrontend #include "GpgFrontendBuildInfo.h" #include "GpgFrontendContext.h" #include "test/GpgFrontendTest.h" -namespace po = boost::program_options; - namespace GpgFrontend { auto PrintVersion() -> int { @@ -62,9 +57,7 @@ auto PrintVersion() -> int { return 0; } -auto ParseLogLevel(const po::variables_map& vm) -> spdlog::level::level_enum { - std::string log_level = vm["log-level"].as<std::string>(); - +auto ParseLogLevel(const QString& log_level) -> spdlog::level::level_enum { if (log_level == "trace") { return spdlog::level::trace; } @@ -28,9 +28,6 @@ #pragma once -// boost -#include <boost/program_options.hpp> - #include "GpgFrontendContext.h" namespace GpgFrontend { @@ -39,8 +36,7 @@ namespace GpgFrontend { auto PrintVersion() -> int; -auto ParseLogLevel(const boost::program_options::variables_map&) - -> spdlog::level::level_enum; +auto ParseLogLevel(const QString& level) -> spdlog::level::level_enum; auto RunTest(const GFCxtWPtr&) -> int; diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt index c4eb8049..28216653 100644 --- a/src/core/CMakeLists.txt +++ b/src/core/CMakeLists.txt @@ -77,8 +77,6 @@ endif () target_link_libraries(gpgfrontend_core PUBLIC gpgme assuan gpg-error) # link openssl target_link_libraries(gpgfrontend_core PUBLIC OpenSSL::SSL OpenSSL::Crypto) -# link boost libraries -target_link_libraries(gpgfrontend_core PUBLIC ${Boost_LIBRARIES}) if (MINGW) # for uuid ability in mingw target_link_libraries(gpgfrontend_core PUBLIC bcrypt) diff --git a/src/core/GpgCoreInit.cpp b/src/core/GpgCoreInit.cpp index 3ad5bce6..40e6d9f1 100644 --- a/src/core/GpgCoreInit.cpp +++ b/src/core/GpgCoreInit.cpp @@ -29,8 +29,6 @@ #include <gpgme.h> -#include <boost/date_time.hpp> - #include "core/function/CoreSignalStation.h" #include "core/function/GlobalSettingStation.h" #include "core/function/basic/ChannelObject.h" diff --git a/src/core/function/ArchiveFileOperator.cpp b/src/core/function/ArchiveFileOperator.cpp index af311f3f..60b8b004 100644 --- a/src/core/function/ArchiveFileOperator.cpp +++ b/src/core/function/ArchiveFileOperator.cpp @@ -87,13 +87,13 @@ auto ArchiveCloseWriteCallback(struct archive *, void *client_data) -> int { } void ArchiveFileOperator::NewArchive2DataExchanger( - const std::filesystem::path &target_directory, - std::shared_ptr<GFDataExchanger> exchanger, const OperationCallback &cb) { + const QString &target_directory, std::shared_ptr<GFDataExchanger> exchanger, + const OperationCallback &cb) { RunIOOperaAsync( [=](const DataObjectPtr &data_object) -> GFError { std::array<char, 1024> buff{}; auto ret = 0; - const auto base_path = target_directory.parent_path(); + const auto base_path = QDir(QDir(target_directory).absolutePath()); auto *archive = archive_write_new(); archive_write_add_filter_none(archive); @@ -104,7 +104,13 @@ void ArchiveFileOperator::NewArchive2DataExchanger( auto *disk = archive_read_disk_new(); archive_read_disk_set_standard_lookup(disk); - auto r = archive_read_disk_open(disk, target_directory.c_str()); + +#ifdef WINDOWS + auto r = archive_read_disk_open_w( + disk, target_directory.toStdWString().c_str()); +#else + auto r = archive_read_disk_open(disk, target_directory.toUtf8()); +#endif if (r != ARCHIVE_OK) { GF_CORE_LOG_ERROR("archive_read_disk_open() failed: {}, abort...", @@ -130,10 +136,9 @@ void ArchiveFileOperator::NewArchive2DataExchanger( // turn absolute path to relative path archive_entry_set_pathname( - entry, std::filesystem::relative( - std::filesystem::path(archive_entry_pathname(entry)), - base_path) - .c_str()); + entry, + base_path.relativeFilePath(QString(archive_entry_pathname(entry))) + .toUtf8()); r = archive_write_header(archive, entry); if (r < ARCHIVE_OK) { @@ -172,8 +177,8 @@ void ArchiveFileOperator::NewArchive2DataExchanger( } void ArchiveFileOperator::ExtractArchiveFromDataExchanger( - std::shared_ptr<GFDataExchanger> ex, - const std::filesystem::path &target_path, const OperationCallback &cb) { + std::shared_ptr<GFDataExchanger> ex, const QString &target_path, + const OperationCallback &cb) { RunIOOperaAsync( [=](const DataObjectPtr &data_object) -> GFError { auto *archive = archive_read_new(); @@ -225,9 +230,8 @@ void ArchiveFileOperator::ExtractArchiveFromDataExchanger( } archive_entry_set_pathname( - entry, (target_path / - std::filesystem::path(archive_entry_pathname(entry))) - .c_str()); + entry, + (target_path + "/" + archive_entry_pathname(entry)).toUtf8()); r = archive_write_header(ext, entry); if (r != ARCHIVE_OK) { @@ -254,8 +258,7 @@ void ArchiveFileOperator::ExtractArchiveFromDataExchanger( cb, "archive_read_new"); } -void ArchiveFileOperator::ListArchive( - const std::filesystem::path &archive_path) { +void ArchiveFileOperator::ListArchive(const QString &archive_path) { struct archive *a; struct archive_entry *entry; int r; @@ -263,7 +266,7 @@ void ArchiveFileOperator::ListArchive( a = archive_read_new(); archive_read_support_filter_all(a); archive_read_support_format_all(a); - r = archive_read_open_filename(a, archive_path.u8string().c_str(), + r = archive_read_open_filename(a, archive_path.toUtf8(), 10240); // Note 1 if (r != ARCHIVE_OK) return; while (archive_read_next_header(a, &entry) == ARCHIVE_OK) { diff --git a/src/core/function/ArchiveFileOperator.h b/src/core/function/ArchiveFileOperator.h index ce3022bd..bfeec0c4 100644 --- a/src/core/function/ArchiveFileOperator.h +++ b/src/core/function/ArchiveFileOperator.h @@ -42,7 +42,7 @@ class GPGFRONTEND_CORE_EXPORT ArchiveFileOperator { * * @param archive_path */ - static void ListArchive(const std::filesystem::path &archive_path); + static void ListArchive(const QString &archive_path); /** * @brief Create a Archive object @@ -52,9 +52,9 @@ class GPGFRONTEND_CORE_EXPORT ArchiveFileOperator { * @param compress * @param files */ - static void NewArchive2DataExchanger( - const std::filesystem::path &target_directory, - std::shared_ptr<GFDataExchanger>, const OperationCallback &cb); + static void NewArchive2DataExchanger(const QString &target_directory, + std::shared_ptr<GFDataExchanger>, + const OperationCallback &cb); /** * @brief @@ -63,7 +63,7 @@ class GPGFRONTEND_CORE_EXPORT ArchiveFileOperator { * @param base_path */ static void ExtractArchiveFromDataExchanger( - std::shared_ptr<GFDataExchanger> fd, - const std::filesystem::path &target_path, const OperationCallback &cb); + std::shared_ptr<GFDataExchanger> fd, const QString &target_path, + const OperationCallback &cb); }; } // namespace GpgFrontend diff --git a/src/core/function/DataObjectOperator.cpp b/src/core/function/DataObjectOperator.cpp index f756e3e7..3033f23b 100644 --- a/src/core/function/DataObjectOperator.cpp +++ b/src/core/function/DataObjectOperator.cpp @@ -37,31 +37,30 @@ namespace GpgFrontend { void DataObjectOperator::init_app_secure_key() { GF_CORE_LOG_TRACE("initializing application secure key"); - WriteFile(app_secure_key_path_.c_str(), + WriteFile(app_secure_key_path_, PassphraseGenerator::GetInstance().Generate(256).toUtf8()); - std::filesystem::permissions( - app_secure_key_path_, - std::filesystem::perms::owner_read | std::filesystem::perms::owner_write); + QFile::setPermissions(app_secure_key_path_, + QFileDevice::ReadOwner | QFileDevice::WriteOwner); } DataObjectOperator::DataObjectOperator(int channel) : SingletonFunctionObject<DataObjectOperator>(channel) { - if (!is_directory(app_secure_path_)) create_directory(app_secure_path_); + if (!QDir(app_secure_path_).exists()) QDir(app_secure_path_).mkdir("."); - if (!exists(app_secure_key_path_)) { + if (!QDir(app_secure_key_path_).exists()) { init_app_secure_key(); } QByteArray key; - if (!ReadFile(app_secure_key_path_.c_str(), key)) { + if (!ReadFile(app_secure_key_path_, key)) { GF_CORE_LOG_ERROR("failed to read app secure key file: {}", - app_secure_key_path_.u8string()); + app_secure_key_path_); throw std::runtime_error("failed to read app secure key file"); } hash_key_ = QCryptographicHash::hash(key, QCryptographicHash::Sha256); GF_CORE_LOG_TRACE("app secure key loaded {} bytes", hash_key_.size()); - if (!exists(app_data_objs_path_)) create_directory(app_data_objs_path_); + if (!QDir(app_data_objs_path_).exists()) QDir(app_data_objs_path_).mkpath("."); } auto DataObjectOperator::SaveDataObj(const QString& _key, @@ -82,16 +81,16 @@ auto DataObjectOperator::SaveDataObj(const QString& _key, .toHex(); } - const auto obj_path = app_data_objs_path_ / hash_obj_key.toStdString(); + const auto obj_path = app_data_objs_path_ + "/" + hash_obj_key; QAESEncryption encryption(QAESEncryption::AES_256, QAESEncryption::ECB, QAESEncryption::Padding::ISO); auto encoded = encryption.encode(QByteArray::fromStdString(to_string(value)), hash_key_); GF_CORE_LOG_TRACE("saving data object {} to {} , size: {} bytes", - hash_obj_key, obj_path.u8string(), encoded.size()); + hash_obj_key, obj_path, encoded.size()); - WriteFile(obj_path.c_str(), encoded); + WriteFile(obj_path, encoded); return _key.isEmpty() ? hash_obj_key : QString(); } @@ -103,18 +102,17 @@ auto DataObjectOperator::GetDataObject(const QString& _key) auto hash_obj_key = QCryptographicHash::hash(hash_key_.append(_key.toUtf8()), QCryptographicHash::Sha256) - .toHex() - .toStdString(); + .toHex(); - const auto obj_path = app_data_objs_path_ / hash_obj_key; + const auto obj_path = app_data_objs_path_ + "/" + hash_obj_key; - if (!std::filesystem::exists(obj_path)) { + if (!QFileInfo(obj_path).exists()) { GF_CORE_LOG_WARN("data object not found, key: {}", _key); return {}; } QByteArray encoded_data; - if (!ReadFile(obj_path.c_str(), encoded_data)) { + if (!ReadFile(obj_path, encoded_data)) { GF_CORE_LOG_ERROR("failed to read data object, key: {}", _key); return {}; } @@ -143,12 +141,12 @@ auto DataObjectOperator::GetDataObjectByRef(const QString& _ref) try { const auto& hash_obj_key = _ref; - const auto obj_path = app_data_objs_path_ / hash_obj_key.toStdString(); + const auto obj_path = app_data_objs_path_ + "/" + hash_obj_key; - if (!std::filesystem::exists(obj_path)) return {}; + if (!QFileInfo(obj_path).exists()) return {}; QByteArray encoded_data; - if (!ReadFile(obj_path.c_str(), encoded_data)) return {}; + if (!ReadFile(obj_path, encoded_data)) return {}; QAESEncryption encryption(QAESEncryption::AES_256, QAESEncryption::ECB, QAESEncryption::Padding::ISO); diff --git a/src/core/function/DataObjectOperator.h b/src/core/function/DataObjectOperator.h index a262bfc2..3d0606d6 100644 --- a/src/core/function/DataObjectOperator.h +++ b/src/core/function/DataObjectOperator.h @@ -62,15 +62,16 @@ class GPGFRONTEND_CORE_EXPORT DataObjectOperator GlobalSettingStation &global_setting_station_ = GlobalSettingStation::GetInstance(); ///< GlobalSettingStation - std::filesystem::path app_secure_path_ = - global_setting_station_.GetAppConfigPath() / - "secure"; ///< Where sensitive information is stored - std::filesystem::path app_secure_key_path_ = - app_secure_path_ / "app.key"; ///< Where the key of data object is stored - std::filesystem::path app_data_objs_path_ = - global_setting_station_.GetAppDataPath() / "data_objs"; ///< Where data - ///< object is - ///< stored + QString app_secure_path_ = + global_setting_station_.GetAppConfigPath() + + "/secure"; ///< Where sensitive information is stored + QString app_secure_key_path_ = + app_secure_path_ + + "/app.key"; ///< Where the key of data object is stored + QString app_data_objs_path_ = + global_setting_station_.GetAppDataPath() + "/data_objs"; ///< Where data + ///< object is + ///< stored QByteArray hash_key_; ///< Hash key }; diff --git a/src/core/function/GlobalSettingStation.cpp b/src/core/function/GlobalSettingStation.cpp index 53220a18..f6403765 100644 --- a/src/core/function/GlobalSettingStation.cpp +++ b/src/core/function/GlobalSettingStation.cpp @@ -28,7 +28,6 @@ #include "GlobalSettingStation.h" -#include <boost/dll.hpp> #include <filesystem> #include "core/module/ModuleManager.h" @@ -43,58 +42,58 @@ class GlobalSettingStation::Impl { * */ explicit Impl() noexcept { - GF_CORE_LOG_INFO("app path: {}", app_path_.u8string()); - auto portable_file_path = app_path_ / "PORTABLE.txt"; - if (std::filesystem::exists(portable_file_path)) { + GF_CORE_LOG_INFO("app path: {}", working_path_); + auto portable_file_path = working_path_ + "/PORTABLE.txt"; + if (QFileInfo(portable_file_path).exists()) { GF_CORE_LOG_INFO( "dectected portable mode, reconfiguring config and data path..."); Module::UpsertRTValue("core", "env.state.portable", 1); - app_configure_path_ = app_path_.parent_path(); - config_dir_path_ = app_configure_path_ / "conf"; - main_config_path_ = config_dir_path_ / "main.cfg"; - module_config_path_ = config_dir_path_ / "module.cfg"; + app_configure_path_ = working_path_; + config_dir_path_ = app_configure_path_ + "/conf"; + main_config_path_ = config_dir_path_ + "/main.cfg"; + module_config_path_ = config_dir_path_ + "/module.cfg"; - app_data_path_ = app_path_.parent_path(); - app_log_path_ = app_data_path_ / "logs"; - app_data_objs_path_ = app_data_path_ / "data_objs"; + app_data_path_ = working_path_; + app_log_path_ = app_data_path_ + "/logs"; + app_data_objs_path_ = app_data_path_ + "/data_objs"; } - GF_CORE_LOG_INFO("app configure path: {}", app_configure_path_.u8string()); - GF_CORE_LOG_INFO("app data path: {}", app_data_path_.u8string()); - GF_CORE_LOG_INFO("app log path: {}", app_log_path_.u8string()); - GF_CORE_LOG_INFO("app locale path: {}", app_locale_path_.u8string()); - GF_CORE_LOG_INFO("app conf path: {}", main_config_path_.u8string()); + GF_CORE_LOG_INFO("app configure path: {}", app_configure_path_); + 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 conf path: {}", main_config_path_); GF_CORE_LOG_INFO("app log files total size: {}", GetLogFilesSize()); GF_CORE_LOG_INFO("app data objects files total size: {}", GetDataObjectsFilesSize()); - if (!is_directory(app_configure_path_)) { - create_directory(app_configure_path_); + if (!QDir(app_configure_path_).exists()) { + QDir(app_configure_path_).mkpath("."); } - if (!is_directory(app_data_path_)) create_directory(app_data_path_); - if (!is_directory(app_log_path_)) create_directory(app_log_path_); - if (!is_directory(config_dir_path_)) create_directory(config_dir_path_); + if (!QDir(app_data_path_).exists()) QDir(app_data_path_).mkpath("."); + if (!QDir(app_log_path_).exists()) QDir(app_log_path_).mkpath("."); + if (!QDir(config_dir_path_).exists()) QDir(config_dir_path_).mkpath("."); - if (!exists(main_config_path_)) { + if (!QDir(main_config_path_).exists()) { try { - this->ui_cfg_.writeFile(main_config_path_.u8string().c_str()); + this->ui_cfg_.writeFile(main_config_path_.toUtf8()); GF_CORE_LOG_DEBUG( "user interface configuration successfully written to {}", - main_config_path_.u8string()); + main_config_path_); } catch (const libconfig::FileIOException &fioex) { GF_CORE_LOG_DEBUG( "i/o error while writing UserInterface configuration file {}", - main_config_path_.u8string()); + main_config_path_); } } else { try { - this->ui_cfg_.readFile(main_config_path_.u8string().c_str()); + this->ui_cfg_.readFile(main_config_path_.toUtf8()); GF_CORE_LOG_DEBUG( "user interface configuration successfully read from {}", - main_config_path_.u8string()); + main_config_path_); } catch (const libconfig::FileIOException &fioex) { GF_CORE_LOG_ERROR( "i/o error while reading UserInterface configure file"); @@ -145,67 +144,55 @@ class GlobalSettingStation::Impl { /** * @brief Get the App Dir object * - * @return std::filesystem::path + * @return QString */ - [[nodiscard]] auto GetAppDir() const -> std::filesystem::path { - return app_path_; - } + [[nodiscard]] auto GetAppDir() const -> QString { return working_path_; } - [[nodiscard]] auto GetAppDataPath() const -> std::filesystem::path { + [[nodiscard]] auto GetAppDataPath() const -> QString { return app_data_path_; } /** * @brief Get the Log Dir object * - * @return std::filesystem::path + * @return QString */ - [[nodiscard]] auto GetLogDir() const -> std::filesystem::path { - return app_log_path_; - } + [[nodiscard]] auto GetLogDir() const -> QString { return app_log_path_; } /** - * @brief Get the Standalone Database Dir object + * @brief Get the App Config Path object * - * @return std::filesystem::path + * @return QString */ - [[nodiscard]] auto GetStandaloneDatabaseDir() const -> std::filesystem::path { - auto db_path = app_configure_path_ / "db"; - if (!std::filesystem::exists(db_path)) { - std::filesystem::create_directory(db_path); - } - return db_path; - } - - [[nodiscard]] auto GetAppConfigPath() const -> std::filesystem::path { + [[nodiscard]] auto GetAppConfigPath() const -> QString { return app_configure_path_; } /** * @brief Get the Locale Dir object * - * @return std::filesystem::path + * @return QString */ - [[nodiscard]] auto GetLocaleDir() const -> std::filesystem::path { + [[nodiscard]] auto GetLocaleDir() const -> QString { return app_locale_path_; } /** * @brief Get the Resource Dir object * - * @return std::filesystem::path + * @return QString */ - [[nodiscard]] auto GetResourceDir() const -> std::filesystem::path { + [[nodiscard]] auto GetResourceDir() const -> QString { return app_resource_path_; } /** * @brief Get the Certs Dir object * - * @return std::filesystem::path + * @return QString */ - [[nodiscard]] auto GetCertsDir() const -> std::filesystem::path { - return app_resource_path_ / "certs"; + [[nodiscard]] auto GetCertsDir() const -> QString { + return app_resource_path_ + "/certs"; } /** @@ -214,61 +201,53 @@ class GlobalSettingStation::Impl { */ void SyncSettings() noexcept { try { - ui_cfg_.writeFile(main_config_path_.u8string().c_str()); + ui_cfg_.writeFile(main_config_path_.toUtf8()); GF_CORE_LOG_DEBUG("updated ui configuration successfully written to {}", - main_config_path_.u8string()); + main_config_path_); } catch (const libconfig::FileIOException &fioex) { GF_CORE_LOG_ERROR("i/o error while writing ui configuration file: {}", - main_config_path_.u8string()); + main_config_path_); } } private: - std::filesystem::path app_path_ = - std::filesystem::path(boost::dll::program_location().string()) - .parent_path(); + QString working_path_ = QDir::currentPath(); - std::filesystem::path app_data_path_ = - std::filesystem::path{ - QStandardPaths::writableLocation(QStandardPaths::AppLocalDataLocation) - .toStdString()} / - "GpgFrontend"; ///< Program Data Location + QString app_data_path_ = QString{QStandardPaths::writableLocation( + QStandardPaths::AppLocalDataLocation)} + + "/GpgFrontend"; ///< Program Data Location - std::filesystem::path app_log_path_ = - app_data_path_ / "logs"; ///< Program Data Location + QString app_log_path_ = app_data_path_ + "/logs"; ///< Program Data Location - std::filesystem::path app_data_objs_path_ = - app_data_path_ / "data_objs"; ///< Object storage path + QString app_data_objs_path_ = + app_data_path_ + "/data_objs"; ///< Object storage path #ifdef LINUX_INSTALL_BUILD - std::filesystem::path app_resource_path_ = - std::filesystem::path(APP_LOCALSTATE_PATH) / - "gpgfrontend"; ///< Program Data Location + QString app_resource_path_ = + QString(APP_LOCALSTATE_PATH) / "gpgfrontend"; ///< Program Data Location #else - std::filesystem::path app_resource_path_ = - RESOURCE_DIR_BOOST_PATH(app_path_); ///< Program Data Location + QString app_resource_path_ = + RESOURCE_DIR_BOOST_PATH(working_path_); ///< Program Data Location #endif #ifdef LINUX_INSTALL_BUILD - std::filesystem::path app_locale_path_ = + QString app_locale_path_ = QString(APP_LOCALE_PATH); ///< Program Data Location #else - std::filesystem::path app_locale_path_ = - app_resource_path_ / "locales"; ///< Program Data Location + QString app_locale_path_ = + app_resource_path_ + "/locales"; ///< Program Data Location #endif - std::filesystem::path app_configure_path_ = - std::filesystem::path{ - QStandardPaths::writableLocation(QStandardPaths::AppConfigLocation) - .toStdString()} / - "GpgFrontend"; ///< Program Configure Location - std::filesystem::path config_dir_path_ = - app_configure_path_ / "conf"; ///< Configure File Directory Location - std::filesystem::path main_config_path_ = - config_dir_path_ / "main.cfg"; ///< Main Configure File Location - std::filesystem::path module_config_path_ = - config_dir_path_ / "module.cfg"; ///< Main Configure File Location + QString app_configure_path_ = QString{QStandardPaths::writableLocation( + QStandardPaths::AppConfigLocation)} + + "/GpgFrontend"; ///< Program Configure Location + QString config_dir_path_ = + app_configure_path_ + "/conf"; ///< Configure File Directory Location + QString main_config_path_ = + config_dir_path_ + "/main.cfg"; ///< Main Configure File Location + QString module_config_path_ = + config_dir_path_ + "/module.cfg"; ///< Main Configure File Location libconfig::Config ui_cfg_; ///< UI Configure File @@ -291,37 +270,31 @@ auto GlobalSettingStation::GetMainSettings() noexcept -> libconfig::Setting & { return p_->GetMainSettings(); } -auto GlobalSettingStation::GetAppDir() const -> std::filesystem::path { +auto GlobalSettingStation::GetAppDir() const -> QString { return p_->GetAppDir(); } -auto GlobalSettingStation::GetAppDataPath() const -> std::filesystem::path { +auto GlobalSettingStation::GetAppDataPath() const -> QString { return p_->GetAppDataPath(); } -[[nodiscard]] auto GlobalSettingStation::GetLogDir() const - -> std::filesystem::path { +[[nodiscard]] auto GlobalSettingStation::GetLogDir() const -> QString { return p_->GetLogDir(); } -auto GlobalSettingStation::GetStandaloneDatabaseDir() const - -> std::filesystem::path { - return p_->GetStandaloneDatabaseDir(); -} - -auto GlobalSettingStation::GetAppConfigPath() const -> std::filesystem::path { +auto GlobalSettingStation::GetAppConfigPath() const -> QString { return p_->GetAppConfigPath(); } -auto GlobalSettingStation::GetLocaleDir() const -> std::filesystem::path { +auto GlobalSettingStation::GetLocaleDir() const -> QString { return p_->GetLocaleDir(); } -auto GlobalSettingStation::GetResourceDir() const -> std::filesystem::path { +auto GlobalSettingStation::GetResourceDir() const -> QString { return p_->GetResourceDir(); } -auto GlobalSettingStation::GetCertsDir() const -> std::filesystem::path { +auto GlobalSettingStation::GetCertsDir() const -> QString { return p_->GetCertsDir(); } diff --git a/src/core/function/GlobalSettingStation.h b/src/core/function/GlobalSettingStation.h index 5611161b..cd1b331b 100644 --- a/src/core/function/GlobalSettingStation.h +++ b/src/core/function/GlobalSettingStation.h @@ -67,57 +67,50 @@ class GPGFRONTEND_CORE_EXPORT GlobalSettingStation /** * @brief Get the App Dir object * - * @return std::filesystem::path + * @return QString */ - [[nodiscard]] auto GetAppDir() const -> std::filesystem::path; + [[nodiscard]] auto GetAppDir() const -> QString; /** * @brief Gets the application data directory. * @return Path to the application data directory. */ - [[nodiscard]] auto GetAppDataPath() const -> std::filesystem::path; + [[nodiscard]] auto GetAppDataPath() const -> QString; /** * @brief Get the Log Dir object * - * @return std::filesystem::path - */ - [[nodiscard]] auto GetLogDir() const -> std::filesystem::path; - - /** - * @brief Get the Standalone Database Dir object - * - * @return std::filesystem::path + * @return QString */ - [[nodiscard]] auto GetStandaloneDatabaseDir() const -> std::filesystem::path; + [[nodiscard]] auto GetLogDir() const -> QString; /** * @brief Get the App Config Path object * - * @return std::filesystem::path + * @return QString */ - [[nodiscard]] auto GetAppConfigPath() const -> std::filesystem::path; + [[nodiscard]] auto GetAppConfigPath() const -> QString; /** * @brief Get the Locale Dir object * - * @return std::filesystem::path + * @return QString */ - [[nodiscard]] auto GetLocaleDir() const -> std::filesystem::path; + [[nodiscard]] auto GetLocaleDir() const -> QString; /** * @brief Get the Resource Dir object * - * @return std::filesystem::path + * @return QString */ - [[nodiscard]] auto GetResourceDir() const -> std::filesystem::path; + [[nodiscard]] auto GetResourceDir() const -> QString; /** * @brief Get the Certs Dir object * - * @return std::filesystem::path + * @return QString */ - [[nodiscard]] auto GetCertsDir() const -> std::filesystem::path; + [[nodiscard]] auto GetCertsDir() const -> QString; /** * @brief Get the Log Files Size object diff --git a/src/core/function/KeyPackageOperator.cpp b/src/core/function/KeyPackageOperator.cpp index 929bfda1..d15859a3 100644 --- a/src/core/function/KeyPackageOperator.cpp +++ b/src/core/function/KeyPackageOperator.cpp @@ -40,17 +40,18 @@ namespace GpgFrontend { -auto KeyPackageOperator::GeneratePassphrase( - const std::filesystem::path& phrase_path, QString& phrase) -> bool { +auto KeyPackageOperator::GeneratePassphrase(const QString& phrase_path, + QString& phrase) -> bool { phrase = PassphraseGenerator::GetInstance().Generate(256); GF_CORE_LOG_DEBUG("generated passphrase: {} bytes", phrase.size()); - return WriteFile(phrase_path.c_str(), phrase.toUtf8()); + return WriteFile(phrase_path, phrase.toUtf8()); } -void KeyPackageOperator::GenerateKeyPackage( - const std::filesystem::path& key_package_path, - const QString& key_package_name, const KeyArgsList& keys, QString& phrase, - bool secret, const OperationCallback& cb) { +void KeyPackageOperator::GenerateKeyPackage(const QString& key_package_path, + const QString& key_package_name, + const KeyArgsList& keys, + QString& phrase, bool secret, + const OperationCallback& cb) { GF_CORE_LOG_DEBUG("generating key package: {}", key_package_name); GpgKeyImportExporter::GetInstance().ExportKeys( @@ -77,32 +78,30 @@ void KeyPackageOperator::GenerateKeyPackage( auto encoded_data = encryption.encode(data, hash_key); GF_CORE_LOG_DEBUG("writing key package, name: {}", key_package_name); - cb(WriteFile(key_package_path.c_str(), encoded_data) ? 0 : -1, + cb(WriteFile(key_package_path, encoded_data) ? 0 : -1, TransferParams()); return; }); } -auto KeyPackageOperator::ImportKeyPackage( - const std::filesystem::path& key_package_path, - const std::filesystem::path& phrase_path) +auto KeyPackageOperator::ImportKeyPackage(const QString& key_package_path, + const QString& phrase_path) -> std::tuple<bool, std::shared_ptr<GpgImportInformation>> { - GF_CORE_LOG_DEBUG("importing key package: {}", key_package_path.u8string()); + GF_CORE_LOG_DEBUG("importing key package: {}", key_package_path); QByteArray encrypted_data; - ReadFile(key_package_path.c_str(), encrypted_data); + ReadFile(key_package_path, encrypted_data); if (encrypted_data.isEmpty()) { - GF_CORE_LOG_ERROR("failed to read key package: {}", - key_package_path.u8string()); + GF_CORE_LOG_ERROR("failed to read key package: {}", key_package_path); return {false, nullptr}; }; QByteArray passphrase; - ReadFile(phrase_path.c_str(), passphrase); + ReadFile(phrase_path, passphrase); GF_CORE_LOG_DEBUG("passphrase: {} bytes", passphrase.size()); if (passphrase.size() != 256) { - GF_CORE_LOG_ERROR("failed to read passphrase: {}", phrase_path.u8string()); + GF_CORE_LOG_ERROR("failed to read passphrase: {}", phrase_path); return {false, nullptr}; } @@ -138,7 +137,7 @@ auto KeyPackageOperator::GenerateKeyPackageName() -> QString { * @return QString key package name */ auto KeyPackageOperator::generate_key_package_name() -> QString { - return QString("KeyPackage_%1%") + return QString("KeyPackage_%1") .arg(QRandomGenerator::global()->bounded(999, 99999)); } diff --git a/src/core/function/KeyPackageOperator.h b/src/core/function/KeyPackageOperator.h index abfb59b6..968e14f5 100644 --- a/src/core/function/KeyPackageOperator.h +++ b/src/core/function/KeyPackageOperator.h @@ -47,8 +47,8 @@ class GPGFRONTEND_CORE_EXPORT KeyPackageOperator { * @return true if passphrase was generated and saved * @return false if passphrase was not generated and saved */ - static auto GeneratePassphrase(const std::filesystem::path &phrase_path, - QString &phrase) -> bool; + static auto GeneratePassphrase(const QString &phrase_path, QString &phrase) + -> bool; /** * @brief generate the name of the key package @@ -68,7 +68,7 @@ class GPGFRONTEND_CORE_EXPORT KeyPackageOperator { * @return true if key package was generated * @return false if key package was not generated */ - static void GenerateKeyPackage(const std::filesystem::path &key_package_path, + static void GenerateKeyPackage(const QString &key_package_path, const QString &key_package_name, const KeyArgsList &keys, QString &phrase, bool secret, const OperationCallback &cb); @@ -82,8 +82,8 @@ class GPGFRONTEND_CORE_EXPORT KeyPackageOperator { * @return true if key package was imported * @return false if key package was not imported */ - static auto ImportKeyPackage(const std::filesystem::path &key_package_path, - const std::filesystem::path &phrase_path) + static auto ImportKeyPackage(const QString &key_package_path, + const QString &phrase_path) -> std::tuple<bool, std::shared_ptr<GpgImportInformation>>; private: diff --git a/src/core/function/LoggerManager.cpp b/src/core/function/LoggerManager.cpp index c800224a..3b88e4f0 100644 --- a/src/core/function/LoggerManager.cpp +++ b/src/core/function/LoggerManager.cpp @@ -70,8 +70,7 @@ auto LoggerManager::RegisterAsyncLogger(const QString& id, -> std::shared_ptr<spdlog::logger> { // get the log directory auto log_file_path = - (GlobalSettingStation::GetInstance().GetLogDir() / id.toStdString()); - log_file_path.replace_extension(".log"); + GlobalSettingStation::GetInstance().GetLogDir() + "/" + id + ".log"; // sinks std::vector<spdlog::sink_ptr> sinks; @@ -79,7 +78,7 @@ auto LoggerManager::RegisterAsyncLogger(const QString& id, spdlog::sinks::stderr_color_sink_mt>()); sinks.push_back(GpgFrontend::SecureCreateSharedObject< spdlog::sinks::rotating_file_sink_mt>( - log_file_path.u8string(), 1048576 * 32, 8)); + log_file_path.toUtf8().constData(), 1048576 * 32, 8)); // logger auto logger = GpgFrontend::SecureCreateSharedObject<spdlog::async_logger>( @@ -106,8 +105,7 @@ auto LoggerManager::RegisterSyncLogger(const QString& id, -> std::shared_ptr<spdlog::logger> { // get the log directory auto log_file_path = - (GlobalSettingStation::GetInstance().GetLogDir() / id.toStdString()); - log_file_path.replace_extension(".log"); + GlobalSettingStation::GetInstance().GetLogDir() + "/" + id + ".log"; // sinks std::vector<spdlog::sink_ptr> sinks; @@ -115,7 +113,7 @@ auto LoggerManager::RegisterSyncLogger(const QString& id, spdlog::sinks::stderr_color_sink_mt>()); sinks.push_back(GpgFrontend::SecureCreateSharedObject< spdlog::sinks::rotating_file_sink_mt>( - log_file_path.u8string(), 1048576 * 32, 8)); + log_file_path.toUtf8().constData(), 1048576 * 32, 8)); // logger auto logger = GpgFrontend::SecureCreateSharedObject<spdlog::logger>( diff --git a/src/core/function/gpg/GpgCommandExecutor.cpp b/src/core/function/gpg/GpgCommandExecutor.cpp index 713d9aba..8246e6a1 100644 --- a/src/core/function/gpg/GpgCommandExecutor.cpp +++ b/src/core/function/gpg/GpgCommandExecutor.cpp @@ -76,15 +76,14 @@ auto BuildTaskFromExecCtx(const GpgCommandExecutor::ExecuteContext &context) GF_CORE_LOG_DEBUG("process runner called, data object size: {}", data_object->GetObjectSize()); - if (!data_object->Check<QString, std::vector<QString>, - GpgCommandExecutorInteractor, + if (!data_object->Check<QString, QStringList, GpgCommandExecutorInteractor, GpgCommandExecutorCallback>()) { throw std::runtime_error("invalid data object size"); } // get arguments auto cmd = ExtractParams<QString>(data_object, 0); - auto arguments = ExtractParams<std::vector<QString>>(data_object, 1); + auto arguments = ExtractParams<QStringList>(data_object, 1); auto interact_func = ExtractParams<GpgCommandExecutorInteractor>(data_object, 2); auto callback = ExtractParams<GpgCommandExecutorCallback>(data_object, 3); diff --git a/src/core/function/gpg/GpgCommandExecutor.h b/src/core/function/gpg/GpgCommandExecutor.h index 995fb603..d161406a 100644 --- a/src/core/function/gpg/GpgCommandExecutor.h +++ b/src/core/function/gpg/GpgCommandExecutor.h @@ -43,13 +43,13 @@ class GPGFRONTEND_CORE_EXPORT GpgCommandExecutor { public: struct ExecuteContext { QString cmd; - QList<QString> arguments; + QStringList arguments; GpgCommandExecutorCallback cb_func; GpgCommandExecutorInteractor int_func; Module::TaskRunnerPtr task_runner = nullptr; ExecuteContext( - QString cmd, QList<QString> arguments, + QString cmd, QStringList arguments, GpgCommandExecutorCallback callback = [](int, const QString &, const QString &) {}, Module::TaskRunnerPtr task_runner = nullptr, diff --git a/src/core/function/gpg/GpgFileOpera.cpp b/src/core/function/gpg/GpgFileOpera.cpp index 53cc6099..a4663150 100644 --- a/src/core/function/gpg/GpgFileOpera.cpp +++ b/src/core/function/gpg/GpgFileOpera.cpp @@ -29,7 +29,6 @@ #include "core/function/ArchiveFileOperator.h" #include "core/function/gpg/GpgBasicOperator.h" -#include "core/model/GFBuffer.h" #include "core/model/GpgData.h" #include "core/model/GpgDecryptResult.h" #include "core/model/GpgEncryptResult.h" @@ -38,7 +37,6 @@ #include "core/model/GpgVerifyResult.h" #include "core/utils/AsyncUtils.h" #include "core/utils/GpgUtils.h" -#include "core/utils/IOUtils.h" namespace GpgFrontend { @@ -47,9 +45,8 @@ constexpr ssize_t kDataExchangerSize = 8192; GpgFileOpera::GpgFileOpera(int channel) : SingletonFunctionObject<GpgFileOpera>(channel) {} -void GpgFileOpera::EncryptFile(std::vector<GpgKey> keys, - const std::filesystem::path& in_path, bool ascii, - const std::filesystem::path& out_path, +void GpgFileOpera::EncryptFile(std::vector<GpgKey> keys, const QString& in_path, + bool ascii, const QString& out_path, const GpgOperationCallback& cb) { RunGpgOperaAsync( [=](const DataObjectPtr& data_object) -> GpgError { @@ -73,9 +70,8 @@ void GpgFileOpera::EncryptFile(std::vector<GpgKey> keys, } void GpgFileOpera::EncryptDirectory(std::vector<GpgKey> keys, - const std::filesystem::path& in_path, - bool ascii, - const std::filesystem::path& out_path, + const QString& in_path, bool ascii, + const QString& out_path, const GpgOperationCallback& cb) { auto ex = std::make_shared<GFDataExchanger>(kDataExchangerSize); @@ -108,8 +104,7 @@ void GpgFileOpera::EncryptDirectory(std::vector<GpgKey> keys, }); } -void GpgFileOpera::DecryptFile(const std::filesystem::path& in_path, - const std::filesystem::path& out_path, +void GpgFileOpera::DecryptFile(const QString& in_path, const QString& out_path, const GpgOperationCallback& cb) { RunGpgOperaAsync( [=](const DataObjectPtr& data_object) -> GpgError { @@ -126,8 +121,8 @@ void GpgFileOpera::DecryptFile(const std::filesystem::path& in_path, cb, "gpgme_op_decrypt", "2.1.0"); } -void GpgFileOpera::DecryptArchive(const std::filesystem::path& in_path, - const std::filesystem::path& out_path, +void GpgFileOpera::DecryptArchive(const QString& in_path, + const QString& out_path, const GpgOperationCallback& cb) { auto ex = std::make_shared<GFDataExchanger>(kDataExchangerSize); @@ -151,9 +146,8 @@ void GpgFileOpera::DecryptArchive(const std::filesystem::path& in_path, cb, "gpgme_op_decrypt", "2.1.0"); } -void GpgFileOpera::SignFile(KeyArgsList keys, - const std::filesystem::path& in_path, bool ascii, - const std::filesystem::path& out_path, +void GpgFileOpera::SignFile(KeyArgsList keys, const QString& in_path, + bool ascii, const QString& out_path, const GpgOperationCallback& cb) { RunGpgOperaAsync( [=](const DataObjectPtr& data_object) -> GpgError { @@ -177,8 +171,8 @@ void GpgFileOpera::SignFile(KeyArgsList keys, cb, "gpgme_op_sign", "2.1.0"); } -void GpgFileOpera::VerifyFile(const std::filesystem::path& data_path, - const std::filesystem::path& sign_path, +void GpgFileOpera::VerifyFile(const QString& data_path, + const QString& sign_path, const GpgOperationCallback& cb) { RunGpgOperaAsync( [=](const DataObjectPtr& data_object) -> GpgError { @@ -186,7 +180,7 @@ void GpgFileOpera::VerifyFile(const std::filesystem::path& data_path, GpgData data_in(data_path, true); GpgData data_out; - if (!sign_path.empty()) { + if (!sign_path.isEmpty()) { GpgData sig_data(sign_path, true); err = CheckGpgError(gpgme_op_verify(ctx_.DefaultContext(), sig_data, data_in, nullptr)); @@ -205,9 +199,8 @@ void GpgFileOpera::VerifyFile(const std::filesystem::path& data_path, } void GpgFileOpera::EncryptSignFile(KeyArgsList keys, KeyArgsList signer_keys, - const std::filesystem::path& in_path, - bool ascii, - const std::filesystem::path& out_path, + const QString& in_path, bool ascii, + const QString& out_path, const GpgOperationCallback& cb) { RunGpgOperaAsync( [=](const DataObjectPtr& data_object) -> GpgError { @@ -238,9 +231,8 @@ void GpgFileOpera::EncryptSignFile(KeyArgsList keys, KeyArgsList signer_keys, void GpgFileOpera::EncryptSignDirectory(KeyArgsList keys, KeyArgsList signer_keys, - const std::filesystem::path& in_path, - bool ascii, - const std::filesystem::path& out_path, + const QString& in_path, bool ascii, + const QString& out_path, const GpgOperationCallback& cb) { auto ex = std::make_shared<GFDataExchanger>(kDataExchangerSize); @@ -276,8 +268,8 @@ void GpgFileOpera::EncryptSignDirectory(KeyArgsList keys, }); } -void GpgFileOpera::DecryptVerifyFile(const std::filesystem::path& in_path, - const std::filesystem::path& out_path, +void GpgFileOpera::DecryptVerifyFile(const QString& in_path, + const QString& out_path, const GpgOperationCallback& cb) { RunGpgOperaAsync( [=](const DataObjectPtr& data_object) -> GpgError { @@ -299,8 +291,8 @@ void GpgFileOpera::DecryptVerifyFile(const std::filesystem::path& in_path, cb, "gpgme_op_decrypt_verify", "2.1.0"); } -void GpgFileOpera::DecryptVerifyArchive(const std::filesystem::path& in_path, - const std::filesystem::path& out_path, +void GpgFileOpera::DecryptVerifyArchive(const QString& in_path, + const QString& out_path, const GpgOperationCallback& cb) { auto ex = std::make_shared<GFDataExchanger>(kDataExchangerSize); @@ -329,9 +321,8 @@ void GpgFileOpera::DecryptVerifyArchive(const std::filesystem::path& in_path, cb, "gpgme_op_decrypt_verify", "2.1.0"); } -void GpgFileOpera::EncryptFileSymmetric(const std::filesystem::path& in_path, - bool ascii, - const std::filesystem::path& out_path, +void GpgFileOpera::EncryptFileSymmetric(const QString& in_path, bool ascii, + const QString& out_path, const GpgOperationCallback& cb) { RunGpgOperaAsync( [=](const DataObjectPtr& data_object) -> GpgError { @@ -350,9 +341,9 @@ void GpgFileOpera::EncryptFileSymmetric(const std::filesystem::path& in_path, cb, "gpgme_op_encrypt_symmetric", "2.1.0"); } -void GpgFileOpera::EncryptDerectorySymmetric( - const std::filesystem::path& in_path, bool ascii, - const std::filesystem::path& out_path, const GpgOperationCallback& cb) { +void GpgFileOpera::EncryptDerectorySymmetric(const QString& in_path, bool ascii, + const QString& out_path, + const GpgOperationCallback& cb) { auto ex = std::make_shared<GFDataExchanger>(kDataExchangerSize); RunGpgOperaAsync( diff --git a/src/core/function/gpg/GpgFileOpera.h b/src/core/function/gpg/GpgFileOpera.h index 76d0eeee..b015ebe9 100644 --- a/src/core/function/gpg/GpgFileOpera.h +++ b/src/core/function/gpg/GpgFileOpera.h @@ -61,9 +61,8 @@ class GPGFRONTEND_CORE_EXPORT GpgFileOpera * @param channel Channel in context * @return unsigned int error code */ - void EncryptFile(KeyArgsList keys, const std::filesystem::path& in_path, - bool ascii, const std::filesystem::path& out_path, - const GpgOperationCallback& cb); + void EncryptFile(KeyArgsList keys, const QString& in_path, bool ascii, + const QString& out_path, const GpgOperationCallback& cb); /** * @brief @@ -74,8 +73,8 @@ class GPGFRONTEND_CORE_EXPORT GpgFileOpera * @param out_path * @param cb */ - void EncryptDirectory(KeyArgsList keys, const std::filesystem::path& in_path, - bool ascii, const std::filesystem::path& out_path, + void EncryptDirectory(KeyArgsList keys, const QString& in_path, bool ascii, + const QString& out_path, const GpgOperationCallback& cb); /** @@ -87,8 +86,8 @@ class GPGFRONTEND_CORE_EXPORT GpgFileOpera * @param channel * @return unsigned int */ - void EncryptFileSymmetric(const std::filesystem::path& in_path, bool ascii, - const std::filesystem::path& out_path, + void EncryptFileSymmetric(const QString& in_path, bool ascii, + const QString& out_path, const GpgOperationCallback& cb); /** @@ -99,9 +98,8 @@ class GPGFRONTEND_CORE_EXPORT GpgFileOpera * @param out_path * @param cb */ - void EncryptDerectorySymmetric(const std::filesystem::path& in_path, - bool ascii, - const std::filesystem::path& out_path, + void EncryptDerectorySymmetric(const QString& in_path, bool ascii, + const QString& out_path, const GpgOperationCallback& cb); /** @@ -112,8 +110,7 @@ class GPGFRONTEND_CORE_EXPORT GpgFileOpera * @param result * @return GpgError */ - void DecryptFile(const std::filesystem::path& in_path, - const std::filesystem::path& out_path, + void DecryptFile(const QString& in_path, const QString& out_path, const GpgOperationCallback& cb); /** @@ -123,8 +120,7 @@ class GPGFRONTEND_CORE_EXPORT GpgFileOpera * @param out_path * @param cb */ - void DecryptArchive(const std::filesystem::path& in_path, - const std::filesystem::path& out_path, + void DecryptArchive(const QString& in_path, const QString& out_path, const GpgOperationCallback& cb); /** @@ -137,9 +133,8 @@ class GPGFRONTEND_CORE_EXPORT GpgFileOpera * @param channel * @return GpgError */ - void SignFile(KeyArgsList keys, const std::filesystem::path& in_path, - bool ascii, const std::filesystem::path& out_path, - const GpgOperationCallback& cb); + void SignFile(KeyArgsList keys, const QString& in_path, bool ascii, + const QString& out_path, const GpgOperationCallback& cb); /** * @brief Verify file with public key @@ -150,8 +145,7 @@ class GPGFRONTEND_CORE_EXPORT GpgFileOpera * @param channel Channel in context * @return GpgError */ - void VerifyFile(const std::filesystem::path& data_path, - const std::filesystem::path& sign_path, + void VerifyFile(const QString& data_path, const QString& sign_path, const GpgOperationCallback& cb); /** @@ -165,9 +159,8 @@ class GPGFRONTEND_CORE_EXPORT GpgFileOpera * @param cb */ void EncryptSignFile(KeyArgsList keys, KeyArgsList signer_keys, - const std::filesystem::path& in_path, bool ascii, - const std::filesystem::path& out_path, - const GpgOperationCallback& cb); + const QString& in_path, bool ascii, + const QString& out_path, const GpgOperationCallback& cb); /** * @brief @@ -180,8 +173,8 @@ class GPGFRONTEND_CORE_EXPORT GpgFileOpera * @param cb */ void EncryptSignDirectory(KeyArgsList keys, KeyArgsList signer_keys, - const std::filesystem::path& in_path, bool ascii, - const std::filesystem::path& out_path, + const QString& in_path, bool ascii, + const QString& out_path, const GpgOperationCallback& cb); /** @@ -193,8 +186,7 @@ class GPGFRONTEND_CORE_EXPORT GpgFileOpera * @param verify_res * @return GpgError */ - void DecryptVerifyFile(const std::filesystem::path& in_path, - const std::filesystem::path& out_path, + void DecryptVerifyFile(const QString& in_path, const QString& out_path, const GpgOperationCallback& cb); /** @@ -204,8 +196,7 @@ class GPGFRONTEND_CORE_EXPORT GpgFileOpera * @param out_path * @param cb */ - void DecryptVerifyArchive(const std::filesystem::path& in_path, - const std::filesystem::path& out_path, + void DecryptVerifyArchive(const QString& in_path, const QString& out_path, const GpgOperationCallback& cb); private: diff --git a/src/core/function/gpg/GpgKeyManager.cpp b/src/core/function/gpg/GpgKeyManager.cpp index e6ff7214..8d7d9a28 100644 --- a/src/core/function/gpg/GpgKeyManager.cpp +++ b/src/core/function/gpg/GpgKeyManager.cpp @@ -28,9 +28,6 @@ #include "GpgKeyManager.h" -#include <boost/algorithm/string.hpp> -#include <boost/date_time/posix_time/conversion.hpp> - #include "core/GpgModel.h" #include "core/function/gpg/GpgBasicOperator.h" #include "core/function/gpg/GpgKeyGetter.h" @@ -41,8 +38,7 @@ GpgFrontend::GpgKeyManager::GpgKeyManager(int channel) auto GpgFrontend::GpgKeyManager::SignKey( const GpgFrontend::GpgKey& target, GpgFrontend::KeyArgsList& keys, - const QString& uid, - const std::unique_ptr<boost::posix_time::ptime>& expires) -> bool { + const QString& uid, const std::unique_ptr<QDateTime>& expires) -> bool { GpgBasicOperator::GetInstance().SetSigners(keys, true); unsigned int flags = 0; @@ -51,7 +47,7 @@ auto GpgFrontend::GpgKeyManager::SignKey( if (expires == nullptr) { flags |= GPGME_KEYSIGN_NOEXPIRE; } else { - expires_time_t = to_time_t(*expires); + expires_time_t = expires->toSecsSinceEpoch(); } auto err = CheckGpgError( @@ -77,14 +73,13 @@ auto GpgFrontend::GpgKeyManager::RevSign( return true; } -auto GpgFrontend::GpgKeyManager::SetExpire( - const GpgFrontend::GpgKey& key, std::unique_ptr<GpgSubKey>& subkey, - std::unique_ptr<boost::posix_time::ptime>& expires) -> bool { - using namespace boost::posix_time; - +auto GpgFrontend::GpgKeyManager::SetExpire(const GpgFrontend::GpgKey& key, + std::unique_ptr<GpgSubKey>& subkey, + std::unique_ptr<QDateTime>& expires) + -> bool { unsigned long expires_time = 0; - if (expires != nullptr) expires_time = to_time_t(ptime(*expires)); + if (expires != nullptr) expires_time = expires->toSecsSinceEpoch(); const char* sub_fprs = nullptr; @@ -191,7 +186,7 @@ auto GpgFrontend::GpgKeyManager::interactor_cb_fnc(void* handle, const char* status, const char* args, int fd) -> gpgme_error_t { - auto handle_struct = static_cast<AutomatonHandelStruct*>(handle); + auto* handle_struct = static_cast<AutomatonHandelStruct*>(handle); QString status_s = status; QString args_s = args; GF_CORE_LOG_DEBUG( diff --git a/src/core/function/gpg/GpgKeyManager.h b/src/core/function/gpg/GpgKeyManager.h index 39570d96..ecb345bf 100644 --- a/src/core/function/gpg/GpgKeyManager.h +++ b/src/core/function/gpg/GpgKeyManager.h @@ -35,10 +35,6 @@ #include "core/function/gpg/GpgContext.h" #include "core/typedef/GpgTypedef.h" -namespace boost::posix_time { -class ptime; -} - namespace GpgFrontend { /** @@ -64,8 +60,7 @@ class GPGFRONTEND_CORE_EXPORT GpgKeyManager * @return if successful */ auto SignKey(const GpgKey& target, KeyArgsList& keys, const QString& uid, - const std::unique_ptr<boost::posix_time::ptime>& expires) - -> bool; + const std::unique_ptr<QDateTime>& expires) -> bool; /** * @brief @@ -88,7 +83,7 @@ class GPGFRONTEND_CORE_EXPORT GpgKeyManager * @return false */ auto SetExpire(const GpgKey& key, std::unique_ptr<GpgSubKey>& subkey, - std::unique_ptr<boost::posix_time::ptime>& expires) -> bool; + std::unique_ptr<QDateTime>& expires) -> bool; /** * @brief diff --git a/src/core/function/gpg/GpgKeyOpera.cpp b/src/core/function/gpg/GpgKeyOpera.cpp index 88419237..d31165be 100644 --- a/src/core/function/gpg/GpgKeyOpera.cpp +++ b/src/core/function/gpg/GpgKeyOpera.cpp @@ -30,10 +30,6 @@ #include <gpg-error.h> -#include <boost/algorithm/string.hpp> -#include <boost/asio.hpp> -#include <boost/date_time/posix_time/conversion.hpp> -#include <boost/process/async_pipe.hpp> #include <memory> #include "core/GpgModel.h" @@ -41,12 +37,12 @@ #include "core/function/gpg/GpgKeyGetter.h" #include "core/model/DataObject.h" #include "core/model/GpgGenKeyInfo.h" +#include "core/model/GpgGenerateKeyResult.h" #include "core/module/ModuleManager.h" +#include "core/typedef/GpgTypedef.h" #include "core/utils/AsyncUtils.h" #include "core/utils/CommonUtils.h" #include "core/utils/GpgUtils.h" -#include "model/GpgGenerateKeyResult.h" -#include "typedef/GpgTypedef.h" namespace GpgFrontend { @@ -81,13 +77,11 @@ void GpgKeyOpera::DeleteKeys(GpgFrontend::KeyIdArgsListPtr key_ids) { * @return if successful */ auto GpgKeyOpera::SetExpire(const GpgKey& key, const SubkeyId& subkey_fpr, - std::unique_ptr<boost::posix_time::ptime>& expires) - -> GpgError { + std::unique_ptr<QDateTime>& expires) -> GpgError { unsigned long expires_time = 0; if (expires != nullptr) { - expires_time = to_time_t(*expires) - std::chrono::system_clock::to_time_t( - std::chrono::system_clock::now()); + expires_time = QDateTime::currentDateTime().secsTo(*expires); } GpgError err; @@ -176,9 +170,8 @@ void GpgKeyOpera::GenerateKey(const std::shared_ptr<GenKeyInfo>& params, const char* algo = algo_utf8.toUtf8(); unsigned long expires = 0; - expires = to_time_t(boost::posix_time::ptime(params->GetExpireTime())) - - std::chrono::system_clock::to_time_t( - std::chrono ::system_clock::now()); + + expires = QDateTime::currentDateTime().secsTo(params->GetExpireTime()); GpgError err; unsigned int flags = 0; @@ -227,9 +220,7 @@ void GpgKeyOpera::GenerateSubkey(const GpgKey& key, const char* algo = algo_utf8.toUtf8(); unsigned long expires = 0; - expires = to_time_t(boost::posix_time::ptime(params->GetExpireTime())) - - std::chrono::system_clock::to_time_t( - std::chrono::system_clock::now()); + expires = QDateTime::currentDateTime().secsTo(params->GetExpireTime()); unsigned int flags = 0; @@ -264,9 +255,8 @@ void GpgKeyOpera::GenerateKeyWithSubkey( const char* algo = algo_utf8.toUtf8(); unsigned long expires = 0; - expires = to_time_t(boost::posix_time::ptime(params->GetExpireTime())) - - std::chrono::system_clock::to_time_t( - std::chrono ::system_clock::now()); + + expires = QDateTime::currentDateTime().secsTo(params->GetExpireTime()); GpgError err; unsigned int flags = 0; @@ -310,10 +300,8 @@ void GpgKeyOpera::GenerateKeyWithSubkey( algo = algo_utf8.toUtf8(); expires = 0; - expires = to_time_t(boost::posix_time::ptime( - subkey_params->GetExpireTime())) - - std::chrono::system_clock::to_time_t( - std::chrono::system_clock::now()); + expires = + QDateTime::currentDateTime().secsTo(subkey_params->GetExpireTime()); flags = 0; if (subkey_params->IsAllowEncryption()) flags |= GPGME_CREATE_ENCR; diff --git a/src/core/function/gpg/GpgKeyOpera.h b/src/core/function/gpg/GpgKeyOpera.h index 83320cdd..a060af1a 100644 --- a/src/core/function/gpg/GpgKeyOpera.h +++ b/src/core/function/gpg/GpgKeyOpera.h @@ -33,10 +33,6 @@ #include "core/function/gpg/GpgContext.h" #include "core/typedef/GpgTypedef.h" -namespace boost::posix_time { -class ptime; -} // namespace boost::posix_time - namespace GpgFrontend { /** * @brief @@ -82,8 +78,7 @@ class GPGFRONTEND_CORE_EXPORT GpgKeyOpera * @return GpgError */ auto SetExpire(const GpgKey& key, const SubkeyId& subkey_fpr, - std::unique_ptr<boost::posix_time::ptime>& expires) - -> GpgError; + std::unique_ptr<QDateTime>& expires) -> GpgError; /** * @brief diff --git a/src/core/model/GpgData.cpp b/src/core/model/GpgData.cpp index e3d5e666..bd8c31a5 100644 --- a/src/core/model/GpgData.cpp +++ b/src/core/model/GpgData.cpp @@ -92,10 +92,14 @@ GpgData::GpgData(int fd) : fd_(fd), data_cbs_() { data_ref_ = std::unique_ptr<struct gpgme_data, DataRefDeleter>(data); } -GpgData::GpgData(const std::filesystem::path& path, bool read) { +GpgData::GpgData(const QString& path, bool read) { gpgme_data_t data; - fp_ = fopen(path.string().c_str(), read ? "rb" : "wb"); + // support unicode path + QFile file(path); + file.open(read ? QIODevice::ReadOnly : QIODevice::WriteOnly); + fp_ = fdopen(dup(file.handle()), read ? "rb" : "wb"); + auto err = gpgme_data_new_from_stream(&data, fp_); assert(gpgme_err_code(err) == GPG_ERR_NO_ERROR); diff --git a/src/core/model/GpgData.h b/src/core/model/GpgData.h index f0ef2a49..358ebd19 100644 --- a/src/core/model/GpgData.h +++ b/src/core/model/GpgData.h @@ -76,7 +76,7 @@ class GPGFRONTEND_CORE_EXPORT GpgData { * * @param path */ - explicit GpgData(const std::filesystem::path& path, bool read); + explicit GpgData(const QString& path, bool read); /** * @brief Construct a new Gpg Data object diff --git a/src/core/model/GpgGenKeyInfo.cpp b/src/core/model/GpgGenKeyInfo.cpp index 3e705f16..60f76d96 100644 --- a/src/core/model/GpgGenKeyInfo.cpp +++ b/src/core/model/GpgGenKeyInfo.cpp @@ -144,14 +144,14 @@ void GenKeyInfo::SetKeyLength(int m_key_size) { GenKeyInfo::key_size_ = m_key_size; } -void GenKeyInfo::SetExpireTime(const boost::posix_time::ptime &m_expired) { +void GenKeyInfo::SetExpireTime(const QDateTime &m_expired) { if (!IsNonExpired()) { GenKeyInfo::expired_ = m_expired; } } void GenKeyInfo::SetNonExpired(bool m_non_expired) { - if (!m_non_expired) this->expired_ = boost::posix_time::from_time_t(0); + if (!m_non_expired) this->expired_ = QDateTime::fromSecsSinceEpoch(0); GenKeyInfo::non_expired_ = m_non_expired; } @@ -293,10 +293,9 @@ void GenKeyInfo::SetComment(const QString &m_comment) { /** * @brief Get the Expired object * - * @return const boost::posix_time::ptime& + * @return const QDateTime& */ -[[nodiscard]] auto GenKeyInfo::GetExpireTime() const - -> const boost::posix_time::ptime & { +[[nodiscard]] auto GenKeyInfo::GetExpireTime() const -> const QDateTime & { return expired_; } diff --git a/src/core/model/GpgGenKeyInfo.h b/src/core/model/GpgGenKeyInfo.h index cf12e8b4..166c6b0f 100644 --- a/src/core/model/GpgGenKeyInfo.h +++ b/src/core/model/GpgGenKeyInfo.h @@ -28,8 +28,6 @@ #pragma once -#include <boost/date_time.hpp> - namespace GpgFrontend { class GPGFRONTEND_CORE_EXPORT GenKeyInfo { @@ -160,16 +158,16 @@ class GPGFRONTEND_CORE_EXPORT GenKeyInfo { /** * @brief Get the Expired object * - * @return const boost::posix_time::ptime& + * @return const QDateTime& */ - [[nodiscard]] auto GetExpireTime() const -> const boost::posix_time::ptime &; + [[nodiscard]] auto GetExpireTime() const -> const QDateTime &; /** * @brief Set the Expired object * * @param m_expired */ - void SetExpireTime(const boost::posix_time::ptime &m_expired); + void SetExpireTime(const QDateTime &m_expired); /** * @brief @@ -344,10 +342,8 @@ class GPGFRONTEND_CORE_EXPORT GenKeyInfo { QString algo_; ///< int key_size_ = 2048; - boost::posix_time::ptime expired_ = - boost::posix_time::second_clock::local_time() + - boost::gregorian::years(2); ///< - bool non_expired_ = false; ///< + QDateTime expired_ = QDateTime::currentDateTime().addYears(2); + bool non_expired_ = false; ///< bool no_passphrase_ = false; ///< bool allow_no_pass_phrase_ = true; ///< diff --git a/src/core/model/GpgKey.cpp b/src/core/model/GpgKey.cpp index 73c67045..a53aac5f 100644 --- a/src/core/model/GpgKey.cpp +++ b/src/core/model/GpgKey.cpp @@ -125,17 +125,17 @@ auto GpgKey::GetPublicKeyAlgo() const -> QString { return gpgme_pubkey_algo_name(key_ref_->subkeys->pubkey_algo); } -auto GpgKey::GetLastUpdateTime() const -> boost::posix_time::ptime { - return boost::posix_time::from_time_t( +auto GpgKey::GetLastUpdateTime() const -> QDateTime { + return QDateTime::fromSecsSinceEpoch( static_cast<time_t>(key_ref_->last_update)); } -auto GpgKey::GetExpireTime() const -> boost::posix_time::ptime { - return boost::posix_time::from_time_t(key_ref_->subkeys->expires); +auto GpgKey::GetExpireTime() const -> QDateTime { + return QDateTime::fromSecsSinceEpoch(key_ref_->subkeys->expires); }; -auto GpgKey::GetCreateTime() const -> boost::posix_time::ptime { - return boost::posix_time::from_time_t(key_ref_->subkeys->timestamp); +auto GpgKey::GetCreateTime() const -> QDateTime { + return QDateTime::fromSecsSinceEpoch(key_ref_->subkeys->timestamp); }; auto GpgKey::GetPrimaryKeyLength() const -> unsigned int { diff --git a/src/core/model/GpgKey.h b/src/core/model/GpgKey.h index 09224304..2e540410 100644 --- a/src/core/model/GpgKey.h +++ b/src/core/model/GpgKey.h @@ -115,23 +115,23 @@ class GPGFRONTEND_CORE_EXPORT GpgKey { /** * @brief * - * @return boost::posix_time::ptime + * @return QDateTime */ - [[nodiscard]] auto GetLastUpdateTime() const -> boost::posix_time::ptime; + [[nodiscard]] auto GetLastUpdateTime() const -> QDateTime; /** * @brief * - * @return boost::posix_time::ptime + * @return QDateTime */ - [[nodiscard]] auto GetExpireTime() const -> boost::posix_time::ptime; + [[nodiscard]] auto GetExpireTime() const -> QDateTime; /** * @brief Create a time object * - * @return boost::posix_time::ptime + * @return QDateTime */ - [[nodiscard]] auto GetCreateTime() const -> boost::posix_time::ptime; + [[nodiscard]] auto GetCreateTime() const -> QDateTime; /** * @brief s diff --git a/src/core/model/GpgKeySignature.cpp b/src/core/model/GpgKeySignature.cpp index eef46816..3182000c 100644 --- a/src/core/model/GpgKeySignature.cpp +++ b/src/core/model/GpgKeySignature.cpp @@ -62,12 +62,12 @@ QString GpgKeySignature::GetPubkeyAlgo() const { return gpgme_pubkey_algo_name(signature_ref_->pubkey_algo); } -boost::posix_time::ptime GpgKeySignature::GetCreateTime() const { - return boost::posix_time::from_time_t(signature_ref_->timestamp); +QDateTime GpgKeySignature::GetCreateTime() const { + return QDateTime::fromSecsSinceEpoch(signature_ref_->timestamp); } -boost::posix_time::ptime GpgKeySignature::GetExpireTime() const { - return boost::posix_time::from_time_t(signature_ref_->expires); +QDateTime GpgKeySignature::GetExpireTime() const { + return QDateTime::fromSecsSinceEpoch(signature_ref_->expires); } QString GpgKeySignature::GetUID() const { return signature_ref_->uid; } diff --git a/src/core/model/GpgKeySignature.h b/src/core/model/GpgKeySignature.h index a15db99d..c9ceeccc 100644 --- a/src/core/model/GpgKeySignature.h +++ b/src/core/model/GpgKeySignature.h @@ -28,8 +28,6 @@ #pragma once -#include <boost/date_time.hpp> - #include "core/typedef/GpgTypedef.h" /** @@ -100,16 +98,16 @@ class GPGFRONTEND_CORE_EXPORT GpgKeySignature { /** * @brief Create a time object * - * @return boost::posix_time::ptime + * @return QDateTime */ - [[nodiscard]] auto GetCreateTime() const -> boost::posix_time::ptime; + [[nodiscard]] auto GetCreateTime() const -> QDateTime; /** * @brief * - * @return boost::posix_time::ptime + * @return QDateTime */ - [[nodiscard]] auto GetExpireTime() const -> boost::posix_time::ptime; + [[nodiscard]] auto GetExpireTime() const -> QDateTime; /** * @brief diff --git a/src/core/model/GpgSignature.cpp b/src/core/model/GpgSignature.cpp index 64bf7e37..e2cb7e4b 100644 --- a/src/core/model/GpgSignature.cpp +++ b/src/core/model/GpgSignature.cpp @@ -100,19 +100,19 @@ auto GpgSignature::GetHashAlgo() const -> QString { /** * @brief Create a time object * - * @return boost::posix_time::ptime + * @return QDateTime */ -auto GpgSignature::GetCreateTime() const -> boost::posix_time::ptime { - return boost::posix_time::from_time_t(signature_ref_->timestamp); +auto GpgSignature::GetCreateTime() const -> QDateTime { + return QDateTime::fromSecsSinceEpoch(signature_ref_->timestamp); } /** * @brief * - * @return boost::posix_time::ptime + * @return QDateTime */ -auto GpgSignature::GetExpireTime() const -> boost::posix_time::ptime { - return boost::posix_time::from_time_t(signature_ref_->exp_timestamp); +auto GpgSignature::GetExpireTime() const -> QDateTime { + return QDateTime::fromSecsSinceEpoch(signature_ref_->exp_timestamp); } /** diff --git a/src/core/model/GpgSignature.h b/src/core/model/GpgSignature.h index 68ecf094..316b9100 100644 --- a/src/core/model/GpgSignature.h +++ b/src/core/model/GpgSignature.h @@ -28,8 +28,6 @@ #pragma once -#include <boost/date_time.hpp> - #include "core/typedef/GpgTypedef.h" namespace GpgFrontend { @@ -78,16 +76,16 @@ class GPGFRONTEND_CORE_EXPORT GpgSignature { /** * @brief Create a time object * - * @return boost::posix_time::ptime + * @return QDateTime */ - [[nodiscard]] auto GetCreateTime() const -> boost::posix_time::ptime; + [[nodiscard]] auto GetCreateTime() const -> QDateTime; /** * @brief * - * @return boost::posix_time::ptime + * @return QDateTime */ - [[nodiscard]] auto GetExpireTime() const -> boost::posix_time::ptime; + [[nodiscard]] auto GetExpireTime() const -> QDateTime; /** * @brief diff --git a/src/core/model/GpgSubKey.cpp b/src/core/model/GpgSubKey.cpp index ccf50e76..eaef1498 100644 --- a/src/core/model/GpgSubKey.cpp +++ b/src/core/model/GpgSubKey.cpp @@ -87,12 +87,12 @@ auto GpgSubKey::IsSecretKey() const -> bool { return subkey_ref_->secret; } auto GpgSubKey::IsCardKey() const -> bool { return subkey_ref_->is_cardkey; } -auto GpgSubKey::GetCreateTime() const -> boost::posix_time::ptime { - return boost::posix_time::from_time_t(subkey_ref_->timestamp); +auto GpgSubKey::GetCreateTime() const -> QDateTime { + return QDateTime::fromSecsSinceEpoch(subkey_ref_->timestamp); } -auto GpgSubKey::GetExpireTime() const -> boost::posix_time::ptime { - return boost::posix_time::from_time_t(subkey_ref_->expires); +auto GpgSubKey::GetExpireTime() const -> QDateTime { + return QDateTime::fromSecsSinceEpoch(subkey_ref_->expires); } } // namespace GpgFrontend diff --git a/src/core/model/GpgSubKey.h b/src/core/model/GpgSubKey.h index 2556d915..d8268c34 100644 --- a/src/core/model/GpgSubKey.h +++ b/src/core/model/GpgSubKey.h @@ -28,8 +28,6 @@ #pragma once -#include <boost/date_time.hpp> - namespace GpgFrontend { /** @@ -149,16 +147,16 @@ class GPGFRONTEND_CORE_EXPORT GpgSubKey { /** * @brief * - * @return boost::posix_time::ptime + * @return QDateTime */ - [[nodiscard]] auto GetCreateTime() const -> boost::posix_time::ptime; + [[nodiscard]] auto GetCreateTime() const -> QDateTime; /** * @brief * - * @return boost::posix_time::ptime + * @return QDateTime */ - [[nodiscard]] boost::posix_time::ptime GetExpireTime() const; + [[nodiscard]] QDateTime GetExpireTime() const; /** * @brief Construct a new Gpg Sub Key object diff --git a/src/core/module/GlobalModuleContext.cpp b/src/core/module/GlobalModuleContext.cpp index cac3dfbb..16650c96 100644 --- a/src/core/module/GlobalModuleContext.cpp +++ b/src/core/module/GlobalModuleContext.cpp @@ -28,8 +28,6 @@ #include "GlobalModuleContext.h" -#include <boost/date_time.hpp> -#include <boost/random.hpp> #include <set> #include <unordered_map> #include <unordered_set> @@ -46,11 +44,7 @@ namespace GpgFrontend::Module { class GlobalModuleContext::Impl { public: - explicit Impl() - : random_gen_( - (boost::posix_time::microsec_clock::universal_time() - - boost::posix_time::ptime(boost::gregorian::date(1970, 1, 1))) - .total_milliseconds()) { + explicit Impl() { // Initialize acquired channels with default values. acquired_channel_.insert(kGpgFrontendDefaultChannel); acquired_channel_.insert(kGpgFrontendNonAsciiChannel); @@ -299,16 +293,13 @@ class GlobalModuleContext::Impl { module_events_table_; std::set<int> acquired_channel_; - boost::random::mt19937 random_gen_; TaskRunnerPtr default_task_runner_; auto acquire_new_unique_channel() -> int { - boost::random::uniform_int_distribution<> dist(1, 65535); - - int random_channel = dist(random_gen_); + int random_channel = QRandomGenerator::global()->bounded(65535); // Ensure the acquired channel is unique. while (acquired_channel_.find(random_channel) != acquired_channel_.end()) { - random_channel = dist(random_gen_); + random_channel = QRandomGenerator::global()->bounded(65535); } // Add the acquired channel to the set. diff --git a/src/core/thread/Task.cpp b/src/core/thread/Task.cpp index 459fb55a..ae6b6760 100644 --- a/src/core/thread/Task.cpp +++ b/src/core/thread/Task.cpp @@ -30,10 +30,6 @@ #include <qscopedpointer.h> -#include <boost/stacktrace.hpp> -#include <boost/uuid/uuid.hpp> -#include <boost/uuid/uuid_generators.hpp> -#include <boost/uuid/uuid_io.hpp> #include <utility> #include "utils/MemoryUtils.h" @@ -154,9 +150,6 @@ class Task::Impl { GF_CORE_LOG_TRACE("task {} was end.", GetFullID()); } catch (std::exception &e) { GF_CORE_LOG_ERROR("exception was caught at task: {}", e.what()); - GF_CORE_LOG_ERROR( - "stacktrace of the exception: {}", - boost::stacktrace::to_string(boost::stacktrace::stacktrace())); } // raise signal to anounce after runnable returned if (parent_->autoDelete()) emit parent_->SignalTaskShouldEnd(rtn_); @@ -248,18 +241,12 @@ class Task::Impl { #ifdef RELEASE } catch (std::exception &e) { GF_CORE_LOG_ERROR("exception was caught at task callback: {}", e.what()); - GF_CORE_LOG_ERROR( - "stacktrace of the exception: {}", - boost::stacktrace::to_string(boost::stacktrace::stacktrace())); // raise signal, announcing this task comes to an end GF_CORE_LOG_TRACE("for task {}, its life comes to an end at chaos.", GetFullID()); emit parent_->SignalTaskEnd(); } catch (...) { GF_CORE_LOG_ERROR("unknown exception was caught"); - GF_CORE_LOG_ERROR( - "stacktrace of the exception: {}", - boost::stacktrace::to_string(boost::stacktrace::stacktrace())); // raise signal, announcing this task comes to an end GF_CORE_LOG_TRACE( "for task {}, its life comes to an end at unknown chaos.", diff --git a/src/core/utils/CommonUtils.cpp b/src/core/utils/CommonUtils.cpp index 0e6eaf64..0b182241 100644 --- a/src/core/utils/CommonUtils.cpp +++ b/src/core/utils/CommonUtils.cpp @@ -28,17 +28,15 @@ #include "CommonUtils.h" -#include <boost/algorithm/string.hpp> -#include <boost/lexical_cast.hpp> - namespace GpgFrontend { auto BeautifyFingerprint(QString fingerprint) -> QString { auto len = fingerprint.size(); - QTextStream out; + QString buffer; + QTextStream out(&buffer); decltype(len) count = 0; while (count < len) { - if ((count != 0U) && !(count % 5)) out << " "; + if ((count != 0U) && ((count % 5) == 0)) out << " "; out << fingerprint[count]; count++; } diff --git a/src/core/utils/FilesystemUtils.cpp b/src/core/utils/FilesystemUtils.cpp index 0d878759..9e531955 100644 --- a/src/core/utils/FilesystemUtils.cpp +++ b/src/core/utils/FilesystemUtils.cpp @@ -32,36 +32,27 @@ namespace GpgFrontend { auto GetOnlyFileNameWithPath(const QString &path) -> QString { // Create a path object from given string - std::filesystem::path path_obj(path.toStdString()); + QFileInfo file_info(path); // Check if file name in the path object has extension - if (path_obj.has_filename()) { + if (!file_info.fileName().isEmpty()) { // Fetch the extension from path object and return - return (path_obj.parent_path() / path_obj.stem()).c_str(); + return file_info.path() + "/" + file_info.baseName(); } // In case of no extension return empty string return {}; } auto GetFileExtension(const QString &path) -> QString { - // Create a path object from given string - std::filesystem::path path_obj(path.toStdString()); - - // Check if file name in the path object has extension - if (path_obj.has_extension()) { - // Fetch the extension from path object and return - return path_obj.extension().c_str(); - } - // In case of no extension return empty string - return {}; + return QFileInfo(path).suffix(); } /** * @brief * */ -auto GetFileSizeByPath(const std::filesystem::path &path, - const QString &filename_pattern) -> int64_t { - auto dir = QDir(QString::fromStdString(path.u8string())); +auto GetFileSizeByPath(const QString &path, const QString &filename_pattern) + -> int64_t { + auto dir = QDir(path); QFileInfoList const file_list = dir.entryInfoList(QStringList() << filename_pattern, QDir::Files); qint64 total_size = 0; @@ -98,9 +89,9 @@ auto GetHumanFriendlyFileSize(int64_t size) -> QString { * @brief * */ -void DeleteAllFilesByPattern(const std::filesystem::path &path, +void DeleteAllFilesByPattern(const QString &path, const QString &filename_pattern) { - auto dir = QDir(QString::fromStdString(path.u8string())); + auto dir = QDir(path); QStringList const log_files = dir.entryList(QStringList() << filename_pattern, QDir::Files); diff --git a/src/core/utils/FilesystemUtils.h b/src/core/utils/FilesystemUtils.h index addd37ac..0b58bbb7 100644 --- a/src/core/utils/FilesystemUtils.h +++ b/src/core/utils/FilesystemUtils.h @@ -55,7 +55,7 @@ auto GPGFRONTEND_CORE_EXPORT GetOnlyFileNameWithPath(const QString& path) * @return int64_t */ auto GPGFRONTEND_CORE_EXPORT GetFileSizeByPath( - const std::filesystem::path& path, const QString& filename_pattern) + const QString& path, const QString& filename_pattern) -> int64_t; /** @@ -73,6 +73,6 @@ auto GPGFRONTEND_CORE_EXPORT GetHumanFriendlyFileSize(int64_t size) -> QString; * @param filename_pattern */ void GPGFRONTEND_CORE_EXPORT DeleteAllFilesByPattern( - const std::filesystem::path& path, const QString& filename_pattern); + const QString& path, const QString& filename_pattern); } // namespace GpgFrontend
\ No newline at end of file diff --git a/src/core/utils/GpgUtils.cpp b/src/core/utils/GpgUtils.cpp index 7ee78a31..75a412e7 100644 --- a/src/core/utils/GpgUtils.cpp +++ b/src/core/utils/GpgUtils.cpp @@ -28,8 +28,6 @@ #include "GpgUtils.h" -#include <boost/algorithm/string.hpp> - namespace GpgFrontend { inline auto Trim(QString& s) -> QString { return s.trimmed(); } @@ -88,12 +86,9 @@ auto CheckGpgError(GpgError err, const QString& /*comment*/) -> GpgError { } auto TextIsSigned(QString text) -> int { - using boost::algorithm::ends_with; - using boost::algorithm::starts_with; - auto trim_text = Trim(text); - if (starts_with(trim_text, PGP_SIGNED_BEGIN) && - ends_with(trim_text, PGP_SIGNED_END)) { + if (trim_text.startsWith(PGP_SIGNED_BEGIN) && + trim_text.endsWith(PGP_SIGNED_END)) { return 2; } if (text.contains(PGP_SIGNED_BEGIN) && text.contains(PGP_SIGNED_END)) { diff --git a/src/core/utils/GpgUtils.h b/src/core/utils/GpgUtils.h index 328de031..e6a466dc 100644 --- a/src/core/utils/GpgUtils.h +++ b/src/core/utils/GpgUtils.h @@ -88,7 +88,7 @@ auto GPGFRONTEND_CORE_EXPORT TextIsSigned(BypeArrayRef text) -> int; * * @param opera * @param ascii - * @return std::filesystem::path + * @return QString */ auto GPGFRONTEND_CORE_EXPORT SetExtensionOfOutputFile(const QString& path, GpgOperation opera, @@ -100,7 +100,7 @@ auto GPGFRONTEND_CORE_EXPORT SetExtensionOfOutputFile(const QString& path, * @param path * @param opera * @param ascii - * @return std::filesystem::path + * @return QString */ auto GPGFRONTEND_CORE_EXPORT SetExtensionOfOutputFileForArchive( const QString& path, GpgOperation opera, bool ascii) -> QString; diff --git a/src/core/utils/IOUtils.cpp b/src/core/utils/IOUtils.cpp index fc667cb4..0eefe894 100644 --- a/src/core/utils/IOUtils.cpp +++ b/src/core/utils/IOUtils.cpp @@ -28,12 +28,7 @@ #include "IOUtils.h" -#include <boost/uuid/uuid.hpp> -#include <boost/uuid/uuid_generators.hpp> -#include <boost/uuid/uuid_io.hpp> -#include <sstream> - -#include "GpgModel.h" +#include "core/GpgModel.h" namespace GpgFrontend { @@ -51,7 +46,7 @@ auto ReadFile(const QString& file_name, QByteArray& data) -> bool { auto WriteFile(const QString& file_name, const QByteArray& data) -> bool { QFile file(file_name); if (!file.open(QIODevice::WriteOnly)) { - GF_CORE_LOG_ERROR("failed to open file: {}", file_name); + GF_CORE_LOG_ERROR("failed to open file for writing: {}", file_name); return false; } file.write(data); diff --git a/src/init.cpp b/src/init.cpp index 1b453cad..e82bccd1 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -30,7 +30,6 @@ #include <qcoreapplication.h> -#include <boost/date_time.hpp> #include <filesystem> #include <string> @@ -111,7 +110,7 @@ void InitGlobalBasicalEnv(const GFCxtWPtr &p_ctx, bool gui_mode) { // change path to search for related InitGlobalPathEnv(); - ctx->InitApplication(gui_mode); + ctx->InitApplication(); // should load module system first Module::ModuleInitArgs module_init_args; diff --git a/src/main.cpp b/src/main.cpp index 92ef55ee..700e304e 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -30,11 +30,7 @@ * \mainpage GpgFrontend Develop Document Main Page */ -#include <cstddef> -#include <cstdlib> -#include <iostream> #include <memory> -#include <string> #include "GpgFrontendContext.h" #include "app.h" @@ -42,8 +38,6 @@ #include "core/utils/MemoryUtils.h" #include "init.h" -namespace po = boost::program_options; - /** * * @param argc @@ -61,43 +55,36 @@ auto main(int argc, char* argv[]) -> int { GpgFrontend::GFCxtSPtr ctx = GpgFrontend::SecureCreateSharedObject<GpgFrontend::GpgFrontendContext>( argc, argv); + ctx->InitApplication(); + auto rtn = 0; // initialize qt resources Q_INIT_RESOURCE(gpgfrontend); - po::options_description desc("Allowed options"); + QCommandLineParser parser; + parser.addHelpOption(); + parser.addOptions({ + {{"v", "version"}, "show version information"}, + {{"t", "test"}, "run all unit test cases"}, + {{"l", "log-level"}, + "set log level (trace, debug, info, warn, error)", + "debug"}, + }); - desc.add_options()("help,h", "produce help message")( - "version,v", "show version information")( - "log-level,l", po::value<std::string>()->default_value("info"), - "set log level (trace, debug, info, warn, error)")( - "test,t", "run all unit test cases"); - - po::variables_map vm; - po::store(po::parse_command_line(argc, argv, desc), vm); - po::notify(vm); + parser.process(*ctx->GetApp()); ctx->log_level = spdlog::level::info; - if (vm.count("help") != 0U) { - std::cout << desc << "\n"; - return 0; - } - - if (vm.count("version") != 0U) { + if (parser.isSet("v")) { return GpgFrontend::PrintVersion(); } - if (vm.count("log-level") != 0U) { - ctx->log_level = GpgFrontend::ParseLogLevel(vm); - } - - if (vm.count("log-level") != 0U) { - ctx->log_level = GpgFrontend::ParseLogLevel(vm); + if (parser.isSet("l")) { + ctx->log_level = GpgFrontend::ParseLogLevel(parser.value("l")); } - if (vm.count("test") != 0U) { + if (parser.isSet("t")) { ctx->gather_external_gnupg_info = false; ctx->load_default_gpg_context = false; diff --git a/src/module/integrated/gnupg_info_gathering_module/GnuPGInfoGatheringModule.cpp b/src/module/integrated/gnupg_info_gathering_module/GnuPGInfoGatheringModule.cpp index 9f9216ac..c7b87b5b 100644 --- a/src/module/integrated/gnupg_info_gathering_module/GnuPGInfoGatheringModule.cpp +++ b/src/module/integrated/gnupg_info_gathering_module/GnuPGInfoGatheringModule.cpp @@ -28,8 +28,6 @@ #include "GnuPGInfoGatheringModule.h" -#include <boost/algorithm/string.hpp> -#include <boost/format/format_fwd.hpp> #include <nlohmann/json.hpp> #include <string> #include <vector> @@ -114,8 +112,8 @@ auto GnuPGInfoGatheringModule::Exec(EventRefrernce event) -> int { if (exit_code != 0) { MODULE_LOG_ERROR( - "gpgconf execute error, process stderr: {} ,process stdout: " - "{}", + "gpgconf execute error, process stderr: {}, " + "process stdout: {}", p_err, p_out); return; } @@ -343,7 +341,7 @@ auto GnuPGInfoGatheringModule::Exec(EventRefrernce event) -> int { nlohmann::json const jsonlized_option_info = info; UpsertRTValue(GetModuleIdentifier(), - QString("gnupg.components.%1%.options.%2%") + QString("gnupg.components.%1.options.%2") .arg(component_info.name.c_str()) .arg(option_name), QString::fromStdString(static_cast<std::string>( diff --git a/src/test/GpgFrontendTest.cpp b/src/test/GpgFrontendTest.cpp index b7f59336..34698863 100644 --- a/src/test/GpgFrontendTest.cpp +++ b/src/test/GpgFrontendTest.cpp @@ -30,10 +30,6 @@ #include <gtest/gtest.h> -#include <boost/date_time.hpp> -#include <boost/dll.hpp> -#include <filesystem> - #include "core/GpgConstants.h" #include "core/function/GlobalSettingStation.h" #include "core/function/basic/ChannelObject.h" @@ -64,7 +60,7 @@ void ConfigureGpgContext() { db_path.path()); if (db_path.exists()) db_path.rmdir("."); - db_path.mkdir("."); + db_path.mkpath("."); GpgContext::CreateInstance( kGpgFrontendDefaultChannel, [=]() -> ChannelObjectPtr { @@ -103,18 +99,18 @@ void ImportPrivateKeys(const QString& data_path, void SetupGlobalTestEnv() { auto app_path = GlobalSettingStation::GetInstance().GetAppDir(); - auto test_path = app_path / "test"; - auto test_config_path = test_path / "conf" / "test.cfg"; - auto test_data_path = test_path / "data"; + auto test_path = app_path + "/test"; + auto test_config_path = test_path + "/conf/test.cfg"; + auto test_data_path = test_path + "/data"; - GF_TEST_LOG_INFO("test config file path: {}", test_config_path.string()); - GF_TEST_LOG_INFO("test data file path: {}", test_data_path.string()); + GF_TEST_LOG_INFO("test config file path: {}", test_config_path); + GF_TEST_LOG_INFO("test data file path: {}", test_data_path); libconfig::Config cfg; - ASSERT_NO_THROW(cfg.readFile(test_config_path.c_str())); + ASSERT_NO_THROW(cfg.readFile(test_config_path.toUtf8())); auto& root = cfg.getRoot(); - ImportPrivateKeys(test_data_path.c_str(), root); + ImportPrivateKeys(test_data_path, root); } auto ExecuteAllTestCase(GpgFrontendContext args) -> int { diff --git a/src/test/core/GpgCoreTest.h b/src/test/core/GpgCoreTest.h index b436118a..26097f2c 100644 --- a/src/test/core/GpgCoreTest.h +++ b/src/test/core/GpgCoreTest.h @@ -30,8 +30,6 @@ #include <gtest/gtest.h> -#include <boost/date_time.hpp> - namespace GpgFrontend::Test { class GpgCoreTest : public ::testing::Test { diff --git a/src/test/core/GpgCoreTestFileBasicOpera.cpp b/src/test/core/GpgCoreTestFileBasicOpera.cpp index e409570f..029ff6fc 100644 --- a/src/test/core/GpgCoreTestFileBasicOpera.cpp +++ b/src/test/core/GpgCoreTestFileBasicOpera.cpp @@ -51,7 +51,7 @@ TEST_F(GpgCoreTest, CoreFileEncryptDecrTest) { auto output_file = GetTempFilePath(); GpgFileOpera::GetInstance().EncryptFile( - {encrypt_key}, input_file.toStdString(), true, output_file.toStdString(), + {encrypt_key}, input_file, true, output_file, [output_file, &callback_called_flag](GpgError err, const DataObjectPtr& data_obj) { ASSERT_TRUE((data_obj->Check<GpgEncryptResult>())); @@ -62,7 +62,7 @@ TEST_F(GpgCoreTest, CoreFileEncryptDecrTest) { auto decrpypt_output_file = GetTempFilePath(); GpgFileOpera::GetInstance().DecryptFile( - output_file.toStdString(), decrpypt_output_file.toStdString(), + output_file, decrpypt_output_file, [decrpypt_output_file, &callback_called_flag]( GpgError err, const DataObjectPtr& data_obj) { auto d_result = ExtractParams<GpgDecryptResult>(data_obj, 0); @@ -96,7 +96,7 @@ TEST_F(GpgCoreTest, CoreFileEncryptSymmetricDecrTest) { auto output_file = GetTempFilePath(); GpgFileOpera::GetInstance().EncryptFileSymmetric( - input_file.toStdString(), true, output_file.toStdString(), + input_file, true, output_file, [&callback_called_flag, output_file](GpgError err, const DataObjectPtr& data_obj) { ASSERT_TRUE((data_obj->Check<GpgEncryptResult>())); @@ -106,7 +106,7 @@ TEST_F(GpgCoreTest, CoreFileEncryptSymmetricDecrTest) { auto decrpypt_output_file = GetTempFilePath(); GpgFileOpera::GetInstance().DecryptFile( - output_file.toStdString(), decrpypt_output_file.toStdString(), + output_file, decrpypt_output_file, [&callback_called_flag, decrpypt_output_file]( GpgError err, const DataObjectPtr& data_obj) { ASSERT_TRUE((data_obj->Check<GpgDecryptResult>())); @@ -143,7 +143,7 @@ TEST_F(GpgCoreTest, CoreFileSignVerifyNormalTest) { auto output_file = GetTempFilePath(); GpgFileOpera::GetInstance().SignFile( - {sign_key}, input_file.toStdString(), true, output_file.toStdString(), + {sign_key}, input_file, true, output_file, [&callback_called_flag, input_file, output_file]( GpgError err, const DataObjectPtr& data_obj) { ASSERT_TRUE((data_obj->Check<GpgSignResult>())); @@ -152,7 +152,7 @@ TEST_F(GpgCoreTest, CoreFileSignVerifyNormalTest) { ASSERT_EQ(CheckGpgError(err), GPG_ERR_NO_ERROR); GpgFileOpera::GetInstance().VerifyFile( - input_file.toStdString(), output_file.toStdString(), + input_file, output_file, [&callback_called_flag](GpgError err, const DataObjectPtr& data_obj) { auto d_result = ExtractParams<GpgVerifyResult>(data_obj, 0); @@ -188,8 +188,7 @@ TEST_F(GpgCoreTest, CoreFileEncryptSignDecrVerifyTest) { ASSERT_TRUE(sign_key.IsHasActualSigningCapability()); GpgFileOpera::GetInstance().EncryptSignFile( - {encrypt_key}, {sign_key}, input_file.toStdString(), true, - output_file.toStdString(), + {encrypt_key}, {sign_key}, input_file, true, output_file, [&callback_called_flag, output_file](GpgError err, const DataObjectPtr& data_obj) { ASSERT_TRUE((data_obj->Check<GpgEncryptResult, GpgSignResult>())); @@ -201,7 +200,7 @@ TEST_F(GpgCoreTest, CoreFileEncryptSignDecrVerifyTest) { auto decrpypt_output_file = GetTempFilePath(); GpgFileOpera::GetInstance().DecryptVerifyFile( - output_file.toStdString(), decrpypt_output_file.toStdString(), + output_file, decrpypt_output_file, [&callback_called_flag, decrpypt_output_file]( GpgError err, const DataObjectPtr& data_obj) { ASSERT_TRUE( diff --git a/src/test/core/GpgCoreTestKeyModel.cpp b/src/test/core/GpgCoreTestKeyModel.cpp index 1f3a5292..cf1fd9ea 100644 --- a/src/test/core/GpgCoreTestKeyModel.cpp +++ b/src/test/core/GpgCoreTestKeyModel.cpp @@ -84,18 +84,18 @@ TEST_F(GpgCoreTest, GpgKeyTest) { ASSERT_EQ(key.GetId(), "81704859182661FB"); ASSERT_EQ(key.GetFingerprint(), "9490795B78F8AFE9F93BD09281704859182661FB"); ASSERT_EQ(key.GetExpireTime(), - boost::posix_time::from_iso_string("20230905T040000")); + QDateTime::fromString("20230905T040000", Qt::ISODate)); ASSERT_EQ(key.GetPublicKeyAlgo(), "RSA"); ASSERT_EQ(key.GetPrimaryKeyLength(), 3072); ASSERT_EQ(key.GetLastUpdateTime(), - boost::posix_time::from_iso_string("19700101T000000")); + QDateTime::fromString("19700101T000000", Qt::ISODate)); ASSERT_EQ(key.GetCreateTime(), - boost::posix_time::from_iso_string("20210905T060153")); + QDateTime::fromString("20210905T060153", Qt::ISODate)); ASSERT_EQ(key.GetOwnerTrust(), "Unknown"); - ASSERT_EQ(key.IsExpired(), key.GetExpireTime() < - boost::posix_time::second_clock::local_time()); + ASSERT_EQ(key.IsExpired(), + key.GetExpireTime() < QDateTime::currentDateTime()); } TEST_F(GpgCoreTest, GpgSubKeyTest) { @@ -109,7 +109,7 @@ TEST_F(GpgCoreTest, GpgSubKeyTest) { ASSERT_FALSE(sub_key.IsRevoked()); ASSERT_FALSE(sub_key.IsDisabled()); ASSERT_EQ(sub_key.GetCreateTime(), - boost::posix_time::from_iso_string("20210905T060153")); + QDateTime::fromString("20210905T060153", Qt::ISODate)); ASSERT_FALSE(sub_key.IsCardKey()); ASSERT_TRUE(sub_key.IsPrivateKey()); @@ -123,11 +123,10 @@ TEST_F(GpgCoreTest, GpgSubKeyTest) { ASSERT_FALSE(sub_key.IsHasSigningCapability()); ASSERT_TRUE(sub_key.IsHasEncryptionCapability()); ASSERT_EQ(key.GetExpireTime(), - boost::posix_time::from_iso_string("20230905T040000")); + QDateTime::fromString("20230905T040000", Qt::ISODate)); - ASSERT_EQ( - sub_key.IsExpired(), - sub_key.GetExpireTime() < boost::posix_time::second_clock::local_time()); + ASSERT_EQ(sub_key.IsExpired(), + sub_key.GetExpireTime() < QDateTime::currentDateTime()); } TEST_F(GpgCoreTest, GpgUIDTest) { diff --git a/src/test/core/GpgCoreTestKeygen.cpp b/src/test/core/GpgCoreTestKeygen.cpp index 93544d85..57e7cbb9 100644 --- a/src/test/core/GpgCoreTestKeygen.cpp +++ b/src/test/core/GpgCoreTestKeygen.cpp @@ -29,6 +29,8 @@ #include <gtest/gtest.h> #include <qeventloop.h> +#include <cstddef> + #include "GpgCoreTest.h" #include "core/function/gpg/GpgKeyGetter.h" #include "core/function/gpg/GpgKeyOpera.h" @@ -92,8 +94,8 @@ TEST_F(GpgCoreTest, GenerateKeyTest_1) { keygen_info->SetAlgo(std::get<1>(keygen_info->GetSupportedKeyAlgo()[0])); keygen_info->SetKeyLength(4096); keygen_info->SetNonExpired(false); - keygen_info->SetExpireTime(boost::posix_time::second_clock::local_time() + - boost::posix_time::hours(24)); + keygen_info->SetExpireTime( + QDateTime::currentDateTime().addSecs(static_cast<qint64>(24 * 3600))); keygen_info->SetNonPassPhrase(false); std::atomic_bool callback_called_flag{false}; diff --git a/src/ui/GpgFrontendApplication.cpp b/src/ui/GpgFrontendApplication.cpp index a4c4e2db..df59d0c6 100644 --- a/src/ui/GpgFrontendApplication.cpp +++ b/src/ui/GpgFrontendApplication.cpp @@ -29,7 +29,6 @@ #include "ui/GpgFrontendApplication.h" #include <QTextCodec> -#include <boost/stacktrace.hpp> #include "GpgFrontendBuildInfo.h" @@ -59,9 +58,6 @@ bool GpgFrontendApplication::notify(QObject *receiver, QEvent *event) { return QApplication::notify(receiver, event); } catch (const std::exception &ex) { GF_UI_LOG_ERROR("exception was caught in notify: {}", ex.what()); - GF_UI_LOG_ERROR( - "stacktrace of the exception: {}", - boost::stacktrace::to_string(boost::stacktrace::stacktrace())); QMessageBox::information(nullptr, _("Standard Exception Thrown"), _("Oops, an standard exception was thrown " "during the running of the " @@ -70,9 +66,6 @@ bool GpgFrontendApplication::notify(QObject *receiver, QEvent *event) { "please report this problem if you can.")); } catch (...) { GF_UI_LOG_ERROR("unknown exception was caught in notify"); - GF_UI_LOG_ERROR( - "stacktrace of the exception: {}", - boost::stacktrace::to_string(boost::stacktrace::stacktrace())); QMessageBox::information( nullptr, _("Unhandled Exception Thrown"), _("Oops, an unhandled exception was thrown " diff --git a/src/ui/GpgFrontendUIInit.cpp b/src/ui/GpgFrontendUIInit.cpp index 5734dc29..900bc948 100644 --- a/src/ui/GpgFrontendUIInit.cpp +++ b/src/ui/GpgFrontendUIInit.cpp @@ -253,10 +253,9 @@ void InitLocale() { GF_UI_LOG_DEBUG("lang from settings: {}", lang); GF_UI_LOG_DEBUG("project name: {}", PROJECT_NAME); - GF_UI_LOG_DEBUG("locales path: {}", - GpgFrontend::GlobalSettingStation::GetInstance() - .GetLocaleDir() - .u8string()); + GF_UI_LOG_DEBUG( + "locales path: {}", + GpgFrontend::GlobalSettingStation::GetInstance().GetLocaleDir()); #ifndef WINDOWS if (!lang.empty()) { @@ -294,10 +293,9 @@ void InitLocale() { } #endif - bindtextdomain(PROJECT_NAME, GpgFrontend::GlobalSettingStation::GetInstance() - .GetLocaleDir() - .u8string() - .c_str()); + bindtextdomain( + PROJECT_NAME, + GpgFrontend::GlobalSettingStation::GetInstance().GetLocaleDir().toUtf8()); bind_textdomain_codeset(PROJECT_NAME, "utf-8"); textdomain(PROJECT_NAME); } diff --git a/src/ui/UserInterfaceUtils.cpp b/src/ui/UserInterfaceUtils.cpp index b6b1fa9e..2c353d19 100644 --- a/src/ui/UserInterfaceUtils.cpp +++ b/src/ui/UserInterfaceUtils.cpp @@ -32,7 +32,6 @@ #include <qdialog.h> #include <QtNetwork> -#include <boost/format/format_fwd.hpp> #include <string> #include <utility> #include <vector> @@ -276,8 +275,8 @@ void CommonUtils::RaiseFailureMessageBox(QWidget *parent, GpgError err) { QMessageBox::critical( parent, _("Failure"), - QString(_("Gpg Operation failed.\n\nError code: %1%\nSource: " - " %2%\nDescription: %3%")) + QString(_("Gpg Operation failed.\n\nError code: %1\nSource: " + " %2\nDescription: %3")) .arg(err_code) .arg(desc.first) .arg(desc.second)); diff --git a/src/ui/dialog/details/VerifyDetailsDialog.cpp b/src/ui/dialog/details/VerifyDetailsDialog.cpp index 00251d4a..ba23b2c6 100644 --- a/src/ui/dialog/details/VerifyDetailsDialog.cpp +++ b/src/ui/dialog/details/VerifyDetailsDialog.cpp @@ -64,8 +64,7 @@ void VerifyDetailsDialog::slot_refresh() { } // Get timestamp of signature of current text - QDateTime timestamp; - timestamp.setSecsSinceEpoch(to_time_t(signatures[0].GetCreateTime())); + QDateTime timestamp = signatures[0].GetCreateTime(); // Set the title widget depending on sign status if (gpg_err_code(signatures[0].GetStatus()) == GPG_ERR_BAD_SIGNATURE) { @@ -77,7 +76,7 @@ void VerifyDetailsDialog::slot_refresh() { m_vbox_layout->addWidget(new QLabel(info)); } else { const auto info = - QString(_("Signed on %1%")).arg(QLocale::system().toString(timestamp)) + + QString(_("Signed on %1")).arg(QLocale::system().toString(timestamp)) + "<br/>" + _("It Contains") + ": " + "<br/><br/>"; m_vbox_layout->addWidget(new QLabel(info)); } diff --git a/src/ui/dialog/help/AboutDialog.cpp b/src/ui/dialog/help/AboutDialog.cpp index e38777f3..6f8dedc2 100644 --- a/src/ui/dialog/help/AboutDialog.cpp +++ b/src/ui/dialog/help/AboutDialog.cpp @@ -121,10 +121,8 @@ InfoTab::InfoTab(QWidget* parent) : QWidget(parent) { } TranslatorsTab::TranslatorsTab(QWidget* parent) : QWidget(parent) { - QFile translators_qfile; - auto translators_file = - GlobalSettingStation::GetInstance().GetResourceDir() / "TRANSLATORS"; - translators_qfile.setFileName(translators_file); + QFile translators_qfile(GlobalSettingStation::GetInstance().GetResourceDir() + + "/TRANSLATORS"); #ifdef LINUX if (!translators_qfile.exists()) { translators_qfile.setFileName("/usr/local/share/GpgFrontend/TRANSLATORS"); @@ -143,8 +141,7 @@ TranslatorsTab::TranslatorsTab(QWidget* parent) : QWidget(parent) { auto* notice_label = new QLabel( _("If you think there are any problems with the translation, why not " "participate in the translation work? If you want to participate, " - "please " - "read the document or contact me via email."), + "please read the document or contact me via email."), this); notice_label->setWordWrap(true); main_layout->addWidget(notice_label); diff --git a/src/ui/dialog/help/GnupgTab.cpp b/src/ui/dialog/help/GnupgTab.cpp index ed47c38c..9749877f 100644 --- a/src/ui/dialog/help/GnupgTab.cpp +++ b/src/ui/dialog/help/GnupgTab.cpp @@ -101,7 +101,7 @@ void GpgFrontend::UI::GnupgTab::process_software_info() { for (auto& component : components) { auto component_info_json = Module::RetrieveRTValueTypedOrDefault( "com.bktus.gpgfrontend.module.integrated.gnupg-info-gathering", - QString("gnupg.components.%1%").arg(component), QString{}); + QString("gnupg.components.%1").arg(component), QString{}); GF_UI_LOG_DEBUG("got gnupg component {} info from rt, info: {}", component, component_info_json); @@ -148,12 +148,12 @@ void GpgFrontend::UI::GnupgTab::process_software_info() { for (auto& component : components) { auto options = Module::ListRTChildKeys( "com.bktus.gpgfrontend.module.integrated.gnupg-info-gathering", - QString("gnupg.components.%1%.options").arg(component)); + QString("gnupg.components.%1.options").arg(component)); for (auto& option : options) { const auto option_info = nlohmann::json::parse( Module::RetrieveRTValueTypedOrDefault( "com.bktus.gpgfrontend.module.integrated.gnupg-info-gathering", - QString("gnupg.components.%1%.options.%2%") + QString("gnupg.components.%1.options.%2") .arg(component) .arg(option), QString{}) @@ -172,12 +172,12 @@ void GpgFrontend::UI::GnupgTab::process_software_info() { for (auto& component : components) { auto options = Module::ListRTChildKeys( "com.bktus.gpgfrontend.module.integrated.gnupg-info-gathering", - QString("gnupg.components.%1%.options").arg(component)); + QString("gnupg.components.%1.options").arg(component)); for (auto& option : options) { auto option_info_json = Module::RetrieveRTValueTypedOrDefault( "com.bktus.gpgfrontend.module.integrated.gnupg-info-gathering", - QString("gnupg.components.%1%.options.%2%") + QString("gnupg.components.%1.options.%2") .arg(component) .arg(option), QString{}); diff --git a/src/ui/dialog/import_export/ExportKeyPackageDialog.cpp b/src/ui/dialog/import_export/ExportKeyPackageDialog.cpp index 62631905..2883d486 100644 --- a/src/ui/dialog/import_export/ExportKeyPackageDialog.cpp +++ b/src/ui/dialog/import_export/ExportKeyPackageDialog.cpp @@ -67,8 +67,7 @@ GpgFrontend::UI::ExportKeyPackageDialog::ExportKeyPackageDialog( // check path if (file_name.isEmpty()) return; - if (!KeyPackageOperator::GeneratePassphrase(file_name.toStdString(), - passphrase_)) { + if (!KeyPackageOperator::GeneratePassphrase(file_name, passphrase_)) { QMessageBox::critical( this, _("Error"), _("An error occurred while generating the passphrase file.")); @@ -111,9 +110,8 @@ GpgFrontend::UI::ExportKeyPackageDialog::ExportKeyPackageDialog( CommonUtils::WaitForOpera( this, _("Generating"), [this, keys](const OperaWaitingHd& op_hd) { KeyPackageOperator::GenerateKeyPackage( - ui_->outputPathLabel->text().toStdString(), - ui_->nameValueLabel->text(), *keys, passphrase_, - ui_->includeSecretKeyCheckBox->isChecked(), + ui_->outputPathLabel->text(), ui_->nameValueLabel->text(), *keys, + passphrase_, ui_->includeSecretKeyCheckBox->isChecked(), [=](GFError err, const DataObjectPtr&) { // stop waiting op_hd(); diff --git a/src/ui/dialog/key_generate/KeygenDialog.cpp b/src/ui/dialog/key_generate/KeygenDialog.cpp index 27281b3c..893ebb54 100644 --- a/src/ui/dialog/key_generate/KeygenDialog.cpp +++ b/src/ui/dialog/key_generate/KeygenDialog.cpp @@ -134,21 +134,10 @@ void KeyGenDialog::slot_key_gen_accept() { gen_key_info_->SetNonExpired(true); if (gen_subkey_info_ != nullptr) gen_subkey_info_->SetNonExpired(true); } else { -#ifdef GPGFRONTEND_GUI_QT6 - gen_key_info_->SetExpireTime(boost::posix_time::from_time_t( - date_edit_->dateTime().toSecsSinceEpoch())); + gen_key_info_->SetExpireTime(date_edit_->dateTime()); if (gen_subkey_info_ != nullptr) { - gen_subkey_info_->SetExpireTime(boost::posix_time::from_time_t( - date_edit_->dateTime().toSecsSinceEpoch())); + gen_subkey_info_->SetExpireTime(date_edit_->dateTime()); } -#else - gen_key_info_->SetExpireTime( - boost::posix_time::from_time_t(date_edit_->dateTime().toTime_t())); - if (gen_subkey_info_ != nullptr) { - gen_subkey_info_->SetExpireTime( - boost::posix_time::from_time_t(date_edit_->dateTime().toTime_t())); - } -#endif } CommonUtils::WaitForOpera( diff --git a/src/ui/dialog/key_generate/SubkeyGenerateDialog.cpp b/src/ui/dialog/key_generate/SubkeyGenerateDialog.cpp index 2d995255..9af2c0e9 100644 --- a/src/ui/dialog/key_generate/SubkeyGenerateDialog.cpp +++ b/src/ui/dialog/key_generate/SubkeyGenerateDialog.cpp @@ -28,7 +28,6 @@ #include "SubkeyGenerateDialog.h" -#include <boost/format/format_fwd.hpp> #include <cassert> #include <cstddef> @@ -280,13 +279,7 @@ void SubkeyGenerateDialog::slot_key_gen_accept() { if (expire_check_box_->checkState() != 0U) { gen_key_info_->SetNonExpired(true); } else { -#ifdef GPGFRONTEND_GUI_QT6 - gen_key_info_->SetExpireTime(boost::posix_time::from_time_t( - date_edit_->dateTime().toSecsSinceEpoch())); -#else - gen_key_info_->SetExpireTime( - boost::posix_time::from_time_t(date_edit_->dateTime().toTime_t())); -#endif + gen_key_info_->SetExpireTime(date_edit_->dateTime()); } CommonUtils::WaitForOpera( diff --git a/src/ui/dialog/keypair_details/KeyPairDetailTab.cpp b/src/ui/dialog/keypair_details/KeyPairDetailTab.cpp index 2770f9af..5863dfe9 100644 --- a/src/ui/dialog/keypair_details/KeyPairDetailTab.cpp +++ b/src/ui/dialog/keypair_details/KeyPairDetailTab.cpp @@ -242,38 +242,22 @@ void KeyPairDetailTab::slot_refresh_key_info() { key_size_val = QString::number(key_.GetPrimaryKeyLength()); - if (to_time_t(boost::posix_time::ptime(key_.GetExpireTime())) == 0) { + if (key_.GetExpireTime().toSecsSinceEpoch() == 0) { expire_var_label_->setText(_("Never Expire")); } else { -#ifdef GPGFRONTEND_GUI_QT6 - expire_var_label_->setText(QLocale::system().toString( - QDateTime::fromSecsSinceEpoch(to_time_t(key_.GetExpireTime())))); -#else - expire_var_label_->setText(QLocale::system().toString( - QDateTime::fromTime_t(to_time_t(key_.GetExpireTime())))); -#endif + expire_var_label_->setText( + QLocale::system().toString((key_.GetExpireTime()))); } key_algo_val = key_.GetPublicKeyAlgo(); -#ifdef GPGFRONTEND_GUI_QT6 - created_var_label_->setText(QLocale::system().toString( - QDateTime::fromSecsSinceEpoch(to_time_t(key_.GetCreateTime())))); -#else - created_var_label_->setText(QLocale::system().toString( - QDateTime::fromTime_t(to_time_t(key_.GetCreateTime())))); -#endif + created_var_label_->setText(QLocale::system().toString(key_.GetCreateTime())); - if (to_time_t(boost::posix_time::ptime(key_.GetLastUpdateTime())) == 0) { + if (key_.GetLastUpdateTime().toSecsSinceEpoch() == 0) { last_update_var_label_->setText(_("No Data")); } else { -#ifdef GPGFRONTEND_GUI_QT6 - last_update_var_label_->setText(QLocale::system().toString( - QDateTime::fromSecsSinceEpoch(to_time_t(key_.GetLastUpdateTime())))); -#else - last_update_var_label_->setText(QLocale::system().toString( - QDateTime::fromTime_t(to_time_t(key_.GetLastUpdateTime())))); -#endif + last_update_var_label_->setText( + QLocale::system().toString(key_.GetLastUpdateTime())); } key_size_var_label_->setText(key_size_val); diff --git a/src/ui/dialog/keypair_details/KeyPairSubkeyTab.cpp b/src/ui/dialog/keypair_details/KeyPairSubkeyTab.cpp index 3281d0b8..71d2d9fe 100644 --- a/src/ui/dialog/keypair_details/KeyPairSubkeyTab.cpp +++ b/src/ui/dialog/keypair_details/KeyPairSubkeyTab.cpp @@ -157,8 +157,8 @@ void KeyPairSubkeyTab::create_subkey_list() { subkey_list_->setAlternatingRowColors(true); QStringList labels; - labels << _("Subkey ID") << _("Key Size") << _("Algo") - << _("Create Date (UTC)") << _("Expire Date (UTC)"); + labels << _("Subkey ID") << _("Key Size") << _("Algo") << _("Create Date") + << _("Expire Date"); subkey_list_->setHorizontalHeaderLabels(labels); subkey_list_->horizontalHeader()->setStretchLastSection(false); @@ -194,16 +194,14 @@ void KeyPairSubkeyTab::slot_refresh_subkey_list() { tmp2->setTextAlignment(Qt::AlignCenter); subkey_list_->setItem(row, 2, tmp2); - auto* tmp3 = new QTableWidgetItem( - QString::fromStdString(to_iso_string(subkeys.GetCreateTime()))); + auto* tmp3 = new QTableWidgetItem(subkeys.GetCreateTime().toString()); tmp3->setTextAlignment(Qt::AlignCenter); subkey_list_->setItem(row, 3, tmp3); - auto* tmp4 = new QTableWidgetItem( - boost::posix_time::to_time_t( - boost::posix_time::ptime(subkeys.GetExpireTime())) == 0 - ? _("Never Expire") - : QString::fromStdString(to_iso_string(subkeys.GetExpireTime()))); + auto* tmp4 = + new QTableWidgetItem(subkeys.GetExpireTime().toSecsSinceEpoch() == 0 + ? _("Never Expire") + : subkeys.GetExpireTime().toString()); tmp4->setTextAlignment(Qt::AlignCenter); subkey_list_->setItem(row, 4, tmp4); @@ -236,17 +234,14 @@ void KeyPairSubkeyTab::slot_refresh_subkey_detail() { key_id_var_label_->setText(subkey.GetID()); key_size_var_label_->setText(QString::number(subkey.GetKeyLength())); - time_t subkey_time_t = boost::posix_time::to_time_t( - boost::posix_time::ptime(subkey.GetExpireTime())); + time_t subkey_time_t = subkey.GetExpireTime().toSecsSinceEpoch(); expire_var_label_->setText( - subkey_time_t == 0 - ? _("Never Expires") - : QLocale::system().toString(QDateTime::fromSecsSinceEpoch( - to_time_t(subkey.GetExpireTime())))); + subkey_time_t == 0 ? _("Never Expires") + : QLocale::system().toString(subkey.GetExpireTime())); if (subkey_time_t != 0 && - subkey.GetExpireTime() < boost::posix_time::second_clock::local_time()) { + subkey.GetExpireTime() < QDateTime::currentDateTime()) { auto palette_expired = expire_var_label_->palette(); palette_expired.setColor(expire_var_label_->foregroundRole(), Qt::red); expire_var_label_->setPalette(palette_expired); @@ -257,8 +252,8 @@ void KeyPairSubkeyTab::slot_refresh_subkey_detail() { } algorithm_var_label_->setText(subkey.GetPubkeyAlgo()); - created_var_label_->setText(QLocale::system().toString( - QDateTime::fromSecsSinceEpoch(to_time_t(subkey.GetCreateTime())))); + created_var_label_->setText( + QLocale::system().toString(subkey.GetCreateTime())); std::stringstream usage_steam; @@ -328,7 +323,7 @@ void KeyPairSubkeyTab::contextMenuEvent(QContextMenuEvent* event) { } } -const GpgSubKey& KeyPairSubkeyTab::get_selected_subkey() { +auto KeyPairSubkeyTab::get_selected_subkey() -> const GpgSubKey& { int row = 0; for (int i = 0; i < subkey_list_->rowCount(); i++) { diff --git a/src/ui/dialog/keypair_details/KeyPairUIDTab.cpp b/src/ui/dialog/keypair_details/KeyPairUIDTab.cpp index a39d87fc..00310c34 100644 --- a/src/ui/dialog/keypair_details/KeyPairUIDTab.cpp +++ b/src/ui/dialog/keypair_details/KeyPairUIDTab.cpp @@ -160,8 +160,8 @@ void KeyPairUIDTab::create_sign_list() { sig_list_->setAlternatingRowColors(true); QStringList labels; - labels << _("Key ID") << _("Name") << _("Email") << _("Create Date (UTC)") - << _("Expired Date (UTC)"); + labels << _("Key ID") << _("Name") << _("Email") << _("Create Date") + << _("Expired Date"); sig_list_->setHorizontalHeaderLabels(labels); sig_list_->horizontalHeader()->setStretchLastSection(false); } @@ -220,11 +220,11 @@ void KeyPairUIDTab::slot_refresh_uid_list() { void KeyPairUIDTab::slot_refresh_tofu_info() { if (this->tofu_tabs_ == nullptr) return; - int uidRow = 0; + int uid_row = 0; tofu_tabs_->clear(); for (const auto& uid : buffered_uids_) { // Only Show Selected UID Signatures - if (!uid_list_->item(uidRow++, 0)->isSelected()) { + if (!uid_list_->item(uid_row++, 0)->isSelected()) { continue; } auto tofu_infos = uid.GetTofuInfos(); @@ -279,29 +279,14 @@ void KeyPairUIDTab::slot_refresh_sig_list() { auto* tmp3 = new QTableWidgetItem(sig.GetEmail()); sig_list_->setItem(sig_row, 2, tmp3); } -#ifdef GPGFRONTEND_GUI_QT6 - auto* tmp4 = new QTableWidgetItem(QLocale::system().toString( - QDateTime::fromSecsSinceEpoch(to_time_t(sig.GetCreateTime())))); -#else - auto* tmp4 = new QTableWidgetItem(QLocale::system().toString( - QDateTime::fromTime_t(to_time_t(sig.GetCreateTime())))); -#endif + auto* tmp4 = + new QTableWidgetItem(QLocale::system().toString(sig.GetCreateTime())); sig_list_->setItem(sig_row, 3, tmp4); -#ifdef GPGFRONTEND_GUI_QT6 auto* tmp5 = new QTableWidgetItem( - boost::posix_time::to_time_t(sig.GetExpireTime()) == 0 + sig.GetExpireTime().toSecsSinceEpoch() == 0 ? _("Never Expires") - : QLocale::system().toString(QDateTime::fromSecsSinceEpoch( - to_time_t(sig.GetExpireTime())))); -#else - auto* tmp5 = new QTableWidgetItem( - boost::posix_time::to_time_t( - boost::posix_time::ptime(sig.GetExpireTime())) == 0 - ? _("Never Expires") - : QLocale::system().toString( - QDateTime::fromTime_t(to_time_t(sig.GetExpireTime())))); -#endif + : QLocale::system().toString(sig.GetExpireTime())); tmp5->setTextAlignment(Qt::AlignCenter); sig_list_->setItem(sig_row, 4, tmp5); diff --git a/src/ui/dialog/keypair_details/KeySetExpireDateDialog.cpp b/src/ui/dialog/keypair_details/KeySetExpireDateDialog.cpp index 2e5eb6f7..c9738f98 100644 --- a/src/ui/dialog/keypair_details/KeySetExpireDateDialog.cpp +++ b/src/ui/dialog/keypair_details/KeySetExpireDateDialog.cpp @@ -64,18 +64,12 @@ void KeySetExpireDateDialog::slot_confirm() { ui_->dateEdit->date().toString().toStdString(), ui_->timeEdit->time().toString().toStdString()); auto datetime = QDateTime(ui_->dateEdit->date(), ui_->timeEdit->time()); - std::unique_ptr<boost::posix_time::ptime> expires = nullptr; + std::unique_ptr<QDateTime> expires = nullptr; if (ui_->noExpirationCheckBox->checkState() == Qt::Unchecked) { -#ifdef GPGFRONTEND_GUI_QT6 - expires = std::make_unique<boost::posix_time::ptime>( - boost::posix_time::from_time_t( - datetime.toLocalTime().toSecsSinceEpoch())); -#else - expires = std::make_unique<boost::posix_time::ptime>( - boost::posix_time::from_time_t(datetime.toLocalTime().toTime_t())); -#endif + expires = std::make_unique<QDateTime>(datetime.toLocalTime()); + GF_UI_LOG_DEBUG("keyid: {}", m_key_.GetId(), m_subkey_, - to_iso_string(*expires)); + expires->toSecsSinceEpoch()); } else { GF_UI_LOG_DEBUG("keyid: {}", m_key_.GetId(), m_subkey_, "Non Expired"); } @@ -126,13 +120,8 @@ void KeySetExpireDateDialog::init() { ui_->dateEdit->setMinimumDateTime(min_date_time); // set default date time to expire date time -#ifdef GPGFRONTEND_GUI_QT6 - auto current_expire_time = - QDateTime::fromSecsSinceEpoch(to_time_t(m_key_.GetExpireTime())); -#else - auto current_expire_time = - QDateTime::fromTime_t(to_time_t(m_key_.GetExpireTime())); -#endif + auto current_expire_time = m_key_.GetExpireTime(); + ui_->dateEdit->setDateTime(current_expire_time); ui_->timeEdit->setDateTime(current_expire_time); diff --git a/src/ui/dialog/keypair_details/KeyUIDSignDialog.cpp b/src/ui/dialog/keypair_details/KeyUIDSignDialog.cpp index 47b8eb93..55cafe55 100644 --- a/src/ui/dialog/keypair_details/KeyUIDSignDialog.cpp +++ b/src/ui/dialog/keypair_details/KeyUIDSignDialog.cpp @@ -109,14 +109,7 @@ void KeyUIDSignDialog::slot_sign_key(bool clicked) { auto keys = GpgKeyGetter::GetInstance().GetKeys(key_ids); GF_UI_LOG_DEBUG("key info got"); -#ifdef GPGFRONTEND_GUI_QT6 - auto expires = - std::make_unique<boost::posix_time::ptime>(boost::posix_time::from_time_t( - expires_edit_->dateTime().toSecsSinceEpoch())); -#else - auto expires = std::make_unique<boost::posix_time::ptime>( - boost::posix_time::from_time_t(expires_edit_->dateTime().toTime_t())); -#endif + auto expires = std::make_unique<QDateTime>(expires_edit_->dateTime()); GF_UI_LOG_DEBUG("sign start"); for (const auto& uid : *m_uids_) { diff --git a/src/ui/dialog/settings/SettingsDialog.cpp b/src/ui/dialog/settings/SettingsDialog.cpp index daf5ac86..c69fb071 100644 --- a/src/ui/dialog/settings/SettingsDialog.cpp +++ b/src/ui/dialog/settings/SettingsDialog.cpp @@ -133,7 +133,7 @@ auto SettingsDialog::ListLanguages() -> QHash<QString, QString> { auto locale_path = GlobalSettingStation::GetInstance().GetLocaleDir(); - auto locale_dir = QDir(QString::fromStdString(locale_path.string())); + auto locale_dir = QDir(locale_path); QStringList file_names = locale_dir.entryList(QStringList("*")); for (const auto& locale : file_names) { diff --git a/src/ui/dialog/settings/SettingsGeneral.cpp b/src/ui/dialog/settings/SettingsGeneral.cpp index 1d770b52..ff459a0e 100644 --- a/src/ui/dialog/settings/SettingsGeneral.cpp +++ b/src/ui/dialog/settings/SettingsGeneral.cpp @@ -82,7 +82,7 @@ GeneralTab::GeneralTab(QWidget* parent) connect(ui_->clearAllLogFilesButton, &QPushButton::clicked, this, [=]() { GlobalSettingStation::GetInstance().ClearAllLogFiles(); ui_->clearAllLogFilesButton->setText( - QString(_("Clear All Log (Total Size: %s)")) + QString(_("Clear All Log (Total Size: %1)")) .arg(GlobalSettingStation::GetInstance().GetLogFilesSize())); }); @@ -97,7 +97,7 @@ GeneralTab::GeneralTab(QWidget* parent) if (reply == QMessageBox::Yes) { GlobalSettingStation::GetInstance().ClearAllDataObjects(); ui_->clearAllDataObjectsButton->setText( - QString(_("Clear All Data Objects (Total Size: %s)")) + QString(_("Clear All Data Objects (Total Size: %1)")) .arg(GlobalSettingStation::GetInstance() .GetDataObjectsFilesSize())); } diff --git a/src/ui/main_window/KeyMgmt.cpp b/src/ui/main_window/KeyMgmt.cpp index 4d51c552..87b576b8 100644 --- a/src/ui/main_window/KeyMgmt.cpp +++ b/src/ui/main_window/KeyMgmt.cpp @@ -515,11 +515,10 @@ void KeyMgmt::SlotImportKeyPackage() { if (key_package_file_name.isEmpty() || key_file_name.isEmpty()) return; - GF_UI_LOG_INFO("importing key package: {}", - key_package_file_name.toStdString()); + GF_UI_LOG_INFO("importing key package: {}", key_package_file_name); const auto [success, info] = KeyPackageOperator::ImportKeyPackage( - key_package_file_name.toStdString(), key_file_name.toStdString()); + key_package_file_name, key_file_name); if (success) { emit SignalStatusBarChanged(QString(_("key(s) imported"))); diff --git a/src/ui/main_window/MainWindowFileSlotFunction.cpp b/src/ui/main_window/MainWindowFileSlotFunction.cpp index e698ee6c..fee4d493 100644 --- a/src/ui/main_window/MainWindowFileSlotFunction.cpp +++ b/src/ui/main_window/MainWindowFileSlotFunction.cpp @@ -87,8 +87,7 @@ void MainWindow::SlotFileEncrypt(const QString& path) { CommonUtils::WaitForOpera( this, _("Symmetrically Encrypting"), [=](const OperaWaitingHd& op_hd) { GpgFileOpera::GetInstance().EncryptFileSymmetric( - path.toStdString(), !non_ascii_when_export, - out_path.toStdString(), + path, !non_ascii_when_export, out_path, [=](GpgError err, const DataObjectPtr& data_obj) { // stop waiting op_hd(); @@ -129,9 +128,8 @@ void MainWindow::SlotFileEncrypt(const QString& path) { CommonUtils::WaitForOpera( this, _("Encrypting"), [=](const OperaWaitingHd& op_hd) { GpgFileOpera::GetInstance().EncryptFile( - {p_keys->begin(), p_keys->end()}, path.toStdString(), - !non_ascii_when_export, out_path.toStdString(), - [=](GpgError err, const DataObjectPtr& data_obj) { + {p_keys->begin(), p_keys->end()}, path, !non_ascii_when_export, + out_path, [=](GpgError err, const DataObjectPtr& data_obj) { // stop waiting op_hd(); @@ -196,8 +194,7 @@ void MainWindow::SlotDirectoryEncrypt(const QString& path) { this, _("Archiving & Symmetrically Encrypting"), [=](const OperaWaitingHd& op_hd) { GpgFileOpera::GetInstance().EncryptDerectorySymmetric( - path.toStdString(), !non_ascii_when_export, - out_path.toStdString(), + path, !non_ascii_when_export, out_path, [=](GpgError err, const DataObjectPtr& data_obj) { // stop waiting op_hd(); @@ -238,9 +235,8 @@ void MainWindow::SlotDirectoryEncrypt(const QString& path) { CommonUtils::WaitForOpera( this, _("Archiving & Encrypting"), [=](const OperaWaitingHd& op_hd) { GpgFileOpera::GetInstance().EncryptDirectory( - {p_keys->begin(), p_keys->end()}, path.toStdString(), - !non_ascii_when_export, out_path.toStdString(), - [=](GpgError err, const DataObjectPtr& data_obj) { + {p_keys->begin(), p_keys->end()}, path, !non_ascii_when_export, + out_path, [=](GpgError err, const DataObjectPtr& data_obj) { // stop waiting op_hd(); @@ -287,8 +283,7 @@ void MainWindow::SlotFileDecrypt(const QString& path) { CommonUtils::WaitForOpera( this, _("Decrypting"), [=](const OperaWaitingHd& op_hd) { GpgFileOpera::GetInstance().DecryptFile( - path.toStdString(), out_path.toStdString(), - [=](GpgError err, const DataObjectPtr& data_obj) { + path, out_path, [=](GpgError err, const DataObjectPtr& data_obj) { // stop waiting op_hd(); @@ -334,8 +329,7 @@ void MainWindow::SlotArchiveDecrypt(const QString& path) { CommonUtils::WaitForOpera( this, _("Decrypting & Extrating"), [=](const OperaWaitingHd& op_hd) { GpgFileOpera::GetInstance().DecryptArchive( - path.toStdString(), out_path.toStdString(), - [=](GpgError err, const DataObjectPtr& data_obj) { + path, out_path, [=](GpgError err, const DataObjectPtr& data_obj) { // stop waiting op_hd(); @@ -404,9 +398,8 @@ void MainWindow::SlotFileSign(const QString& path) { CommonUtils::WaitForOpera( this, _("Signing"), [=](const OperaWaitingHd& op_hd) { GpgFileOpera::GetInstance().SignFile( - {keys->begin(), keys->end()}, path.toStdString(), - !non_ascii_when_export, sig_file_path.toStdString(), - [=](GpgError err, const DataObjectPtr& data_obj) { + {keys->begin(), keys->end()}, path, !non_ascii_when_export, + sig_file_path, [=](GpgError err, const DataObjectPtr& data_obj) { // stop waiting op_hd(); @@ -475,7 +468,7 @@ void MainWindow::SlotFileVerify(const QString& path) { CommonUtils::WaitForOpera( this, _("Verifying"), [=](const OperaWaitingHd& op_hd) { GpgFileOpera::GetInstance().VerifyFile( - data_file_path.toStdString(), sign_file_path.toStdString(), + data_file_path, sign_file_path, [=](GpgError err, const DataObjectPtr& data_obj) { // stop waiting op_hd(); @@ -571,8 +564,8 @@ void MainWindow::SlotFileEncryptSign(const QString& path) { this, _("Encrypting and Signing"), [=](const OperaWaitingHd& op_hd) { GpgFileOpera::GetInstance().EncryptSignFile( {p_keys->begin(), p_keys->end()}, - {p_signer_keys->begin(), p_signer_keys->end()}, path.toStdString(), - !non_ascii_when_export, out_path.toStdString(), + {p_signer_keys->begin(), p_signer_keys->end()}, path, + !non_ascii_when_export, out_path, [=](GpgError err, const DataObjectPtr& data_obj) { // stop waiting op_hd(); @@ -671,8 +664,8 @@ void MainWindow::SlotDirectoryEncryptSign(const QString& path) { [=](const OperaWaitingHd& op_hd) { GpgFileOpera::GetInstance().EncryptSignDirectory( {p_keys->begin(), p_keys->end()}, - {p_signer_keys->begin(), p_signer_keys->end()}, path.toStdString(), - !non_ascii_when_export, out_path.toStdString(), + {p_signer_keys->begin(), p_signer_keys->end()}, path, + !non_ascii_when_export, out_path, [=](GpgError err, const DataObjectPtr& data_obj) { // stop waiting op_hd(); @@ -731,8 +724,7 @@ void MainWindow::SlotFileDecryptVerify(const QString& path) { CommonUtils::WaitForOpera( this, _("Decrypting and Verifying"), [=](const OperaWaitingHd& op_hd) { GpgFileOpera::GetInstance().DecryptVerifyFile( - path.toStdString(), out_path.toStdString(), - [=](GpgError err, const DataObjectPtr& data_obj) { + path, out_path, [=](GpgError err, const DataObjectPtr& data_obj) { // stop waiting op_hd(); @@ -799,8 +791,7 @@ void MainWindow::SlotArchiveDecryptVerify(const QString& path) { this, _("Decrypting & Verifying & Extracting"), [=](const OperaWaitingHd& op_hd) { GpgFileOpera::GetInstance().DecryptVerifyArchive( - path.toStdString(), out_path.toStdString(), - [=](GpgError err, const DataObjectPtr& data_obj) { + path, out_path, [=](GpgError err, const DataObjectPtr& data_obj) { // stop waiting op_hd(); diff --git a/src/ui/main_window/MainWindowSlotFunction.cpp b/src/ui/main_window/MainWindowSlotFunction.cpp index 698a63b1..37f49b0d 100644 --- a/src/ui/main_window/MainWindowSlotFunction.cpp +++ b/src/ui/main_window/MainWindowSlotFunction.cpp @@ -26,16 +26,10 @@ * */ -#include <boost/date_time/posix_time/posix_time.hpp> -#include <boost/date_time/posix_time/posix_time_io.hpp> -#include <cstddef> - #include "MainWindow.h" -#include "core/GpgConstants.h" #include "core/GpgModel.h" #include "core/function/gpg/GpgKeyGetter.h" #include "core/function/gpg/GpgKeyImportExporter.h" -#include "core/function/gpg/GpgKeyManager.h" #include "core/module/ModuleManager.h" #include "core/typedef/GpgTypedef.h" #include "core/utils/CommonUtils.h" @@ -103,12 +97,10 @@ void MainWindow::slot_append_keys_create_datetime() { return; } - auto create_datetime_format_str = - QString::fromStdString( - boost::posix_time::to_iso_extended_string(key.GetCreateTime())) + - " (UTC) " + "\n"; - - edit_->SlotAppendText2CurTextPage(create_datetime_format_str); + auto create_datetime_format_str_local = + QLocale::system().toString(key.GetCreateTime()) + _(" (Local Time) ") + + "\n"; + edit_->SlotAppendText2CurTextPage(create_datetime_format_str_local); } void MainWindow::slot_append_keys_expire_datetime() { @@ -126,9 +118,7 @@ void MainWindow::slot_append_keys_expire_datetime() { } auto create_datetime_format_str = - QString::fromStdString( - boost::posix_time::to_iso_extended_string(key.GetCreateTime())) + - " (UTC) " + "\n"; + key.GetCreateTime().toString() + " (UTC) " + "\n"; edit_->SlotAppendText2CurTextPage(create_datetime_format_str); } diff --git a/src/ui/widgets/PlainTextEditorPage.cpp b/src/ui/widgets/PlainTextEditorPage.cpp index 009e627c..0a4d9d1a 100644 --- a/src/ui/widgets/PlainTextEditorPage.cpp +++ b/src/ui/widgets/PlainTextEditorPage.cpp @@ -69,7 +69,7 @@ PlainTextEditorPage::PlainTextEditorPage(QString file_path, QWidget *parent) if (!read_done_) return; auto text = ui_->textPage->document()->toPlainText(); - auto str = QString(_("%1% character(s)")).arg(text.size()); + auto str = QString(_("%1 character(s)")).arg(text.size()); this->ui_->characterLabel->setText(str); }); diff --git a/src/ui/widgets/TextEdit.cpp b/src/ui/widgets/TextEdit.cpp index 6fd93f7b..e29184b8 100644 --- a/src/ui/widgets/TextEdit.cpp +++ b/src/ui/widgets/TextEdit.cpp @@ -220,7 +220,7 @@ bool TextEdit::save_file(const QString& fileName) { return true; } QMessageBox::warning(this, _("Warning"), - QString(_("Cannot read file %1%:\n%2%.")) + QString(_("Cannot read file %1:\n%2.")) .arg(fileName) .arg(file.errorString())); return false; |