diff options
author | saturneric <[email protected]> | 2024-03-02 18:48:44 +0000 |
---|---|---|
committer | saturneric <[email protected]> | 2024-03-02 18:48:44 +0000 |
commit | 154ebea202d64669143ee6bb33f6327d141343c3 (patch) | |
tree | 3d9a6e5cac15f6575a4c1994ba8fd3d8607bfa65 /src/core | |
parent | refactor: remove qt6 core5compat dependencies (diff) | |
download | GpgFrontend-154ebea202d64669143ee6bb33f6327d141343c3.tar.gz GpgFrontend-154ebea202d64669143ee6bb33f6327d141343c3.zip |
refactor: reduce core prebuild headers and isolate core to modules
Diffstat (limited to 'src/core')
-rw-r--r-- | src/core/GpgCoreInit.h | 2 | ||||
-rw-r--r-- | src/core/GpgFrontendCore.h | 20 | ||||
-rw-r--r-- | src/core/function/CoreSignalStation.h | 2 | ||||
-rw-r--r-- | src/core/function/SecureMemoryAllocator.h | 4 | ||||
-rw-r--r-- | src/core/function/gpg/GpgContext.h | 2 | ||||
-rw-r--r-- | src/core/log/QtLoggerFmt.h | 64 | ||||
-rw-r--r-- | src/core/model/GpgData.h | 2 | ||||
-rw-r--r-- | src/core/model/GpgGenKeyInfo.h | 2 | ||||
-rw-r--r-- | src/core/model/GpgGenerateKeyResult.h | 2 | ||||
-rw-r--r-- | src/core/model/GpgImportInformation.h | 4 | ||||
-rw-r--r-- | src/core/model/GpgPassphraseContext.cpp | 1 | ||||
-rw-r--r-- | src/core/model/GpgPassphraseContext.h | 2 | ||||
-rw-r--r-- | src/core/model/GpgSubKey.h | 4 | ||||
-rw-r--r-- | src/core/model/GpgTOFUInfo.h | 4 | ||||
-rw-r--r-- | src/core/module/ModuleInit.cpp | 74 | ||||
-rw-r--r-- | src/core/module/ModuleInit.h | 53 | ||||
-rw-r--r-- | src/core/typedef/GpgTypedef.h | 2 | ||||
-rw-r--r-- | src/core/utils/BuildInfoUtils.h | 2 | ||||
-rw-r--r-- | src/core/utils/CacheUtils.h | 2 | ||||
-rw-r--r-- | src/core/utils/FilesystemUtils.h | 10 | ||||
-rw-r--r-- | src/core/utils/LocalizedUtils.h | 2 | ||||
-rw-r--r-- | src/core/utils/LogUtils.h | 49 |
22 files changed, 212 insertions, 97 deletions
diff --git a/src/core/GpgCoreInit.h b/src/core/GpgCoreInit.h index 15f0254d..ecd6afea 100644 --- a/src/core/GpgCoreInit.h +++ b/src/core/GpgCoreInit.h @@ -28,7 +28,7 @@ #pragma once -#include "GpgConstants.h" +#include "core/GpgFrontendCoreExport.h" namespace GpgFrontend { diff --git a/src/core/GpgFrontendCore.h b/src/core/GpgFrontendCore.h index 14b1f878..f07824cf 100644 --- a/src/core/GpgFrontendCore.h +++ b/src/core/GpgFrontendCore.h @@ -30,23 +30,3 @@ // Qt #include <QtCore> - -// std -#include <cstdint> -#include <vector> - -// spdlog library configuration -#define SPDLOG_ACTIVE_LEVEL SPDLOG_LEVEL_TRACE -#include <spdlog/spdlog.h> - -// logger fmt -#include "log/QtLoggerFmt.h" - -// gpgme library -#include <gpgme.h> - -// logbal includes or macroes -#include "GpgFrontend.h" - -// dll export macroes -#include "GpgFrontendCoreExport.h" diff --git a/src/core/function/CoreSignalStation.h b/src/core/function/CoreSignalStation.h index e0a11fa3..8827c803 100644 --- a/src/core/function/CoreSignalStation.h +++ b/src/core/function/CoreSignalStation.h @@ -28,7 +28,7 @@ #pragma once -#include "core/GpgFrontendCore.h" +#include "core/GpgFrontendCoreExport.h" namespace GpgFrontend { diff --git a/src/core/function/SecureMemoryAllocator.h b/src/core/function/SecureMemoryAllocator.h index e9f1c1c3..e86d54d6 100644 --- a/src/core/function/SecureMemoryAllocator.h +++ b/src/core/function/SecureMemoryAllocator.h @@ -28,9 +28,7 @@ #pragma once -#include <cstdint> -#include <memory> - +#include "core/GpgFrontendCoreExport.h" #include "core/utils/LogUtils.h" namespace GpgFrontend { diff --git a/src/core/function/gpg/GpgContext.h b/src/core/function/gpg/GpgContext.h index d473a341..2a8f6fdd 100644 --- a/src/core/function/gpg/GpgContext.h +++ b/src/core/function/gpg/GpgContext.h @@ -28,6 +28,8 @@ #pragma once +#include <gpgme.h> + #include "core/function/SecureMemoryAllocator.h" #include "core/function/basic/GpgFunctionObject.h" diff --git a/src/core/log/QtLoggerFmt.h b/src/core/log/QtLoggerFmt.h deleted file mode 100644 index e7ac2c82..00000000 --- a/src/core/log/QtLoggerFmt.h +++ /dev/null @@ -1,64 +0,0 @@ -/** - * Copyright (C) 2021 Saturneric <[email protected]> - * - * This file is part of GpgFrontend. - * - * GpgFrontend is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * GpgFrontend is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with GpgFrontend. If not, see <https://www.gnu.org/licenses/>. - * - * The initial version of the source code is inherited from - * the gpg4usb project, which is under GPL-3.0-or-later. - * - * All the source code of GpgFrontend was modified and released by - * Saturneric <[email protected]> starting on May 12, 2021. - * - * SPDX-License-Identifier: GPL-3.0-or-later - * - */ - -#pragma once - -template <> -struct fmt::formatter<QString> { - // Parses format specifications. - constexpr auto parse(format_parse_context& ctx) -> decltype(ctx.begin()) { - return ctx.begin(); - } - - // Formats the QString qstr and writes it to the output. - template <typename FormatContext> - auto format(const QString& qstr, FormatContext& ctx) const - -> decltype(ctx.out()) { - // Convert QString to UTF-8 QString (to handle Unicode characters - // correctly) - QByteArray utf8_array = qstr.toUtf8(); - return fmt::format_to(ctx.out(), "{}", utf8_array.constData()); - } -}; - -template <> -struct fmt::formatter<QByteArray> { - // Parses format specifications. - constexpr auto parse(format_parse_context& ctx) -> decltype(ctx.begin()) { - return ctx.begin(); - } - - // Formats the QString qstr and writes it to the output. - template <typename FormatContext> - auto format(const QByteArray& qarray, FormatContext& ctx) const - -> decltype(ctx.out()) { - // Convert QString to UTF-8 QString (to handle Unicode characters - // correctly) - return fmt::format_to(ctx.out(), "{}", qarray.constData()); - } -}; diff --git a/src/core/model/GpgData.h b/src/core/model/GpgData.h index 358ebd19..eb1d7621 100644 --- a/src/core/model/GpgData.h +++ b/src/core/model/GpgData.h @@ -28,6 +28,8 @@ #pragma once +#include <gpgme.h> + #include "core/GpgFrontendCoreExport.h" #include "core/model/GFBuffer.h" #include "core/typedef/CoreTypedef.h" diff --git a/src/core/model/GpgGenKeyInfo.h b/src/core/model/GpgGenKeyInfo.h index 166c6b0f..65a7d03e 100644 --- a/src/core/model/GpgGenKeyInfo.h +++ b/src/core/model/GpgGenKeyInfo.h @@ -28,6 +28,8 @@ #pragma once +#include "core/GpgFrontendCoreExport.h" + namespace GpgFrontend { class GPGFRONTEND_CORE_EXPORT GenKeyInfo { diff --git a/src/core/model/GpgGenerateKeyResult.h b/src/core/model/GpgGenerateKeyResult.h index f312d415..dfd92ae1 100644 --- a/src/core/model/GpgGenerateKeyResult.h +++ b/src/core/model/GpgGenerateKeyResult.h @@ -28,6 +28,8 @@ #pragma once +#include <gpgme.h> + #include "core/GpgFrontendCore.h" #include "core/GpgFrontendCoreExport.h" diff --git a/src/core/model/GpgImportInformation.h b/src/core/model/GpgImportInformation.h index 5f85a338..cbe5a265 100644 --- a/src/core/model/GpgImportInformation.h +++ b/src/core/model/GpgImportInformation.h @@ -28,6 +28,10 @@ #pragma once +#include <gpgme.h> + +#include "core/GpgFrontendCoreExport.h" + namespace GpgFrontend { /** diff --git a/src/core/model/GpgPassphraseContext.cpp b/src/core/model/GpgPassphraseContext.cpp index 5df3f5a8..0156c04d 100644 --- a/src/core/model/GpgPassphraseContext.cpp +++ b/src/core/model/GpgPassphraseContext.cpp @@ -28,6 +28,7 @@ #include "GpgPassphraseContext.h" + namespace GpgFrontend { GpgPassphraseContext::GpgPassphraseContext(const QString& uids_info, diff --git a/src/core/model/GpgPassphraseContext.h b/src/core/model/GpgPassphraseContext.h index 2bc1ac75..1db36f62 100644 --- a/src/core/model/GpgPassphraseContext.h +++ b/src/core/model/GpgPassphraseContext.h @@ -30,6 +30,8 @@ #pragma once +#include "core/GpgFrontendCoreExport.h" + namespace GpgFrontend { class GPGFRONTEND_CORE_EXPORT GpgPassphraseContext : public QObject { diff --git a/src/core/model/GpgSubKey.h b/src/core/model/GpgSubKey.h index 83d75e2d..8257eab8 100644 --- a/src/core/model/GpgSubKey.h +++ b/src/core/model/GpgSubKey.h @@ -28,6 +28,10 @@ #pragma once +#include <gpgme.h> + +#include "core/GpgFrontendCoreExport.h" + namespace GpgFrontend { /** diff --git a/src/core/model/GpgTOFUInfo.h b/src/core/model/GpgTOFUInfo.h index ec4c49b7..5e8d83d4 100644 --- a/src/core/model/GpgTOFUInfo.h +++ b/src/core/model/GpgTOFUInfo.h @@ -28,6 +28,10 @@ #pragma once +#include <gpgme.h> + +#include "core/GpgFrontendCoreExport.h" + namespace GpgFrontend { /** * @brief diff --git a/src/core/module/ModuleInit.cpp b/src/core/module/ModuleInit.cpp new file mode 100644 index 00000000..d74ea1c4 --- /dev/null +++ b/src/core/module/ModuleInit.cpp @@ -0,0 +1,74 @@ +/** + * Copyright (C) 2021 Saturneric <[email protected]> + * + * This file is part of GpgFrontend. + * + * GpgFrontend is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * GpgFrontend is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GpgFrontend. If not, see <https://www.gnu.org/licenses/>. + * + * The initial version of the source code is inherited from + * the gpg4usb project, which is under GPL-3.0-or-later. + * + * All the source code of GpgFrontend was modified and released by + * Saturneric <[email protected]> starting on May 12, 2021. + * + * SPDX-License-Identifier: GPL-3.0-or-later + * + */ + +#include "ModuleInit.h" + +#include <QCoreApplication> +#include <QDir> + +#include "core/module/ModuleManager.h" +#include "core/thread/Task.h" +#include "core/thread/TaskRunnerGetter.h" + +namespace GpgFrontend::Module { + +void LoadGpgFrontendModules(ModuleInitArgs) { + // must init at default thread before core + Thread::TaskRunnerGetter::GetInstance().GetTaskRunner()->PostTask( + new Thread::Task( + [](const DataObjectPtr&) -> int { + GF_CORE_LOG_INFO("loading modules..."); + + auto exec_binary_path = QCoreApplication::applicationDirPath(); + auto mods_path = exec_binary_path + "/mods"; + + if (!QDir(mods_path).exists()) { + GF_CORE_LOG_INFO("module directory not found, abort..."); + return -1; + } + + GF_CORE_LOG_INFO("the path of modules directory: {}", mods_path); + + for (const auto& module_library_name : + QDir(mods_path).entryList(QStringList() << "*.so" + << "*.dll" + << "*.dylib", + QDir::Files)) { + ModuleManager::GetInstance().LoadModule(mods_path + "/" + + module_library_name); + } + + GF_CORE_LOG_INFO("load modules done."); + return 0; + }, + "modules_system_init_task")); +} + +void ShutdownGpgFrontendModules() {} + +} // namespace GpgFrontend::Module
\ No newline at end of file diff --git a/src/core/module/ModuleInit.h b/src/core/module/ModuleInit.h new file mode 100644 index 00000000..e7e86f0f --- /dev/null +++ b/src/core/module/ModuleInit.h @@ -0,0 +1,53 @@ +/** + * Copyright (C) 2021 Saturneric <[email protected]> + * + * This file is part of GpgFrontend. + * + * GpgFrontend is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * GpgFrontend is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GpgFrontend. If not, see <https://www.gnu.org/licenses/>. + * + * The initial version of the source code is inherited from + * the gpg4usb project, which is under GPL-3.0-or-later. + * + * All the source code of GpgFrontend was modified and released by + * Saturneric <[email protected]> starting on May 12, 2021. + * + * SPDX-License-Identifier: GPL-3.0-or-later + * + */ + +#pragma once + +#include <spdlog/spdlog.h> + +#include "core/GpgFrontendCoreExport.h" + +namespace GpgFrontend::Module { + +struct ModuleInitArgs { + spdlog::level::level_enum log_level; +}; + +/** + * @brief init the module library + * + */ +void GPGFRONTEND_CORE_EXPORT LoadGpgFrontendModules(ModuleInitArgs args); + +/** + * @brief shutdown the module library + * + */ +void GPGFRONTEND_CORE_EXPORT ShutdownGpgFrontendModules(); + +}; // namespace GpgFrontend::Module diff --git a/src/core/typedef/GpgTypedef.h b/src/core/typedef/GpgTypedef.h index cf0887bf..599c5c59 100644 --- a/src/core/typedef/GpgTypedef.h +++ b/src/core/typedef/GpgTypedef.h @@ -28,7 +28,7 @@ #pragma once -#include <tuple> +#include <gpgme.h> #include "core/model/DataObject.h" diff --git a/src/core/utils/BuildInfoUtils.h b/src/core/utils/BuildInfoUtils.h index bac5d8a5..07b0bb21 100644 --- a/src/core/utils/BuildInfoUtils.h +++ b/src/core/utils/BuildInfoUtils.h @@ -28,6 +28,8 @@ #pragma once +#include "core/GpgFrontendCoreExport.h" + namespace GpgFrontend { /** diff --git a/src/core/utils/CacheUtils.h b/src/core/utils/CacheUtils.h index 48b9ac4b..eae45353 100644 --- a/src/core/utils/CacheUtils.h +++ b/src/core/utils/CacheUtils.h @@ -28,6 +28,8 @@ #pragma once +#include "core/GpgFrontendCoreExport.h" + namespace GpgFrontend { /** diff --git a/src/core/utils/FilesystemUtils.h b/src/core/utils/FilesystemUtils.h index 0b58bbb7..0bc90ac5 100644 --- a/src/core/utils/FilesystemUtils.h +++ b/src/core/utils/FilesystemUtils.h @@ -28,6 +28,8 @@ #pragma once +#include "core/GpgFrontendCoreExport.h" + namespace GpgFrontend { /** @@ -54,8 +56,8 @@ auto GPGFRONTEND_CORE_EXPORT GetOnlyFileNameWithPath(const QString& path) * @param filename_pattern The pattern of the file name, e.g. "*.txt" * @return int64_t */ -auto GPGFRONTEND_CORE_EXPORT GetFileSizeByPath( - const QString& path, const QString& filename_pattern) +auto GPGFRONTEND_CORE_EXPORT GetFileSizeByPath(const QString& path, + const QString& filename_pattern) -> int64_t; /** @@ -72,7 +74,7 @@ auto GPGFRONTEND_CORE_EXPORT GetHumanFriendlyFileSize(int64_t size) -> QString; * @param path * @param filename_pattern */ -void GPGFRONTEND_CORE_EXPORT DeleteAllFilesByPattern( - const QString& path, const QString& filename_pattern); +void GPGFRONTEND_CORE_EXPORT +DeleteAllFilesByPattern(const QString& path, const QString& filename_pattern); } // namespace GpgFrontend
\ No newline at end of file diff --git a/src/core/utils/LocalizedUtils.h b/src/core/utils/LocalizedUtils.h index b93b500c..10ada833 100644 --- a/src/core/utils/LocalizedUtils.h +++ b/src/core/utils/LocalizedUtils.h @@ -28,6 +28,8 @@ #pragma once +#include "core/GpgFrontendCoreExport.h" + namespace GpgFrontend { auto GPGFRONTEND_CORE_EXPORT GetLocalizedDateByTimestamp(time_t) -> QString; diff --git a/src/core/utils/LogUtils.h b/src/core/utils/LogUtils.h index a1a5685a..e8dc6f3b 100644 --- a/src/core/utils/LogUtils.h +++ b/src/core/utils/LogUtils.h @@ -28,6 +28,49 @@ #pragma once +// spdlog library configuration +#undef SPDLOG_ACTIVE_LEVEL +#define SPDLOG_ACTIVE_LEVEL SPDLOG_LEVEL_TRACE +#include <spdlog/spdlog.h> + +// logger fmt +#include "core/GpgFrontendCoreExport.h" + +template <> +struct fmt::formatter<QString> { + // Parses format specifications. + constexpr auto parse(format_parse_context& ctx) -> decltype(ctx.begin()) { + return ctx.begin(); + } + + // Formats the QString qstr and writes it to the output. + template <typename FormatContext> + auto format(const QString& qstr, FormatContext& ctx) const + -> decltype(ctx.out()) { + // Convert QString to UTF-8 QString (to handle Unicode characters + // correctly) + QByteArray utf8_array = qstr.toUtf8(); + return fmt::format_to(ctx.out(), "{}", utf8_array.constData()); + } +}; + +template <> +struct fmt::formatter<QByteArray> { + // Parses format specifications. + constexpr auto parse(format_parse_context& ctx) -> decltype(ctx.begin()) { + return ctx.begin(); + } + + // Formats the QString qstr and writes it to the output. + template <typename FormatContext> + auto format(const QByteArray& qarray, FormatContext& ctx) const + -> decltype(ctx.out()) { + // Convert QString to UTF-8 QString (to handle Unicode characters + // correctly) + return fmt::format_to(ctx.out(), "{}", qarray.constData()); + } +}; + namespace GpgFrontend { /** @@ -50,7 +93,7 @@ auto GPGFRONTEND_CORE_EXPORT GetCoreLogger() -> std::shared_ptr<spdlog::logger>; * * @return std::shared_ptr<spdlog::logger> */ -auto GPGFRONTEND_CORE_EXPORT GetLogger(const QString &) +auto GPGFRONTEND_CORE_EXPORT GetLogger(const QString&) -> std::shared_ptr<spdlog::logger>; /** @@ -65,7 +108,7 @@ void GPGFRONTEND_CORE_EXPORT SetDefaultLogLevel(spdlog::level::level_enum); * * @return auto */ -void GPGFRONTEND_CORE_EXPORT RegisterAsyncLogger(const QString &, +void GPGFRONTEND_CORE_EXPORT RegisterAsyncLogger(const QString&, spdlog::level::level_enum); /** @@ -73,7 +116,7 @@ void GPGFRONTEND_CORE_EXPORT RegisterAsyncLogger(const QString &, * * @return auto */ -void GPGFRONTEND_CORE_EXPORT RegisterSyncLogger(const QString &, +void GPGFRONTEND_CORE_EXPORT RegisterSyncLogger(const QString&, spdlog::level::level_enum); } // namespace GpgFrontend |