diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml index 5ecd6340..f196e58c 100644 --- a/.github/workflows/codeql-analysis.yml +++ b/.github/workflows/codeql-analysis.yml @@ -62,9 +62,34 @@ jobs: run: | sudo apt-get update sudo apt-get -y install build-essential binutils git autoconf automake gettext texinfo - sudo apt-get -y install gcc g++ libconfig++-dev libboost-all-dev ninja-build + sudo apt-get -y install gcc g++ ninja-build + sudo apt-get -y install libarchive-dev libconfig++-dev libboost-all-dev sudo apt-get -y install gpg + - name: Build gpg-error (Linux) + run: | + cd ${{github.workspace}}/third_party/libgpg-error + ./autogen.sh + ./configure --enable-maintainer-mode && make -j2 + sudo make install + cd ${{github.workspace}} + + - name: Build assuan (Linux) + run: | + cd ${{github.workspace}}/third_party/libassuan + ./autogen.sh + ./configure --enable-maintainer-mode && make -j2 + sudo make install + cd ${{github.workspace}} + + - name: Build GpgME (Linux) + run: | + cd ${{github.workspace}}/third_party/gpgme + ./autogen.sh + ./configure --enable-maintainer-mode --enable-languages=cpp && make -j2 + sudo make install + cd ${{github.workspace}} + - name: Cache Qt id: cache-qt uses: actions/cache@v1 diff --git a/.github/workflows/debug.yml b/.github/workflows/debug.yml index e96cfb6f..b8468ba7 100644 --- a/.github/workflows/debug.yml +++ b/.github/workflows/debug.yml @@ -41,7 +41,8 @@ jobs: run: | sudo apt-get update sudo apt-get -y install build-essential binutils git autoconf automake gettext texinfo - sudo apt-get -y install gcc g++ libconfig++-dev libboost-all-dev ninja-build + sudo apt-get -y install gcc g++ ninja-build + sudo apt-get -y install libarchive-dev libconfig++-dev libboost-all-dev libssl-dev sudo apt-get -y install gpg if: matrix.os == 'ubuntu-latest' @@ -61,13 +62,40 @@ jobs: - name: Install Dependence (macOS) run: | - brew install cmake git autoconf automake qt@5 texinfo gettext openssl@1.1 - brew install boost ninja + brew install cmake autoconf automake qt@5 texinfo gettext openssl@1.1 + brew install boost ninja libarchive libconfig gpgme brew unlink gettext && brew link --force gettext brew link qt@5 brew link openssl@1.1 --force if: matrix.os == 'macos-10.15' + - name: Build gpg-error (Linux) + run: | + cd ${{github.workspace}}/third_party/libgpg-error + ./autogen.sh + ./configure --enable-maintainer-mode && make -j2 + sudo make install + cd ${{github.workspace}} + if: matrix.os == 'ubuntu-latest' + + - name: Build assuan (Linux) + run: | + cd ${{github.workspace}}/third_party/libassuan + ./autogen.sh + ./configure --enable-maintainer-mode && make -j2 + sudo make install + cd ${{github.workspace}} + if: matrix.os == 'ubuntu-latest' + + - name: Build GpgME (Linux) + run: | + cd ${{github.workspace}}/third_party/gpgme + ./autogen.sh + ./configure --enable-maintainer-mode --enable-languages=cpp && make -j2 + sudo make install + cd ${{github.workspace}} + if: matrix.os == 'ubuntu-latest' + - name: Cache Qt id: cache-qt uses: actions/cache@v1 @@ -99,15 +127,6 @@ jobs: pacman --noconfirm -S --needed mingw-w64-x86_64-libarchive if: matrix.os == 'windows-latest' - - name: Build GpgME (Windows) - shell: msys2 {0} - run: | - cd $(echo "/${{github.workspace}}/third_party/gpgme" | sed 's/\\/\//g' | sed 's/://') - ./autogen.sh - ./configure --enable-maintainer-mode --enable-static=yes --disable-gpg-test --enable-languages=cpp LDFLAGS="-static" && make -j2 - make install - if: matrix.os == 'windows-latest' - - name: Build GpgFrontend (Linux) # Build your GpgFrontend with the given configuration run: | diff --git a/.github/workflows/release-deb-package.yml b/.github/workflows/release-deb-package.yml index ea6869f6..454a579f 100644 --- a/.github/workflows/release-deb-package.yml +++ b/.github/workflows/release-deb-package.yml @@ -38,11 +38,39 @@ jobs: - name: Install Dependence (Ubuntu 20.04) run: | sudo apt-get update - sudo apt-get -y install build-essential binutils git autoconf automake gettext texinfo qt5-default ninja-build - sudo apt-get -y install gcc g++ libconfig++-dev libboost-all-dev + sudo apt-get -y install build-essential binutils git autoconf automake gettext texinfo qt5-default + sudo apt-get -y install gcc g++ ninja-build + sudo apt-get -y install libarchive-dev libconfig++-dev libboost-all-dev libssl-dev sudo apt-get -y install gpg if: matrix.os == 'ubuntu-20.04' + - name: Build gpg-error (Linux) + run: | + cd ${{github.workspace}}/third_party/libgpg-error + ./autogen.sh + ./configure --enable-maintainer-mode --enable-static=yes && make -j2 + sudo make install + cd ${{github.workspace}} + if: matrix.os == 'ubuntu-20.04' + + - name: Build assuan (Linux) + run: | + cd ${{github.workspace}}/third_party/libassuan + ./autogen.sh + ./configure --enable-maintainer-mode && make -j2 + sudo make install + cd ${{github.workspace}} + if: matrix.os == 'ubuntu-20.04' + + - name: Build GpgME (Linux) + run: | + cd ${{github.workspace}}/third_party/gpgme + ./autogen.sh + ./configure --enable-maintainer-mode --enable-languages=cpp && make -j2 + sudo make install + cd ${{github.workspace}} + if: matrix.os == 'ubuntu-20.04' + - name: Build & Package GpgFrontend (Linux DEB Package) # Build your program with the given configuration run: | diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 70a883d5..32577559 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -44,9 +44,10 @@ jobs: run: | sudo apt-get update sudo apt-get -y install build-essential binutils git autoconf automake gettext texinfo - sudo apt-get -y install gcc-8 g++-8 libconfig++-dev libboost-all-dev + sudo apt-get -y install gcc-8 g++-8 ninja-build + sudo apt-get -y install libconfig++-dev libboost-all-dev libarchive-dev libssl-dev sudo apt-get -y install gpgsm libxcb-xinerama0 libxcb-icccm4-dev libcups2-dev libdrm-dev libegl1-mesa-dev - sudo apt-get -y install libgcrypt11-dev libnss3-dev libpci-dev libpulse-dev libudev-dev libxtst-dev gyp ninja-build + sudo apt-get -y install libgcrypt11-dev libnss3-dev libpci-dev libpulse-dev libudev-dev libxtst-dev gyp sudo apt-get -y install libglu1-mesa-dev libfontconfig1-dev libx11-xcb-dev libicu-dev libxcb-image0 sudo apt-get -y install libglu1-mesa-dev libfontconfig1-dev libx11-xcb-dev libicu-dev libxcb-* sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-8 8 @@ -68,13 +69,40 @@ jobs: - name: Install Dependence (macOS) run: | - brew install cmake git autoconf automake qt@5 texinfo gettext openssl@1.1 - brew install boost ninja + brew install cmake autoconf automake qt@5 texinfo gettext openssl@1.1 + brew install boost ninja libarchive libconfig gpgme brew unlink gettext && brew link --force gettext brew link qt@5 brew link openssl@1.1 --force if: matrix.os == 'macos-10.15' + - name: Build gpg-error (Linux) + run: | + cd ${{github.workspace}}/third_party/libgpg-error + ./autogen.sh + ./configure --enable-maintainer-mode && make -j2 + sudo make install + cd ${{github.workspace}} + if: matrix.os == 'ubuntu-18.04' + + - name: Build assuan (Linux) + run: | + cd ${{github.workspace}}/third_party/libassuan + ./autogen.sh + ./configure --enable-maintainer-mode && make -j2 + sudo make install + cd ${{github.workspace}} + if: matrix.os == 'ubuntu-18.04' + + - name: Build GpgME (Linux) + run: | + cd ${{github.workspace}}/third_party/gpgme + ./autogen.sh + ./configure --enable-maintainer-mode --enable-languages=cpp && make -j2 + sudo make install + cd ${{github.workspace}} + if: matrix.os == 'ubuntu-18.04' + - name: Cache Qt id: cache-qt uses: actions/cache@v1 @@ -105,15 +133,6 @@ jobs: pacman --noconfirm -S --needed mingw-w64-x86_64-ninja mingw-w64-x86_64-gnupg mingw-w64-x86_64-libarchive if: matrix.os == 'windows-2019' - - name: Build GpgME (Windows) - shell: msys2 {0} - run: | - cd $(echo "/${{github.workspace}}/third_party/gpgme" | sed 's/\\/\//g' | sed 's/://') - ./autogen.sh - ./configure --enable-maintainer-mode --enable-static=yes --disable-gpg-test --enable-languages=cpp LDFLAGS="-static" && make -j2 - make install - if: matrix.os == 'windows-2019' - - name: Build GpgFrontend (Linux) # Build your GpgFrontend with the given configuration run: | diff --git a/.gitignore b/.gitignore index 501d044a..d1ac8c97 100644 --- a/.gitignore +++ b/.gitignore @@ -2,6 +2,7 @@ src/GpgFrontend.h src/GpgFrontendBuildInfo.h src/GpgFrontendBuildInstallInfo.h +src/core/GpgFrontendCoreExport.h docs/ # gettext diff --git a/.gitmodules b/.gitmodules index 3815e764..9131b1ff 100644 --- a/.gitmodules +++ b/.gitmodules @@ -7,9 +7,6 @@ [submodule "third_party/libgpg-error"] path = third_party/libgpg-error url = https://github.com/saturneric/libgpg-error -[submodule "third_party/vmime"] - path = third_party/vmime - url = https://github.com/saturneric/vmime.git [submodule "third_party/json"] path = third_party/json url = https://github.com/saturneric/json @@ -19,9 +16,6 @@ [submodule "third_party/qt-aes"] path = third_party/qt-aes url = https://github.com/saturneric/Qt-AES -[submodule "third_party/smtp-mime"] - path = third_party/smtp-mime - url = https://github.com/saturneric/SmtpClient-for-Qt.git [submodule "third_party/libarchive"] path = third_party/libarchive url = https://github.com/saturneric/libarchive.git diff --git a/CMakeLists.txt b/CMakeLists.txt index 7ceb9d00..37c2d2d1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -27,7 +27,7 @@ cmake_minimum_required(VERSION 3.16) # define project -project(GpgFrontend VERSION 2.0.5 LANGUAGES CXX) +project(GpgFrontend VERSION 2.0.6 LANGUAGES CXX) # show cmake version message(STATUS "GpgFrontend Build Configuration Started CMAKE Version ${CMAKE_VERSION}") @@ -213,7 +213,7 @@ message(STATUS "Define CMAKE_BUILD_TYPE ${CMAKE_BUILD_TYPE}") if (${CMAKE_BUILD_TYPE} STREQUAL "Release") set(BUILD_FLAG 0) ADD_DEFINITIONS(-DRELEASE) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O2") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3") # Release Version force to build using option STABLE_APPLICATION_BUILD set(FULL_APPLICATION_BUILD 0) set(STABLE_APPLICATION_BUILD 1) @@ -265,6 +265,9 @@ message(STATUS "GpgFrontend Build Timestamp ${BUILD_TIMESTAMP}") message(STATUS "GpgFrontend Build Version ${BUILD_VERSION}") message(STATUS "GpgFrontend Git Repo Version ${GIT_VERSION}") +# support for dymatic libraries +include (GenerateExportHeader) + # Windows IF (MINGW) message(STATUS "GpgFrontend Configuration For OS Platform Microsoft Windows") @@ -273,8 +276,10 @@ IF (MINGW) set(OS_PLATFORM 0) add_definitions(-DWINDOWS) - set(Boost_USE_STATIC_LIBS ON) - set(CMAKE_EXE_LINKER_FLAGS "-static-libgcc -static-libstdc++ -static") + set(Boost_USE_STATIC_LIBS OFF) + set(Boost_USE_MULTITHREADED ON) + set(Boost_USE_STATIC_RUNTIME OFF) + include_directories( ${CMAKE_CURRENT_SOURCE_DIR}/src ${CMAKE_CURRENT_SOURCE_DIR}/third_party diff --git a/README.md b/README.md index be0ff216..3b7942f4 100644 --- a/README.md +++ b/README.md @@ -120,7 +120,7 @@ $ ./release/GpgFrontend.exe Install and compile dependencies. ```shell -$ brew install cmake git autoconf automake qt@5 texinfo gettext openssl@1.1 +$ brew install cmake git autoconf automake qt@5 texinfo gettext openssl@1.1 libarchive $ brew install boost ninja $ brew unlink gettext && brew link --force gettext $ brew link qt@5 @@ -152,13 +152,36 @@ Install and compile dependencies. ```shell $ sudo apt-get update -$ sudo apt-get -y install gettext texinfo git ninja-build cmake -$ sudo apt-get -y install gcc g++ build-essential binutils autoconf automake -$ sudo apt-get -y libboost-all-dev qt5-default +$ sudo apt-get -y install build-essential binutils git autoconf automake gettext texinfo +$ sudo apt-get -y install gcc-8 g++-8 ninja-build +$ sudo apt-get -y install libconfig++-dev libboost-all-dev libarchive-dev libssl-dev $ sudo apt-get -y install gpg # If you need to run directly after building. ``` -Build the code and make the deb package. +Compile and install libgpg-error/libassuan/gpgme. Notice: These in third_party directory is newer than those in apt. + +```shell +# libgpg-error +$ cd GpgFrontend +$ cd ./third_party/libgpg-error +$ ./autogen.sh +$ ./configure --enable-maintainer-mode && make +$ sudo make install +# libassuan +$ cd GpgFrontend +$ cd ./third_party/libassuan +$ ./autogen.sh +$ ./configure --enable-maintainer-mode && make +$ sudo make install +# gpgme +$ cd GpgFrontend +$ cd ./third_party/gpgme +$ ./autogen.sh +$ ./configure --enable-maintainer-mode --enable-languages=cpp && make +$ sudo make install +``` + +Build the code and make the deb package(Please use Ubuntu 20.04 or later). ```shell $ cd GpgFrontend @@ -168,7 +191,7 @@ $ ninja $ ninja package ``` -Build the code separately for debug. +Build the code separately for debug(Please use ubuntu 18.04 or later). ```shell $ cd GpgFrontend @@ -178,7 +201,7 @@ $ ninja $ ./release/GpgFrontend # run the program ``` -Package the AppImage. +Package the AppImage(Should use ubuntu 18.04). ```shell $ cd GpgFrontend diff --git a/TRANSLATORS b/TRANSLATORS index a5e9b011..c63b1352 100644 --- a/TRANSLATORS +++ b/TRANSLATORS @@ -1,5 +1,6 @@ Translators: +Fabian HĂȘche (fr_FR) Google Translation Machine Reviewers: -Saturneric(zh_CN) \ No newline at end of file +Saturneric (zh_CN) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 0769f11a..482bfac4 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -24,6 +24,21 @@ # # SPDX-License-Identifier: GPL-3.0-or-later +# configure for output path and resources +if (APPLICATION_BUILD) + aux_source_directory(. BASE_SOURCE) + set(APP_ICON_RESOURCE_WINDOWS "${CMAKE_SOURCE_DIR}/gpgfrontend.rc") + set_property(SOURCE gpgfrontend.rc APPEND PROPERTY OBJECT_DEPENDS ${CMAKE_SOURCE_DIR}/gpgfrontend.ico) + + if (NOT XCODE_BUILD) + # Set Binary Output Path + set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/release) + else () + # Set Binary Output Path + set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/${CMAKE_BUILD_TYPE}) + endif () +endif () + if (GPG_CORE) message(STATUS "Build Gpg Core") @@ -47,21 +62,6 @@ if (ADVANCE_SUPPORT) add_subdirectory(advance) endif () -if (APPLICATION_BUILD) - aux_source_directory(. BASE_SOURCE) - set(APP_ICON_RESOURCE_WINDOWS "${CMAKE_SOURCE_DIR}/gpgfrontend.rc") - set_property(SOURCE gpgfrontend.rc APPEND PROPERTY OBJECT_DEPENDS ${CMAKE_SOURCE_DIR}/gpgfrontend.ico) - - if (NOT XCODE_BUILD) - # Set Binary Output Path - set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/release) - else () - # Set Binary Output Path - set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/${CMAKE_BUILD_TYPE}) - endif () -endif () - - if (APPLICATION_BUILD) # Set Resource Output Path if (${CMAKE_BUILD_TYPE} STREQUAL "Release") @@ -257,13 +257,13 @@ endif () if (APPLICATION_BUILD) target_link_libraries(${AppName} gpgfrontend_ui) IF (MINGW) - message(STATUS "Link Application Static Library For MINGW") + message(STATUS "Link Application Library For MINGW") target_link_libraries(${AppName} crypto) elseif (APPLE) - message(STATUS "Link Application Static Library For macOS") + message(STATUS "Link Application Library For macOS") target_link_libraries(${AppName} intl) else () - message(STATUS "Link Application Static Library For Linux") + message(STATUS "Link Application Library For Linux") target_link_libraries(${AppName} crypto pthread) endif () endif () @@ -274,12 +274,21 @@ target_compile_features(${AppName} PUBLIC cxx_std_17) # if building linux package if (LINUX AND LINUX_INSTALL_SOFTWARE) if (INSTALL_GPGFRONTEND_APP) - install(TARGETS ${AppName} + install(TARGETS ${AppName} gpgfrontend_core gpgfrontend_ui EXPORT GpgFrontendTargets RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} ) + install(DIRECTORY /usr/local/lib/ + DESTINATION ${CMAKE_INSTALL_LIBDIR} + FILES_MATCHING PATTERN "libgpgme.so*") + install(DIRECTORY /usr/local/lib/ + DESTINATION ${CMAKE_INSTALL_LIBDIR} + FILES_MATCHING PATTERN "libassuan.so*") + install(DIRECTORY /usr/local/lib/ + DESTINATION ${CMAKE_INSTALL_LIBDIR} + FILES_MATCHING PATTERN "libgpg-error.so*") install(FILES ${CMAKE_SOURCE_DIR}/TRANSLATORS DESTINATION /usr/local/share/${AppName}/) install(FILES ${CMAKE_SOURCE_DIR}/resource/meta/pub.gpgfrontend.gpgfrontend.appdata.xml @@ -304,7 +313,7 @@ if (LINUX AND LINUX_INSTALL_SOFTWARE) set(CPACK_DEBIAN_PACKAGE_ARCHITECTURE "amd64") set(CPACK_PACKAGE_CONTACT "eric@bktus.com") SET(CPACK_DEBIAN_PACKAGE_MAINTAINER "Saturneric") - set(CPACK_DEBIAN_PACKAGE_DEPENDS "gpg (>= 2.2), libqt5core5a (>= 5.9), libqt5gui5 (>= 5.9), libqt5widgets5 (>= 5.9), libqt5network5 (>= 5.9), libqt5printsupport5 (>= 5.9), libconfig++-dev (>=1.5)") + set(CPACK_DEBIAN_PACKAGE_DEPENDS "gpg (>= 2.2), libqt5core5a (>= 5.9), libqt5gui5 (>= 5.9), libqt5widgets5 (>= 5.9), libqt5network5 (>= 5.9), libqt5printsupport5 (>= 5.9), libconfig++9v5 (>=1.5), libarchive13(>= 3.4), openssl(>= 1.1.1)") set(CPACK_PACKAGE_VERSION_MAJOR "${PROJECT_VERSION_MAJOR}") set(CPACK_PACKAGE_VERSION_MINOR "${PROJECT_VERSION_MINOR}") set(CPACK_PACKAGE_VERSION_PATCH "${PROJECT_VERSION_PATCH}") diff --git a/src/before_exit.cpp b/src/before_exit.cpp index 50604a54..04e245db 100644 --- a/src/before_exit.cpp +++ b/src/before_exit.cpp @@ -34,5 +34,4 @@ */ void before_exit() { LOG(INFO) << "called"; - GpgFrontend::GlobalSettingStation::GetInstance().ResetRootCerts(); } diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt index 7903ef80..dde81c0a 100644 --- a/src/core/CMakeLists.txt +++ b/src/core/CMakeLists.txt @@ -28,44 +28,45 @@ aux_source_directory(./function/result_analyse GPG_SOURCE) aux_source_directory(./function/gpg GPG_SOURCE) aux_source_directory(./function/aes GPG_SOURCE) aux_source_directory(./function GPG_SOURCE) +aux_source_directory(./thread GPG_SOURCE) aux_source_directory(./model GPG_SOURCE) +aux_source_directory(./common GPG_SOURCE) aux_source_directory(. GPG_SOURCE) # define libgpgfrontend_core -add_library(gpgfrontend_core STATIC ${GPG_SOURCE}) +set(CMAKE_CXX_VISIBILITY_PRESET hidden) +set(CMAKE_VISIBILITY_INLINES_HIDDEN 1) +add_library(gpgfrontend_core SHARED ${GPG_SOURCE}) +set(_export_file "${CMAKE_CURRENT_SOURCE_DIR}/GpgFrontendCoreExport.h") +generate_export_header(gpgfrontend_core EXPORT_FILE_NAME "${_export_file}") set(UTILS_DIR ${CMAKE_SOURCE_DIR}/utils) set(GPGME_LIB_DIR ${UTILS_DIR}/gpgme/lib) # link third-party libraries -target_link_libraries(gpgfrontend_core easyloggingpp config++) -# link boost libraries -target_link_libraries(gpgfrontend_core Boost::date_time Boost::system) +target_link_libraries(gpgfrontend_core config++) +if (NOT LINUX) + target_link_libraries(gpgfrontend_core config++ intl) +endif () + +# easyloggingpp +target_include_directories(gpgfrontend_core PUBLIC + ${CMAKE_SOURCE_DIR}/third_party/easyloggingpp/src) +target_sources(gpgfrontend_core PUBLIC + ${CMAKE_SOURCE_DIR}/third_party/easyloggingpp/src/easylogging++.cc) + # link gnupg libraries target_link_libraries(gpgfrontend_core gpgme assuan gpg-error) # link openssl target_link_libraries(gpgfrontend_core OpenSSL::SSL OpenSSL::Crypto) # link Qt AES target_link_libraries(gpgfrontend_core QtAES) -# link vmime -if (NOT LINUX) - # macOS - target_link_libraries(gpgfrontend_core - gpgfrontend_vmime intl iconv) - if (MINGW) - target_link_libraries(gpgfrontend_core ws2_32) - endif () -else () - target_link_libraries(gpgfrontend_core - gpgfrontend_vmime anl ssl crypto) -endif () +# link boost libraries +target_link_libraries(gpgfrontend_core ${Boost_LIBRARIES}) + # link libarchive -if (MINGW) - find_library(LIBARCHIVE_LIB libarchive.a) - target_link_libraries(gpgfrontend_core ${LIBARCHIVE_LIB} b2 expat lz4 zstd bcrypt lzma bz2 z) -else () - target_link_libraries(gpgfrontend_core archive_static) -endif () +target_link_libraries(gpgfrontend_core archive) + # link json target_link_libraries(gpgfrontend_core nlohmann_json::nlohmann_json) diff --git a/src/core/GpgConstants.h b/src/core/GpgConstants.h index 8c6977ac..f3f0c6e6 100644 --- a/src/core/GpgConstants.h +++ b/src/core/GpgConstants.h @@ -29,14 +29,14 @@ #ifndef GPG_CONSTANTS_H #define GPG_CONSTANTS_H +#include #include #include #include -#include -#include -#include "GpgFrontend.h" +// dll export macro +#include "GpgFrontendCoreExport.h" const int RESTART_CODE = 1000; ///< @@ -74,7 +74,8 @@ using GpgGenKeyResult = std::shared_ptr; ///< * @param result * @return GpgEncrResult */ -GpgEncrResult _new_result(gpgme_encrypt_result_t&& result); +GPGFRONTEND_CORE_EXPORT GpgEncrResult +_new_result(gpgme_encrypt_result_t&& result); /** * @brief @@ -82,7 +83,8 @@ GpgEncrResult _new_result(gpgme_encrypt_result_t&& result); * @param result * @return GpgDecrResult */ -GpgDecrResult _new_result(gpgme_decrypt_result_t&& result); +GPGFRONTEND_CORE_EXPORT GpgDecrResult +_new_result(gpgme_decrypt_result_t&& result); /** * @brief @@ -90,7 +92,7 @@ GpgDecrResult _new_result(gpgme_decrypt_result_t&& result); * @param result * @return GpgSignResult */ -GpgSignResult _new_result(gpgme_sign_result_t&& result); +GPGFRONTEND_CORE_EXPORT GpgSignResult _new_result(gpgme_sign_result_t&& result); /** * @brief @@ -98,7 +100,8 @@ GpgSignResult _new_result(gpgme_sign_result_t&& result); * @param result * @return GpgVerifyResult */ -GpgVerifyResult _new_result(gpgme_verify_result_t&& result); +GPGFRONTEND_CORE_EXPORT GpgVerifyResult +_new_result(gpgme_verify_result_t&& result); /** * @brief @@ -106,7 +109,8 @@ GpgVerifyResult _new_result(gpgme_verify_result_t&& result); * @param result * @return GpgGenKeyResult */ -GpgGenKeyResult _new_result(gpgme_genkey_result_t&& result); +GPGFRONTEND_CORE_EXPORT GpgGenKeyResult +_new_result(gpgme_genkey_result_t&& result); // Error Info Printer @@ -116,7 +120,7 @@ GpgGenKeyResult _new_result(gpgme_genkey_result_t&& result); * @param err * @return GpgError */ -GpgError check_gpg_error(GpgError err); +GPGFRONTEND_CORE_EXPORT GpgError check_gpg_error(GpgError err); /** * @brief @@ -125,7 +129,8 @@ GpgError check_gpg_error(GpgError err); * @param comment * @return GpgError */ -GpgError check_gpg_error(GpgError gpgmeError, const std::string& comment); +GPGFRONTEND_CORE_EXPORT GpgError check_gpg_error(GpgError gpgmeError, + const std::string& comment); /** * @brief @@ -134,7 +139,7 @@ GpgError check_gpg_error(GpgError gpgmeError, const std::string& comment); * @param predict * @return gpg_err_code_t */ -gpg_err_code_t check_gpg_error_2_err_code( +GPGFRONTEND_CORE_EXPORT gpg_err_code_t check_gpg_error_2_err_code( gpgme_error_t err, gpgme_error_t predict = GPG_ERR_NO_ERROR); // Fingerprint @@ -145,7 +150,8 @@ gpg_err_code_t check_gpg_error_2_err_code( * @param fingerprint * @return std::string */ -std::string beautify_fingerprint(BypeArrayConstRef fingerprint); +GPGFRONTEND_CORE_EXPORT std::string beautify_fingerprint( + BypeArrayConstRef fingerprint); // File Operation @@ -165,8 +171,8 @@ std::string read_all_data_in_file(const std::string& path); * @return true * @return false */ -bool write_buffer_to_file(const std::string& path, - const std::string& out_buffer); +GPGFRONTEND_CORE_EXPORT bool write_buffer_to_file( + const std::string& path, const std::string& out_buffer); /** * @brief Get the file extension object @@ -202,7 +208,7 @@ const int GPGFRONTEND_NON_ASCII_CHANNEL = 2; ///< * @brief * */ -class GpgConstants { +class GPGFRONTEND_CORE_EXPORT GpgConstants { public: static const char* PGP_CRYPT_BEGIN; ///< static const char* PGP_CRYPT_END; ///< diff --git a/src/core/GpgContext.cpp b/src/core/GpgContext.cpp index 1897202f..0da963ee 100644 --- a/src/core/GpgContext.cpp +++ b/src/core/GpgContext.cpp @@ -43,6 +43,9 @@ namespace GpgFrontend { +GpgContext::GpgContext(int channel) + : SingletonFunctionObject(channel) {} + /** * Constructor * Set up gpgme-context, set paths to app-run path diff --git a/src/core/GpgContext.h b/src/core/GpgContext.h index 7de6bcad..b148fcb5 100644 --- a/src/core/GpgContext.h +++ b/src/core/GpgContext.h @@ -56,7 +56,8 @@ struct GpgContextInitArgs { * @brief * */ -class GpgContext : public SingletonFunctionObject { +class GPGFRONTEND_CORE_EXPORT GpgContext + : public SingletonFunctionObject { public: /** * @brief Construct a new Gpg Context object @@ -70,8 +71,7 @@ class GpgContext : public SingletonFunctionObject { * * @param channel */ - explicit GpgContext(int channel) - : SingletonFunctionObject(channel) {} + explicit GpgContext(int channel); /** * @brief Destroy the Gpg Context object @@ -161,4 +161,4 @@ class GpgContext : public SingletonFunctionObject { }; } // namespace GpgFrontend -#endif // __SGPGMEPP_CONTEXT_H__ +#endif // __SGPGMEPP_CONTEXT_H__ \ No newline at end of file diff --git a/src/core/GpgCoreInit.cpp b/src/core/GpgCoreInit.cpp index 6d9963d6..e9b8fcdc 100644 --- a/src/core/GpgCoreInit.cpp +++ b/src/core/GpgCoreInit.cpp @@ -28,9 +28,47 @@ #include "GpgCoreInit.h" -#include "GpgContext.h" +#include "core/GpgContext.h" +#include "core/function/GlobalSettingStation.h" -void GpgFrontend::init_gpgfrontend_core() { +// init easyloggingpp library +INITIALIZE_EASYLOGGINGPP + +namespace GpgFrontend { + +/** + * @brief setup logging system and do proper initialization + * + */ +void init_logging() { + using namespace boost::posix_time; + using namespace boost::gregorian; + + ptime now = second_clock::local_time(); + + el::Loggers::addFlag(el::LoggingFlag::AutoSpacing); + el::Configurations defaultConf; + defaultConf.setToDefault(); + el::Loggers::reconfigureLogger("default", defaultConf); + + // apply settings + defaultConf.setGlobally(el::ConfigurationType::Format, + "%datetime %level %func %msg"); + + // get the log directory + auto logfile_path = + (GlobalSettingStation::GetInstance().GetLogDir() / to_iso_string(now)); + logfile_path.replace_extension(".log"); + defaultConf.setGlobally(el::ConfigurationType::Filename, + logfile_path.u8string()); + + el::Loggers::reconfigureLogger("default", defaultConf); + + LOG(INFO) << _("log file path") << logfile_path; +} + +void init_gpgfrontend_core() { + // init default channel GpgFrontend::GpgContext::CreateInstance( GPGFRONTEND_DEFAULT_CHANNEL, [&]() -> std::unique_ptr { @@ -38,6 +76,7 @@ void GpgFrontend::init_gpgfrontend_core() { return std::make_unique(args); }); + // init non-ascii channel GpgFrontend::GpgContext::CreateInstance( GPGFRONTEND_NON_ASCII_CHANNEL, [&]() -> std::unique_ptr { @@ -47,10 +86,12 @@ void GpgFrontend::init_gpgfrontend_core() { }); } -void GpgFrontend::new_default_settings_channel(int channel) { +void new_default_settings_channel(int channel) { GpgFrontend::GpgContext::CreateInstance( channel, [&]() -> std::unique_ptr { GpgFrontend::GpgContextInitArgs args; return std::make_unique(args); }); -} \ No newline at end of file +} + +} // namespace GpgFrontend \ No newline at end of file diff --git a/src/core/GpgCoreInit.h b/src/core/GpgCoreInit.h index 5ac804da..752fe4c3 100644 --- a/src/core/GpgCoreInit.h +++ b/src/core/GpgCoreInit.h @@ -33,6 +33,12 @@ namespace GpgFrontend { +/** + * @brief + * + */ +void init_logging(); + /** * @brief * diff --git a/src/core/GpgFrontendCore.h b/src/core/GpgFrontendCore.h index 5931695d..90bc36be 100644 --- a/src/core/GpgFrontendCore.h +++ b/src/core/GpgFrontendCore.h @@ -32,6 +32,7 @@ #include "GpgFrontend.h" // std includes +#include #include // boost includes @@ -40,22 +41,14 @@ // Qt includes #include -// vmime includes -#define VMIME_STATIC -#undef VMIME_HAVE_MLANG -#include - // libconfig includes -#undef LIBCONFIGXX_STATIC -#define LIBCONFIGXX_STATIC #include - // libarchive includes #include #include -#include "core/GpgModel.h" +#include "GpgConstants.h" #endif // GPGFRONTEND_GPGFRONTENDCORE_H diff --git a/src/core/GpgGenKeyInfo.h b/src/core/GpgGenKeyInfo.h index 59ced710..73dd9680 100644 --- a/src/core/GpgGenKeyInfo.h +++ b/src/core/GpgGenKeyInfo.h @@ -39,7 +39,7 @@ namespace GpgFrontend { -class GenKeyInfo { +class GPGFRONTEND_CORE_EXPORT GenKeyInfo { bool standalone_ = false; ///< bool subkey_ = false; ///< std::string name_; ///< diff --git a/src/core/GpgModel.h b/src/core/GpgModel.h index e3d43332..d8d4e6fe 100644 --- a/src/core/GpgModel.h +++ b/src/core/GpgModel.h @@ -29,10 +29,7 @@ #ifndef GPGFRONTEND_ZH_CN_TS_GPGMODEL_H #define GPGFRONTEND_ZH_CN_TS_GPGMODEL_H -#include -#include - -#include "GpgConstants.h" +#include "core/GpgConstants.h" #include "core/model/GpgData.h" #include "core/model/GpgKey.h" #include "core/model/GpgSignature.h" diff --git a/src/ui/thread/SMTPConnectionTestThread.cpp b/src/core/common/CoreCommonUtil.cpp similarity index 62% rename from src/ui/thread/SMTPConnectionTestThread.cpp rename to src/core/common/CoreCommonUtil.cpp index 95cc8f72..69d26f72 100644 --- a/src/ui/thread/SMTPConnectionTestThread.cpp +++ b/src/core/common/CoreCommonUtil.cpp @@ -24,25 +24,17 @@ * */ -#include "SMTPConnectionTestThread.h" -namespace GpgFrontend::UI { +#include "CoreCommonUtil.h" -void SMTPConnectionTestThread::run() { - SmtpClient smtp(host_.c_str(), port_, connection_type_); - if (identify_) { - smtp.setUser(username_.c_str()); - smtp.setPassword(password_.c_str()); - } - if (!smtp.connectToHost()) { - emit SignalSMTPConnectionTestResult("Fail to connect SMTP server"); - return; - } - if (!smtp.login()) { - emit SignalSMTPConnectionTestResult("Fail to login"); - return; +namespace GpgFrontend { + +std::unique_ptr CoreCommonUtil::instance_ = nullptr; ///< + +CoreCommonUtil *CoreCommonUtil::GetInstance() { + LOG(INFO) << "called"; + if (instance_ == nullptr) { + instance_ = std::make_unique(); } - smtp.quit(); - emit SignalSMTPConnectionTestResult("Succeed in testing connection"); + return instance_.get(); } - -} // namespace GpgFrontend::UI +} // namespace GpgFrontend diff --git a/src/ui/mail/SenderPicker.h b/src/core/common/CoreCommonUtil.h similarity index 55% rename from src/ui/mail/SenderPicker.h rename to src/core/common/CoreCommonUtil.h index ce8cd8e6..074b4fd3 100644 --- a/src/ui/mail/SenderPicker.h +++ b/src/core/common/CoreCommonUtil.h @@ -19,48 +19,45 @@ * 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 starting on May 12, 2021. - * - * SPDX-License-Identifier: GPL-3.0-or-later + * The source code version of this software was modified and released + * by Saturneric starting on May 12, 2021. * */ -#ifndef GPGFRONTEND_SENDERPICKER_H -#define GPGFRONTEND_SENDERPICKER_H - -#include "GpgFrontendUI.h" +#ifndef GPGFRONTEND_CORECOMMONUTIL_H +#define GPGFRONTEND_CORECOMMONUTIL_H -namespace GpgFrontend::UI { +#include "core/GpgFrontendCore.h" -class KeyList; +namespace GpgFrontend { -/** - * @brief - * - */ -class SenderPicker : public QDialog { +class GPGFRONTEND_CORE_EXPORT CoreCommonUtil : public QObject { Q_OBJECT - public: /** - * @brief Construct a new Sender Picker object + * @brief Construct a new Core Common Util object * - * @param current_key_id - * @param parent */ - explicit SenderPicker(const KeyId& current_key_id, QWidget* parent = nullptr); + static CoreCommonUtil *GetInstance(); /** - * @brief Get the Checked Sender object + * @brief * - * @return GpgFrontend::KeyId */ - GpgFrontend::KeyId GetCheckedSender(); + CoreCommonUtil() = default; + + signals: + + /** + * @brief + * + */ + void SignalGnupgNotInstall(); private: - KeyList* key_list_; ///< + static std::unique_ptr instance_; ///< }; -} // namespace GpgFrontend::UI -#endif // GPGFRONTEND_SENDERPICKER_H +} // namespace GpgFrontend + +#endif // GPGFRONTEND_CORECOMMONUTIL_H diff --git a/src/core/function/ArchiveFileOperator.h b/src/core/function/ArchiveFileOperator.h index 324d9d53..28d1ad65 100644 --- a/src/core/function/ArchiveFileOperator.h +++ b/src/core/function/ArchiveFileOperator.h @@ -42,7 +42,7 @@ struct ArchiveStruct { std::string name; }; -class ArchiveFileOperator { +class GPGFRONTEND_CORE_EXPORT ArchiveFileOperator { public: static void ListArchive(const std::filesystem::path &archive_path); diff --git a/src/core/function/DataObjectOperator.cpp b/src/core/function/DataObjectOperator.cpp index 1e216dd6..d5b746d6 100644 --- a/src/core/function/DataObjectOperator.cpp +++ b/src/core/function/DataObjectOperator.cpp @@ -29,6 +29,7 @@ #include "DataObjectOperator.h" #include +#include #include "core/function/FileOperator.h" #include "core/function/PassphraseGenerator.h" @@ -65,7 +66,6 @@ GpgFrontend::DataObjectOperator::DataObjectOperator(int channel) std::string GpgFrontend::DataObjectOperator::SaveDataObj( const std::string& _key, const nlohmann::json& value) { - std::string _hash_obj_key = {}; if (_key.empty()) { _hash_obj_key = @@ -92,7 +92,8 @@ std::string GpgFrontend::DataObjectOperator::SaveDataObj( auto encoded = encryption.encode(QByteArray::fromStdString(to_string(value)), hash_key_); - LOG(INFO) << _("Saving data object") << _hash_obj_key << "to" << obj_path << encoded.size() << "bytes"; + LOG(INFO) << _("Saving data object") << _hash_obj_key << "to" << obj_path + << encoded.size() << "bytes"; FileOperator::WriteFileStd(obj_path.u8string(), encoded.toStdString()); @@ -128,7 +129,8 @@ std::optional GpgFrontend::DataObjectOperator::GetDataObject( QAESEncryption encryption(QAESEncryption::AES_256, QAESEncryption::ECB, QAESEncryption::Padding::ISO); - LOG(INFO) << _("Decrypting data object") << encoded.size() << hash_key_.size(); + LOG(INFO) << _("Decrypting data object") << encoded.size() + << hash_key_.size(); auto decoded = encryption.removePadding(encryption.decode(encoded, hash_key_)); diff --git a/src/core/function/DataObjectOperator.h b/src/core/function/DataObjectOperator.h index 0ce4e313..1b52ec32 100644 --- a/src/core/function/DataObjectOperator.h +++ b/src/core/function/DataObjectOperator.h @@ -37,7 +37,8 @@ namespace GpgFrontend { -class DataObjectOperator : public SingletonFunctionObject { +class GPGFRONTEND_CORE_EXPORT DataObjectOperator + : public SingletonFunctionObject { public: /** * @brief DataObjectOperator constructor diff --git a/src/core/function/FileOperator.h b/src/core/function/FileOperator.h index aa2c3b73..a727b1de 100644 --- a/src/core/function/FileOperator.h +++ b/src/core/function/FileOperator.h @@ -37,7 +37,7 @@ namespace GpgFrontend { * @brief provides file operations * */ -class FileOperator { +class GPGFRONTEND_CORE_EXPORT FileOperator { public: /** * @brief read file content using std struct diff --git a/src/core/function/GlobalSettingStation.cpp b/src/core/function/GlobalSettingStation.cpp index 8850cbe4..db8d1bc3 100644 --- a/src/core/function/GlobalSettingStation.cpp +++ b/src/core/function/GlobalSettingStation.cpp @@ -28,12 +28,6 @@ #include "GlobalSettingStation.h" -#include -#include - -#include -#include - #include "core/function/FileOperator.h" void GpgFrontend::GlobalSettingStation::SyncSettings() noexcept { @@ -95,47 +89,6 @@ GpgFrontend::GlobalSettingStation::GlobalSettingStation(int channel) noexcept } } -void GpgFrontend::GlobalSettingStation::AddRootCert( - const std::filesystem::path &path) { - std::string out_buffer; - if (!FileOperator::ReadFileStd(path, out_buffer)) { - LOG(ERROR) << _("Failed to read root certificate file") << path; - return; - } - - auto mem_bio = std::shared_ptr( - BIO_new_mem_buf(out_buffer.data(), static_cast(out_buffer.size())), - [](BIO *_p) { BIO_free(_p); }); - - auto x509 = std::shared_ptr( - PEM_read_bio_X509(mem_bio.get(), nullptr, nullptr, nullptr), - [](X509 *_p) { X509_free(_p); }); - - if (!x509) return; - - root_certs_.push_back(x509); -} - -vmime::shared_ptr -GpgFrontend::GlobalSettingStation::GetCertVerifier() const { - auto p_cv = - vmime::make_shared(); - - std::vector> - _root_certs; - for (const auto &cert : root_certs_) { - _root_certs.push_back( - std::make_shared( - cert.get())); - } - return p_cv; -} - -const std::vector> - &GpgFrontend::GlobalSettingStation::GetRootCerts() { - return root_certs_; -} - void GpgFrontend::GlobalSettingStation::init_app_secure_key() {} GpgFrontend::GlobalSettingStation::~GlobalSettingStation() noexcept = default; diff --git a/src/core/function/GlobalSettingStation.h b/src/core/function/GlobalSettingStation.h index d6521c8a..0df6bd21 100644 --- a/src/core/function/GlobalSettingStation.h +++ b/src/core/function/GlobalSettingStation.h @@ -38,18 +38,13 @@ #include "core/GpgFrontendCore.h" #include "core/GpgFunctionObject.h" -namespace vmime::security::cert { -class defaultCertificateVerifier; -class X509Certificate; -} // namespace vmime::security::cert - namespace GpgFrontend { /** * @brief * */ -class GlobalSettingStation +class GPGFRONTEND_CORE_EXPORT GlobalSettingStation : public SingletonFunctionObject { public: /** @@ -145,36 +140,6 @@ class GlobalSettingStation return app_resource_path_ / "certs"; } - /** - * @brief Get the Cert Verifier object - * - * @return std::shared_ptr< - * vmime::security::cert::defaultCertificateVerifier> - */ - [[nodiscard]] std::shared_ptr< - vmime::security::cert::defaultCertificateVerifier> - GetCertVerifier() const; - - /** - * @brief - * - * @param path - */ - void AddRootCert(const std::filesystem::path &path); - - /** - * @brief Get the Root Certs object - * - * @return const std::vector>& - */ - const std::vector> &GetRootCerts(); - - /** - * @brief - * - */ - void ResetRootCerts() { root_certs_.clear(); } - /** * @brief sync the settings to the file * @@ -218,8 +183,7 @@ class GlobalSettingStation std::filesystem::path ui_config_path_ = ui_config_dir_path_ / "ui.cfg"; ///< UI Configure File Location - libconfig::Config ui_cfg_; ///< - std::vector> root_certs_; ///< + libconfig::Config ui_cfg_; ///< UI Configure File /** * @brief diff --git a/src/core/function/KeyPackageOperator.h b/src/core/function/KeyPackageOperator.h index cd344688..00b0dbaa 100644 --- a/src/core/function/KeyPackageOperator.h +++ b/src/core/function/KeyPackageOperator.h @@ -38,7 +38,7 @@ namespace GpgFrontend { * @brief give the possibility to import or export a key package * */ -class KeyPackageOperator { +class GPGFRONTEND_CORE_EXPORT KeyPackageOperator { public: /** * @brief generate passphrase for key package and save it to file diff --git a/src/core/function/PassphraseGenerator.h b/src/core/function/PassphraseGenerator.h index d1cc7607..a61356fe 100644 --- a/src/core/function/PassphraseGenerator.h +++ b/src/core/function/PassphraseGenerator.h @@ -39,7 +39,7 @@ namespace GpgFrontend { * * This class is used to generate a passphrase. */ -class PassphraseGenerator +class GPGFRONTEND_CORE_EXPORT PassphraseGenerator : public SingletonFunctionObject { public: /** diff --git a/src/core/function/gpg/GpgBasicOperator.cpp b/src/core/function/gpg/GpgBasicOperator.cpp index b92404a9..97399b4e 100644 --- a/src/core/function/gpg/GpgBasicOperator.cpp +++ b/src/core/function/gpg/GpgBasicOperator.cpp @@ -32,6 +32,9 @@ #include "GpgKeyGetter.h" +GpgFrontend::GpgBasicOperator::GpgBasicOperator(int channel) + : SingletonFunctionObject(channel) {} + GpgFrontend::GpgError GpgFrontend::GpgBasicOperator::Encrypt( KeyListPtr keys, GpgFrontend::BypeArrayRef in_buffer, GpgFrontend::ByteArrayPtr& out_buffer, GpgFrontend::GpgEncrResult& result) { @@ -95,11 +98,9 @@ GpgFrontend::GpgError GpgFrontend::GpgBasicOperator::Verify( return err; } -GpgFrontend::GpgError GpgFrontend::GpgBasicOperator::Sign(KeyListPtr signers, - BypeArrayRef in_buffer, - ByteArrayPtr& out_buffer, - gpgme_sig_mode_t mode, - GpgSignResult& result) { +GpgFrontend::GpgError GpgFrontend::GpgBasicOperator::Sign( + KeyListPtr signers, BypeArrayRef in_buffer, ByteArrayPtr& out_buffer, + gpgme_sig_mode_t mode, GpgSignResult& result) { gpgme_error_t err; // Set Singers of this opera diff --git a/src/core/function/gpg/GpgBasicOperator.h b/src/core/function/gpg/GpgBasicOperator.h index 9b9d9f63..696ac9dc 100644 --- a/src/core/function/gpg/GpgBasicOperator.h +++ b/src/core/function/gpg/GpgBasicOperator.h @@ -40,7 +40,8 @@ namespace GpgFrontend { * @brief Basic operation collection * */ -class GpgBasicOperator : public SingletonFunctionObject { +class GPGFRONTEND_CORE_EXPORT GpgBasicOperator + : public SingletonFunctionObject { public: /** * @brief Construct a new Basic Operator object @@ -48,8 +49,7 @@ class GpgBasicOperator : public SingletonFunctionObject { * @param channel Channel corresponding to the context */ explicit GpgBasicOperator( - int channel = SingletonFunctionObject::GetDefaultChannel()) - : SingletonFunctionObject(channel) {} + int channel = SingletonFunctionObject::GetDefaultChannel()); /** * @brief Call the interface provided by gpgme for encryption operation diff --git a/src/core/function/gpg/GpgCommandExecutor.cpp b/src/core/function/gpg/GpgCommandExecutor.cpp index a6a67d08..2292ed0e 100644 --- a/src/core/function/gpg/GpgCommandExecutor.cpp +++ b/src/core/function/gpg/GpgCommandExecutor.cpp @@ -26,6 +26,10 @@ * */ #include "GpgCommandExecutor.h" + +GpgFrontend::GpgCommandExecutor::GpgCommandExecutor(int channel) + : SingletonFunctionObject(channel) {} + #ifndef WINDOWS #include #endif diff --git a/src/core/function/gpg/GpgCommandExecutor.h b/src/core/function/gpg/GpgCommandExecutor.h index 49baf406..00d9b43d 100644 --- a/src/core/function/gpg/GpgCommandExecutor.h +++ b/src/core/function/gpg/GpgCommandExecutor.h @@ -42,7 +42,7 @@ namespace GpgFrontend { * @brief Extra commands related to GPG * */ -class GpgCommandExecutor : public SingletonFunctionObject { +class GPGFRONTEND_CORE_EXPORT GpgCommandExecutor : public SingletonFunctionObject { public: /** * @brief Construct a new Gpg Command Executor object @@ -50,8 +50,7 @@ class GpgCommandExecutor : public SingletonFunctionObject { * @param channel Corresponding context */ explicit GpgCommandExecutor( - int channel = SingletonFunctionObject::GetDefaultChannel()) - : SingletonFunctionObject(channel) {} + int channel = SingletonFunctionObject::GetDefaultChannel()); #ifndef WINDOWS diff --git a/src/core/function/gpg/GpgFileOpera.cpp b/src/core/function/gpg/GpgFileOpera.cpp index 25357288..30678cf0 100644 --- a/src/core/function/gpg/GpgFileOpera.cpp +++ b/src/core/function/gpg/GpgFileOpera.cpp @@ -30,24 +30,28 @@ #include #include -#include "GpgConstants.h" #include "GpgBasicOperator.h" +#include "GpgConstants.h" #include "function/FileOperator.h" +GpgFrontend::GpgFileOpera::GpgFileOpera(int channel) + : SingletonFunctionObject(channel) {} + GpgFrontend::GpgError GpgFrontend::GpgFileOpera::EncryptFile( KeyListPtr keys, const std::string& in_path, const std::string& out_path, GpgEncrResult& result, int _channel) { - #ifdef WINDOWS - auto in_path_std = std::filesystem::path(QString::fromStdString(in_path).toStdU16String()); - auto out_path_std = std::filesystem::path(QString::fromStdString(out_path).toStdU16String()); + auto in_path_std = + std::filesystem::path(QString::fromStdString(in_path).toStdU16String()); + auto out_path_std = + std::filesystem::path(QString::fromStdString(out_path).toStdU16String()); #else - auto in_path_std = std::filesystem::path(in_path); - auto out_path_std = std::filesystem::path(out_path); + auto in_path_std = std::filesystem::path(in_path); + auto out_path_std = std::filesystem::path(out_path); #endif std::string in_buffer; - if(!FileOperator::ReadFileStd(in_path_std, in_buffer)) { + if (!FileOperator::ReadFileStd(in_path_std, in_buffer)) { throw std::runtime_error("read file error"); } @@ -67,17 +71,18 @@ GpgFrontend::GpgError GpgFrontend::GpgFileOpera::EncryptFile( GpgFrontend::GpgError GpgFrontend::GpgFileOpera::DecryptFile( const std::string& in_path, const std::string& out_path, GpgDecrResult& result) { - #ifdef WINDOWS - auto in_path_std = std::filesystem::path(QString::fromStdString(in_path).toStdU16String()); - auto out_path_std = std::filesystem::path(QString::fromStdString(out_path).toStdU16String()); + auto in_path_std = + std::filesystem::path(QString::fromStdString(in_path).toStdU16String()); + auto out_path_std = + std::filesystem::path(QString::fromStdString(out_path).toStdU16String()); #else auto in_path_std = std::filesystem::path(in_path); auto out_path_std = std::filesystem::path(out_path); #endif std::string in_buffer; - if(!FileOperator::ReadFileStd(in_path_std, in_buffer)) { + if (!FileOperator::ReadFileStd(in_path_std, in_buffer)) { throw std::runtime_error("read file error"); } std::unique_ptr out_buffer; @@ -100,17 +105,18 @@ gpgme_error_t GpgFrontend::GpgFileOpera::SignFile(KeyListPtr keys, const std::string& out_path, GpgSignResult& result, int _channel) { - #ifdef WINDOWS - auto in_path_std = std::filesystem::path(QString::fromStdString(in_path).toStdU16String()); - auto out_path_std = std::filesystem::path(QString::fromStdString(out_path).toStdU16String()); + auto in_path_std = + std::filesystem::path(QString::fromStdString(in_path).toStdU16String()); + auto out_path_std = + std::filesystem::path(QString::fromStdString(out_path).toStdU16String()); #else auto in_path_std = std::filesystem::path(in_path); auto out_path_std = std::filesystem::path(out_path); #endif std::string in_buffer; - if(!FileOperator::ReadFileStd(in_path_std, in_buffer)) { + if (!FileOperator::ReadFileStd(in_path_std, in_buffer)) { throw std::runtime_error("read file error"); } std::unique_ptr out_buffer; @@ -129,17 +135,18 @@ gpgme_error_t GpgFrontend::GpgFileOpera::SignFile(KeyListPtr keys, gpgme_error_t GpgFrontend::GpgFileOpera::VerifyFile( const std::string& data_path, const std::string& sign_path, GpgVerifyResult& result, int _channel) { - #ifdef WINDOWS - auto data_path_std = std::filesystem::path(QString::fromStdString(data_path).toStdU16String()); - auto sign_path_std = std::filesystem::path(QString::fromStdString(sign_path).toStdU16String()); + auto data_path_std = + std::filesystem::path(QString::fromStdString(data_path).toStdU16String()); + auto sign_path_std = + std::filesystem::path(QString::fromStdString(sign_path).toStdU16String()); #else auto data_path_std = std::filesystem::path(data_path); auto sign_path_std = std::filesystem::path(sign_path); #endif std::string in_buffer; - if(!FileOperator::ReadFileStd(data_path_std, in_buffer)) { + if (!FileOperator::ReadFileStd(data_path_std, in_buffer)) { throw std::runtime_error("read file error"); } std::unique_ptr sign_buffer = nullptr; @@ -148,11 +155,10 @@ gpgme_error_t GpgFrontend::GpgFileOpera::VerifyFile( if (!FileOperator::ReadFileStd(sign_path_std, sign_buffer_str)) { throw std::runtime_error("read file error"); } - sign_buffer = - std::make_unique(sign_buffer_str); + sign_buffer = std::make_unique(sign_buffer_str); } - auto err = GpgBasicOperator::GetInstance(_channel).Verify(in_buffer, sign_buffer, - result); + auto err = GpgBasicOperator::GetInstance(_channel).Verify( + in_buffer, sign_buffer, result); return err; } @@ -160,17 +166,18 @@ gpg_error_t GpgFrontend::GpgFileOpera::EncryptSignFile( KeyListPtr keys, KeyListPtr signer_keys, const std::string& in_path, const std::string& out_path, GpgEncrResult& encr_res, GpgSignResult& sign_res, int _channel) { - #ifdef WINDOWS - auto in_path_std = std::filesystem::path(QString::fromStdString(in_path).toStdU16String()); - auto out_path_std = std::filesystem::path(QString::fromStdString(out_path).toStdU16String()); + auto in_path_std = + std::filesystem::path(QString::fromStdString(in_path).toStdU16String()); + auto out_path_std = + std::filesystem::path(QString::fromStdString(out_path).toStdU16String()); #else auto in_path_std = std::filesystem::path(in_path); auto out_path_std = std::filesystem::path(out_path); #endif std::string in_buffer; - if(!FileOperator::ReadFileStd(in_path_std, in_buffer)) { + if (!FileOperator::ReadFileStd(in_path_std, in_buffer)) { throw std::runtime_error("read file error"); } std::unique_ptr out_buffer = nullptr; @@ -190,23 +197,24 @@ gpg_error_t GpgFrontend::GpgFileOpera::EncryptSignFile( gpg_error_t GpgFrontend::GpgFileOpera::DecryptVerifyFile( const std::string& in_path, const std::string& out_path, GpgDecrResult& decr_res, GpgVerifyResult& verify_res) { - #ifdef WINDOWS - auto in_path_std = std::filesystem::path(QString::fromStdString(in_path).toStdU16String()); - auto out_path_std = std::filesystem::path(QString::fromStdString(out_path).toStdU16String()); + auto in_path_std = + std::filesystem::path(QString::fromStdString(in_path).toStdU16String()); + auto out_path_std = + std::filesystem::path(QString::fromStdString(out_path).toStdU16String()); #else auto in_path_std = std::filesystem::path(in_path); auto out_path_std = std::filesystem::path(out_path); #endif std::string in_buffer; - if(!FileOperator::ReadFileStd(in_path_std, in_buffer)) { + if (!FileOperator::ReadFileStd(in_path_std, in_buffer)) { throw std::runtime_error("read file error"); } std::unique_ptr out_buffer = nullptr; - auto err = GpgBasicOperator::GetInstance().DecryptVerify(in_buffer, out_buffer, - decr_res, verify_res); + auto err = GpgBasicOperator::GetInstance().DecryptVerify( + in_buffer, out_buffer, decr_res, verify_res); if (check_gpg_error_2_err_code(err) == GPG_ERR_NO_ERROR) if (!FileOperator::WriteFileStd(out_path_std, *out_buffer)) { @@ -218,17 +226,18 @@ gpg_error_t GpgFrontend::GpgFileOpera::DecryptVerifyFile( unsigned int GpgFrontend::GpgFileOpera::EncryptFileSymmetric( const std::string& in_path, const std::string& out_path, GpgFrontend::GpgEncrResult& result, int _channel) { - #ifdef WINDOWS - auto in_path_std = std::filesystem::path(QString::fromStdString(in_path).toStdU16String()); - auto out_path_std = std::filesystem::path(QString::fromStdString(out_path).toStdU16String()); + auto in_path_std = + std::filesystem::path(QString::fromStdString(in_path).toStdU16String()); + auto out_path_std = + std::filesystem::path(QString::fromStdString(out_path).toStdU16String()); #else auto in_path_std = std::filesystem::path(in_path); auto out_path_std = std::filesystem::path(out_path); #endif std::string in_buffer; - if(!FileOperator::ReadFileStd(in_path_std, in_buffer)) { + if (!FileOperator::ReadFileStd(in_path_std, in_buffer)) { throw std::runtime_error("read file error"); } diff --git a/src/core/function/gpg/GpgFileOpera.h b/src/core/function/gpg/GpgFileOpera.h index f21bf04c..3f223535 100644 --- a/src/core/function/gpg/GpgFileOpera.h +++ b/src/core/function/gpg/GpgFileOpera.h @@ -40,11 +40,12 @@ namespace GpgFrontend { * GpgBasicOperator * @class class: GpgBasicOperator */ -class GpgFileOpera : public SingletonFunctionObject { +class GPGFRONTEND_CORE_EXPORT GpgFileOpera + : public SingletonFunctionObject { public: + explicit GpgFileOpera( - int channel = SingletonFunctionObject::GetDefaultChannel()) - : SingletonFunctionObject(channel) {} + int channel = SingletonFunctionObject::GetDefaultChannel()); /** * @brief Encrypted file diff --git a/src/core/function/gpg/GpgKeyGetter.cpp b/src/core/function/gpg/GpgKeyGetter.cpp index 1a4715e7..cbd40efc 100644 --- a/src/core/function/gpg/GpgKeyGetter.cpp +++ b/src/core/function/gpg/GpgKeyGetter.cpp @@ -32,6 +32,9 @@ #include "GpgConstants.h" +GpgFrontend::GpgKeyGetter::GpgKeyGetter(int channel) + : SingletonFunctionObject(channel) {} + GpgFrontend::GpgKey GpgFrontend::GpgKeyGetter::GetKey(const std::string& fpr) { gpgme_key_t _p_key = nullptr; gpgme_get_key(ctx_, fpr.c_str(), &_p_key, 1); @@ -57,6 +60,9 @@ GpgFrontend::KeyLinkListPtr GpgFrontend::GpgKeyGetter::FetchKey() { auto keys_list = std::make_unique(); + LOG(INFO) << "GpgKeyGetter FetchKey" + << "ctx address" << ctx_; + err = gpgme_op_keylist_start(ctx_, nullptr, 0); assert(check_gpg_error_2_err_code(err) == GPG_ERR_NO_ERROR); diff --git a/src/core/function/gpg/GpgKeyGetter.h b/src/core/function/gpg/GpgKeyGetter.h index cde027a0..d63238f5 100644 --- a/src/core/function/gpg/GpgKeyGetter.h +++ b/src/core/function/gpg/GpgKeyGetter.h @@ -39,7 +39,8 @@ namespace GpgFrontend { * @brief * */ -class GpgKeyGetter : public SingletonFunctionObject { +class GPGFRONTEND_CORE_EXPORT GpgKeyGetter + : public SingletonFunctionObject { public: /** * @brief Construct a new Gpg Key Getter object @@ -47,8 +48,7 @@ class GpgKeyGetter : public SingletonFunctionObject { * @param channel */ explicit GpgKeyGetter( - int channel = SingletonFunctionObject::GetDefaultChannel()) - : SingletonFunctionObject(channel) {} + int channel = SingletonFunctionObject::GetDefaultChannel()); /** * @brief Get the Key object diff --git a/src/core/function/gpg/GpgKeyImportExporter.cpp b/src/core/function/gpg/GpgKeyImportExporter.cpp index 0f1ebfa2..206282ae 100644 --- a/src/core/function/gpg/GpgKeyImportExporter.cpp +++ b/src/core/function/gpg/GpgKeyImportExporter.cpp @@ -31,6 +31,9 @@ #include "GpgConstants.h" #include "GpgKeyGetter.h" +GpgFrontend::GpgKeyImportExporter::GpgKeyImportExporter(int channel) + : SingletonFunctionObject(channel) {} + /** * Import key pair * @param inBuffer input byte array @@ -176,3 +179,23 @@ bool GpgFrontend::GpgKeyImportExporter::ExportSecretKeyShortest( std::swap(out_buffer, temp_out_buffer); return check_gpg_error_2_err_code(err) == GPG_ERR_NO_ERROR; } + +GpgFrontend::GpgImportInformation::GpgImportInformation() = default; + +GpgFrontend::GpgImportInformation::GpgImportInformation( + gpgme_import_result_t result) { + if (result->unchanged) unchanged = result->unchanged; + if (result->considered) considered = result->considered; + if (result->no_user_id) no_user_id = result->no_user_id; + if (result->imported) imported = result->imported; + if (result->imported_rsa) imported_rsa = result->imported_rsa; + if (result->unchanged) unchanged = result->unchanged; + if (result->new_user_ids) new_user_ids = result->new_user_ids; + if (result->new_sub_keys) new_sub_keys = result->new_sub_keys; + if (result->new_signatures) new_signatures = result->new_signatures; + if (result->new_revocations) new_revocations = result->new_revocations; + if (result->secret_read) secret_read = result->secret_read; + if (result->secret_imported) secret_imported = result->secret_imported; + if (result->secret_unchanged) secret_unchanged = result->secret_unchanged; + if (result->not_imported) not_imported = result->not_imported; +} diff --git a/src/core/function/gpg/GpgKeyImportExporter.h b/src/core/function/gpg/GpgKeyImportExporter.h index d7e6deae..7603c17d 100644 --- a/src/core/function/gpg/GpgKeyImportExporter.h +++ b/src/core/function/gpg/GpgKeyImportExporter.h @@ -54,45 +54,31 @@ typedef std::list GpgImportedKeyList; ///< * @brief * */ -class GpgImportInformation { +class GPGFRONTEND_CORE_EXPORT GpgImportInformation { public: - GpgImportInformation() = default; + GpgImportInformation(); /** * @brief Construct a new Gpg Import Information object * * @param result */ - explicit GpgImportInformation(gpgme_import_result_t result) { - if (result->unchanged) unchanged = result->unchanged; - if (result->considered) considered = result->considered; - if (result->no_user_id) no_user_id = result->no_user_id; - if (result->imported) imported = result->imported; - if (result->imported_rsa) imported_rsa = result->imported_rsa; - if (result->unchanged) unchanged = result->unchanged; - if (result->new_user_ids) new_user_ids = result->new_user_ids; - if (result->new_sub_keys) new_sub_keys = result->new_sub_keys; - if (result->new_signatures) new_signatures = result->new_signatures; - if (result->new_revocations) new_revocations = result->new_revocations; - if (result->secret_read) secret_read = result->secret_read; - if (result->secret_imported) secret_imported = result->secret_imported; - if (result->secret_unchanged) secret_unchanged = result->secret_unchanged; - if (result->not_imported) not_imported = result->not_imported; - } - - int considered = 0; ///< - int no_user_id = 0; ///< - int imported = 0; ///< - int imported_rsa = 0; ///< - int unchanged = 0; ///< - int new_user_ids = 0; ///< - int new_sub_keys = 0; ///< - int new_signatures = 0; ///< - int new_revocations = 0; ///< - int secret_read = 0; ///< - int secret_imported = 0; ///< - int secret_unchanged = 0; ///< - int not_imported = 0; ///< + explicit GpgImportInformation(gpgme_import_result_t result); + + int considered = 0; ///< + int no_user_id = 0; ///< + int imported = 0; ///< + int imported_rsa = 0; ///< + int unchanged = 0; ///< + int new_user_ids = 0; ///< + int new_sub_keys = 0; ///< + int new_signatures = 0; ///< + int new_revocations = 0; ///< + int secret_read = 0; ///< + int secret_imported = 0; ///< + int secret_unchanged = 0; ///< + int not_imported = 0; ///< + GpgImportedKeyList importedKeys; ///< }; @@ -100,7 +86,7 @@ class GpgImportInformation { * @brief * */ -class GpgKeyImportExporter +class GPGFRONTEND_CORE_EXPORT GpgKeyImportExporter : public SingletonFunctionObject { public: /** @@ -109,8 +95,7 @@ class GpgKeyImportExporter * @param channel */ explicit GpgKeyImportExporter( - int channel = SingletonFunctionObject::GetDefaultChannel()) - : SingletonFunctionObject(channel) {} + int channel = SingletonFunctionObject::GetDefaultChannel()); /** * @brief diff --git a/src/core/function/gpg/GpgKeyManager.cpp b/src/core/function/gpg/GpgKeyManager.cpp index c17df49e..050a8238 100644 --- a/src/core/function/gpg/GpgKeyManager.cpp +++ b/src/core/function/gpg/GpgKeyManager.cpp @@ -34,6 +34,9 @@ #include "GpgBasicOperator.h" #include "GpgKeyGetter.h" +GpgFrontend::GpgKeyManager::GpgKeyManager(int channel) + : SingletonFunctionObject(channel) {} + bool GpgFrontend::GpgKeyManager::SignKey( const GpgFrontend::GpgKey& target, GpgFrontend::KeyArgsList& keys, const std::string& uid, diff --git a/src/core/function/gpg/GpgKeyManager.h b/src/core/function/gpg/GpgKeyManager.h index 5bcac545..22738594 100644 --- a/src/core/function/gpg/GpgKeyManager.h +++ b/src/core/function/gpg/GpgKeyManager.h @@ -39,7 +39,8 @@ namespace GpgFrontend { * @brief * */ -class GpgKeyManager : public SingletonFunctionObject { +class GPGFRONTEND_CORE_EXPORT GpgKeyManager + : public SingletonFunctionObject { public: /** * @brief Construct a new Gpg Key Manager object @@ -47,8 +48,7 @@ class GpgKeyManager : public SingletonFunctionObject { * @param channel */ explicit GpgKeyManager( - int channel = SingletonFunctionObject::GetDefaultChannel()) - : SingletonFunctionObject(channel) {} + int channel = SingletonFunctionObject::GetDefaultChannel()); /** * @brief Sign a key pair(actually a certain uid) diff --git a/src/core/function/gpg/GpgKeyOpera.cpp b/src/core/function/gpg/GpgKeyOpera.cpp index 23dcae9f..e36edfd9 100644 --- a/src/core/function/gpg/GpgKeyOpera.cpp +++ b/src/core/function/gpg/GpgKeyOpera.cpp @@ -41,6 +41,10 @@ #include "GpgCommandExecutor.h" #include "GpgKeyGetter.h" +GpgFrontend::GpgKeyOpera::GpgKeyOpera( + int channel) + : SingletonFunctionObject(channel) {} + /** * Delete keys * @param uidList key ids @@ -178,6 +182,8 @@ GpgFrontend::GpgError GpgFrontend::GpgKeyOpera::GenerateKey( GpgError err; + LOG(INFO) << "ctx version" << ctx_.GetInfo().GnupgVersion; + if (ctx_.GetInfo().GnupgVersion >= "2.1.0") { unsigned int flags = 0; diff --git a/src/core/function/gpg/GpgKeyOpera.h b/src/core/function/gpg/GpgKeyOpera.h index 04571c10..703eb824 100644 --- a/src/core/function/gpg/GpgKeyOpera.h +++ b/src/core/function/gpg/GpgKeyOpera.h @@ -44,7 +44,8 @@ class GenKeyInfo; * @brief * */ -class GpgKeyOpera : public SingletonFunctionObject { +class GPGFRONTEND_CORE_EXPORT GpgKeyOpera + : public SingletonFunctionObject { public: /** * @brief Construct a new Gpg Key Opera object @@ -52,8 +53,7 @@ class GpgKeyOpera : public SingletonFunctionObject { * @param channel */ explicit GpgKeyOpera( - int channel = SingletonFunctionObject::GetDefaultChannel()) - : SingletonFunctionObject(channel) {} + int channel = SingletonFunctionObject::GetDefaultChannel()); /** * @brief diff --git a/src/core/function/gpg/GpgUIDOperator.cpp b/src/core/function/gpg/GpgUIDOperator.cpp index dd0c43f6..33c29fa4 100644 --- a/src/core/function/gpg/GpgUIDOperator.cpp +++ b/src/core/function/gpg/GpgUIDOperator.cpp @@ -30,8 +30,11 @@ #include "boost/format.hpp" +GpgFrontend::GpgUIDOperator::GpgUIDOperator(int channel) + : SingletonFunctionObject(channel) {} + bool GpgFrontend::GpgUIDOperator::AddUID(const GpgFrontend::GpgKey& key, - const std::string& uid) { + const std::string& uid) { auto err = gpgme_op_adduid(ctx_, gpgme_key_t(key), uid.c_str(), 0); if (check_gpg_error_2_err_code(err) == GPG_ERR_NO_ERROR) return true; @@ -40,7 +43,7 @@ bool GpgFrontend::GpgUIDOperator::AddUID(const GpgFrontend::GpgKey& key, } bool GpgFrontend::GpgUIDOperator::RevUID(const GpgFrontend::GpgKey& key, - const std::string& uid) { + const std::string& uid) { auto err = check_gpg_error(gpgme_op_revuid(ctx_, gpgme_key_t(key), uid.c_str(), 0)); if (check_gpg_error_2_err_code(err) == GPG_ERR_NO_ERROR) @@ -50,7 +53,7 @@ bool GpgFrontend::GpgUIDOperator::RevUID(const GpgFrontend::GpgKey& key, } bool GpgFrontend::GpgUIDOperator::SetPrimaryUID(const GpgFrontend::GpgKey& key, - const std::string& uid) { + const std::string& uid) { auto err = check_gpg_error(gpgme_op_set_uid_flag( ctx_, gpgme_key_t(key), uid.c_str(), "primary", nullptr)); if (check_gpg_error_2_err_code(err) == GPG_ERR_NO_ERROR) @@ -59,9 +62,9 @@ bool GpgFrontend::GpgUIDOperator::SetPrimaryUID(const GpgFrontend::GpgKey& key, return false; } bool GpgFrontend::GpgUIDOperator::AddUID(const GpgFrontend::GpgKey& key, - const std::string& name, - const std::string& comment, - const std::string& email) { + const std::string& name, + const std::string& comment, + const std::string& email) { LOG(INFO) << "GpgFrontend::UidOperator::AddUID" << name << comment << email; auto uid = boost::format("%1%(%2%)<%3%>") % name % comment % email; return AddUID(key, uid.str()); diff --git a/src/core/function/gpg/GpgUIDOperator.h b/src/core/function/gpg/GpgUIDOperator.h index 479505e5..c4a7d87b 100644 --- a/src/core/function/gpg/GpgUIDOperator.h +++ b/src/core/function/gpg/GpgUIDOperator.h @@ -37,11 +37,16 @@ namespace GpgFrontend { * @brief * */ -class GpgUIDOperator : public SingletonFunctionObject { +class GPGFRONTEND_CORE_EXPORT GpgUIDOperator + : public SingletonFunctionObject { public: + /** + * @brief Construct a new Gpg UID Opera object + * + * @param channel + */ explicit GpgUIDOperator( - int channel = SingletonFunctionObject::GetDefaultChannel()) - : SingletonFunctionObject(channel) {} + int channel = SingletonFunctionObject::GetDefaultChannel()); /** * create a new uid in certain key pair diff --git a/src/core/function/result_analyse/GpgDecryptResultAnalyse.h b/src/core/function/result_analyse/GpgDecryptResultAnalyse.h index af42f995..1fc08d1f 100644 --- a/src/core/function/result_analyse/GpgDecryptResultAnalyse.h +++ b/src/core/function/result_analyse/GpgDecryptResultAnalyse.h @@ -38,7 +38,8 @@ namespace GpgFrontend { * @brief * */ -class GpgDecryptResultAnalyse : public GpgResultAnalyse { +class GPGFRONTEND_CORE_EXPORT GpgDecryptResultAnalyse + : public GpgResultAnalyse { public: /** * @brief Construct a new Decrypt Result Analyse object diff --git a/src/core/function/result_analyse/GpgEncryptResultAnalyse.h b/src/core/function/result_analyse/GpgEncryptResultAnalyse.h index c5125fdc..6811ef06 100644 --- a/src/core/function/result_analyse/GpgEncryptResultAnalyse.h +++ b/src/core/function/result_analyse/GpgEncryptResultAnalyse.h @@ -37,7 +37,8 @@ namespace GpgFrontend { * @brief * */ -class GpgEncryptResultAnalyse : public GpgResultAnalyse { +class GPGFRONTEND_CORE_EXPORT GpgEncryptResultAnalyse + : public GpgResultAnalyse { public: /** * @brief Construct a new Encrypt Result Analyse object diff --git a/src/core/function/result_analyse/GpgResultAnalyse.h b/src/core/function/result_analyse/GpgResultAnalyse.h index 888c6449..e609505f 100644 --- a/src/core/function/result_analyse/GpgResultAnalyse.h +++ b/src/core/function/result_analyse/GpgResultAnalyse.h @@ -34,7 +34,7 @@ #include "core/GpgConstants.h" namespace GpgFrontend { -class GpgResultAnalyse { +class GPGFRONTEND_CORE_EXPORT GpgResultAnalyse { public: /** * @brief Construct a new Result Analyse object diff --git a/src/core/function/result_analyse/GpgSignResultAnalyse.h b/src/core/function/result_analyse/GpgSignResultAnalyse.h index d593b33d..43a78942 100644 --- a/src/core/function/result_analyse/GpgSignResultAnalyse.h +++ b/src/core/function/result_analyse/GpgSignResultAnalyse.h @@ -37,7 +37,7 @@ namespace GpgFrontend { * @brief * */ -class GpgSignResultAnalyse : public GpgResultAnalyse { +class GPGFRONTEND_CORE_EXPORT GpgSignResultAnalyse : public GpgResultAnalyse { public: /** * @brief Construct a new Sign Result Analyse object diff --git a/src/core/function/result_analyse/GpgVerifyResultAnalyse.h b/src/core/function/result_analyse/GpgVerifyResultAnalyse.h index 12e4b7ff..ce8e03ad 100644 --- a/src/core/function/result_analyse/GpgVerifyResultAnalyse.h +++ b/src/core/function/result_analyse/GpgVerifyResultAnalyse.h @@ -37,7 +37,7 @@ namespace GpgFrontend { * @brief * */ -class GpgVerifyResultAnalyse : public GpgResultAnalyse { +class GPGFRONTEND_CORE_EXPORT GpgVerifyResultAnalyse : public GpgResultAnalyse { public: /** * @brief Construct a new Verify Result Analyse object diff --git a/src/core/model/GpgData.cpp b/src/core/model/GpgData.cpp index 7fda4416..5aa95dc6 100644 --- a/src/core/model/GpgData.cpp +++ b/src/core/model/GpgData.cpp @@ -73,4 +73,6 @@ GpgFrontend::ByteArrayPtr GpgFrontend::GpgData::Read2Buffer() { } } return out_buffer; -} \ No newline at end of file +} + +GpgFrontend::GpgData::operator gpgme_data_t() { return data_ref_.get(); } \ No newline at end of file diff --git a/src/core/model/GpgData.h b/src/core/model/GpgData.h index c06f78d6..816465d3 100644 --- a/src/core/model/GpgData.h +++ b/src/core/model/GpgData.h @@ -58,7 +58,7 @@ class GpgData { * * @return gpgme_data_t */ - operator gpgme_data_t() { return data_ref_.get(); } + operator gpgme_data_t(); /** * @brief diff --git a/src/core/model/GpgKey.cpp b/src/core/model/GpgKey.cpp index b0952cfa..4b9d11d3 100644 --- a/src/core/model/GpgKey.cpp +++ b/src/core/model/GpgKey.cpp @@ -37,6 +37,118 @@ GpgFrontend::GpgKey &GpgFrontend::GpgKey::operator=(GpgKey &&k) noexcept { return *this; } +bool GpgFrontend::GpgKey::operator==(const GpgKey &o) const { + return o.GetId() == this->GetId(); +} + +bool GpgFrontend::GpgKey::operator<=(const GpgKey &o) const { + return this->GetId() < o.GetId(); +} + +GpgFrontend::GpgKey::operator gpgme_key_t() const { + return key_ref_.get(); +} + +bool GpgFrontend::GpgKey::IsGood() const { return key_ref_ != nullptr; } + +std::string GpgFrontend::GpgKey::GetId() const { + return key_ref_->subkeys->keyid; +} + +std::string GpgFrontend::GpgKey::GetName() const { + return key_ref_->uids->name; +}; + +std::string GpgFrontend::GpgKey::GetEmail() const { + return key_ref_->uids->email; +} + +std::string GpgFrontend::GpgKey::GetComment() const { + return key_ref_->uids->comment; +} + +std::string GpgFrontend::GpgKey::GetFingerprint() const { + return key_ref_->fpr; +} + +std::string GpgFrontend::GpgKey::GetProtocol() const { + return gpgme_get_protocol_name(key_ref_->protocol); +} + +std::string GpgFrontend::GpgKey::GetOwnerTrust() const { + switch (key_ref_->owner_trust) { + case GPGME_VALIDITY_UNKNOWN: + return "Unknown"; + case GPGME_VALIDITY_UNDEFINED: + return "Undefined"; + case GPGME_VALIDITY_NEVER: + return "Never"; + case GPGME_VALIDITY_MARGINAL: + return "Marginal"; + case GPGME_VALIDITY_FULL: + return "FULL"; + case GPGME_VALIDITY_ULTIMATE: + return "Ultimate"; + } + return "Invalid"; +} + +std::string GpgFrontend::GpgKey::GetPublicKeyAlgo() const { + return gpgme_pubkey_algo_name(key_ref_->subkeys->pubkey_algo); +} + +boost::posix_time::ptime GpgFrontend::GpgKey::GetLastUpdateTime() const { + return boost::posix_time::from_time_t( + static_cast(key_ref_->last_update)); +} + +boost::posix_time::ptime GpgFrontend::GpgKey::GetExpireTime() const { + return boost::posix_time::from_time_t(key_ref_->subkeys->expires); +}; + +boost::posix_time::ptime GpgFrontend::GpgKey::GetCreateTime() const { + return boost::posix_time::from_time_t(key_ref_->subkeys->timestamp); +}; + +unsigned int GpgFrontend::GpgKey::GetPrimaryKeyLength() const { + return key_ref_->subkeys->length; +} + +bool GpgFrontend::GpgKey::IsHasEncryptionCapability() const { + return key_ref_->can_encrypt; +} + +bool GpgFrontend::GpgKey::IsHasSigningCapability() const { + return key_ref_->can_sign; +} + +bool GpgFrontend::GpgKey::IsHasCertificationCapability() const { + return key_ref_->can_certify; +} + +bool GpgFrontend::GpgKey::IsHasAuthenticationCapability() const { + return key_ref_->can_authenticate; +} + +bool GpgFrontend::GpgKey::IsHasCardKey() const { + auto subkeys = GetSubKeys(); + return std::any_of( + subkeys->begin(), subkeys->end(), + [](const GpgSubKey &subkey) -> bool { return subkey.IsCardKey(); }); +} + +bool GpgFrontend::GpgKey::IsPrivateKey() const { return key_ref_->secret; } + +bool GpgFrontend::GpgKey::IsExpired() const { return key_ref_->expired; } + +bool GpgFrontend::GpgKey::IsRevoked() const { return key_ref_->revoked; } + +bool GpgFrontend::GpgKey::IsDisabled() const { return key_ref_->disabled; } + +bool GpgFrontend::GpgKey::IsHasMasterKey() const { + return key_ref_->subkeys->secret; +} + std::unique_ptr> GpgFrontend::GpgKey::GetSubKeys() const { auto p_keys = std::make_unique>(); @@ -113,3 +225,14 @@ bool GpgFrontend::GpgKey::IsHasActualEncryptionCapability() const { else return false; } + + +GpgFrontend::GpgKey GpgFrontend::GpgKey::Copy() const { + gpgme_key_ref(key_ref_.get()); + auto* _new_key_ref = key_ref_.get(); + return GpgKey(std::move(_new_key_ref)); +} + +void GpgFrontend::GpgKey::_key_ref_deleter::operator()(gpgme_key_t _key) { + if (_key != nullptr) gpgme_key_unref(_key); +} diff --git a/src/core/model/GpgKey.h b/src/core/model/GpgKey.h index 14315d4c..457b6540 100644 --- a/src/core/model/GpgKey.h +++ b/src/core/model/GpgKey.h @@ -41,7 +41,7 @@ namespace GpgFrontend { * @brief * */ -class GpgKey { +class GPGFRONTEND_CORE_EXPORT GpgKey { public: /** * @brief @@ -49,122 +49,91 @@ class GpgKey { * @return true * @return false */ - [[nodiscard]] bool IsGood() const { return key_ref_ != nullptr; } + [[nodiscard]] bool IsGood() const; /** * @brief * * @return std::string */ - [[nodiscard]] std::string GetId() const { return key_ref_->subkeys->keyid; } + [[nodiscard]] std::string GetId() const; /** * @brief * * @return std::string */ - [[nodiscard]] std::string GetName() const { return key_ref_->uids->name; }; + [[nodiscard]] std::string GetName() const; /** * @brief * * @return std::string */ - [[nodiscard]] std::string GetEmail() const { return key_ref_->uids->email; } + [[nodiscard]] std::string GetEmail() const; /** * @brief * * @return std::string */ - [[nodiscard]] std::string GetComment() const { - return key_ref_->uids->comment; - } + [[nodiscard]] std::string GetComment() const; /** * @brief * * @return std::string */ - [[nodiscard]] std::string GetFingerprint() const { return key_ref_->fpr; } + [[nodiscard]] std::string GetFingerprint() const; /** * @brief * * @return std::string */ - [[nodiscard]] std::string GetProtocol() const { - return gpgme_get_protocol_name(key_ref_->protocol); - } + [[nodiscard]] std::string GetProtocol() const; /** * @brief * * @return std::string */ - [[nodiscard]] std::string GetOwnerTrust() const { - switch (key_ref_->owner_trust) { - case GPGME_VALIDITY_UNKNOWN: - return "Unknown"; - case GPGME_VALIDITY_UNDEFINED: - return "Undefined"; - case GPGME_VALIDITY_NEVER: - return "Never"; - case GPGME_VALIDITY_MARGINAL: - return "Marginal"; - case GPGME_VALIDITY_FULL: - return "FULL"; - case GPGME_VALIDITY_ULTIMATE: - return "Ultimate"; - } - return "Invalid"; - } + [[nodiscard]] std::string GetOwnerTrust() const; /** * @brief * * @return std::string */ - [[nodiscard]] std::string GetPublicKeyAlgo() const { - return gpgme_pubkey_algo_name(key_ref_->subkeys->pubkey_algo); - } + [[nodiscard]] std::string GetPublicKeyAlgo() const; /** * @brief * * @return boost::posix_time::ptime */ - [[nodiscard]] boost::posix_time::ptime GetLastUpdateTime() const { - return boost::posix_time::from_time_t( - static_cast(key_ref_->last_update)); - } + [[nodiscard]] boost::posix_time::ptime GetLastUpdateTime() const; /** * @brief * * @return boost::posix_time::ptime */ - [[nodiscard]] boost::posix_time::ptime GetExpireTime() const { - return boost::posix_time::from_time_t(key_ref_->subkeys->expires); - }; + [[nodiscard]] boost::posix_time::ptime GetExpireTime() const; /** * @brief Create a time object * * @return boost::posix_time::ptime */ - [[nodiscard]] boost::posix_time::ptime GetCreateTime() const { - return boost::posix_time::from_time_t(key_ref_->subkeys->timestamp); - }; + [[nodiscard]] boost::posix_time::ptime GetCreateTime() const; /** * @brief s * * @return unsigned int */ - [[nodiscard]] unsigned int GetPrimaryKeyLength() const { - return key_ref_->subkeys->length; - } + [[nodiscard]] unsigned int GetPrimaryKeyLength() const; /** * @brief @@ -172,9 +141,7 @@ class GpgKey { * @return true * @return false */ - [[nodiscard]] bool IsHasEncryptionCapability() const { - return key_ref_->can_encrypt; - } + [[nodiscard]] bool IsHasEncryptionCapability() const; /** * @brief @@ -191,9 +158,7 @@ class GpgKey { * @return true * @return false */ - [[nodiscard]] bool IsHasSigningCapability() const { - return key_ref_->can_sign; - } + [[nodiscard]] bool IsHasSigningCapability() const; /** * @brief @@ -209,9 +174,7 @@ class GpgKey { * @return true * @return false */ - [[nodiscard]] bool IsHasCertificationCapability() const { - return key_ref_->can_certify; - } + [[nodiscard]] bool IsHasCertificationCapability() const; /** * @brief @@ -227,9 +190,7 @@ class GpgKey { * @return true * @return false */ - [[nodiscard]] bool IsHasAuthenticationCapability() const { - return key_ref_->can_authenticate; - } + [[nodiscard]] bool IsHasAuthenticationCapability() const; /** * @brief @@ -245,12 +206,7 @@ class GpgKey { * @return true * @return false */ - [[nodiscard]] bool IsHasCardKey() const { - auto subkeys = GetSubKeys(); - return std::any_of( - subkeys->begin(), subkeys->end(), - [](const GpgSubKey& subkey) -> bool { return subkey.IsCardKey(); }); - } + [[nodiscard]] bool IsHasCardKey() const; /** * @brief @@ -258,7 +214,7 @@ class GpgKey { * @return true * @return false */ - [[nodiscard]] bool IsPrivateKey() const { return key_ref_->secret; } + [[nodiscard]] bool IsPrivateKey() const; /** * @brief @@ -266,7 +222,7 @@ class GpgKey { * @return true * @return false */ - [[nodiscard]] bool IsExpired() const { return key_ref_->expired; } + [[nodiscard]] bool IsExpired() const; /** * @brief @@ -274,7 +230,7 @@ class GpgKey { * @return true * @return false */ - [[nodiscard]] bool IsRevoked() const { return key_ref_->revoked; } + [[nodiscard]] bool IsRevoked() const; /** * @brief @@ -282,7 +238,7 @@ class GpgKey { * @return true * @return false */ - [[nodiscard]] bool IsDisabled() const { return key_ref_->disabled; } + [[nodiscard]] bool IsDisabled() const; /** * @brief @@ -290,9 +246,7 @@ class GpgKey { * @return true * @return false */ - [[nodiscard]] bool IsHasMasterKey() const { - return key_ref_->subkeys->secret; - } + [[nodiscard]] bool IsHasMasterKey() const; /** * @brief @@ -364,7 +318,7 @@ class GpgKey { * @return true * @return false */ - bool operator==(const GpgKey& o) const { return o.GetId() == this->GetId(); } + bool operator==(const GpgKey& o) const; /** * @brief @@ -373,35 +327,29 @@ class GpgKey { * @return true * @return false */ - bool operator<=(const GpgKey& o) const { return this->GetId() < o.GetId(); } + bool operator<=(const GpgKey& o) const; /** * @brief * * @return gpgme_key_t */ - explicit operator gpgme_key_t() const { return key_ref_.get(); } + explicit operator gpgme_key_t() const; /** * @brief * * @return GpgKey */ - [[nodiscard]] GpgKey Copy() const { - gpgme_key_ref(key_ref_.get()); - auto* _new_key_ref = key_ref_.get(); - return GpgKey(std::move(_new_key_ref)); - } + [[nodiscard]] GpgKey Copy() const; private: /** * @brief * */ - struct _key_ref_deleter { - void operator()(gpgme_key_t _key) { - if (_key != nullptr) gpgme_key_unref(_key); - } + struct GPGFRONTEND_CORE_EXPORT _key_ref_deleter { + void operator()(gpgme_key_t _key); }; using KeyRefHandler = diff --git a/src/core/model/GpgKeySignature.cpp b/src/core/model/GpgKeySignature.cpp index 0c11a93b..aa196391 100644 --- a/src/core/model/GpgKeySignature.cpp +++ b/src/core/model/GpgKeySignature.cpp @@ -28,5 +28,67 @@ #include "core/model/GpgKeySignature.h" +GpgFrontend::GpgKeySignature::GpgKeySignature() = default; + +GpgFrontend::GpgKeySignature::~GpgKeySignature() = default; + GpgFrontend::GpgKeySignature::GpgKeySignature(gpgme_key_sig_t sig) : signature_ref_(sig, [&](gpgme_key_sig_t signature) {}) {} + +GpgFrontend::GpgKeySignature::GpgKeySignature(GpgKeySignature &&) noexcept = + default; + +GpgFrontend::GpgKeySignature &GpgFrontend::GpgKeySignature::operator=( + GpgKeySignature &&) noexcept = default; + +bool GpgFrontend::GpgKeySignature::IsRevoked() const { + return signature_ref_->revoked; +} + +bool GpgFrontend::GpgKeySignature::IsExpired() const { + return signature_ref_->expired; +} + +bool GpgFrontend::GpgKeySignature::IsInvalid() const { + return signature_ref_->invalid; +} + +bool GpgFrontend::GpgKeySignature::IsExportable() const { + return signature_ref_->exportable; +} + +gpgme_error_t GpgFrontend::GpgKeySignature::GetStatus() const { + return signature_ref_->status; +} + +std::string GpgFrontend::GpgKeySignature::GetKeyID() const { + return signature_ref_->keyid; +} + +std::string GpgFrontend::GpgKeySignature::GetPubkeyAlgo() const { + return gpgme_pubkey_algo_name(signature_ref_->pubkey_algo); +} + +boost::posix_time::ptime GpgFrontend::GpgKeySignature::GetCreateTime() const { + return boost::posix_time::from_time_t(signature_ref_->timestamp); +} + +boost::posix_time::ptime GpgFrontend::GpgKeySignature::GetExpireTime() const { + return boost::posix_time::from_time_t(signature_ref_->expires); +} + +std::string GpgFrontend::GpgKeySignature::GetUID() const { + return signature_ref_->uid; +} + +std::string GpgFrontend::GpgKeySignature::GetName() const { + return signature_ref_->name; +} + +std::string GpgFrontend::GpgKeySignature::GetEmail() const { + return signature_ref_->email; +} + +std::string GpgFrontend::GpgKeySignature::GetComment() const { + return signature_ref_->comment; +} \ No newline at end of file diff --git a/src/core/model/GpgKeySignature.h b/src/core/model/GpgKeySignature.h index 33b84904..25de2c75 100644 --- a/src/core/model/GpgKeySignature.h +++ b/src/core/model/GpgKeySignature.h @@ -44,7 +44,7 @@ namespace GpgFrontend { * @brief * */ -class GpgKeySignature { +class GPGFRONTEND_CORE_EXPORT GpgKeySignature { public: /** * @brief @@ -52,7 +52,7 @@ class GpgKeySignature { * @return true * @return false */ - [[nodiscard]] bool IsRevoked() const { return signature_ref_->revoked; } + [[nodiscard]] bool IsRevoked() const; /** * @brief @@ -60,7 +60,7 @@ class GpgKeySignature { * @return true * @return false */ - [[nodiscard]] bool IsExpired() const { return signature_ref_->expired; } + [[nodiscard]] bool IsExpired() const; /** * @brief @@ -68,7 +68,7 @@ class GpgKeySignature { * @return true * @return false */ - [[nodiscard]] bool IsInvalid() const { return signature_ref_->invalid; } + [[nodiscard]] bool IsInvalid() const; /** * @brief @@ -76,92 +76,82 @@ class GpgKeySignature { * @return true * @return false */ - [[nodiscard]] bool IsExportable() const { return signature_ref_->exportable; } + [[nodiscard]] bool IsExportable() const; /** * @brief * * @return gpgme_error_t */ - [[nodiscard]] gpgme_error_t GetStatus() const { - return signature_ref_->status; - } + [[nodiscard]] gpgme_error_t GetStatus() const; /** * @brief * * @return std::string */ - [[nodiscard]] std::string GetKeyID() const { return signature_ref_->keyid; } + [[nodiscard]] std::string GetKeyID() const; /** * @brief * * @return std::string */ - [[nodiscard]] std::string GetPubkeyAlgo() const { - return gpgme_pubkey_algo_name(signature_ref_->pubkey_algo); - } + [[nodiscard]] std::string GetPubkeyAlgo() const; /** * @brief Create a time object * * @return boost::posix_time::ptime */ - [[nodiscard]] boost::posix_time::ptime GetCreateTime() const { - return boost::posix_time::from_time_t(signature_ref_->timestamp); - } + [[nodiscard]] boost::posix_time::ptime GetCreateTime() const; /** * @brief * * @return boost::posix_time::ptime */ - [[nodiscard]] boost::posix_time::ptime GetExpireTime() const { - return boost::posix_time::from_time_t(signature_ref_->expires); - } + [[nodiscard]] boost::posix_time::ptime GetExpireTime() const; /** * @brief * * @return std::string */ - [[nodiscard]] std::string GetUID() const { return signature_ref_->uid; } + [[nodiscard]] std::string GetUID() const; /** * @brief * * @return std::string */ - [[nodiscard]] std::string GetName() const { return signature_ref_->name; } + [[nodiscard]] std::string GetName() const; /** * @brief * * @return std::string */ - [[nodiscard]] std::string GetEmail() const { return signature_ref_->email; } + [[nodiscard]] std::string GetEmail() const; /** * @brief * * @return std::string */ - [[nodiscard]] std::string GetComment() const { - return signature_ref_->comment; - } + [[nodiscard]] std::string GetComment() const; /** * @brief Construct a new Gpg Key Signature object * */ - GpgKeySignature() = default; + GpgKeySignature(); /** * @brief Destroy the Gpg Key Signature object * */ - ~GpgKeySignature() = default; + ~GpgKeySignature(); /** * @brief Construct a new Gpg Key Signature object @@ -174,7 +164,7 @@ class GpgKeySignature { * @brief Construct a new Gpg Key Signature object * */ - GpgKeySignature(GpgKeySignature &&) noexcept = default; + GpgKeySignature(GpgKeySignature &&) noexcept; /** * @brief Construct a new Gpg Key Signature object @@ -187,7 +177,7 @@ class GpgKeySignature { * * @return GpgKeySignature& */ - GpgKeySignature &operator=(GpgKeySignature &&) noexcept = default; + GpgKeySignature &operator=(GpgKeySignature &&) noexcept; /** * @brief diff --git a/src/core/model/GpgSignature.cpp b/src/core/model/GpgSignature.cpp index f8084442..73f9179d 100644 --- a/src/core/model/GpgSignature.cpp +++ b/src/core/model/GpgSignature.cpp @@ -28,5 +28,103 @@ #include "GpgSignature.h" +/** + * @brief Construct a new Gpg Signature object + * + */ +GpgFrontend::GpgSignature::GpgSignature(GpgSignature &&) noexcept = default; + +/** + * @brief + * + * @return GpgSignature& + */ +GpgFrontend::GpgSignature &GpgFrontend::GpgSignature::operator=( + GpgFrontend::GpgSignature &&) noexcept = default; + GpgFrontend::GpgSignature::GpgSignature(gpgme_signature_t sig) : signature_ref_(sig, [&](gpgme_signature_t signature) {}) {} + +/** + * @brief + * + * @return gpgme_validity_t + */ +gpgme_validity_t GpgFrontend::GpgSignature::GetValidity() const { + return signature_ref_->validity; +} + +/** + * @brief + * + * @return gpgme_error_t + */ +gpgme_error_t GpgFrontend::GpgSignature::GetStatus() const { + return signature_ref_->status; +} + +/** + * @brief + * + * @return gpgme_error_t + */ +gpgme_error_t GpgFrontend::GpgSignature::GetSummary() const { + return signature_ref_->summary; +} + +/** + * @brief + * + * @return std::string + */ +std::string GpgFrontend::GpgSignature::GetPubkeyAlgo() const { + return gpgme_pubkey_algo_name(signature_ref_->pubkey_algo); +} + +/** + * @brief + * + * @return std::string + */ +std::string GpgFrontend::GpgSignature::GetHashAlgo() const { + return gpgme_hash_algo_name(signature_ref_->hash_algo); +} + +/** + * @brief Create a time object + * + * @return boost::posix_time::ptime + */ +boost::posix_time::ptime GpgFrontend::GpgSignature::GetCreateTime() const { + return boost::posix_time::from_time_t(signature_ref_->timestamp); +} + +/** + * @brief + * + * @return boost::posix_time::ptime + */ +boost::posix_time::ptime GpgFrontend::GpgSignature::GetExpireTime() const { + return boost::posix_time::from_time_t(signature_ref_->exp_timestamp); +} + +/** + * @brief + * + * @return std::string + */ +std::string GpgFrontend::GpgSignature::GetFingerprint() const { + return signature_ref_->fpr; +} + +/** + * @brief Construct a new Gpg Signature object + * + */ +GpgFrontend::GpgSignature::GpgSignature() = default; + +/** + * @brief Destroy the Gpg Signature object + * + */ +GpgFrontend::GpgSignature::~GpgSignature() = default; diff --git a/src/core/model/GpgSignature.h b/src/core/model/GpgSignature.h index 942f0097..2e49c4d7 100644 --- a/src/core/model/GpgSignature.h +++ b/src/core/model/GpgSignature.h @@ -40,91 +40,75 @@ namespace GpgFrontend { * @brief * */ -class GpgSignature { +class GPGFRONTEND_CORE_EXPORT GpgSignature { public: /** * @brief * * @return gpgme_validity_t */ - [[nodiscard]] gpgme_validity_t GetValidity() const { - return signature_ref_->validity; - } + [[nodiscard]] gpgme_validity_t GetValidity() const; /** * @brief * * @return gpgme_error_t */ - [[nodiscard]] gpgme_error_t GetStatus() const { - return signature_ref_->status; - } + [[nodiscard]] gpgme_error_t GetStatus() const; /** * @brief * * @return gpgme_error_t */ - [[nodiscard]] gpgme_error_t GetSummary() const { - return signature_ref_->summary; - } + [[nodiscard]] gpgme_error_t GetSummary() const; /** * @brief * * @return std::string */ - [[nodiscard]] std::string GetPubkeyAlgo() const { - return gpgme_pubkey_algo_name(signature_ref_->pubkey_algo); - } + [[nodiscard]] std::string GetPubkeyAlgo() const; /** * @brief * * @return std::string */ - [[nodiscard]] std::string GetHashAlgo() const { - return gpgme_hash_algo_name(signature_ref_->hash_algo); - } + [[nodiscard]] std::string GetHashAlgo() const; /** * @brief Create a time object * * @return boost::posix_time::ptime */ - [[nodiscard]] boost::posix_time::ptime GetCreateTime() const { - return boost::posix_time::from_time_t(signature_ref_->timestamp); - } + [[nodiscard]] boost::posix_time::ptime GetCreateTime() const; /** * @brief * * @return boost::posix_time::ptime */ - [[nodiscard]] boost::posix_time::ptime GetExpireTime() const { - return boost::posix_time::from_time_t(signature_ref_->exp_timestamp); - } + [[nodiscard]] boost::posix_time::ptime GetExpireTime() const; /** * @brief * * @return std::string */ - [[nodiscard]] std::string GetFingerprint() const { - return signature_ref_->fpr; - } + [[nodiscard]] std::string GetFingerprint() const; /** * @brief Construct a new Gpg Signature object * */ - GpgSignature() = default; + GpgSignature(); /** * @brief Destroy the Gpg Signature object * */ - ~GpgSignature() = default; + ~GpgSignature(); /** * @brief Construct a new Gpg Signature object @@ -137,7 +121,7 @@ class GpgSignature { * @brief Construct a new Gpg Signature object * */ - GpgSignature(GpgSignature &&) noexcept = default; + GpgSignature(GpgSignature &&) noexcept; /** * @brief Construct a new Gpg Signature object @@ -150,7 +134,7 @@ class GpgSignature { * * @return GpgSignature& */ - GpgSignature &operator=(GpgSignature &&) noexcept = default; + GpgSignature &operator=(GpgSignature &&) noexcept; /** * @brief diff --git a/src/core/model/GpgSubKey.cpp b/src/core/model/GpgSubKey.cpp index 767f9c5d..e63816b1 100644 --- a/src/core/model/GpgSubKey.cpp +++ b/src/core/model/GpgSubKey.cpp @@ -27,5 +27,77 @@ */ #include "core/model/GpgSubKey.h" +GpgFrontend::GpgSubKey::GpgSubKey() = default; + GpgFrontend::GpgSubKey::GpgSubKey(gpgme_subkey_t subkey) : _subkey_ref(subkey, [&](gpgme_subkey_t subkey) {}) {} + +GpgFrontend::GpgSubKey::GpgSubKey(GpgSubKey&& o) noexcept { + swap(_subkey_ref, o._subkey_ref); +} + +GpgFrontend::GpgSubKey& GpgFrontend::GpgSubKey::operator=( + GpgSubKey&& o) noexcept { + swap(_subkey_ref, o._subkey_ref); + return *this; +}; + +bool GpgFrontend::GpgSubKey::operator==(const GpgSubKey& o) const { + return GetFingerprint() == o.GetFingerprint(); +} + +std::string GpgFrontend::GpgSubKey::GetID() const { return _subkey_ref->keyid; } + +std::string GpgFrontend::GpgSubKey::GetFingerprint() const { + return _subkey_ref->fpr; +} + +std::string GpgFrontend::GpgSubKey::GetPubkeyAlgo() const { + return gpgme_pubkey_algo_name(_subkey_ref->pubkey_algo); +} + +unsigned int GpgFrontend::GpgSubKey::GetKeyLength() const { + return _subkey_ref->length; +} + +bool GpgFrontend::GpgSubKey::IsHasEncryptionCapability() const { + return _subkey_ref->can_encrypt; +} + +bool GpgFrontend::GpgSubKey::IsHasSigningCapability() const { + return _subkey_ref->can_sign; +} + +bool GpgFrontend::GpgSubKey::IsHasCertificationCapability() const { + return _subkey_ref->can_certify; +} + +bool GpgFrontend::GpgSubKey::IsHasAuthenticationCapability() const { + return _subkey_ref->can_authenticate; +} + +bool GpgFrontend::GpgSubKey::IsPrivateKey() const { + return _subkey_ref->secret; +} + +bool GpgFrontend::GpgSubKey::IsExpired() const { return _subkey_ref->expired; } + +bool GpgFrontend::GpgSubKey::IsRevoked() const { return _subkey_ref->revoked; } + +bool GpgFrontend::GpgSubKey::IsDisabled() const { + return _subkey_ref->disabled; +} + +bool GpgFrontend::GpgSubKey::IsSecretKey() const { return _subkey_ref->secret; } + +bool GpgFrontend::GpgSubKey::IsCardKey() const { + return _subkey_ref->is_cardkey; +} + +boost::posix_time::ptime GpgFrontend::GpgSubKey::GetCreateTime() const { + return boost::posix_time::from_time_t(_subkey_ref->timestamp); +} + +boost::posix_time::ptime GpgFrontend::GpgSubKey::GetExpireTime() const { + return boost::posix_time::from_time_t(_subkey_ref->expires); +} diff --git a/src/core/model/GpgSubKey.h b/src/core/model/GpgSubKey.h index 1aadcdac..5a86d21d 100644 --- a/src/core/model/GpgSubKey.h +++ b/src/core/model/GpgSubKey.h @@ -40,39 +40,35 @@ namespace GpgFrontend { * @brief * */ -class GpgSubKey { +class GPGFRONTEND_CORE_EXPORT GpgSubKey { public: /** * @brief * * @return std::string */ - [[nodiscard]] std::string GetID() const { return _subkey_ref->keyid; } + [[nodiscard]] std::string GetID() const; /** * @brief * * @return std::string */ - [[nodiscard]] std::string GetFingerprint() const { return _subkey_ref->fpr; } + [[nodiscard]] std::string GetFingerprint() const; /** * @brief * * @return std::string */ - [[nodiscard]] std::string GetPubkeyAlgo() const { - return gpgme_pubkey_algo_name(_subkey_ref->pubkey_algo); - } + [[nodiscard]] std::string GetPubkeyAlgo() const; /** * @brief * * @return unsigned int */ - [[nodiscard]] unsigned int GetKeyLength() const { - return _subkey_ref->length; - } + [[nodiscard]] unsigned int GetKeyLength() const; /** * @brief @@ -80,9 +76,7 @@ class GpgSubKey { * @return true * @return false */ - [[nodiscard]] bool IsHasEncryptionCapability() const { - return _subkey_ref->can_encrypt; - } + [[nodiscard]] bool IsHasEncryptionCapability() const; /** * @brief @@ -90,9 +84,7 @@ class GpgSubKey { * @return true * @return false */ - [[nodiscard]] bool IsHasSigningCapability() const { - return _subkey_ref->can_sign; - } + [[nodiscard]] bool IsHasSigningCapability() const; /** * @brief @@ -100,9 +92,7 @@ class GpgSubKey { * @return true * @return false */ - [[nodiscard]] bool IsHasCertificationCapability() const { - return _subkey_ref->can_certify; - } + [[nodiscard]] bool IsHasCertificationCapability() const; /** * @brief @@ -110,9 +100,7 @@ class GpgSubKey { * @return true * @return false */ - [[nodiscard]] bool IsHasAuthenticationCapability() const { - return _subkey_ref->can_authenticate; - } + [[nodiscard]] bool IsHasAuthenticationCapability() const; /** * @brief @@ -120,7 +108,7 @@ class GpgSubKey { * @return true * @return false */ - [[nodiscard]] bool IsPrivateKey() const { return _subkey_ref->secret; } + [[nodiscard]] bool IsPrivateKey() const; /** * @brief @@ -128,7 +116,7 @@ class GpgSubKey { * @return true * @return false */ - [[nodiscard]] bool IsExpired() const { return _subkey_ref->expired; } + [[nodiscard]] bool IsExpired() const; /** * @brief @@ -136,7 +124,7 @@ class GpgSubKey { * @return true * @return false */ - [[nodiscard]] bool IsRevoked() const { return _subkey_ref->revoked; } + [[nodiscard]] bool IsRevoked() const; /** * @brief @@ -144,7 +132,7 @@ class GpgSubKey { * @return true * @return false */ - [[nodiscard]] bool IsDisabled() const { return _subkey_ref->disabled; } + [[nodiscard]] bool IsDisabled() const; /** * @brief @@ -152,7 +140,7 @@ class GpgSubKey { * @return true * @return false */ - [[nodiscard]] bool IsSecretKey() const { return _subkey_ref->secret; } + [[nodiscard]] bool IsSecretKey() const; /** * @brief @@ -160,31 +148,27 @@ class GpgSubKey { * @return true * @return false */ - [[nodiscard]] bool IsCardKey() const { return _subkey_ref->is_cardkey; } + [[nodiscard]] bool IsCardKey() const; /** * @brief * * @return boost::posix_time::ptime */ - [[nodiscard]] boost::posix_time::ptime GetCreateTime() const { - return boost::posix_time::from_time_t(_subkey_ref->timestamp); - } + [[nodiscard]] boost::posix_time::ptime GetCreateTime() const; /** * @brief * * @return boost::posix_time::ptime */ - [[nodiscard]] boost::posix_time::ptime GetExpireTime() const { - return boost::posix_time::from_time_t(_subkey_ref->expires); - } + [[nodiscard]] boost::posix_time::ptime GetExpireTime() const; /** * @brief Construct a new Gpg Sub Key object * */ - GpgSubKey() = default; + GpgSubKey(); /** * @brief Construct a new Gpg Sub Key object @@ -198,7 +182,7 @@ class GpgSubKey { * * @param o */ - GpgSubKey(GpgSubKey&& o) noexcept { swap(_subkey_ref, o._subkey_ref); } + GpgSubKey(GpgSubKey&& o) noexcept; /** * @brief Construct a new Gpg Sub Key object @@ -212,10 +196,7 @@ class GpgSubKey { * @param o * @return GpgSubKey& */ - GpgSubKey& operator=(GpgSubKey&& o) noexcept { - swap(_subkey_ref, o._subkey_ref); - return *this; - }; + GpgSubKey& operator=(GpgSubKey&& o) noexcept; /** * @brief @@ -231,9 +212,7 @@ class GpgSubKey { * @return true * @return false */ - bool operator==(const GpgSubKey& o) const { - return GetFingerprint() == o.GetFingerprint(); - } + bool operator==(const GpgSubKey& o) const; private: using SubkeyRefHandler = diff --git a/src/core/model/GpgTOFUInfo.cpp b/src/core/model/GpgTOFUInfo.cpp index 8c83b360..84ce1e29 100644 --- a/src/core/model/GpgTOFUInfo.cpp +++ b/src/core/model/GpgTOFUInfo.cpp @@ -28,5 +28,64 @@ #include "GpgTOFUInfo.h" +GpgFrontend::GpgTOFUInfo::GpgTOFUInfo() = default; + GpgFrontend::GpgTOFUInfo::GpgTOFUInfo(gpgme_tofu_info_t tofu_info) : _tofu_info_ref(tofu_info, [&](gpgme_tofu_info_t tofu_info) {}) {} + +GpgFrontend::GpgTOFUInfo::GpgTOFUInfo(GpgTOFUInfo&& o) noexcept { + swap(_tofu_info_ref, o._tofu_info_ref); +} + +GpgFrontend::GpgTOFUInfo& GpgFrontend::GpgTOFUInfo::operator=( + GpgTOFUInfo&& o) noexcept { + swap(_tofu_info_ref, o._tofu_info_ref); + return *this; +}; + +unsigned GpgFrontend::GpgTOFUInfo::GetValidity() const { + return _tofu_info_ref->validity; +} + +unsigned GpgFrontend::GpgTOFUInfo::GetPolicy() const { + return _tofu_info_ref->policy; +} + +unsigned long GpgFrontend::GpgTOFUInfo::GetSignCount() const { + return _tofu_info_ref->signcount; +} + +unsigned long GpgFrontend::GpgTOFUInfo::GetEncrCount() const { + return _tofu_info_ref->encrcount; +} + +unsigned long GpgFrontend::GpgTOFUInfo::GetSignFirst() const { + return _tofu_info_ref->signfirst; +} + +/** + * @brief + * + * @return unsigned long + */ +unsigned long GpgFrontend::GpgTOFUInfo::GetSignLast() const { + return _tofu_info_ref->signlast; +} + +/** + * @brief + * + * @return unsigned long + */ +unsigned long GpgFrontend::GpgTOFUInfo::GetEncrLast() const { + return _tofu_info_ref->encrlast; +} + +/** + * @brief + * + * @return std::string + */ +std::string GpgFrontend::GpgTOFUInfo::GetDescription() const { + return _tofu_info_ref->description; +} \ No newline at end of file diff --git a/src/core/model/GpgTOFUInfo.h b/src/core/model/GpgTOFUInfo.h index b2fea4cf..b82a4eb2 100644 --- a/src/core/model/GpgTOFUInfo.h +++ b/src/core/model/GpgTOFUInfo.h @@ -36,83 +36,68 @@ namespace GpgFrontend { * @brief * */ -class GpgTOFUInfo { +class GPGFRONTEND_CORE_EXPORT GpgTOFUInfo { public: /** * @brief * * @return unsigned */ - [[nodiscard]] unsigned GetValidity() const { - return _tofu_info_ref->validity; - } - + [[nodiscard]] unsigned GetValidity() const; /** * @brief * * @return unsigned */ - [[nodiscard]] unsigned GetPolicy() const { return _tofu_info_ref->policy; } + [[nodiscard]] unsigned GetPolicy() const; /** * @brief * * @return unsigned long */ - [[nodiscard]] unsigned long GetSignCount() const { - return _tofu_info_ref->signcount; - } + [[nodiscard]] unsigned long GetSignCount() const; /** * @brief * * @return unsigned long */ - [[nodiscard]] unsigned long GetEncrCount() const { - return _tofu_info_ref->encrcount; - } + [[nodiscard]] unsigned long GetEncrCount() const; /** * @brief * * @return unsigned long */ - [[nodiscard]] unsigned long GetSignFirst() const { - return _tofu_info_ref->signfirst; - } + [[nodiscard]] unsigned long GetSignFirst() const; /** * @brief * * @return unsigned long */ - [[nodiscard]] unsigned long GetSignLast() const { - return _tofu_info_ref->signlast; - } + [[nodiscard]] unsigned long GetSignLast() const; /** * @brief * * @return unsigned long */ - [[nodiscard]] unsigned long GetEncrLast() const { - return _tofu_info_ref->encrlast; - } + [[nodiscard]] unsigned long GetEncrLast() const; /** * @brief * * @return std::string */ - [[nodiscard]] std::string GetDescription() const { - return _tofu_info_ref->description; - } + [[nodiscard]] std::string GetDescription() const; /** * @brief Construct a new Gpg T O F U Info object * */ - GpgTOFUInfo() = default; + GpgTOFUInfo(); /** * @brief Construct a new Gpg T O F U Info object @@ -126,9 +111,7 @@ class GpgTOFUInfo { * * @param o */ - GpgTOFUInfo(GpgTOFUInfo&& o) noexcept { - swap(_tofu_info_ref, o._tofu_info_ref); - } + GpgTOFUInfo(GpgTOFUInfo&& o) noexcept; /** * @brief Construct a new Gpg T O F U Info object @@ -142,10 +125,7 @@ class GpgTOFUInfo { * @param o * @return GpgTOFUInfo& */ - GpgTOFUInfo& operator=(GpgTOFUInfo&& o) noexcept { - swap(_tofu_info_ref, o._tofu_info_ref); - return *this; - }; + GpgTOFUInfo& operator=(GpgTOFUInfo&& o) noexcept; /** * @brief diff --git a/src/core/model/GpgUID.cpp b/src/core/model/GpgUID.cpp index 6d98c882..d87192c3 100644 --- a/src/core/model/GpgUID.cpp +++ b/src/core/model/GpgUID.cpp @@ -28,5 +28,45 @@ #include "core/model/GpgUID.h" +GpgFrontend::GpgUID::GpgUID() = default; + GpgFrontend::GpgUID::GpgUID(gpgme_user_id_t uid) - : uid_ref_(uid, [&](gpgme_user_id_t uid) {}) {} \ No newline at end of file + : uid_ref_(uid, [&](gpgme_user_id_t uid) {}) {} + +GpgFrontend::GpgUID::GpgUID(GpgUID &&o) noexcept { swap(uid_ref_, o.uid_ref_); } + +std::string GpgFrontend::GpgUID::GetName() const { return uid_ref_->name; } + +std::string GpgFrontend::GpgUID::GetEmail() const { return uid_ref_->email; } + +std::string GpgFrontend::GpgUID::GetComment() const { + return uid_ref_->comment; +} + +std::string GpgFrontend::GpgUID::GetUID() const { return uid_ref_->uid; } + +bool GpgFrontend::GpgUID::GetRevoked() const { return uid_ref_->revoked; } + +bool GpgFrontend::GpgUID::GetInvalid() const { return uid_ref_->invalid; } + +std::unique_ptr> +GpgFrontend::GpgUID::GetTofuInfos() const { + auto infos = std::make_unique>(); + auto info_next = uid_ref_->tofu; + while (info_next != nullptr) { + infos->push_back(GpgTOFUInfo(info_next)); + info_next = info_next->next; + } + return infos; +} + +std::unique_ptr> +GpgFrontend::GpgUID::GetSignatures() const { + auto sigs = std::make_unique>(); + auto sig_next = uid_ref_->signatures; + while (sig_next != nullptr) { + sigs->push_back(GpgKeySignature(sig_next)); + sig_next = sig_next->next; + } + return sigs; +} diff --git a/src/core/model/GpgUID.h b/src/core/model/GpgUID.h index 7f8daf98..670c318d 100644 --- a/src/core/model/GpgUID.h +++ b/src/core/model/GpgUID.h @@ -37,35 +37,35 @@ namespace GpgFrontend { * @brief * */ -class GpgUID { +class GPGFRONTEND_CORE_EXPORT GpgUID { public: /** * @brief * * @return std::string */ - [[nodiscard]] std::string GetName() const { return uid_ref_->name; } + [[nodiscard]] std::string GetName() const; /** * @brief * * @return std::string */ - [[nodiscard]] std::string GetEmail() const { return uid_ref_->email; } + [[nodiscard]] std::string GetEmail() const; /** * @brief * * @return std::string */ - [[nodiscard]] std::string GetComment() const { return uid_ref_->comment; } + [[nodiscard]] std::string GetComment() const; /** * @brief * * @return std::string */ - [[nodiscard]] std::string GetUID() const { return uid_ref_->uid; } + [[nodiscard]] std::string GetUID() const; /** * @brief @@ -73,7 +73,7 @@ class GpgUID { * @return true * @return false */ - [[nodiscard]] bool GetRevoked() const { return uid_ref_->revoked; } + [[nodiscard]] bool GetRevoked() const; /** * @brief @@ -81,22 +81,14 @@ class GpgUID { * @return true * @return false */ - [[nodiscard]] bool GetInvalid() const { return uid_ref_->invalid; } + [[nodiscard]] bool GetInvalid() const; /** * @brief * * @return std::unique_ptr> */ - [[nodiscard]] std::unique_ptr> GetTofuInfos() const { - auto infos = std::make_unique>(); - auto info_next = uid_ref_->tofu; - while (info_next != nullptr) { - infos->push_back(GpgTOFUInfo(info_next)); - info_next = info_next->next; - } - return infos; - } + [[nodiscard]] std::unique_ptr> GetTofuInfos() const; /** * @brief @@ -104,21 +96,13 @@ class GpgUID { * @return std::unique_ptr> */ [[nodiscard]] std::unique_ptr> GetSignatures() - const { - auto sigs = std::make_unique>(); - auto sig_next = uid_ref_->signatures; - while (sig_next != nullptr) { - sigs->push_back(GpgKeySignature(sig_next)); - sig_next = sig_next->next; - } - return sigs; - } + const; /** * @brief Construct a new Gpg U I D object * */ - GpgUID() = default; + GpgUID(); /** * @brief Construct a new Gpg U I D object @@ -132,7 +116,7 @@ class GpgUID { * * @param o */ - GpgUID(GpgUID &&o) noexcept { swap(uid_ref_, o.uid_ref_); } + GpgUID(GpgUID &&o) noexcept; /** * @brief Construct a new Gpg U I D object @@ -146,10 +130,7 @@ class GpgUID { * @param o * @return GpgUID& */ - GpgUID &operator=(GpgUID &&o) noexcept { - swap(uid_ref_, o.uid_ref_); - return *this; - } + GpgUID &operator=(GpgUID &&o) noexcept; /** * @brief diff --git a/src/ui/thread/CtxCheckThread.cpp b/src/core/thread/CtxCheckThread.cpp similarity index 81% rename from src/ui/thread/CtxCheckThread.cpp rename to src/core/thread/CtxCheckThread.cpp index b1e50b94..77571dfd 100644 --- a/src/ui/thread/CtxCheckThread.cpp +++ b/src/core/thread/CtxCheckThread.cpp @@ -24,19 +24,23 @@ * */ -#include "CtxCheckThread.h" +#include "core/thread/CtxCheckThread.h" #include "core/GpgContext.h" #include "core/GpgCoreInit.h" +#include "core/common/CoreCommonUtil.h" #include "core/function/gpg/GpgKeyGetter.h" -#include "ui/UserInterfaceUtils.h" -GpgFrontend::UI::CtxCheckThread::CtxCheckThread() : QThread(nullptr) { +GpgFrontend::CtxCheckThread::CtxCheckThread() : QThread(nullptr) { connect(this, &CtxCheckThread::SignalGnupgNotInstall, - CommonUtils::GetInstance(), &CommonUtils::SignalGnupgNotInstall); + CoreCommonUtil::GetInstance(), + &CoreCommonUtil::SignalGnupgNotInstall); } -void GpgFrontend::UI::CtxCheckThread::run() { +void GpgFrontend::CtxCheckThread::run() { + // init logging + init_logging(); + // Init GpgFrontend Core init_gpgfrontend_core(); diff --git a/src/ui/thread/CtxCheckThread.h b/src/core/thread/CtxCheckThread.h similarity index 90% rename from src/ui/thread/CtxCheckThread.h rename to src/core/thread/CtxCheckThread.h index 36281525..c597141f 100644 --- a/src/ui/thread/CtxCheckThread.h +++ b/src/core/thread/CtxCheckThread.h @@ -26,13 +26,15 @@ #ifndef GPGFRONTEND_CTXCHECKTRHEAD_H #define GPGFRONTEND_CTXCHECKTRHEAD_H -#include "ui/GpgFrontendUI.h" -namespace GpgFrontend::UI { + +#include "core/GpgFrontendCore.h" + +namespace GpgFrontend { /** * @brief * */ -class CtxCheckThread : public QThread { +class GPGFRONTEND_CORE_EXPORT CtxCheckThread : public QThread { Q_OBJECT public: /** @@ -55,6 +57,6 @@ class CtxCheckThread : public QThread { */ void run() override; }; -} // namespace GpgFrontend::UI +} // namespace GpgFrontend #endif // GPGFRONTEND_CTXCHECKTRHEAD_H diff --git a/src/init.cpp b/src/init.cpp index f5bbb750..7aefc00f 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -26,8 +26,6 @@ * */ -#include - #include "core/function/GlobalSettingStation.h" /** @@ -51,58 +49,6 @@ std::vector get_files_of_directory( return path_list; } -/** - * @brief setup logging system and do proper initialization - * - */ -void init_logging() { - using namespace boost::posix_time; - using namespace boost::gregorian; - - ptime now = second_clock::local_time(); - - el::Loggers::addFlag(el::LoggingFlag::AutoSpacing); - el::Configurations defaultConf; - defaultConf.setToDefault(); - el::Loggers::reconfigureLogger("default", defaultConf); - - // apply settings - defaultConf.setGlobally(el::ConfigurationType::Format, - "%datetime %level %func %msg"); - - // get the log directory - auto logfile_path = - (GpgFrontend::GlobalSettingStation::GetInstance().GetLogDir() / - to_iso_string(now)); - logfile_path.replace_extension(".log"); - defaultConf.setGlobally(el::ConfigurationType::Filename, - logfile_path.u8string()); - - el::Loggers::reconfigureLogger("default", defaultConf); - - LOG(INFO) << _("log file path") << logfile_path; -} - -/** - * @brief load all certificates from the given path - * and add them to the given certificate store in GlobalSettingStation - */ -void init_certs() { - // get the certificate directory - auto cert_file_paths = get_files_of_directory( - GpgFrontend::GlobalSettingStation::GetInstance().GetCertsDir()); - - // get the instance of the GlobalSettingStation - auto& _instance = GpgFrontend::GlobalSettingStation::GetInstance(); - for (const auto& cert_file_path : cert_file_paths) { - // add the certificate to the store - _instance.AddRootCert(cert_file_path); - } - - // show the number of loaded certificates - LOG(INFO) << _("root certs loaded") << _instance.GetRootCerts().size(); -} - /** * @brief setup the locale and load the translations * diff --git a/src/main.cpp b/src/main.cpp index a63d2d02..51d977b2 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -36,8 +36,9 @@ #include "GpgFrontendBuildInfo.h" #include "core/GpgFunctionObject.h" +#include "core/thread/CtxCheckThread.h" +#include "ui/GpgFrontendUIInit.h" #include "ui/main_window/MainWindow.h" -#include "ui/thread/CtxCheckThread.h" #if !defined(RELEASE) && defined(WINDOWS) #include "core/function/GlobalSettingStation.h" @@ -53,18 +54,6 @@ INITIALIZE_EASYLOGGINGPP */ jmp_buf recover_env; -/** - * @brief - * - */ -extern void init_logging(); - -/** - * @brief - * - */ -extern void init_certs(); - /** * @brief * @@ -114,12 +103,6 @@ int main(int argc, char* argv[]) { QApplication::setAttribute(Qt::AA_UseHighDpiPixmaps); #endif - // initialize logging system - init_logging(); - - // init certs for tls connection - init_certs(); - // set the extra information of the build QApplication::setApplicationVersion(BUILD_VERSION); QApplication::setApplicationName(PROJECT_NAME); @@ -142,21 +125,8 @@ int main(int argc, char* argv[]) { file.close(); #endif -#ifdef GPG_STANDALONE_MODE - LOG(INFO) << "GPG_STANDALONE_MODE Enabled"; - auto gpg_path = GpgFrontend::GlobalSettingStation::GetInstance() - .GetStandaloneGpgBinDir(); - auto db_path = GpgFrontend::GlobalSettingStation::GetInstance() - .GetStandaloneDatabaseDir(); - GpgFrontend::GpgContext::CreateInstance( - GpgFrontend::SingletonFunctionObject< - GpgFrontend::GpgContext>::GetDefaultChannel(), - std::make_unique(true, db_path.u8string(), true, - gpg_path.u8string())); -#endif - // create the thread to load the gpg context - auto* init_ctx_thread = new GpgFrontend::UI::CtxCheckThread(); + auto* init_ctx_thread = new GpgFrontend::CtxCheckThread(); QApplication::connect(init_ctx_thread, &QThread::finished, init_ctx_thread, &QThread::deleteLater); @@ -195,6 +165,9 @@ int main(int argc, char* argv[]) { &QEventLoop::quit); loop.exec(); + // init ui logging + GpgFrontend::UI::init_logging(); + /** * internationalisation. loop to restart main window * with changed translation when settings change. diff --git a/src/ui/CMakeLists.txt b/src/ui/CMakeLists.txt index 001a776d..6016e45a 100644 --- a/src/ui/CMakeLists.txt +++ b/src/ui/CMakeLists.txt @@ -38,36 +38,13 @@ aux_source_directory(struct UI_SOURCE) aux_source_directory(import_export UI_SOURCE) aux_source_directory(dialog UI_SOURCE) -if (SMTP_SUPPORT) - aux_source_directory(mail UI_SOURCE) -endif () - # define libgpgfrontend_ui -add_library(gpgfrontend_ui STATIC ${UI_SOURCE}) - -# link smtp-mime -if (SMTP_SUPPORT) - target_link_libraries(gpgfrontend_ui - smtp-mime) -endif () +add_library(gpgfrontend_ui SHARED ${UI_SOURCE}) # link Qt target_link_libraries(gpgfrontend_ui Qt5::Network Qt5::PrintSupport Qt5::Widgets Qt5::Test Qt5::Core) -# link vmime -if (NOT LINUX) - # macOS - target_link_libraries(gpgfrontend_ui - gpgfrontend_vmime intl iconv) - if (MINGW) - target_link_libraries(gpgfrontend_ui ws2_32) - endif () -else () - target_link_libraries(gpgfrontend_ui - gpgfrontend_vmime anl ssl crypto) -endif () - # link gpgfrontend_core target_link_libraries(gpgfrontend_ui gpgfrontend_core) diff --git a/src/ui/GpgFrontendUI.h b/src/ui/GpgFrontendUI.h index ab6e9366..df6d891f 100644 --- a/src/ui/GpgFrontendUI.h +++ b/src/ui/GpgFrontendUI.h @@ -42,7 +42,7 @@ * Project internal dependencies */ #include "GpgFrontend.h" -#include "core/GpgConstants.h" +#include "core/GpgFrontendCore.h" #include "core/GpgModel.h" /** @@ -51,8 +51,4 @@ #include -#ifdef SMTP_SUPPORT -#include -#endif - #endif // GPGFRONTEND_GPGFRONTENDUI_H diff --git a/src/ui/mail/ReceiveMailDialog.h b/src/ui/GpgFrontendUIInit.cpp similarity index 51% rename from src/ui/mail/ReceiveMailDialog.h rename to src/ui/GpgFrontendUIInit.cpp index 2ccb2664..82746551 100644 --- a/src/ui/mail/ReceiveMailDialog.h +++ b/src/ui/GpgFrontendUIInit.cpp @@ -26,55 +26,39 @@ * */ -#ifndef GPGFRONTEND_RECEIVEMAILDIALOG_H -#define GPGFRONTEND_RECEIVEMAILDIALOG_H +#include "GpgFrontendUIInit.h" -#include "ui/GpgFrontendUI.h" +#include "core/function/GlobalSettingStation.h" -class Ui_ReceiveMailDialog; - -namespace vmime::net { -class folder; -}; +// init easyloggingpp library +INITIALIZE_EASYLOGGINGPP namespace GpgFrontend::UI { -class IMAPFolder; +void init_logging() { + using namespace boost::posix_time; + using namespace boost::gregorian; -/** - * @brief - * - */ -class ReceiveMailDialog : public QDialog { - Q_OBJECT - public: - /** - * @brief Construct a new Receive Mail Dialog object - * - * @param parent - */ - explicit ReceiveMailDialog(QWidget* parent); + ptime now = second_clock::local_time(); - private slots: - /** - * @brief - * - */ - void slot_refresh_data(); + el::Loggers::addFlag(el::LoggingFlag::AutoSpacing); + el::Configurations defaultConf; + defaultConf.setToDefault(); + el::Loggers::reconfigureLogger("default", defaultConf); - private: - std::shared_ptr ui_; ///< - std::vector> folders_; ///< + // apply settings + defaultConf.setGlobally(el::ConfigurationType::Format, + "%datetime %level %func %msg"); - /** - * @brief - * - * @param parent_folder - */ - void list_sub_folders(IMAPFolder* parent_folder, - const std::shared_ptr&); -}; + // get the log directory + auto logfile_path = + (GlobalSettingStation::GetInstance().GetLogDir() / to_iso_string(now)); + logfile_path.replace_extension(".log"); + defaultConf.setGlobally(el::ConfigurationType::Filename, + logfile_path.u8string()); -} // namespace GpgFrontend::UI + el::Loggers::reconfigureLogger("default", defaultConf); -#endif // GPGFRONTEND_RECEIVEMAILDIALOG_H + LOG(INFO) << _("log file path") << logfile_path; +} +} // namespace GpgFrontend::UI \ No newline at end of file diff --git a/src/ui/mail/ReceiveMailDialog.cpp b/src/ui/GpgFrontendUIInit.h similarity index 69% rename from src/ui/mail/ReceiveMailDialog.cpp rename to src/ui/GpgFrontendUIInit.h index 765e8baa..ddb791c3 100644 --- a/src/ui/mail/ReceiveMailDialog.cpp +++ b/src/ui/GpgFrontendUIInit.h @@ -26,17 +26,18 @@ * */ -#include "ReceiveMailDialog.h" +#ifndef GPGFRONTEND_GPGFRONTENDUIINIT_H +#define GPGFRONTEND_GPGFRONTENDUIINIT_H -#include "ui_ReceiveMailDialog.h" +#include "GpgFrontendUI.h" -GpgFrontend::UI::ReceiveMailDialog::ReceiveMailDialog(QWidget *parent) - : QDialog(parent), ui_(std::make_shared()) { - ui_->setupUi(this); -} +namespace GpgFrontend::UI { -void GpgFrontend::UI::ReceiveMailDialog::slot_refresh_data() {} +/** + * @brief + */ +void init_logging(); + +}; // namespace GpgFrontend::UI -void GpgFrontend::UI::ReceiveMailDialog::list_sub_folders( - GpgFrontend::UI::IMAPFolder *parent_folder, - const std::shared_ptr &) {} +#endif // GPGFRONTEND_GPGFRONTENDUIINIT_H diff --git a/src/ui/KeyMgmt.cpp b/src/ui/KeyMgmt.cpp index 57d8ba1f..30bc8a1b 100755 --- a/src/ui/KeyMgmt.cpp +++ b/src/ui/KeyMgmt.cpp @@ -42,6 +42,7 @@ #include "core/function/GlobalSettingStation.h" namespace GpgFrontend::UI { + KeyMgmt::KeyMgmt(QWidget* parent) : QMainWindow(parent) { /* the list of Keys available*/ key_list_ = new KeyList(KeyMenuAbility::ALL, this); diff --git a/src/ui/UserInterfaceUtils.cpp b/src/ui/UserInterfaceUtils.cpp index 8353d28b..52b7eb28 100644 --- a/src/ui/UserInterfaceUtils.cpp +++ b/src/ui/UserInterfaceUtils.cpp @@ -30,13 +30,11 @@ #include +#include "core/common/CoreCommonUtil.h" #include "core/function/FileOperator.h" -#include "core/function/result_analyse/GpgResultAnalyse.h" +#include "core/function/GlobalSettingStation.h" #include "ui/SignalStation.h" #include "ui/dialog/WaitingDialog.h" -#include "ui/mail/SendMailDialog.h" -#include "core/function/GlobalSettingStation.h" -#include "ui/widgets/InfoBoardWidget.h" #include "ui/widgets/TextEdit.h" namespace GpgFrontend::UI { @@ -44,31 +42,6 @@ namespace GpgFrontend::UI { std::unique_ptr GpgFrontend::UI::CommonUtils::instance_ = nullptr; -#ifdef SMTP_SUPPORT -void send_an_email(QWidget *parent, InfoBoardWidget *info_board, - const QString &text, bool attach_signature) { - info_board->AddOptionalAction(_("Send Encrypted Mail"), [=]() { - bool smtp_enabled = false; - try { - smtp_enabled = GlobalSettingStation::GetInstance().GetUISettings().lookup( - "smtp.enable"); - } catch (...) { - LOG(INFO) << "Reading smtp settings error"; - } - if (smtp_enabled) { - auto dialog = new SendMailDialog(text, parent); - dialog->SetContentEncryption(false); - dialog->SetAttachSignature(attach_signature); - dialog->show(); - } else { - QMessageBox::warning(nullptr, _("Function Disabled"), - _("Please go to the settings interface to " - "enable and configure this function.")); - } - }); -} -#endif - void show_verify_details(QWidget *parent, InfoBoardWidget *info_board, GpgError error, const GpgVerifyResult &verify_result) { // take out result @@ -156,6 +129,8 @@ CommonUtils *CommonUtils::GetInstance() { } CommonUtils::CommonUtils() : QWidget(nullptr) { + connect(CoreCommonUtil::GetInstance(), &CoreCommonUtil::SignalGnupgNotInstall, + this, &CommonUtils::SignalGnupgNotInstall); connect(this, &CommonUtils::SignalKeyStatusUpdated, SignalStation::GetInstance(), &SignalStation::SignalKeyDatabaseRefresh); @@ -252,7 +227,7 @@ void CommonUtils::SlotExecuteGpgCommand( } void CommonUtils::SlotImportKeyFromKeyServer( - int ctx_channel, const KeyIdArgsList &key_ids, + const KeyIdArgsList &key_ids, const ImportCallbackFunctiopn &callback) { std::string target_keyserver; if (target_keyserver.empty()) { @@ -274,7 +249,7 @@ void CommonUtils::SlotImportKeyFromKeyServer( } auto thread = - QThread::create([target_keyserver, key_ids, callback, ctx_channel]() { + QThread::create([target_keyserver, key_ids, callback]() { QUrl target_keyserver_url(target_keyserver.c_str()); auto network_manager = std::make_unique(); @@ -323,7 +298,7 @@ void CommonUtils::SlotImportKeyFromKeyServer( // Try importing GpgImportInformation result = - GpgKeyImportExporter::GetInstance(ctx_channel) + GpgKeyImportExporter::GetInstance() .ImportKey(std::move(key_data_ptr)); if (result.imported == 1) { diff --git a/src/ui/UserInterfaceUtils.h b/src/ui/UserInterfaceUtils.h index 9d73e9b5..a7f20f10 100644 --- a/src/ui/UserInterfaceUtils.h +++ b/src/ui/UserInterfaceUtils.h @@ -42,18 +42,6 @@ namespace GpgFrontend::UI { class InfoBoardWidget; class TextEdit; -#ifdef SMTP_SUPPORT -/** - * @brief - * - * @param parent - * @param info_board - * @param text - * @param attach_signature - */ -void send_an_email(QWidget* parent, InfoBoardWidget* info_board, - const QString& text, bool attach_signature = true); -#endif /** * @brief * @@ -194,7 +182,7 @@ class CommonUtils : public QWidget { * @param callback */ static void SlotImportKeyFromKeyServer( - int ctx_channel, const GpgFrontend::KeyIdArgsList& key_ids, + const GpgFrontend::KeyIdArgsList& key_ids, const GpgFrontend::UI::CommonUtils::ImportCallbackFunctiopn& callback); /** diff --git a/src/ui/mail/EmailListEditor.cpp b/src/ui/mail/EmailListEditor.cpp deleted file mode 100644 index b5147115..00000000 --- a/src/ui/mail/EmailListEditor.cpp +++ /dev/null @@ -1,106 +0,0 @@ -/** - * Copyright (C) 2021 Saturneric - * - * 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 . - * - * 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 starting on May 12, 2021. - * - * SPDX-License-Identifier: GPL-3.0-or-later - * - */ - -#include "EmailListEditor.h" - -#include "ui_EmailListEditor.h" - -GpgFrontend::UI::EmailListEditor::EmailListEditor(const QString& email_list, - QWidget* parent) - : QDialog(parent), ui_(std::make_shared()) { - ui_->setupUi(this); - - QStringList email_string_list = email_list.split(';'); - - if (!email_string_list.isEmpty()) { - for (const auto& recipient : email_string_list) { - auto _recipient = recipient.trimmed(); - if (check_email_address(_recipient)) { - auto item = new QListWidgetItem(_recipient); - ui_->emaillistWidget->addItem(item); - item->setFlags(item->flags() | Qt::ItemIsEditable); - } - } - } - - connect(ui_->addEmailAddressButton, &QPushButton::clicked, this, [=]() { - auto item = new QListWidgetItem("new email address"); - ui_->emaillistWidget->addItem(item); - item->setFlags(item->flags() | Qt::ItemIsEditable); - }); - - connect(ui_->actionDelete_Selected_Email_Address, &QAction::triggered, this, - [=]() { - const auto row_size = ui_->emaillistWidget->count(); - for (int i = 0; i < row_size; i++) { - auto item = ui_->emaillistWidget->item(i); - if (!item->isSelected()) continue; - delete ui_->emaillistWidget->takeItem( - ui_->emaillistWidget->row(item)); - break; - } - }); - - ui_->titleLabel->setText(_("Email List:")); - ui_->tipsLabel->setText( - _("Tips: You can double-click the email address in the edit list, or " - "click the email to pop up the option menu.")); - ui_->addEmailAddressButton->setText(_("Add An Email Address")); - this->setWindowTitle(_("Email List Editor")); - ui_->actionDelete_Selected_Email_Address->setText(_("Delete")); - - popup_menu_ = new QMenu(this); - popup_menu_->addAction(ui_->actionDelete_Selected_Email_Address); - - this->exec(); -} - -bool GpgFrontend::UI::EmailListEditor::check_email_address( - const QString& email_address) { - return re_email_.match(email_address).hasMatch(); -} - -QString GpgFrontend::UI::EmailListEditor::GetEmailList() { - QString email_list; - for (int i = 0; i < ui_->emaillistWidget->count(); ++i) { - QListWidgetItem* item = ui_->emaillistWidget->item(i); - if (check_email_address(item->text())) { - email_list.append(item->text()); - email_list.append("; "); - } - } - return email_list; -} - -void GpgFrontend::UI::EmailListEditor::contextMenuEvent( - QContextMenuEvent* event) { - QWidget::contextMenuEvent(event); - if (ui_->emaillistWidget->selectedItems().length() > 0) { - popup_menu_->exec(event->globalPos()); - } -} diff --git a/src/ui/mail/EmailListEditor.h b/src/ui/mail/EmailListEditor.h deleted file mode 100644 index b716ff66..00000000 --- a/src/ui/mail/EmailListEditor.h +++ /dev/null @@ -1,85 +0,0 @@ -/** - * Copyright (C) 2021 Saturneric - * - * 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 . - * - * 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 starting on May 12, 2021. - * - * SPDX-License-Identifier: GPL-3.0-or-later - * - */ - -#ifndef GPGFRONTEND_EMAILLISTEDITOR_H -#define GPGFRONTEND_EMAILLISTEDITOR_H - -#include "GpgFrontendUI.h" - -class Ui_EmailListEditorDialog; - -namespace GpgFrontend::UI { -/** - * @brief - * - */ -class EmailListEditor : public QDialog { - Q_OBJECT - - public: - /** - * @brief Construct a new Email List Editor object - * - * @param email_list - * @param parent - */ - explicit EmailListEditor(const QString& email_list, QWidget* parent); - - /** - * @brief Get the Email List object - * - * @return QString - */ - QString GetEmailList(); - - private: - std::shared_ptr ui_; ///< - QMenu* popup_menu_{}; ///< - QRegularExpression re_email_{ - R"((?:[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*|"(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21\x23-\x5b\x5d-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])*")@(?:(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?|\[(?:(?:(2(5[0-5]|[0-4][0-9])|1[0-9][0-9]|[1-9]?[0-9]))\.){3}(?:(2(5[0-5]|[0-4][0-9])|1[0-9][0-9]|[1-9]?[0-9])|[a-z0-9-]*[a-z0-9]:(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21-\x5a\x53-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])+)\]))"}; - - /** - * @brief - * - * @param email_address - * @return true - * @return false - */ - bool check_email_address(const QString& email_address); - - protected: - /** - * @brief - * - * @param event - */ - void contextMenuEvent(QContextMenuEvent* event) override; -}; -} // namespace GpgFrontend::UI - -#endif // GPGFRONTEND_EMAILLISTEDITOR_H diff --git a/src/ui/mail/IMAPFolder.cpp b/src/ui/mail/IMAPFolder.cpp deleted file mode 100644 index 68a894f7..00000000 --- a/src/ui/mail/IMAPFolder.cpp +++ /dev/null @@ -1,95 +0,0 @@ -/** - * Copyright (C) 2021 Saturneric - * - * 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 . - * - * 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 starting on May 12, 2021. - * - * SPDX-License-Identifier: GPL-3.0-or-later - * - */ - -#include "IMAPFolder.h" - -#include -#include - -GpgFrontend::UI::IMAPFolder::IMAPFolder( - std::shared_ptr folder) - : folder_(std::move(folder)), - tree_node_(new QTreeWidgetItem(static_cast(nullptr), - {"server"})) { - const std::string folder_name = folder_->getName().getBuffer(); - LOG(INFO) << "folder" << folder_name; - - const vmime::net::folderAttributes attr = folder_->getAttributes(); - std::ostringstream attrStr; - - tree_node_->setIcon(0, QIcon(":folder.png")); - if (attr.getSpecialUse() == vmime::net::folderAttributes::SPECIALUSE_ALL) { - LOG(INFO) << "use:All"; - } else if (attr.getSpecialUse() == - vmime::net::folderAttributes::SPECIALUSE_ARCHIVE) { - tree_node_->setIcon(0, QIcon(":archive.png")); - } else if (attr.getSpecialUse() == - vmime::net::folderAttributes::SPECIALUSE_DRAFTS) { - tree_node_->setIcon(0, QIcon(":drafts.png")); - } else if (attr.getSpecialUse() == - vmime::net::folderAttributes::SPECIALUSE_FLAGGED) { - tree_node_->setIcon(0, QIcon(":flag.png")); - } else if (attr.getSpecialUse() == - vmime::net::folderAttributes::SPECIALUSE_JUNK) { - tree_node_->setIcon(0, QIcon(":junk.png")); - } else if (attr.getSpecialUse() == - vmime::net::folderAttributes::SPECIALUSE_SENT) { - tree_node_->setIcon(0, QIcon(":sent.png")); - } else if (attr.getSpecialUse() == - vmime::net::folderAttributes::SPECIALUSE_TRASH) { - tree_node_->setIcon(0, QIcon(":trash.png")); - } else if (attr.getSpecialUse() == - vmime::net::folderAttributes::SPECIALUSE_IMPORTANT) { - tree_node_->setIcon(0, QIcon(":importance.png")); - } - - if (attr.getFlags() & vmime::net::folderAttributes::FLAG_HAS_CHILDREN) { - LOG(INFO) << " flag:HasChildren"; - } - if (attr.getFlags() & vmime::net::folderAttributes::FLAG_NO_OPEN) { - LOG(INFO) << " flag:NoOpen"; - // tree_node_->setDisabled(true); - } - - if (!folder_name.empty()) - tree_node_->setText(0, folder_name.c_str()); - else - tree_node_->setIcon(0, QIcon(":server.png")); -} - -void GpgFrontend::UI::IMAPFolder::SetParentFolder(IMAPFolder *parent_folder) { - parent_folder->GetTreeWidgetItem()->addChild(tree_node_); -} - -QTreeWidgetItem *GpgFrontend::UI::IMAPFolder::GetTreeWidgetItem() { - return tree_node_; -} - -vmime::net::folder *GpgFrontend::UI::IMAPFolder::GetVmimeFolder() { - return folder_.get(); -} diff --git a/src/ui/mail/IMAPFolder.h b/src/ui/mail/IMAPFolder.h deleted file mode 100644 index 7dc52438..00000000 --- a/src/ui/mail/IMAPFolder.h +++ /dev/null @@ -1,91 +0,0 @@ -/** - * Copyright (C) 2021 Saturneric - * - * 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 . - * - * 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 starting on May 12, 2021. - * - * SPDX-License-Identifier: GPL-3.0-or-later - * - */ -#ifndef GPGFRONTEND_IMAPFOLDER_H -#define GPGFRONTEND_IMAPFOLDER_H - -#include "GpgFrontendUI.h" - -namespace vmime::net { -class folder; -}; - -namespace GpgFrontend::UI { -/** - * @brief - * - */ -class IMAPFolder { - public: - /** - * @brief Construct a new IMAPFolder object - * - * @param folder - */ - explicit IMAPFolder(std::shared_ptr folder); - - /** - * @brief Copy and construct the IMAPFolder object - */ - IMAPFolder(const IMAPFolder &) = default; - - /** - * @brief Copy the IMAPFolder object - * - * @return - */ - IMAPFolder &operator=(const IMAPFolder &) = default; - - - /** - * @brief Set the Parent Folder object - * - * @param parent_node - */ - void SetParentFolder(IMAPFolder* parent_node); - - /** - * @brief Get the Tree Widget Item object - * - * @return QTreeWidgetItem* - */ - QTreeWidgetItem* GetTreeWidgetItem(); - - /** - * @brief Get the Vmime Folder object - * - * @return vmime::net::folder* - */ - vmime::net::folder* GetVmimeFolder(); - - private: - std::shared_ptr folder_; ///< - QTreeWidgetItem* tree_node_; ///< -}; -} // namespace GpgFrontend::UI - -#endif // GPGFRONTEND_IMAPFOLDER_H diff --git a/src/ui/mail/RecipientsPicker.cpp b/src/ui/mail/RecipientsPicker.cpp deleted file mode 100644 index d6b8bcc5..00000000 --- a/src/ui/mail/RecipientsPicker.cpp +++ /dev/null @@ -1,80 +0,0 @@ -/** - * Copyright (C) 2021 Saturneric - * - * 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 . - * - * 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 starting on May 12, 2021. - * - * SPDX-License-Identifier: GPL-3.0-or-later - * - */ - -#include "RecipientsPicker.h" - -#include "ui/widgets/KeyList.h" - -GpgFrontend::UI::RecipientsPicker::RecipientsPicker( - const GpgFrontend::KeyIdArgsListPtr& current_key_ids, QWidget* parent) - : QDialog(parent) { - auto confirm_button = new QPushButton(_("Confirm")); - connect(confirm_button,&QPushButton::clicked, this, &RecipientsPicker::accept); - - // Setup KeyList - key_list_ = new KeyList(KeyMenuAbility::NONE, this); - key_list_->AddListGroupTab( - _("Recipient(s)"), KeyListRow::SECRET_OR_PUBLIC_KEY, - KeyListColumn::NAME | KeyListColumn::EmailAddress, - [](const GpgKey& key) -> bool { - return !key.IsPrivateKey() && key.IsHasActualEncryptionCapability(); - }); - key_list_->SlotRefresh(); - - auto key_ids = std::make_unique(); - for (const auto& key_id : *current_key_ids) { - key_ids->push_back(key_id); - } - key_list_->SetChecked(std::move(key_ids)); - - auto* vbox2 = new QVBoxLayout(); - vbox2->addWidget(new QLabel(QString(_("Select Recipient(s)")) + ": ")); - vbox2->addWidget(key_list_); - vbox2->addWidget(new QLabel( - QString(_("We use the public key provided by the recipient to encrypt " - "the text.")) + - "\n" + - _("If you want to send to multiple recipients at the same time, you can " - "select multiple keys."))); - vbox2->addWidget(confirm_button); - vbox2->addStretch(0); - setLayout(vbox2); - - this->setWindowFlags(Qt::Window | Qt::WindowTitleHint | - Qt::CustomizeWindowHint); - - this->setModal(true); - this->setWindowTitle("Recipient(s) Picker"); - this->setMinimumWidth(480); - this->exec(); -} - -GpgFrontend::KeyIdArgsListPtr -GpgFrontend::UI::RecipientsPicker::GetCheckedRecipients() { - return key_list_->GetChecked(); -} diff --git a/src/ui/mail/RecipientsPicker.h b/src/ui/mail/RecipientsPicker.h deleted file mode 100644 index 252bbd58..00000000 --- a/src/ui/mail/RecipientsPicker.h +++ /dev/null @@ -1,68 +0,0 @@ -/** - * Copyright (C) 2021 Saturneric - * - * 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 . - * - * 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 starting on May 12, 2021. - * - * SPDX-License-Identifier: GPL-3.0-or-later - * - */ - -#ifndef GPGFRONTEND_RECIPENTSPICKER_H -#define GPGFRONTEND_RECIPENTSPICKER_H - -#include "GpgFrontendUI.h" - -namespace GpgFrontend::UI { - -class KeyList; - -/** - * @brief - * - */ -class RecipientsPicker : public QDialog { - Q_OBJECT - - public: - /** - * @brief Construct a new Recipients Picker object - * - * @param current_key_ids - * @param parent - */ - explicit RecipientsPicker( - const GpgFrontend::KeyIdArgsListPtr& current_key_ids, - QWidget* parent = nullptr); - - /** - * @brief Get the Checked Recipients object - * - * @return GpgFrontend::KeyIdArgsListPtr - */ - GpgFrontend::KeyIdArgsListPtr GetCheckedRecipients(); - - private: - KeyList* key_list_; ///< -}; -} // namespace GpgFrontend::UI - -#endif // GPGFRONTEND_RECIPENTSPICKER_H diff --git a/src/ui/mail/SendMailDialog.cpp b/src/ui/mail/SendMailDialog.cpp deleted file mode 100644 index 137c941f..00000000 --- a/src/ui/mail/SendMailDialog.cpp +++ /dev/null @@ -1,439 +0,0 @@ -/** - * Copyright (C) 2021 Saturneric - * - * 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 . - * - * 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 starting on May 12, 2021. - * - * SPDX-License-Identifier: GPL-3.0-or-later - * - */ - -#include "SendMailDialog.h" - -#include "core/function/gpg/GpgKeyGetter.h" -#include "ui/mail/EmailListEditor.h" -#include "ui/mail/RecipientsPicker.h" -#include "ui/mail/SenderPicker.h" -#include "ui_SendMailDialog.h" - -#ifdef SMTP_SUPPORT -#include "core/function/GlobalSettingStation.h" -#include "ui/thread/SMTPSendMailThread.h" -#endif - -namespace GpgFrontend::UI { - -SendMailDialog::SendMailDialog(const QString& text, QWidget* parent) - : QDialog(parent), ui_(std::make_shared()) { - // read from settings - init_settings(); - - if (smtp_address_.isEmpty()) { - QMessageBox::critical( - this->parentWidget(), _("Incomplete configuration"), - _("The SMTP address is empty, please go to the setting interface to " - "complete the configuration.")); - - deleteLater(); - return; - } - - ui_->setupUi(this); - - ui_->ccInputWidget->setHidden(true); - ui_->bccInputWidget->setHidden(true); - ui_->textEdit->setText(text); - ui_->errorLabel->setHidden(true); - - ui_->senderEdit->setText(default_sender_); - - if (!default_sender_gpg_key_id_.isEmpty()) { - auto key = GpgKeyGetter::GetInstance().GetKey( - default_sender_gpg_key_id_.toStdString()); - if (key.IsGood() && key.IsPrivateKey() && - key.IsHasActualSigningCapability()) { - sender_key_id_ = key.GetId(); - set_sender_value_label(); - } - } - - connect(ui_->ccButton, &QPushButton::clicked, [=]() { - ui_->ccInputWidget->setHidden(!ui_->ccInputWidget->isHidden()); - ui_->ccEdit->clear(); - }); - connect(ui_->bccButton, &QPushButton::clicked, [=]() { - ui_->bccInputWidget->setHidden(!ui_->bccInputWidget->isHidden()); - ui_->bccEdit->clear(); - }); - -#ifdef SMTP_SUPPORT - connect(ui_->sendMailButton, &QPushButton::clicked, this, - &SendMailDialog::slot_confirm); -#endif - - connect(ui_->senderKeySelectButton, &QPushButton::clicked, this, [=]() { - auto picker = new SenderPicker(sender_key_id_, this); - sender_key_id_ = picker->GetCheckedSender(); - set_sender_value_label(); - }); - - connect(ui_->recipientKeySelectButton, &QPushButton::clicked, this, [=]() { - auto picker = new RecipientsPicker(recipients_key_ids_, this); - recipients_key_ids_ = picker->GetCheckedRecipients(); - set_recipients_value_label(); - }); - - connect(ui_->recipientsEditButton, &QPushButton::clicked, this, [=]() { - auto editor = new EmailListEditor(ui_->recipientEdit->text(), this); - ui_->recipientEdit->setText(editor->GetEmailList()); - }); - - connect(ui_->ccEditButton, &QPushButton::clicked, this, [=]() { - auto editor = new EmailListEditor(ui_->ccEdit->text(), this); - ui_->ccEdit->setText(editor->GetEmailList()); - }); - - connect(ui_->bccEditButton, &QPushButton::clicked, this, [=]() { - auto editor = new EmailListEditor(ui_->bccEdit->text(), this); - ui_->bccEdit->setText(editor->GetEmailList()); - }); - - ui_->ccButton->setText(_("CC")); - ui_->bccButton->setText(_("BCC")); - ui_->senderLabel->setText(_("Sender")); - ui_->recipientLabel->setText(_("Recipient")); - ui_->subjectLabel->setText(_("Mail Subject")); - ui_->bccLabel->setText(_("BCC")); - ui_->ccLabel->setText(_("CC")); - ui_->tipsLabel->setText( - _("Tips: You can fill in multiple email addresses, please separate them " - "with \";\".")); - ui_->sendMailButton->setText(_("Send Message")); - ui_->senderKeySelectButton->setText(_("Select Sender GPG Key")); - ui_->recipientKeySelectButton->setText(_("Select Recipient(s) GPG Key")); - ui_->gpgOperaLabel->setText(_("GPG Operations")); - ui_->attacSignatureCheckBox->setText(_("Attach signature")); - ui_->attachSenderPublickeyCheckBox->setText(_("Attach sender's public key")); - ui_->contentEncryptCheckBox->setText(_("Encrypt content")); - ui_->recipientsEditButton->setText(_("Edit Recipients(s)")); - ui_->ccEditButton->setText(_("Edit CC(s)")); - ui_->bccEditButton->setText(_("Edit BCC(s)")); - ui_->senderKeyLabel->setText(_("Sender GPG Key: ")); - ui_->recipientKeysLabel->setText(_("Recipient(s) GPG Key: ")); - - auto pos = QPoint(100, 100); - LOG(INFO) << "parent" << parent; - if (parent) pos += parent->pos(); - LOG(INFO) << "pos default" << pos.x() << pos.y(); - - move(pos); - - this->setWindowTitle(_("New Message")); - this->setAttribute(Qt::WA_DeleteOnClose); -} - -bool SendMailDialog::check_email_address(const QString& str) { - return re_email_.match(str).hasMatch(); -} - -#ifdef SMTP_SUPPORT - -void SendMailDialog::slot_confirm() { - QString errString; - ui_->errorLabel->clear(); - ui_->errorLabel->setHidden(true); - QStringList rcpt_string_list = ui_->recipientEdit->text().split(';'); - QStringList cc_string_list = ui_->ccEdit->text().split(';'); - QStringList bcc_string_list = ui_->bccEdit->text().split(';'); - - if (rcpt_string_list.isEmpty()) { - errString.append(QString(" ") + _("Recipient cannot be empty") + " \n"); - } else { - for (const auto& reci : rcpt_string_list) { - LOG(INFO) << "Receiver" << reci.trimmed().toStdString(); - if (!check_email_address(reci.trimmed())) { - errString.append(QString(" ") + - _("One or more recipient's email is invalid") + - " \n"); - break; - } - } - } - if (ui_->senderEdit->text().isEmpty()) { - errString.append(QString(" ") + _("Sender cannot be empty") + " \n"); - } else if (!check_email_address(ui_->senderEdit->text())) { - errString.append(QString(" ") + _("Sender's email is invalid") + " \n"); - } - - if (ui_->subjectEdit->text().isEmpty()) { - errString.append(QString(" ") + _("Subject cannot be empty") + " \n"); - } - - if (!ui_->ccEdit->text().isEmpty()) - for (const auto& cc : cc_string_list) { - LOG(INFO) << "cc" << cc.trimmed().toStdString(); - if (!check_email_address(cc.trimmed())) { - errString.append(QString(" ") + _("One or more cc email is invalid") + - " \n"); - break; - } - } - - if (!ui_->bccEdit->text().isEmpty()) - for (const auto& bcc : bcc_string_list) { - LOG(INFO) << "bcc" << bcc.trimmed().toStdString(); - if (!check_email_address(bcc.trimmed())) { - errString.append(QString(" ") + _("One or more bcc email is invalid") + - " \n"); - break; - } - } - - if (!errString.isEmpty()) { - ui_->errorLabel->setAutoFillBackground(true); - QPalette error = ui_->errorLabel->palette(); - error.setColor(QPalette::Window, "#ff8080"); - ui_->errorLabel->setPalette(error); - ui_->errorLabel->setText(errString); - ui_->errorLabel->setHidden(false); - return; - } - - SmtpClient::ConnectionType connection_type_ = - SmtpClient::ConnectionType::TcpConnection; - - if (connection_type_settings_ == "SSL") { - connection_type_ = SmtpClient::ConnectionType::SslConnection; - } else if (connection_type_settings_ == "TLS") { - connection_type_ = SmtpClient::ConnectionType::TlsConnection; - } else if (connection_type_settings_ == "STARTTLS") { - connection_type_ = SmtpClient::ConnectionType::TlsConnection; - } else { - connection_type_ = SmtpClient::ConnectionType::TcpConnection; - } - - auto host = smtp_address_.toStdString(); - auto port = port_; - auto connection_type = connection_type_; - bool identity_needed = identity_enable_; - auto username = username_.toStdString(); - auto password = password_.toStdString(); - auto sender_address = ui_->senderEdit->text().toStdString(); - - auto thread = new SMTPSendMailThread( - host, port, connection_type, identity_needed, username, password, this); - - thread->SetSender(ui_->senderEdit->text()); - thread->SetRecipient(ui_->recipientEdit->text()); - thread->SetCC(ui_->ccEdit->text()); - thread->SetBCC(ui_->bccEdit->text()); - thread->SetSubject(ui_->subjectEdit->text()); - thread->AddTextContent(ui_->textEdit->toPlainText()); - - if (ui_->contentEncryptCheckBox->checkState() == Qt::Checked) { - if (recipients_key_ids_ == nullptr || recipients_key_ids_->empty()) { - QMessageBox::critical( - this, _("Forbidden"), - _("You have checked the encrypted email content, but you have not " - "selected the recipient's GPG key. This is dangerous and the mail " - "will not be encrypted. So the send operation is forbidden")); - return; - } else { - auto key_ids = std::make_unique(); - for (const auto& key_id : *recipients_key_ids_) - key_ids->push_back(key_id); - thread->SetEncryptContent(true, std::move(key_ids)); - } - } - - if (ui_->attacSignatureCheckBox->checkState() == Qt::Checked) { - if (sender_key_id_.empty()) { - QMessageBox::critical( - this, _("Forbidden"), - _("You checked the option to attach signature to the email, but did " - "not specify the sender's GPG Key. This will cause the content of " - "the email to be inconsistent with your expectations, so the " - "operation is prohibited.")); - return; - } else { - thread->SetAttachSignatureFile(true, sender_key_id_); - } - } - - if (ui_->attachSenderPublickeyCheckBox->checkState() == Qt::Checked) { - if (sender_key_id_.empty()) { - QMessageBox::critical( - this, _("Forbidden"), - _("You checked the option to attach your public key to the email, " - "but did not specify the sender's GPG Key. This will cause the " - "content of " - "the email to be inconsistent " - "with your expectations, so the operation is prohibited.")); - return; - } else { - thread->SetAttachPublicKey(true, sender_key_id_); - } - } - - // Waiting Dialog - auto* waiting_dialog = new QProgressDialog(this); - waiting_dialog->setMaximum(0); - waiting_dialog->setMinimum(0); - auto waiting_dialog_label = - new QLabel(QString(_("Sending Email...")) + "

" + - _("If the process does not end for a long time, please check " - "again whether your SMTP server configuration is correct.")); - waiting_dialog_label->setWordWrap(true); - waiting_dialog->setLabel(waiting_dialog_label); - waiting_dialog->resize(420, 120); - connect(thread, &SMTPSendMailThread::SignalSMTPResult, this, - &SendMailDialog::slot_test_smtp_connection_result); - connect(thread, &QThread::finished, [=]() { - waiting_dialog->finished(0); - waiting_dialog->deleteLater(); - }); - connect(waiting_dialog, &QProgressDialog::canceled, [=]() { - LOG(INFO) << "cancel clicked"; - if (thread->isRunning()) thread->terminate(); - }); - - // Show Waiting Dialog - waiting_dialog->show(); - waiting_dialog->setFocus(); - - thread->start(); - QEventLoop loop; - connect(thread, &QThread::finished, &loop, &QEventLoop::quit); - loop.exec(); -} - -void SendMailDialog::init_settings() { - auto& settings = GlobalSettingStation::GetInstance().GetUISettings(); - - try { - ability_enable_ = settings.lookup("smtp.enable"); - } catch (...) { - LOG(ERROR) << _("Setting Operation Error") << _("save_key_checked"); - } - - try { - identity_enable_ = settings.lookup("smtp.identity_enable"); - } catch (...) { - LOG(ERROR) << _("Setting Operation Error") << _("identity_enable"); - } - - try { - smtp_address_ = settings.lookup("smtp.mail_address").c_str(); - } catch (...) { - LOG(ERROR) << _("Setting Operation Error") << _("mail_address"); - } - - try { - username_ = settings.lookup("smtp.username").c_str(); - } catch (...) { - LOG(ERROR) << _("Setting Operation Error") << _("username"); - } - - try { - password_ = settings.lookup("smtp.password").c_str(); - } catch (...) { - LOG(ERROR) << _("Setting Operation Error") << _("password"); - } - - try { - port_ = settings.lookup("smtp.port"); - } catch (...) { - LOG(ERROR) << _("Setting Operation Error") << _("port"); - } - - try { - connection_type_settings_ = settings.lookup("smtp.connection_type").c_str(); - } catch (...) { - LOG(ERROR) << _("Setting Operation Error") << _("connection_type"); - } - - try { - default_sender_ = settings.lookup("smtp.default_sender").c_str(); - } catch (...) { - LOG(ERROR) << _("Setting Operation Error") << _("default_sender"); - } - - try { - default_sender_gpg_key_id_ = - settings.lookup("smtp.default_sender_gpg_key_id").c_str(); - } catch (...) { - LOG(ERROR) << _("Setting Operation Error") - << _("default_sender_gpg_key_id"); - } -} -#endif - -void SendMailDialog::set_sender_value_label() { - auto key = GpgKeyGetter::GetInstance().GetKey(sender_key_id_); - if (key.IsGood()) { - ui_->senderKeyValueLabel->setText(key.GetUIDs()->front().GetUID().c_str()); - } -} - -void SendMailDialog::set_recipients_value_label() { - auto keys = GpgKeyGetter::GetInstance().GetKeys(recipients_key_ids_); - std::stringstream ss; - for (const auto& key : *keys) { - if (key.IsGood()) { - ss << key.GetUIDs()->front().GetUID().c_str() << ";"; - } - } - ui_->recipientsKeyValueLabel->setText(ss.str().c_str()); -} - -void SendMailDialog::slot_test_smtp_connection_result(const QString& result) { - if (result == "Fail to connect SMTP server") { - QMessageBox::critical(this, _("Fail"), _("Fail to Connect SMTP Server.")); - } else if (result == "Fail to login") { - QMessageBox::critical(this, _("Fail"), _("Fail to Login.")); - } else if (result == "Fail to send mail") { - QMessageBox::critical(this, _("Fail"), _("Fail to Login.")); - } else if (result == "Succeed in testing connection") { - QMessageBox::information(this, _("Success"), - _("Succeed in connecting and login")); - } else if (result == "Succeed in sending a test email") { - QMessageBox::information( - this, _("Success"), - _("Succeed in sending the message to the SMTP Server")); - } else if (result == "Fail to encrypt with gpg keys") { - QMessageBox::critical( - this, _("Encryption Error"), - _("An error occurred while encrypting the content of the email. This " - "may be because you did not complete some operations during Gnupg " - "encryption.")); - } else { - QMessageBox::critical(this, _("Fail"), _("Unknown error.")); - } -} -void SendMailDialog::SetContentEncryption(bool on) { - ui_->contentEncryptCheckBox->setCheckState(on ? Qt::Checked : Qt::Unchecked); -} - -void SendMailDialog::SetAttachSignature(bool on) { - ui_->attacSignatureCheckBox->setCheckState(on ? Qt::Checked : Qt::Unchecked); -} - -} // namespace GpgFrontend::UI diff --git a/src/ui/mail/SendMailDialog.h b/src/ui/mail/SendMailDialog.h deleted file mode 100644 index 3d745e11..00000000 --- a/src/ui/mail/SendMailDialog.h +++ /dev/null @@ -1,132 +0,0 @@ -/** - * Copyright (C) 2021 Saturneric - * - * 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 . - * - * 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 starting on May 12, 2021. - * - * SPDX-License-Identifier: GPL-3.0-or-later - * - */ - -#ifndef GPGFRONTEND_SENDMAILDIALOG_H -#define GPGFRONTEND_SENDMAILDIALOG_H - -#include "ui/GpgFrontendUI.h" - -class Ui_SendMailDialog; - -namespace GpgFrontend::UI { - -/** - * @brief - * - */ -class SendMailDialog : public QDialog { - Q_OBJECT - public: - /** - * @brief Construct a new Send Mail Dialog object - * - * @param text - * @param parent - */ - explicit SendMailDialog(const QString& text, QWidget* parent = nullptr); - - /** - * @brief Set the Content Encryption object - * - * @param on - */ - void SetContentEncryption(bool on); - - /** - * @brief Set the Attach Signature object - * - * @param on - */ - void SetAttachSignature(bool on); - - private slots: - - /** - * @brief - * - */ - void slot_confirm(); - - /** - * @brief - * - * @param result - */ - void slot_test_smtp_connection_result(const QString& result); - - private: - /** - * @brief - * - */ - void init_settings(); - - std::shared_ptr ui_; ///< - - bool ability_enable_ = false; ///< - bool identity_enable_ = false; ///< - QString smtp_address_; ///< - QString username_; ///< - QString password_; ///< - QString default_sender_; ///< - QString connection_type_settings_ = "None"; ///< - QString default_sender_gpg_key_id_ = {}; ///< - int port_ = 25; ///< - - GpgFrontend::KeyId sender_key_id_; ///< - GpgFrontend::KeyIdArgsListPtr recipients_key_ids_ = - std::make_unique(); ///< - - QRegularExpression re_email_{ - R"((?:[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*|"(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21\x23-\x5b\x5d-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])*")@(?:(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?|\[(?:(?:(2(5[0-5]|[0-4][0-9])|1[0-9][0-9]|[1-9]?[0-9]))\.){3}(?:(2(5[0-5]|[0-4][0-9])|1[0-9][0-9]|[1-9]?[0-9])|[a-z0-9-]*[a-z0-9]:(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21-\x5a\x53-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])+)\]))"}; - - /** - * @brief - * - * @param str - * @return true - * @return false - */ - bool check_email_address(const QString& str); - - /** - * @brief Set the sender value label object - * - */ - void set_sender_value_label(); - - /** - * @brief Set the recipients value label object - * - */ - void set_recipients_value_label(); -}; - -} // namespace GpgFrontend::UI - -#endif // GPGFRONTEND_SENDMAILDIALOG_H diff --git a/src/ui/mail/SenderPicker.cpp b/src/ui/mail/SenderPicker.cpp deleted file mode 100644 index e3563480..00000000 --- a/src/ui/mail/SenderPicker.cpp +++ /dev/null @@ -1,81 +0,0 @@ -/** - * Copyright (C) 2021 Saturneric - * - * 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 . - * - * 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 starting on May 12, 2021. - * - * SPDX-License-Identifier: GPL-3.0-or-later - * - */ - -#include "SenderPicker.h" - -#include "ui/widgets/KeyList.h" - -GpgFrontend::UI::SenderPicker::SenderPicker(const KeyId& current_key_id, - QWidget* parent) - : QDialog(parent) { - auto confirm_button = new QPushButton(_("Confirm")); - connect(confirm_button, &QPushButton::clicked, this, &SenderPicker::accept); - - // Setup KeyList - key_list_ = new KeyList(KeyMenuAbility::NONE, this); - key_list_->AddListGroupTab(_("Sender"), KeyListRow::ONLY_SECRET_KEY, - KeyListColumn::NAME | KeyListColumn::EmailAddress, - [](const GpgKey& key) -> bool { - return key.IsHasActualSigningCapability(); - }); - key_list_->SlotRefresh(); - - auto key_ids = std::make_unique(); - key_ids->push_back(current_key_id); - key_list_->SetChecked(std::move(key_ids)); - - auto* vbox2 = new QVBoxLayout(); - vbox2->addWidget(new QLabel(QString(_("Select Sender")) + ": ")); - vbox2->addWidget(key_list_); - vbox2->addWidget(new QLabel( - QString( - _("As the sender of the mail, the private key is generally used.")) + - "\n" + - _(" The private key is generally used as a signature for the content of " - "the mail."))); - vbox2->addWidget(confirm_button); - vbox2->addStretch(0); - setLayout(vbox2); - - this->setWindowFlags(Qt::Window | Qt::WindowTitleHint | - Qt::CustomizeWindowHint); - - this->setModal(true); - this->setWindowTitle("Sender Picker"); - this->setMinimumWidth(480); - this->exec(); -} - -GpgFrontend::KeyId GpgFrontend::UI::SenderPicker::GetCheckedSender() { - auto checked_keys = key_list_->GetChecked(); - if (!checked_keys->empty()) { - return key_list_->GetChecked()->front(); - } else { - return {}; - } -} diff --git a/src/ui/main_window/MainWindow.h b/src/ui/main_window/MainWindow.h index 5cc9a15a..c5ba02a2 100644 --- a/src/ui/main_window/MainWindow.h +++ b/src/ui/main_window/MainWindow.h @@ -341,7 +341,6 @@ class MainWindow : public QMainWindow { QToolBar* special_edit_tool_bar_{}; ///< Toolbar holding special edit actions QToolBar* key_tool_bar_{}; ///< Toolbar holding key operations - QToolBar* email_tool_bar_{}; ///< Toolbar holding key operations QToolButton* import_button_{}; ///< Tool button for import dropdown menu in toolbar QDockWidget* key_list_dock_{}; ///< Encrypt Dock @@ -391,12 +390,6 @@ class MainWindow : public QMainWindow { QAction* start_wizard_act_{}; ///< Action to open the wizard QAction* cut_pgp_header_act_{}; ///< Action for cutting the PGP header QAction* add_pgp_header_act_{}; ///< Action for adding the PGP header - -#ifdef SMTP_SUPPORT - QAction* send_mail_act_{}; ///< Action for sending a email - QAction* receive_mail_act_{}; ///< Action for receive emails -#endif - QAction* import_key_from_file_act_{}; ///< QAction* import_key_from_clipboard_act_{}; ///< QAction* import_key_from_key_server_act_{}; ///< diff --git a/src/ui/main_window/MainWindowSlotFunction.cpp b/src/ui/main_window/MainWindowSlotFunction.cpp index f25d696a..0a322f6a 100644 --- a/src/ui/main_window/MainWindowSlotFunction.cpp +++ b/src/ui/main_window/MainWindowSlotFunction.cpp @@ -28,17 +28,6 @@ #include "MainWindow.h" -#ifdef ADVANCE_SUPPORT -#include "advance/UnknownSignersChecker.h" -#endif -#ifdef SERVER_SUPPORT -#include "server/api/PubkeyUploader.h" -#endif - -#ifdef SMTP_SUPPORT -#include "ui/mail/SendMailDialog.h" -#endif - #include "core/function/GlobalSettingStation.h" #include "core/function/gpg/GpgBasicOperator.h" #include "core/function/gpg/GpgKeyGetter.h" @@ -121,11 +110,6 @@ void MainWindow::slot_encrypt() { if (check_gpg_error_2_err_code(error) == GPG_ERR_NO_ERROR) edit_->SlotFillTextEditWithText(QString::fromStdString(*tmp)); info_board_->ResetOptionActionsMenu(); -#ifdef SMTP_SUPPORT - if (check_gpg_error_2_err_code(error) == GPG_ERR_NO_ERROR) - send_an_email(this, info_board_, - edit_->CurTextPage()->GetTextPage()->toPlainText()); -#endif } else { QMessageBox::critical(this, _("Error"), _("An error occurred during operation.")); @@ -381,23 +365,6 @@ void MainWindow::slot_encrypt_sign() { edit_->SlotFillTextEditWithText(QString::fromStdString(*tmp)); info_board_->ResetOptionActionsMenu(); -#ifdef SMTP_SUPPORT - if (check_gpg_error_2_err_code(error) == GPG_ERR_NO_ERROR) - send_an_email(this, info_board_, - edit_->CurTextPage()->GetTextPage()->toPlainText(), false); -#endif - -#ifdef ADVANCE_SUPPORT - infoBoard->addOptionalAction("Shorten Ciphertext", [this]() { - if (settings.value("general/serviceToken").toString().isEmpty()) - QMessageBox::warning(nullptr, _("Service Token Empty"), - _("Please go to the settings interface to set " - "Own Key and get Service Token.")); - else { - shortenCryptText(); - } - }); -#endif } else { QMessageBox::critical(this, _("Error"), _("An error occurred during operation.")); diff --git a/src/ui/main_window/MainWindowUI.cpp b/src/ui/main_window/MainWindowUI.cpp index 01c4bbc9..fa5e6de3 100644 --- a/src/ui/main_window/MainWindowUI.cpp +++ b/src/ui/main_window/MainWindowUI.cpp @@ -28,10 +28,6 @@ #include "MainWindow.h" #include "ui/UserInterfaceUtils.h" -#ifdef SMTP_SUPPORT -#include "ui/mail/ReceiveMailDialog.h" -#include "ui/mail/SendMailDialog.h" -#endif namespace GpgFrontend::UI { @@ -314,23 +310,6 @@ void MainWindow::create_actions() { add_pgp_header_act_ = new QAction(_("Add PGP Header"), this); connect(add_pgp_header_act_, &QAction::triggered, this, &MainWindow::slot_add_pgp_header); - -#ifdef SMTP_SUPPORT - send_mail_act_ = new QAction(_("New Message"), this); - send_mail_act_->setIcon(QIcon(":email.png")); - connect(send_mail_act_, &QAction::triggered, this, [=]() { - auto* dialog = new SendMailDialog({}, this); - dialog->show(); - }); - - receive_mail_act_ = new QAction(_("Message Inbox"), this); - receive_mail_act_->setVisible(false); - receive_mail_act_->setIcon(QIcon(":receive_email.png")); - connect(receive_mail_act_, &QAction::triggered, this, [=]() { - auto* dialog = new ReceiveMailDialog(this); - dialog->show(); - }); -#endif } void MainWindow::create_menus() { @@ -387,11 +366,6 @@ void MainWindow::create_menus() { steganography_menu_ = menuBar()->addMenu(_("Steganography")); steganography_menu_->addAction(cut_pgp_header_act_); steganography_menu_->addAction(add_pgp_header_act_); -#ifdef SMTP_SUPPORT - email_menu_ = menuBar()->addMenu(_("Email")); - email_menu_->addAction(send_mail_act_); - email_menu_->addAction(receive_mail_act_); -#endif view_menu_ = menuBar()->addMenu(_("View")); @@ -442,12 +416,6 @@ void MainWindow::create_tool_bars() { special_edit_tool_bar_->hide(); view_menu_->addAction(special_edit_tool_bar_->toggleViewAction()); - email_tool_bar_ = addToolBar(_("Email")); - email_tool_bar_->setObjectName("emailToolBar"); - email_tool_bar_->addAction(send_mail_act_); - email_tool_bar_->addAction(receive_mail_act_); - view_menu_->addAction(email_tool_bar_->toggleViewAction()); - // Add dropdown menu for key import to keytoolbar import_button_ = new QToolButton(); import_button_->setMenu(import_key_menu_); diff --git a/src/ui/settings/SettingsDialog.cpp b/src/ui/settings/SettingsDialog.cpp index 2c23858f..bf3ce6a8 100644 --- a/src/ui/settings/SettingsDialog.cpp +++ b/src/ui/settings/SettingsDialog.cpp @@ -36,36 +36,19 @@ #include "ui/settings/SettingsNetwork.h" #include "ui/main_window/MainWindow.h" -#ifdef SMTP_SUPPORT -#include "ui/settings/SettingsSendMail.h" -#endif - namespace GpgFrontend::UI { SettingsDialog::SettingsDialog(QWidget* parent) : QDialog(parent) { tab_widget_ = new QTabWidget(); general_tab_ = new GeneralTab(); appearance_tab_ = new AppearanceTab(); -#ifdef SMTP_SUPPORT - send_mail_tab_ = new SendMailTab(); -#endif key_server_tab_ = new KeyserverTab(); network_tab_ = new NetworkTab(); -#ifdef ADVANCED_SUPPORT - advancedTab = new AdvancedTab; -#endif tab_widget_->addTab(general_tab_, _("General")); tab_widget_->addTab(appearance_tab_, _("Appearance")); -#ifdef SMTP_SUPPORT - tab_widget_->addTab(send_mail_tab_, _("Send Mail")); -#endif tab_widget_->addTab(key_server_tab_, _("Key Server")); - // tabWidget->addTab(gpgPathsTab, _("Gpg paths")); tab_widget_->addTab(network_tab_, _("Network")); -#ifdef ADVANCED_SUPPORT - tabWidget->addTab(advancedTab, _("Advanced")); -#endif button_box_ = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel); @@ -105,15 +88,9 @@ void SettingsDialog::SlotAccept() { LOG(INFO) << "Called"; general_tab_->ApplySettings(); -#ifdef SMTP_SUPPORT - send_mail_tab_->ApplySettings(); -#endif appearance_tab_->ApplySettings(); key_server_tab_->ApplySettings(); network_tab_->ApplySettings(); -#ifdef ADVANCED_SUPPORT - advancedTab->applySettings(); -#endif LOG(INFO) << "apply done"; diff --git a/src/ui/settings/SettingsDialog.h b/src/ui/settings/SettingsDialog.h index 000e6599..e123cc6c 100755 --- a/src/ui/settings/SettingsDialog.h +++ b/src/ui/settings/SettingsDialog.h @@ -35,19 +35,10 @@ namespace GpgFrontend::UI { class GeneralTab; - -#ifdef SMTP_SUPPORT -class SendMailTab; -#endif - class AppearanceTab; class KeyserverTab; class NetworkTab; -#ifdef ADVANCED_SUPPORT -class AdvancedTab; -#endif - /** * @brief * @@ -64,15 +55,9 @@ class SettingsDialog : public QDialog { explicit SettingsDialog(QWidget* parent = nullptr); GeneralTab* general_tab_; ///< -#ifdef SMTP_SUPPORT - SendMailTab* send_mail_tab_; ///< -#endif AppearanceTab* appearance_tab_; ///< KeyserverTab* key_server_tab_; ///< NetworkTab* network_tab_; ///< -#ifdef ADVANCED_SUPPORT - AdvancedTab* advanced_tab_; ///< -#endif /** * @brief diff --git a/src/ui/settings/SettingsSendMail.cpp b/src/ui/settings/SettingsSendMail.cpp deleted file mode 100644 index bb948d9a..00000000 --- a/src/ui/settings/SettingsSendMail.cpp +++ /dev/null @@ -1,313 +0,0 @@ -/** - * Copyright (C) 2021 Saturneric - * - * 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 . - * - * 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 starting on May 12, 2021. - * - * SPDX-License-Identifier: GPL-3.0-or-later - * - */ - -#include "SettingsSendMail.h" - -#include "ui/struct/SettingsObject.h" -#include "ui/thread/SMTPConnectionTestThread.h" -#include "ui/thread/SMTPSendMailThread.h" -#include "ui_SendMailSettings.h" - -namespace GpgFrontend::UI { - -SendMailTab::SendMailTab(QWidget* parent) - : QWidget(parent), ui_(std::make_shared()) { - ui_->setupUi(this); - - connect(ui_->enableCheckBox, &QCheckBox::stateChanged, this, - [=](int state) { switch_ui_enabled(state == Qt::Checked); }); - -#ifdef SMTP_SUPPORT - connect(ui_->checkConnectionButton, &QPushButton::clicked, this, - &SendMailTab::slot_check_connection); - connect(ui_->senTestMailButton, &QPushButton::clicked, this, - &SendMailTab::slot_send_test_mail); -#endif - - connect(ui_->identityCheckBox, &QCheckBox::stateChanged, this, - [=](int state) { switch_ui_identity_enabled(state == Qt::Checked); }); - - connect(ui_->connextionSecurityComboBox, &QComboBox::currentTextChanged, this, - [=](const QString& current_text) { - if (current_text == "SSL") { - connection_type_ = SmtpClient::ConnectionType::SslConnection; - } else if (current_text == "TLS" || current_text == "STARTTLS") { - connection_type_ = SmtpClient::ConnectionType::TlsConnection; - } else { - connection_type_ = SmtpClient::ConnectionType::TcpConnection; - } - }); - - ui_->generalGroupBox->setTitle(_("General")); - ui_->identityGroupBox->setTitle(_("Identity Information")); - ui_->preferenceGroupBox->setTitle(_("Preference")); - ui_->operationsGroupBox->setTitle(_("Operations")); - - ui_->enableCheckBox->setText(_("Enable Send Mail Ability")); - ui_->identityCheckBox->setText(_("Need Auth")); - - ui_->smtpServerAddressLabel->setText(_("SMTP Server Address")); - ui_->smtpServerPortLabel->setText(_("SMTP Server Port")); - ui_->connectionSecurityLabel->setText(_("SMTP Connection Security")); - ui_->usernameLabel->setText(_("Username")); - ui_->passwordLabel->setText(_("Password")); - - ui_->senderLabel->setText(_("Default Sender Email")); - ui_->checkConnectionButton->setText(_("Check Connection")); - ui_->senTestMailButton->setText(_("Send Test Email")); - ui_->gpgkeyIdLabel->setText(_("Default Sender GPG Key ID")); - - ui_->tipsLabel->setText( - _("Tips: It is recommended that you build your own mail server or use " - "a trusted mail server. If you don't know the detailed configuration " - "information, you can get it from the mail service provider.")); - - ui_->senTestMailButton->setDisabled(true); - - auto* email_validator = - new QRegularExpressionValidator(re_email_, ui_->defaultSenderEmailEdit); - ui_->defaultSenderEmailEdit->setValidator(email_validator); - - SetSettings(); -} - -void SendMailTab::SetSettings() { - auto smtp_passport = SettingsObject("smtp_passport"); - - ui_->smtpServerAddressEdit->setText( - std::string{smtp_passport.Check("smtp_address", "")}.c_str()); - - ui_->usernameEdit->setText( - std::string{smtp_passport.Check("username", "")}.c_str()); - - ui_->passwordEdit->setText( - std::string{smtp_passport.Check("password", "")}.c_str()); - - ui_->portSpin->setValue(int{smtp_passport.Check("port", 25)}); - - ui_->connextionSecurityComboBox->setCurrentText( - std::string{smtp_passport.Check("connection_type", "None")}.c_str()); - - ui_->defaultSenderEmailEdit->setText( - std::string{smtp_passport.Check("default_sender", "")}.c_str()); - - ui_->gpgKeyIDEdit->setText( - std::string{smtp_passport.Check("default_sender_gpg_key_id", "")} - .c_str()); - - ui_->identityCheckBox->setChecked( - bool{smtp_passport.Check("identity_enable", false)}); - - ui_->enableCheckBox->setChecked(bool{smtp_passport.Check("enable", false)}); - - { - auto state = ui_->identityCheckBox->checkState(); - switch_ui_identity_enabled(state == Qt::Checked); - } - - { - auto state = ui_->enableCheckBox->checkState(); - switch_ui_enabled(state == Qt::Checked); - } -} - -void SendMailTab::ApplySettings() { - try { - auto smtp_passport = SettingsObject("smtp_passport"); - - smtp_passport["smtp_address"] = - ui_->smtpServerAddressEdit->text().toStdString(); - - smtp_passport["username"] = ui_->usernameEdit->text().toStdString(); - - smtp_passport["password"] = ui_->passwordEdit->text().toStdString(); - - smtp_passport["port"] = ui_->portSpin->value(); - - smtp_passport["connection_type"] = - ui_->connextionSecurityComboBox->currentText().toStdString(); - - smtp_passport["default_sender"] = - ui_->defaultSenderEmailEdit->text().toStdString(); - - smtp_passport["default_sender_gpg_key_id"] = - ui_->gpgKeyIDEdit->text().toStdString(); - - smtp_passport["identity_enable"] = ui_->identityCheckBox->isChecked(); - - smtp_passport["enable"] = ui_->enableCheckBox->isChecked(); - - } catch (...) { - LOG(ERROR) << _("apply settings failed"); - } -} - -#ifdef SMTP_SUPPORT -void SendMailTab::slot_check_connection() { - auto host = ui_->smtpServerAddressEdit->text().toStdString(); - auto port = ui_->portSpin->value(); - auto connection_type = connection_type_; - bool identity_needed = ui_->identityCheckBox->isChecked(); - auto username = ui_->usernameEdit->text().toStdString(); - auto password = ui_->passwordEdit->text().toStdString(); - - auto thread = new SMTPConnectionTestThread( - host, port, connection_type, identity_needed, username, password); - - // Waiting Dialog - auto* waiting_dialog = new QProgressDialog(this); - waiting_dialog->setMaximum(0); - waiting_dialog->setMinimum(0); - auto waiting_dialog_label = - new QLabel(QString(_("Test SMTP Connection...")) + "

" + - _("If the process does not end for a long time, please check " - "again whether your SMTP server configuration is correct.")); - waiting_dialog_label->setWordWrap(true); - waiting_dialog->setLabel(waiting_dialog_label); - waiting_dialog->resize(420, 120); - connect(thread, &SMTPConnectionTestThread::SignalSMTPConnectionTestResult, - this, &SendMailTab::slot_test_smtp_connection_result); - connect(thread, &QThread::finished, [=]() { - waiting_dialog->finished(0); - waiting_dialog->deleteLater(); - }); - connect(waiting_dialog, &QProgressDialog::canceled, [=]() { - LOG(INFO) << "cancel clicked"; - if (thread->isRunning()) thread->terminate(); - }); - - // Show Waiting Dialog - waiting_dialog->show(); - waiting_dialog->setFocus(); - - thread->start(); - QEventLoop loop; - connect(thread, &QThread::finished, &loop, &QEventLoop::quit); - loop.exec(); -} -#endif - -#ifdef SMTP_SUPPORT -void SendMailTab::slot_send_test_mail() { - auto host = ui_->smtpServerAddressEdit->text().toStdString(); - auto port = ui_->portSpin->value(); - auto connection_type = connection_type_; - bool identity_needed = ui_->identityCheckBox->isChecked(); - auto username = ui_->usernameEdit->text().toStdString(); - auto password = ui_->passwordEdit->text().toStdString(); - auto sender_address = ui_->defaultSenderEmailEdit->text(); - - auto thread = new SMTPSendMailThread(host, port, connection_type, - identity_needed, username, password); - - // Waiting Dialog - auto* waiting_dialog = new QProgressDialog(this); - waiting_dialog->setMaximum(0); - waiting_dialog->setMinimum(0); - auto waiting_dialog_label = - new QLabel(QString(_("Test SMTP Send Mail Ability...")) + "

" + - _("If the process does not end for a long time, please check " - "again whether your SMTP server configuration is correct.")); - waiting_dialog_label->setWordWrap(true); - waiting_dialog->setLabel(waiting_dialog_label); - waiting_dialog->resize(420, 120); - connect(thread, &SMTPSendMailThread::SignalSMTPResult, this, - &SendMailTab::slot_test_smtp_connection_result); - connect(thread, &QThread::finished, [=]() { - waiting_dialog->finished(0); - waiting_dialog->deleteLater(); - }); - connect(waiting_dialog, &QProgressDialog::canceled, [=]() { - LOG(INFO) << "cancel clicked"; - if (thread->isRunning()) thread->terminate(); - }); - - thread->SetSender(sender_address); - thread->SetRecipient(sender_address); - thread->SetSubject(_("Test Email from GpgFrontend")); - thread->AddTextContent( - _("Hello, this is a test email from GpgFrontend. If you receive this " - "email, it means that you have configured the correct SMTP server " - "parameters.")); - - // Show Waiting Dialog - waiting_dialog->show(); - waiting_dialog->setFocus(); - - thread->start(); - QEventLoop loop; - connect(thread, &QThread::finished, &loop, &QEventLoop::quit); - loop.exec(); -} - -void SendMailTab::slot_test_smtp_connection_result(const QString& result) { - if (result == "Fail to connect SMTP server") { - QMessageBox::critical(this, _("Fail"), _("Fail to Connect SMTP Server.")); - ui_->senTestMailButton->setDisabled(true); - } else if (result == "Fail to login") { - QMessageBox::critical(this, _("Fail"), _("Fail to Login.")); - ui_->senTestMailButton->setDisabled(true); - } else if (result == "Fail to send mail") { - QMessageBox::critical(this, _("Fail"), _("Fail to Login.")); - ui_->senTestMailButton->setDisabled(true); - } else if (result == "Succeed in testing connection") { - QMessageBox::information(this, _("Success"), - _("Succeed in connecting and login")); - ui_->senTestMailButton->setDisabled(false); - } else if (result == "Succeed in sending a test email") { - QMessageBox::information( - this, _("Success"), - _("Succeed in sending a test email to the SMTP Server")); - ui_->senTestMailButton->setDisabled(false); - } else { - QMessageBox::critical(this, _("Fail"), _("Unknown error.")); - ui_->senTestMailButton->setDisabled(true); - } -} - -void SendMailTab::switch_ui_enabled(bool enabled) { - ui_->smtpServerAddressEdit->setDisabled(!enabled); - ui_->portSpin->setDisabled(!enabled); - ui_->connextionSecurityComboBox->setDisabled(!enabled); - - ui_->identityCheckBox->setDisabled(!enabled); - ui_->usernameEdit->setDisabled(!enabled); - ui_->passwordEdit->setDisabled(!enabled); - - ui_->defaultSenderEmailEdit->setDisabled(!enabled); - ui_->gpgKeyIDEdit->setDisabled(!enabled); - ui_->checkConnectionButton->setDisabled(!enabled); -} - -void SendMailTab::switch_ui_identity_enabled(bool enabled) { - ui_->usernameEdit->setDisabled(!enabled); - ui_->passwordEdit->setDisabled(!enabled); -} -#endif - -} // namespace GpgFrontend::UI diff --git a/src/ui/settings/SettingsSendMail.h b/src/ui/settings/SettingsSendMail.h deleted file mode 100644 index 84259844..00000000 --- a/src/ui/settings/SettingsSendMail.h +++ /dev/null @@ -1,119 +0,0 @@ -/** - * Copyright (C) 2021 Saturneric - * - * 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 . - * - * 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 starting on May 12, 2021. - * - * SPDX-License-Identifier: GPL-3.0-or-later - * - */ - -#ifndef GPGFRONTEND_SETTINGSSENDMAIL_H -#define GPGFRONTEND_SETTINGSSENDMAIL_H - -#include "ui/GpgFrontendUI.h" - -class Ui_SendMailSettings; - -namespace GpgFrontend::UI { -/** - * @brief - * - */ -class SendMailTab : public QWidget { - Q_OBJECT - - public: - /** - * @brief Construct a new Send Mail Tab object - * - * @param parent - */ - explicit SendMailTab(QWidget* parent = nullptr); - - /** - * @brief Set the Settings object - * - */ - void SetSettings(); - - /** - * @brief - * - */ - void ApplySettings(); - - signals: - - /** - * @brief - * - * @param needed - */ - void SignalRestartNeeded(bool needed); - - private slots: - - /** - * @brief - * - * @param result - */ - void slot_test_smtp_connection_result(const QString& result); - -#ifdef SMTP_SUPPORT - /** - * @brief - * - */ - void slot_check_connection(); - - /** - * @brief - * - */ - void slot_send_test_mail(); -#endif - - private: - std::shared_ptr ui_; ///< - QRegularExpression re_email_{ - R"((?:[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*|"(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21\x23-\x5b\x5d-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])*")@(?:(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?|\[(?:(?:(2(5[0-5]|[0-4][0-9])|1[0-9][0-9]|[1-9]?[0-9]))\.){3}(?:(2(5[0-5]|[0-4][0-9])|1[0-9][0-9]|[1-9]?[0-9])|[a-z0-9-]*[a-z0-9]:(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21-\x5a\x53-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])+)\]))"}; - SmtpClient::ConnectionType connection_type_ = - SmtpClient::ConnectionType::TcpConnection; ///< - - /** - * @brief - * - * @param enabled - */ - void switch_ui_enabled(bool enabled); - - /** - * @brief - * - * @param enabled - */ - void switch_ui_identity_enabled(bool enabled); -}; -} // namespace GpgFrontend::UI - -#endif // GPGFRONTEND_SETTINGSSENDMAIL_H diff --git a/src/ui/thread/SMTPConnectionTestThread.h b/src/ui/thread/SMTPConnectionTestThread.h deleted file mode 100644 index b37cc09c..00000000 --- a/src/ui/thread/SMTPConnectionTestThread.h +++ /dev/null @@ -1,93 +0,0 @@ -/** - * Copyright (C) 2021 Saturneric - * - * 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 . - * - * The initial version of the source code is inherited from - * the gpg4usb project, which is under GPL-3.0-or-later. - * - * The source code version of this software was modified and released - * by Saturneric starting on May 12, 2021. - * - */ - -#ifndef GPGFRONTEND_SMTPCONNECTIONTESTTHREAD_H -#define GPGFRONTEND_SMTPCONNECTIONTESTTHREAD_H - -#include - -#include "ui/GpgFrontendUI.h" - -namespace GpgFrontend::UI { - -/** - * @brief - * - */ -class SMTPConnectionTestThread : public QThread { - Q_OBJECT - public: - /** - * @brief Construct a new SMTPConnectionTestThread object - * - * @param host - * @param port - * @param connection_type - * @param identify - * @param username - * @param password - * @param parent - */ - explicit SMTPConnectionTestThread(std::string host, int port, - SmtpClient::ConnectionType connection_type, - bool identify, std::string username, - std::string password, - QWidget* parent = nullptr) - : QThread(parent), - host_(std::move(host)), - port_(port), - connection_type_(connection_type), - identify_(identify), - username_(std::move(username)), - password_(std::move(password)) {} - - signals: - /** - * @brief - * - * @param result - */ - void SignalSMTPConnectionTestResult(const QString& result); - - protected: - /** - * @brief - * - */ - void run() override; - - private: - std::string host_; ///< - int port_; ///< - SmtpClient::ConnectionType connection_type_; ///< - bool identify_; ///< - std::string username_; ///< - std::string password_; ///< -}; - -} // namespace GpgFrontend::UI - -#endif // GPGFRONTEND_SMTPCONNECTIONTESTTHREAD_H diff --git a/src/ui/thread/SMTPSendMailThread.cpp b/src/ui/thread/SMTPSendMailThread.cpp deleted file mode 100644 index f1cb1626..00000000 --- a/src/ui/thread/SMTPSendMailThread.cpp +++ /dev/null @@ -1,263 +0,0 @@ -/** - * Copyright (C) 2021 Saturneric - * - * 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 . - * - * The initial version of the source code is inherited from - * the gpg4usb project, which is under GPL-3.0-or-later. - * - * The source code version of this software was modified and released - * by Saturneric starting on May 12, 2021. - * - */ - -#include "SMTPSendMailThread.h" - -#include - -#include "core/function/gpg/GpgBasicOperator.h" -#include "core/function/gpg/GpgKeyGetter.h" -#include "core/function/gpg/GpgKeyImportExporter.h" - -namespace GpgFrontend::UI { - -void SMTPSendMailThread::run() { - SmtpClient smtp(host_.c_str(), port_, connection_type_); - - if (identify_) { - smtp.setUser(username_.c_str()); - smtp.setPassword(password_.c_str()); - } - - if (encrypt_content_ && public_key_ids_ != nullptr && - !public_key_ids_->empty() && !attach_signature_file_) { - message.getContent().setContentType( - "multipart/encrypted; " - "protocol=\"application/pgp-encrypted\""); - } - - if (attach_signature_file_ && !private_key_id_.empty()) { - message.getContent().setContentType( - "multipart/signed; " - "protocol=\"application/pgp-signature\""); - } - - int index = 0; - for (auto& text : texts_) { - const auto plain_text = text->getText().toStdString(); - - // encrypt - if (encrypt_content_ && public_key_ids_ != nullptr && - !public_key_ids_->empty()) { - ByteArrayPtr out_buffer = nullptr; - GpgEncrResult result; - auto in_buffer = std::make_unique(plain_text); - auto keys = GpgKeyGetter::GetInstance().GetKeys(public_key_ids_); - auto err = GpgBasicOperator::GetInstance().Encrypt( - std::move(keys), *in_buffer, out_buffer, result); - - if (check_gpg_error_2_err_code(err) != GPG_ERR_NO_ERROR) { - emit SignalSMTPResult("Fail to encrypt with gpg keys"); - return; - } - text->setText(out_buffer->c_str()); - - // The multipart/encrypted MIME body MUST consist of exactly two body - // parts, the first with content type "application/pgp-encrypted". This - // body contains the control information. A message complying with this - // standard MUST contain a "Version: 1" field in this body. Since the - // OpenPGP packet format contains all other information necessary for - // decrypting, no other information is required here. - auto control_text = std::make_unique("Version: 1\r\n"); - control_text->setContentType("application/pgp-encrypted"); - send_texts_.push_back(std::move(control_text)); - // The second MIME body part MUST contain the actual encrypted data. It - // MUST be labeled with a content type of "application/octet-stream". - text->setContentType("application/octet-stream"); - } - - send_texts_.push_back(std::move(text)); - - // sign - if (attach_signature_file_ && !private_key_id_.empty()) { - ByteArrayPtr out_buffer = nullptr; - GpgSignResult result; - - auto& plain_mime_text = send_texts_.back(); - // In particular, line endings in the encoded data - // MUST use the canonical sequence where appropriate - auto encoded_text = plain_mime_text->getText(); - // As described in section 3 of this document, any trailing - // whitespace MUST then be removed from the signed material. - encoded_text = encoded_text.trimmed(); - encoded_text = encoded_text.replace('\n', "\r\n"); - // An implementation which elects to adhere to the OpenPGP convention - // has to make sure it inserts a pair on the last line of the - // data to be signed and transmitted. - encoded_text.append("\r\n"); - plain_mime_text->setText(encoded_text); - - // This presents serious problems - // for multipart/signed, in particular, where the signature is - // invalidated when such an operation occurs. For this reason all data - // signed according to this protocol MUST be constrained to 7 bits (8- - // bit data MUST be encoded using either Quoted-Printable or Base64). - plain_mime_text->setEncoding(MimePart::_7Bit); - - // As described in [2], the digital signature MUST be calculated - // over both the data to be signed and its set of content headers. - auto text_calculated = plain_mime_text->toString().toStdString(); - - auto in_buffer = std::make_unique(text_calculated); - auto key = GpgKeyGetter::GetInstance().GetKey(private_key_id_); - auto keys = std::make_unique(); - keys->push_back(std::move(key)); - - // The signature MUST be generated detached from the signed data - // so that the process does not alter the signed data in any way. - auto err = GpgBasicOperator::GetInstance().Sign( - std::move(keys), *in_buffer, out_buffer, GPGME_SIG_MODE_DETACH, - result); - - if (check_gpg_error_2_err_code(err) != GPG_ERR_NO_ERROR) { - emit SignalSMTPResult("Fail to sign with gpg keys"); - return; - } - - auto sign_content_name = - boost::format("%1%_sign_%2%.asc") % private_key_id_ % index++; - - // Set MIME Options - send_texts_.push_back(std::make_unique(out_buffer->c_str())); - auto& sig_text = send_texts_.back(); - sig_text->setContentType("application/pgp-signature"); - sig_text->setEncoding(MimePart::_7Bit); - sig_text->setContentName(sign_content_name.str().c_str()); - - // set Message Integrity Check (MIC) algorithm - if (result->signatures != nullptr) { - // The "micalg" parameter for the "application/pgp-signature" - // protocol - // MUST contain exactly one hash-symbol of the format "pgp-", where identifies the Message - // Integrity Check (MIC) algorithm used to generate the signature. - // Hash-symbols are constructed from the text names registered in [1] - // or according to the mechanism defined in that document by - // converting the text name to lower case and prefixing it with the - // four characters "pgp-". - auto hash_algo_name = - std::string(gpgme_hash_algo_name(result->signatures->hash_algo)); - boost::algorithm::to_lower(hash_algo_name); - std::stringstream ss; - ss << message.getContent().getContentType().toStdString(); - ss << "; micalg=pgp-" << hash_algo_name; - message.getContent().setContentType(ss.str().c_str()); - } - } - } - - if (attach_public_key_file_ && !attached_public_key_ids_.empty()) { - auto key = GpgKeyGetter::GetInstance().GetKey(attached_public_key_ids_); - ByteArrayPtr out_buffer = nullptr; - GpgKeyImportExporter::GetInstance().ExportKey(key, out_buffer); - - auto public_key_file_name = - boost::format("%1%_pubkey.asc") % attached_public_key_ids_; - AddFileContent(public_key_file_name.str().c_str(), out_buffer->c_str()); - auto& key_file = files_.back(); - key_file->setEncoding(MimePart::_7Bit); - key_file->setContentType("application/pgp-keys"); - } - - for (const auto& text : send_texts_) { - message.addPart(text.get()); - } - - for (const auto& file : files_) { - message.addPart(file.get()); - } - - // Now we can send the mail - if (!smtp.connectToHost()) { - emit SignalSMTPResult("Fail to connect SMTP server"); - return; - } - if (!smtp.login()) { - emit SignalSMTPResult("Fail to login"); - return; - } - if (!smtp.sendMail(message)) { - emit SignalSMTPResult("Fail to send mail"); - return; - } - smtp.quit(); - emit SignalSMTPResult("Succeed in sending a test email"); -} - -void SMTPSendMailThread::SetBCC(const QString& bccs) { - QStringList bcc_string_list = bccs.split(';'); - for (const auto& bcc : bcc_string_list) { - if (!bcc.isEmpty()) message.addBcc(new EmailAddress(bcc.trimmed())); - } -} - -void SMTPSendMailThread::SetCC(const QString& ccs) { - QStringList cc_string_list = ccs.split(';'); - for (const auto& cc : cc_string_list) { - if (!cc.isEmpty()) message.addCc(new EmailAddress(cc.trimmed())); - } -} - -void SMTPSendMailThread::SetRecipient(const QString& recipients) { - QStringList rcpt_string_list = recipients.split(';'); - for (const auto& rcpt : rcpt_string_list) { - if (!rcpt.isEmpty()) message.addRecipient(new EmailAddress(rcpt.trimmed())); - } -} - -void SMTPSendMailThread::SetSender(const QString& sender) { - message.setSender(new EmailAddress(sender)); -} - -void SMTPSendMailThread::AddTextContent(const QString& content) { - auto text = std::make_unique(content.trimmed()); - texts_.push_back(std::move(text)); -} - -void SMTPSendMailThread::AddFileContent(const QString& file_name, - const QByteArray& content) { - auto file = std::make_unique(content, file_name); - files_.push_back(std::move(file)); -} - -void SMTPSendMailThread::SetEncryptContent( - bool encrypt_content, GpgFrontend::KeyIdArgsListPtr public_key_ids) { - this->encrypt_content_ = encrypt_content; - this->public_key_ids_ = std::move(public_key_ids); -} - -void SMTPSendMailThread::SetAttachSignatureFile( - bool attach_signature_file, GpgFrontend::KeyId private_key_id) { - this->attach_signature_file_ = attach_signature_file; - this->private_key_id_ = std::move(private_key_id); -} - -void SMTPSendMailThread::SetAttachPublicKey( - bool attach_public_key_file, GpgFrontend::KeyId attached_public_key_ids) { - this->attach_public_key_file_ = attach_public_key_file; - this->attached_public_key_ids_ = std::move(attached_public_key_ids); -} -} // namespace GpgFrontend::UI diff --git a/src/ui/thread/SMTPSendMailThread.h b/src/ui/thread/SMTPSendMailThread.h deleted file mode 100644 index 58420bf3..00000000 --- a/src/ui/thread/SMTPSendMailThread.h +++ /dev/null @@ -1,179 +0,0 @@ -/** - * Copyright (C) 2021 Saturneric - * - * 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 . - * - * The initial version of the source code is inherited from - * the gpg4usb project, which is under GPL-3.0-or-later. - * - * The source code version of this software was modified and released - * by Saturneric starting on May 12, 2021. - * - */ - -#ifndef GPGFRONTEND_SMTPSENDMAILTHREAD_H -#define GPGFRONTEND_SMTPSENDMAILTHREAD_H - -#include - -#include "ui/GpgFrontendUI.h" - -namespace GpgFrontend::UI { -/** - * @brief - * - */ -class SMTPSendMailThread : public QThread { - Q_OBJECT - public: - /** - * @brief Construct a new SMTPSendMailThread object - * - * @param host - * @param port - * @param connection_type - * @param identify - * @param username - * @param password - * @param parent - */ - explicit SMTPSendMailThread(std::string host, int port, - SmtpClient::ConnectionType connection_type, - bool identify, std::string username, - std::string password, QWidget* parent = nullptr) - : QThread(parent), - host_(std::move(host)), - port_(port), - connection_type_(connection_type), - identify_(identify), - username_(std::move(username)), - password_(std::move(password)) {} - - void SetSender(const QString& sender); - - /** - * @brief Set the Recipient object - * - * @param recipients - */ - void SetRecipient(const QString& recipients); - - /** - * @brief - * - * @param ccs - */ - void SetCC(const QString& ccs); - - /** - * @brief - * - * @param bccs - */ - void SetBCC(const QString& bccs); - - /** - * @brief Set the Subject object - * - * @param subject - */ - void SetSubject(const QString& subject) { message.setSubject(subject); } - - /** - * @brief - * - * @param content - */ - void AddTextContent(const QString& content); - - /** - * @brief - * - * @param file_name - * @param content - */ - void AddFileContent(const QString& file_name, const QByteArray& content); - - /** - * @brief Set the Encrypt Content object - * - * @param encrypt_content - * @param public_key_ids - */ - void SetEncryptContent(bool encrypt_content, - GpgFrontend::KeyIdArgsListPtr public_key_ids); - - /** - * @brief Set the Attach Signature File object - * - * @param attach_signature_file - * @param private_key_id - */ - void SetAttachSignatureFile(bool attach_signature_file, - GpgFrontend::KeyId private_key_id); - - /** - * @brief Set the Attach Public Key object - * - * @param attach_public_key_file - * @param attached_public_key_ids - */ - void SetAttachPublicKey(bool attach_public_key_file, - GpgFrontend::KeyId attached_public_key_ids); - - signals: - /** - * @brief - * - * @param result - */ - void SignalSMTPResult(const QString& result); - - protected: - /** - * @brief - * - */ - void run() override; - - private: - // SMTP Options - - std::string host_; ///< - int port_; ///< - SmtpClient::ConnectionType connection_type_; ///< - - bool identify_; ///< - std::string username_; ///< - std::string password_; ///< - - MimeMessage message; ///< - std::vector> texts_; ///< - std::vector> send_texts_; ///< - std::vector> files_; ///< - - // GPG Options - - bool encrypt_content_ = false; ///< - GpgFrontend::KeyIdArgsListPtr public_key_ids_; ///< - bool attach_signature_file_ = false; ///< - GpgFrontend::KeyId private_key_id_; ///< - bool attach_public_key_file_ = false; ///< - GpgFrontend::KeyId attached_public_key_ids_; ///< -}; -} // namespace GpgFrontend::UI - -#endif // GPGFRONTEND_SMTPSENDMAILTHREAD_H diff --git a/src/ui/widgets/KeyList.cpp b/src/ui/widgets/KeyList.cpp index 60cfbc84..6292c1a9 100644 --- a/src/ui/widgets/KeyList.cpp +++ b/src/ui/widgets/KeyList.cpp @@ -32,38 +32,22 @@ #include #include "core/GpgCoreInit.h" +#include "core/function/GlobalSettingStation.h" #include "core/function/gpg/GpgKeyGetter.h" #include "ui/SignalStation.h" #include "ui/UserInterfaceUtils.h" -#include "core/function/GlobalSettingStation.h" #include "ui_KeyList.h" namespace GpgFrontend::UI { -int KeyList::key_list_id_ = 2048; - KeyList::KeyList(KeyMenuAbility::AbilityType menu_ability, QWidget* parent) : QWidget(parent), - m_key_list_id_(key_list_id_++), ui_(std::make_shared()), menu_ability_(menu_ability) { init(); } void KeyList::init() { -#ifdef GPG_STANDALONE_MODE - LOG(INFO) << "GPG_STANDALONE_MODE Enabled"; - auto gpg_path = GpgFrontend::GlobalSettingStation::GetInstance() - .GetStandaloneGpgBinDir(); - auto db_path = GpgFrontend::GlobalSettingStation::GetInstance() - .GetStandaloneDatabaseDir(); - GpgContext::CreateInstance( - _m_key_list_id, std::make_unique(true, db_path.u8string(), true, - gpg_path.string())); -#else - new_default_settings_channel(m_key_list_id_); -#endif - ui_->setupUi(this); ui_->menuWidget->setHidden(!menu_ability_); @@ -170,13 +154,13 @@ void KeyList::AddListGroupTab( } void KeyList::SlotRefresh() { - LOG(INFO) << _("Called") << "_m_key_list_id" << m_key_list_id_; + LOG(INFO) << _("Called"); emit SignalRefreshStatusBar(_("Refreshing Key List..."), 3000); - auto thread = QThread::create([this, _id = m_key_list_id_]() { + auto thread = QThread::create([this]() { std::lock_guard guard(buffered_key_list_mutex_); buffered_keys_list_ = nullptr; // buffered keys list - buffered_keys_list_ = GpgKeyGetter::GetInstance(_id).FetchKey(); + buffered_keys_list_ = GpgKeyGetter::GetInstance().FetchKey(); }); connect(thread, &QThread::finished, this, &KeyList::slot_refresh_ui); connect(thread, &QThread::finished, thread, &QThread::deleteLater); @@ -402,8 +386,7 @@ void KeyList::dragEnterEvent(QDragEnterEvent* event) { void KeyList::import_keys(const QByteArray& inBuffer) { auto std_buffer = std::make_unique(inBuffer.toStdString()); GpgImportInformation result = - GpgKeyImportExporter::GetInstance(m_key_list_id_) - .ImportKey(std::move(std_buffer)); + GpgKeyImportExporter::GetInstance().ImportKey(std::move(std_buffer)); new KeyImportDetailDialog(result, false, this); } @@ -412,8 +395,8 @@ void KeyList::slot_double_clicked(const QModelIndex& index) { const auto& buffered_keys = m_key_tables_[ui_->keyGroupTab->currentIndex()].buffered_keys_; if (m_action_ != nullptr) { - const auto key = GpgKeyGetter::GetInstance(m_key_list_id_) - .GetKey(buffered_keys[index.row()].GetId()); + const auto key = + GpgKeyGetter::GetInstance().GetKey(buffered_keys[index.row()].GetId()); m_action_(key, this); } } @@ -464,12 +447,11 @@ void KeyList::slot_sync_with_key_server() { emit SignalRefreshStatusBar(_("Syncing Key List..."), 3000); CommonUtils::SlotImportKeyFromKeyServer( - m_key_list_id_, key_ids, - [=](const std::string& key_id, const std::string& status, - size_t current_index, size_t all_index) { + key_ids, [=](const std::string& key_id, const std::string& status, + size_t current_index, size_t all_index) { LOG(INFO) << _("Called") << key_id << status << current_index << all_index; - auto key = GpgKeyGetter::GetInstance(m_key_list_id_).GetKey(key_id); + auto key = GpgKeyGetter::GetInstance().GetKey(key_id); boost::format status_str = boost::format(_("Sync [%1%/%2%] %3% %4%")) % current_index % all_index % diff --git a/src/ui/widgets/KeyList.h b/src/ui/widgets/KeyList.h index d79f9331..60449ad9 100644 --- a/src/ui/widgets/KeyList.h +++ b/src/ui/widgets/KeyList.h @@ -329,8 +329,6 @@ class KeyList : public QWidget { */ void check_all(); - static int key_list_id_; ///< - int m_key_list_id_; ///< std::mutex buffered_key_list_mutex_; ///< std::shared_ptr ui_; ///< diff --git a/third_party/CMakeLists.txt b/third_party/CMakeLists.txt index 0df99211..2c39eb4d 100644 --- a/third_party/CMakeLists.txt +++ b/third_party/CMakeLists.txt @@ -24,194 +24,14 @@ # # SPDX-License-Identifier: GPL-3.0-or-later -# easyloggingpp -set(build_static_lib 1 CACHE BOOL "" FORCE) -add_subdirectory(easyloggingpp) -target_include_directories(easyloggingpp PUBLIC - ${CMAKE_CURRENT_SOURCE_DIR}/easyloggingpp/src) - # json set(JSON_BuildTests OFF CACHE INTERNAL "") -add_subdirectory(json) +add_subdirectory(json EXCLUDE_FROM_ALL) # qt-aes include(GenerateExportHeader) -add_subdirectory(qt-aes) - -# vmime -set(VMIME_HAVE_MESSAGING_PROTO_SENDMAIL OFF CACHE BOOL "" FORCE) -set(VMIME_HAVE_SASL_SUPPORT OFF CACHE BOOL "" FORCE) -set(VMIME_BUILD_STATIC_LIBRARY ON CACHE BOOL "" FORCE) -set(VMIME_BUILD_SHARED_LIBRARY OFF CACHE BOOL "" FORCE) -set(VMIME_CHARSETCONV_LIB "iconv" CACHE STRING "" FORCE) -set(VMIME_TLS_SUPPORT_LIB "openssl" CACHE STRING "" FORCE) - -set(VMIME_DIR ${CMAKE_CURRENT_SOURCE_DIR}/vmime) -set(VMIME_BIN ${CMAKE_CURRENT_BINARY_DIR}/vmime) - -set(VMIME_INCLUDES ${VMIME_DIR}/src ${CMAKE_BINARY_DIR}/src/vmime/ ${CMAKE_BINARY_DIR}/src/) - -set(VMIME_BIN_STATIC_LIB ${VMIME_BIN}/build/lib/libvmime.a) - -add_subdirectory(vmime) - -add_library(gpgfrontend_vmime STATIC IMPORTED GLOBAL) -add_dependencies(gpgfrontend_vmime vmime-static vmime-static-config) -set_target_properties(gpgfrontend_vmime PROPERTIES IMPORTED_LOCATION ${VMIME_BIN_STATIC_LIB}) -set_target_properties(gpgfrontend_vmime PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "${VMIME_INCLUDES}") - -# gnupg - -include(ExternalProject) - -# libgpg-error - - -if (NOT MINGW) - set(GPG_ERROR_DIR ${CMAKE_CURRENT_SOURCE_DIR}/libgpg-error) - set(GPG_ERROR_BIN ${CMAKE_CURRENT_BINARY_DIR}/libgpg-error) - set(GPG_ERROR_STATIC_LIB ${GPG_ERROR_BIN}/lib/libgpg-error.a) - set(GPG_ERROR_INCLUDES ${GPG_ERROR_BIN}/include) - set(GPG_ERROR_LIBS ${GPG_ERROR_BIN}/lib) - file(MAKE_DIRECTORY ${GPG_ERROR_INCLUDES}) -else () - find_library(GPG_ERROR_STATIC_LIB libgpg-error.a) -endif () - -if (NOT MINGW) - - ExternalProject_Add(libgpg-error - PREFIX ${GPG_ERROR_BIN} - SOURCE_DIR ${GPG_ERROR_DIR} - CONFIGURE_COMMAND ${GPG_ERROR_DIR}/configure --enable-maintainer-mode --prefix=${GPG_ERROR_BIN} --enable-static=yes - BUILD_COMMAND make - INSTALL_COMMAND make install - BUILD_BYPRODUCTS ${GPG_ERROR_STATIC_LIB}) - - ExternalProject_Add_Step(libgpg-error autogen - WORKING_DIRECTORY ${GPG_ERROR_DIR} - COMMAND ${GPG_ERROR_DIR}/autogen.sh - DEPENDERS configure) - -endif () - -add_library(gpg-error STATIC IMPORTED GLOBAL) -if (NOT MINGW) - add_dependencies(gpg-error libgpg-error) - set_target_properties(gpg-error PROPERTIES INTERFACE_INCLUDE_DIRECTORIES ${GPG_ERROR_INCLUDES}) -endif () -set_target_properties(gpg-error PROPERTIES IMPORTED_LOCATION ${GPG_ERROR_STATIC_LIB}) - -# libassuan - -if (NOT MINGW) - set(ASSUAN_DIR ${CMAKE_CURRENT_SOURCE_DIR}/libassuan) - set(ASSUAN_BIN ${CMAKE_CURRENT_BINARY_DIR}/libassuan) - set(ASSUAN_STATIC_LIB ${ASSUAN_BIN}/lib/libassuan.a) - set(ASSUAN_INCLUDES ${ASSUAN_BIN}/include) - set(ASSUAN_LIBS ${ASSUAN_BIN}/lib) - file(MAKE_DIRECTORY ${ASSUAN_INCLUDES}) -else () - find_library(ASSUAN_STATIC_LIB libassuan.a) -endif () - -if (NOT MINGW) - - ExternalProject_Add(libassuan - PREFIX ${ASSUAN_BIN} - SOURCE_DIR ${ASSUAN_DIR} - CONFIGURE_COMMAND ${ASSUAN_DIR}/configure --enable-maintainer-mode --prefix=${ASSUAN_BIN} --enable-static=yes - --with-libgpg-error-prefix=${GPG_ERROR_BIN} - BUILD_COMMAND make - INSTALL_COMMAND make install - BUILD_BYPRODUCTS ${ASSUAN_STATIC_LIB}) - - ExternalProject_Add_Step(libassuan autogen - WORKING_DIRECTORY ${ASSUAN_DIR} - COMMAND ${ASSUAN_DIR}/autogen.sh - DEPENDERS configure) - - ExternalProject_Add_StepDependencies(libassuan autogen libgpg-error) - -endif () - -add_library(assuan STATIC IMPORTED GLOBAL) -if (NOT MINGW) - add_dependencies(assuan libassuan gpg-error) - set_target_properties(assuan PROPERTIES INTERFACE_INCLUDE_DIRECTORIES ${ASSUAN_INCLUDES}) -endif () -set_target_properties(assuan PROPERTIES IMPORTED_LOCATION ${ASSUAN_STATIC_LIB}) - -# gpgme - -if (NOT MINGW) - set(GPGME_DIR ${CMAKE_CURRENT_SOURCE_DIR}/gpgme) - set(GPGME_BIN ${CMAKE_CURRENT_BINARY_DIR}/gpgme) - set(GPGME_STATIC_LIB ${GPGME_BIN}/lib/libgpgme.a) - set(GPGME_INCLUDES ${GPGME_BIN}/include) - file(MAKE_DIRECTORY ${GPGME_INCLUDES}) -else () - find_library(GPGME_STATIC_LIB libgpgme.a) -endif () - -if (NOT MINGW) - - ExternalProject_Add(libgpgme - PREFIX ${GPGME_BIN} - SOURCE_DIR ${GPGME_DIR} - CONFIGURE_COMMAND ${GPGME_DIR}/configure --enable-maintainer-mode --prefix=${GPGME_BIN} --enable-shared=no --enable-static=yes --disable-gpg-test --enable-languages=cpp - --with-libgpg-error-prefix=${GPG_ERROR_BIN} - --with-libassuan-prefix=${ASSUAN_BIN} - "LIB=-lassuan -lgpg-error" - "LDFLAGS=-L${ASSUAN_LIBS} -L${GPG_ERROR_LIBS} " - BUILD_COMMAND make - INSTALL_COMMAND make install - BUILD_BYPRODUCTS ${GPGME_STATIC_LIB}) - - ExternalProject_Add_Step(libgpgme autogen - WORKING_DIRECTORY ${GPGME_DIR} - COMMAND ${GPGME_DIR}/autogen.sh - DEPENDERS configure) - - ExternalProject_Add_StepDependencies(libgpgme autogen libassuan libgpg-error) - -endif () - -add_library(gpgme STATIC IMPORTED GLOBAL) -if (NOT MINGW) - add_dependencies(gpgme libgpgme assuan gpg-error) - set_target_properties(gpgme PROPERTIES INTERFACE_INCLUDE_DIRECTORIES ${GPGME_INCLUDES}) -endif () -set_target_properties(gpgme PROPERTIES IMPORTED_LOCATION ${GPGME_STATIC_LIB}) - -if (SMTP_SUPPORT) - message(STATUS "Build SMTP Support") - aux_source_directory(${CMAKE_CURRENT_SOURCE_DIR}/smtp-mime/src SMTP_MIME_SOURCE) - add_library(smtp-mime STATIC ${SMTP_MIME_SOURCE}) - target_link_libraries(smtp-mime - Qt5::Network Qt5::Core) - target_include_directories(smtp-mime PUBLIC - ${CMAKE_CURRENT_SOURCE_DIR}/smtp-mime/src) - if (XCODE_BUILD) - set_target_properties(smtp-mime - PROPERTIES - ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_BUILD_TYPE} - LIBRARY_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_BUILD_TYPE} - LIBRARY_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_BUILD_TYPE}) - endif () -endif () +add_subdirectory(qt-aes EXCLUDE_FROM_ALL) # encoding detect library aux_source_directory(./encoding-detect ENCODING_DETECT_SOURCE_CODE) -add_library(encoding_detect STATIC ${ENCODING_DETECT_SOURCE_CODE}) - -# libarchive -if (NOT MINGW) - remove_definitions(-DDEBUG) - add_subdirectory(libarchive) -endif () - -if (NOT MINGW) -# libconfig -add_subdirectory(libconfig) -endif () \ No newline at end of file +add_library(encoding_detect STATIC ${ENCODING_DETECT_SOURCE_CODE}) \ No newline at end of file diff --git a/third_party/smtp-mime b/third_party/smtp-mime deleted file mode 160000 index 39d6f35c..00000000 --- a/third_party/smtp-mime +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 39d6f35ca78327ed2c109e30d630e2ea22363cd6 diff --git a/third_party/vmime b/third_party/vmime deleted file mode 160000 index 0c9dc59b..00000000 --- a/third_party/vmime +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 0c9dc59b6ff4e612d97cc2103ff948c5cbab0a7c