diff options
author | saturneric <[email protected]> | 2024-08-05 16:55:32 +0000 |
---|---|---|
committer | saturneric <[email protected]> | 2024-08-05 16:55:32 +0000 |
commit | 795a81bd1edad59ef51e73157b5ad68cfa30e328 (patch) | |
tree | fd9c4da2f1389f0a236d806e005cabb9f5ceab41 /src | |
parent | fix: build pipeline (diff) | |
parent | fix: unchecking some check boxes at gnupg controller will not restart (diff) | |
download | GpgFrontend-2.1.4.tar.gz GpgFrontend-2.1.4.zip |
fix: according to issues and test, apply some fixesv2.1.4
Diffstat (limited to 'src')
-rw-r--r-- | src/CMakeLists.txt | 13 | ||||
-rw-r--r-- | src/core/CMakeLists.txt | 5 | ||||
-rw-r--r-- | src/core/GpgCoreInit.cpp | 14 | ||||
-rw-r--r-- | src/core/function/SecureMemoryAllocator.cpp | 30 | ||||
-rw-r--r-- | src/core/function/gpg/GpgContext.cpp | 10 | ||||
-rw-r--r-- | src/core/function/gpg/GpgContext.h | 3 | ||||
-rw-r--r-- | src/core/thread/Task.cpp | 3 | ||||
-rw-r--r-- | src/ui/GpgFrontendUIInit.cpp | 7 | ||||
-rw-r--r-- | src/ui/UserInterfaceUtils.cpp | 2 | ||||
-rw-r--r-- | src/ui/dialog/controller/GnuPGControllerDialog.cpp | 12 | ||||
-rw-r--r-- | src/ui/dialog/import_export/KeyServerImportDialog.cpp | 12 | ||||
-rw-r--r-- | src/ui/dialog/import_export/KeyServerImportDialog.h | 2 | ||||
-rw-r--r-- | src/ui/dialog/import_export/KeyUploadDialog.cpp | 11 | ||||
-rw-r--r-- | src/ui/dialog/settings/SettingsKeyServer.cpp | 13 | ||||
-rw-r--r-- | src/ui/main_window/MainWindowUI.cpp | 1 | ||||
-rw-r--r-- | src/ui/struct/settings_object/KeyServerSO.h | 3 | ||||
-rw-r--r-- | src/ui/thread/KeyServerImportTask.cpp | 2 | ||||
-rw-r--r-- | src/ui/thread/KeyServerSearchTask.cpp | 8 | ||||
-rw-r--r-- | src/ui/thread/KeyServerSearchTask.h | 2 | ||||
-rw-r--r-- | src/ui/widgets/KeyList.cpp | 4 |
20 files changed, 74 insertions, 83 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 08b6e3a1..51239a4a 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -55,11 +55,6 @@ endif() find_package(OpenSSL REQUIRED) -# mimalloc -if(NOT APPLE) - find_package(mimalloc REQUIRED) -endif() - # Set Build Information configure_file(${CMAKE_SOURCE_DIR}/src/GpgFrontend.h.in ${CMAKE_SOURCE_DIR}/src/GpgFrontend.h @ONLY) configure_file(${CMAKE_SOURCE_DIR}/src/GpgFrontendBuildInfo.h.in ${CMAKE_SOURCE_DIR}/src/GpgFrontendBuildInfo.h @ONLY) @@ -284,14 +279,6 @@ if(BUILD_APPLICATION AND MINGW) list(APPEND ALL_RUNTIME_DEP_PATH_LIST ${_libDllPath}) unset(_libDllPath) - file(GLOB _libDllPath "${MSYS64_BIN_PATH}/libmimalloc*.dll") - list(APPEND ALL_RUNTIME_DEP_PATH_LIST ${_libDllPath}) - - unset(_libDllPath) - file(GLOB _libDllPath "${MSYS64_BIN_PATH}/mimalloc*.dll") - list(APPEND ALL_RUNTIME_DEP_PATH_LIST ${_libDllPath}) - - unset(_libDllPath) file(GLOB _libDllPath "${MSYS64_BIN_PATH}/libarchive*.dll") list(APPEND ALL_RUNTIME_DEP_PATH_LIST ${_libDllPath}) diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt index 81c3f08f..90409e22 100644 --- a/src/core/CMakeLists.txt +++ b/src/core/CMakeLists.txt @@ -50,11 +50,6 @@ generate_export_header(gpgfrontend_core EXPORT_FILE_NAME "${_export_file}") # compile definitions target_compile_definitions(gpgfrontend_core PRIVATE GF_CORE_PRIVATE) -# mimalloc (except apple macos) -if(NOT APPLE) - target_link_libraries(gpgfrontend_core PUBLIC mimalloc) -endif() - # qt-aes target_sources(gpgfrontend_core PRIVATE ${CMAKE_SOURCE_DIR}/third_party/qt-aes/qaesencryption.cpp) diff --git a/src/core/GpgCoreInit.cpp b/src/core/GpgCoreInit.cpp index 3f738835..68acc4cc 100644 --- a/src/core/GpgCoreInit.cpp +++ b/src/core/GpgCoreInit.cpp @@ -304,9 +304,6 @@ void InitGpgFrontendCore(CoreInitArgs args) { auto custom_key_database_path = settings.value("gnupg/custom_key_database_path", QString{}).toString(); - auto custom_gnupg_install_path = - settings.value("gnupg/custom_gnupg_install_path", QString{}).toString(); - auto use_pinentry_as_password_input_dialog = settings .value("gnupg/use_pinentry_as_password_input_dialog", @@ -327,10 +324,14 @@ void InitGpgFrontendCore(CoreInitArgs args) { !custom_key_database_path.isEmpty()) { if (VerifyKeyDatabasePath(QFileInfo(custom_key_database_path))) { key_database_fs_path = - QFileInfo(custom_gnupg_install_path).absoluteFilePath(); + QFileInfo(custom_key_database_path).absoluteFilePath(); + LOG_D() << "use custom gpg key database: " << key_database_fs_path + << "raw:" << custom_key_database_path; + } else { LOG_W() << "custom gpg key database path is not suitable: " - << key_database_fs_path; + << key_database_fs_path + << "raw:" << custom_key_database_path; } } else { @@ -354,8 +355,7 @@ void InitGpgFrontendCore(CoreInitArgs args) { // set custom gnupg path if (!gnupg_install_fs_path.isEmpty()) { - args.custom_gpgconf = true; - args.custom_gpgconf_path = gnupg_install_fs_path; + args.gpgconf_path = gnupg_install_fs_path; } args.offline_mode = forbid_all_gnupg_connection; diff --git a/src/core/function/SecureMemoryAllocator.cpp b/src/core/function/SecureMemoryAllocator.cpp index c24e13f2..47301038 100644 --- a/src/core/function/SecureMemoryAllocator.cpp +++ b/src/core/function/SecureMemoryAllocator.cpp @@ -28,42 +28,22 @@ #include "SecureMemoryAllocator.h" -namespace GpgFrontend { +#include <cstdlib> -#if defined(__APPLE__) && defined(__MACH__) +namespace GpgFrontend { auto SecureMemoryAllocator::Allocate(std::size_t size) -> void* { - auto* addr = malloc(size); + auto* addr = std::malloc(size); if (addr == nullptr) FLOG_F("malloc failed!"); return addr; } auto SecureMemoryAllocator::Reallocate(void* ptr, std::size_t size) -> void* { - auto* addr = realloc(ptr, size); + auto* addr = std::realloc(ptr, size); if (addr == nullptr) FLOG_F("realloc failed!"); return addr; } -void SecureMemoryAllocator::Deallocate(void* p) { free(p); } - -#else - -#include <mimalloc.h> - -auto SecureMemoryAllocator::Allocate(std::size_t size) -> void* { - auto* addr = mi_malloc(size); - if (addr == nullptr) FLOG_F("malloc failed!"); - return addr; -} - -auto SecureMemoryAllocator::Reallocate(void* ptr, std::size_t size) -> void* { - auto* addr = mi_realloc(ptr, size); - if (addr == nullptr) FLOG_F("realloc memory failed!"); - return addr; -} - -void SecureMemoryAllocator::Deallocate(void* p) { mi_free(p); } - -#endif +void SecureMemoryAllocator::Deallocate(void* p) { std::free(p); } } // namespace GpgFrontend
\ No newline at end of file diff --git a/src/core/function/gpg/GpgContext.cpp b/src/core/function/gpg/GpgContext.cpp index 2d9c5992..a661f183 100644 --- a/src/core/function/gpg/GpgContext.cpp +++ b/src/core/function/gpg/GpgContext.cpp @@ -236,11 +236,10 @@ class GpgContext::Impl { const GpgContextInitArgs &args) -> bool { assert(ctx != nullptr); - if (args.custom_gpgconf && !args.custom_gpgconf_path.isEmpty()) { - LOG_D() << "set custom gpgconf path: " << args.custom_gpgconf_path; - auto err = - gpgme_ctx_set_engine_info(ctx, GPGME_PROTOCOL_GPGCONF, - args.custom_gpgconf_path.toUtf8(), nullptr); + if (!args.gpgconf_path.isEmpty()) { + LOG_D() << "set custom gpgconf path: " << args.gpgconf_path; + auto err = gpgme_ctx_set_engine_info(ctx, GPGME_PROTOCOL_GPGCONF, + args.gpgconf_path.toUtf8(), nullptr); if (CheckGpgError(err) != GPG_ERR_NO_ERROR) { LOG_W() << "set gpg context engine info error: " @@ -284,6 +283,7 @@ class GpgContext::Impl { // set custom gpg key db path if (!args_.db_path.isEmpty()) { + LOG_D() << "set context database path to" << args_.db_path; Module::UpsertRTValue("core", "gpgme.ctx.database_path", args_.db_path); } diff --git a/src/core/function/gpg/GpgContext.h b/src/core/function/gpg/GpgContext.h index 7a7ef24b..1ff22b8a 100644 --- a/src/core/function/gpg/GpgContext.h +++ b/src/core/function/gpg/GpgContext.h @@ -46,8 +46,7 @@ struct GpgContextInitArgs { bool offline_mode = false; ///< bool auto_import_missing_key = false; ///< - bool custom_gpgconf = false; ///< - QString custom_gpgconf_path; ///< + QString gpgconf_path; ///< bool use_pinentry = false; ///< }; diff --git a/src/core/thread/Task.cpp b/src/core/thread/Task.cpp index 7a0e76e8..71c3f7b2 100644 --- a/src/core/thread/Task.cpp +++ b/src/core/thread/Task.cpp @@ -164,7 +164,8 @@ class Task::Impl { } }; -Task::Task(QString name) : p_(new Impl(this, name)) {} +Task::Task(QString name) + : p_(SecureCreateUniqueObject<Task::Impl>(this, name)) {} Task::Task(TaskRunnable runnable, QString name, DataObjectPtr data_object) : p_(SecureCreateUniqueObject<Impl>(this, runnable, name, data_object)) {} diff --git a/src/ui/GpgFrontendUIInit.cpp b/src/ui/GpgFrontendUIInit.cpp index 965ce471..9cca46c2 100644 --- a/src/ui/GpgFrontendUIInit.cpp +++ b/src/ui/GpgFrontendUIInit.cpp @@ -48,7 +48,7 @@ QList<QByteArray> loaded_qm_datum; extern void InitUITranslations(); void WaitEnvCheckingProcess() { - FLOG_D("need to waiting for env checking process"); + FLOG_D("need to wait for env checking process"); // create and show loading window before starting the main window auto* waiting_dialog = new QProgressDialog(); @@ -86,8 +86,7 @@ void WaitEnvCheckingProcess() { auto env_state = Module::RetrieveRTValueTypedOrDefault<>("core", "env.state.all", 0); - FLOG_D("ui is ready to waiting for env initialized, env_state: %d", - env_state); + FLOG_D("ui is ready to wait for env initialized, env_state: %d", env_state); // check twice to avoid some unlucky sitations if (env_state == 1) { @@ -200,7 +199,7 @@ void InitGpgFrontendUI(QApplication* /*app*/) { void WaitingAllInitializationFinished() { if (Module::RetrieveRTValueTypedOrDefault<>("core", "env.state.all", 0) == 0) { - LOG_D() << "ui init is done, but cor doesn't, going to waiting for core..."; + LOG_D() << "ui init is done, but core doesn't, going to wait for core..."; WaitEnvCheckingProcess(); } LOG_D() << "application fully initialized..."; diff --git a/src/ui/UserInterfaceUtils.cpp b/src/ui/UserInterfaceUtils.cpp index c6be2715..0f462cf7 100644 --- a/src/ui/UserInterfaceUtils.cpp +++ b/src/ui/UserInterfaceUtils.cpp @@ -560,7 +560,7 @@ void CommonUtils::RemoveKeyFromFavourite(const GpgKey &key) { * */ void CommonUtils::ImportKeyFromKeyServer(const KeyIdArgsList &key_ids) { - KeyServerSO key_server(SettingsObject("general_settings_state")); + KeyServerSO key_server(SettingsObject("key_server")); auto target_keyserver = key_server.GetTargetServer(); auto *task = new KeyServerImportTask(target_keyserver, key_ids); diff --git a/src/ui/dialog/controller/GnuPGControllerDialog.cpp b/src/ui/dialog/controller/GnuPGControllerDialog.cpp index 4cdc4864..859c26aa 100644 --- a/src/ui/dialog/controller/GnuPGControllerDialog.cpp +++ b/src/ui/dialog/controller/GnuPGControllerDialog.cpp @@ -149,6 +149,18 @@ GnuPGControllerDialog::GnuPGControllerDialog(QWidget* parent) this->slot_set_restart_needed(kDeepRestartCode); }); + connect(ui_->keyDatabaseUseCustomCheckBox, &QCheckBox::stateChanged, this, + [=](int) { + // announce the restart + this->slot_set_restart_needed(kDeepRestartCode); + }); + + connect(ui_->useCustomGnuPGInstallPathCheckBox, &QCheckBox::stateChanged, + this, [=](int) { + // announce the restart + this->slot_set_restart_needed(kDeepRestartCode); + }); + #if defined(__APPLE__) && defined(__MACH__) // macOS style settings ui_->buttonBox->setDisabled(true); diff --git a/src/ui/dialog/import_export/KeyServerImportDialog.cpp b/src/ui/dialog/import_export/KeyServerImportDialog.cpp index 47d80090..e1d2be72 100644 --- a/src/ui/dialog/import_export/KeyServerImportDialog.cpp +++ b/src/ui/dialog/import_export/KeyServerImportDialog.cpp @@ -125,12 +125,15 @@ auto KeyServerImportDialog::create_combo_box() -> QComboBox* { combo_box->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred); try { - KeyServerSO key_server(SettingsObject("general_settings_state")); + KeyServerSO key_server(SettingsObject("key_server")); const auto& key_server_list = key_server.server_list; for (const auto& key_server : key_server_list) { combo_box->addItem(key_server); } - combo_box->setCurrentText(key_server.GetTargetServer()); + auto target_key_server = key_server.GetTargetServer(); + LOG_D() << "set combo box to key server: " << target_key_server; + + combo_box->setCurrentText(target_key_server); } catch (...) { FLOG_W("setting operation error server_list default_server"); } @@ -207,7 +210,7 @@ void KeyServerImportDialog::slot_search() { } void KeyServerImportDialog::slot_search_finished( - QNetworkReply::NetworkError error, QByteArray buffer) { + QNetworkReply::NetworkError error, QString err_string, QByteArray buffer) { keys_table_->clearContents(); keys_table_->setRowCount(0); @@ -226,6 +229,7 @@ void KeyServerImportDialog::slot_search_finished( break; default: set_message(tr("Connection Error"), true); + QMessageBox::critical(this, tr("Connection Error"), err_string); } return; } @@ -380,7 +384,7 @@ void KeyServerImportDialog::SlotImport(const KeyIdArgsListPtr& keys) { target_keyserver = key_server_combo_box_->currentText(); } if (target_keyserver.isEmpty()) { - KeyServerSO key_server(SettingsObject("general_settings_state")); + KeyServerSO key_server(SettingsObject("key_server")); target_keyserver = key_server.GetTargetServer(); } std::vector<QString> key_ids; diff --git a/src/ui/dialog/import_export/KeyServerImportDialog.h b/src/ui/dialog/import_export/KeyServerImportDialog.h index 366e214d..3af381e7 100644 --- a/src/ui/dialog/import_export/KeyServerImportDialog.h +++ b/src/ui/dialog/import_export/KeyServerImportDialog.h @@ -90,7 +90,7 @@ class KeyServerImportDialog : public GeneralDialog { * */ void slot_search_finished(QNetworkReply::NetworkError reply, - QByteArray buffer); + QString err_string, QByteArray buffer); /** * @brief diff --git a/src/ui/dialog/import_export/KeyUploadDialog.cpp b/src/ui/dialog/import_export/KeyUploadDialog.cpp index a19f02f2..80408107 100644 --- a/src/ui/dialog/import_export/KeyUploadDialog.cpp +++ b/src/ui/dialog/import_export/KeyUploadDialog.cpp @@ -94,11 +94,12 @@ void KeyUploadDialog::SlotUpload() { void KeyUploadDialog::slot_upload_key_to_server( const GpgFrontend::GFBuffer& keys_data) { - KeyServerSO key_server(SettingsObject("general_settings_state")); - auto target_keyserver = key_server.GetTargetServer(); + KeyServerSO key_server(SettingsObject("key_server")); + auto target_key_server = key_server.GetTargetServer(); - QUrl req_url(target_keyserver + "/pks/add"); - auto* qnam = new QNetworkAccessManager(this); + LOG_D() << "upload public key using key server" << target_key_server; + QUrl req_url(target_key_server + "/pks/add"); + auto* q_nam = new QNetworkAccessManager(this); // Building Post Data QByteArray post_data; @@ -124,7 +125,7 @@ void KeyUploadDialog::slot_upload_key_to_server( post_data.append("keytext").append("=").append(data); // Send Post Data - QNetworkReply* reply = qnam->post(request, post_data); + QNetworkReply* reply = q_nam->post(request, post_data); connect(reply, &QNetworkReply::finished, this, &KeyUploadDialog::slot_upload_finished); diff --git a/src/ui/dialog/settings/SettingsKeyServer.cpp b/src/ui/dialog/settings/SettingsKeyServer.cpp index 5ba03740..38256c8e 100644 --- a/src/ui/dialog/settings/SettingsKeyServer.cpp +++ b/src/ui/dialog/settings/SettingsKeyServer.cpp @@ -94,7 +94,7 @@ KeyserverTab::KeyserverTab(QWidget* parent) connect(ui_->actionSet_As_Default, &QAction::triggered, [=]() { const auto row_size = ui_->keyServerListTable->rowCount(); for (int i = 0; i < row_size; i++) { - const auto item = ui_->keyServerListTable->item(i, 1); + auto* const item = ui_->keyServerListTable->item(i, 1); if (!item->isSelected()) continue; this->default_key_server_ = item->text(); } @@ -164,18 +164,21 @@ void KeyserverTab::slot_add_key_server() { void KeyserverTab::ApplySettings() { SettingsObject key_server_json("key_server"); - KeyServerSO key_server; + KeyServerSO key_server_so; - auto& key_server_list = key_server.server_list; + auto& key_server_list = key_server_so.server_list; const auto list_size = key_server_str_list_.size(); for (int i = 0; i < list_size; i++) { const auto key_server = key_server_str_list_[i]; if (default_key_server_ == key_server) { - key_server_json["default_server"] = i; + LOG_D() << "set default key server as:" << default_key_server_ + << "index: " << i; + key_server_so.default_server = i; } key_server_list << key_server; } - key_server_json.Store(key_server.ToJson()); + LOG_D() << "key server settings json:" << key_server_so.ToJson(); + key_server_json.Store(key_server_so.ToJson()); } void KeyserverTab::slot_refresh_table() { diff --git a/src/ui/main_window/MainWindowUI.cpp b/src/ui/main_window/MainWindowUI.cpp index 49889c06..d0866415 100644 --- a/src/ui/main_window/MainWindowUI.cpp +++ b/src/ui/main_window/MainWindowUI.cpp @@ -168,6 +168,7 @@ void MainWindow::create_actions() { &MainWindow::slot_clean_double_line_breaks); open_settings_act_ = new QAction(tr("Settings"), this); + open_settings_act_->setIcon(QIcon(":/icons/setting.png")); open_settings_act_->setToolTip(tr("Open settings dialog")); open_settings_act_->setMenuRole(QAction::PreferencesRole); open_settings_act_->setShortcut(QKeySequence::Preferences); diff --git a/src/ui/struct/settings_object/KeyServerSO.h b/src/ui/struct/settings_object/KeyServerSO.h index bec829e4..3c508eaf 100644 --- a/src/ui/struct/settings_object/KeyServerSO.h +++ b/src/ui/struct/settings_object/KeyServerSO.h @@ -65,6 +65,9 @@ struct KeyServerSO { } auto GetTargetServer() -> QString { + LOG_D() << "default key server index" << default_server + << "server list size" << server_list.size(); + if (server_list.empty()) this->ResetDefaultServerList(); if (default_server >= server_list.size()) default_server = 0; return server_list[default_server]; diff --git a/src/ui/thread/KeyServerImportTask.cpp b/src/ui/thread/KeyServerImportTask.cpp index 0abeb944..4a1b0e13 100644 --- a/src/ui/thread/KeyServerImportTask.cpp +++ b/src/ui/thread/KeyServerImportTask.cpp @@ -42,7 +42,7 @@ GpgFrontend::UI::KeyServerImportTask::KeyServerImportTask( HoldOnLifeCycle(true); if (keyserver_url_.isEmpty()) { - KeyServerSO key_server(SettingsObject("general_settings_state")); + KeyServerSO key_server(SettingsObject("key_server")); keyserver_url_ = key_server.GetTargetServer(); } } diff --git a/src/ui/thread/KeyServerSearchTask.cpp b/src/ui/thread/KeyServerSearchTask.cpp index 704899a4..2f7f08a7 100644 --- a/src/ui/thread/KeyServerSearchTask.cpp +++ b/src/ui/thread/KeyServerSearchTask.cpp @@ -61,6 +61,12 @@ void GpgFrontend::UI::KeyServerSearchTask::dealing_reply_from_server() { if (network_reply == QNetworkReply::NoError) { buffer = reply_->readAll(); } - emit SignalKeyServerSearchResult(network_reply, buffer); + + LOG_D() << "reply from key server:" << network_reply + << "err string:" << reply_->errorString() + << "reply:" << QString::fromLatin1(buffer); + + emit SignalKeyServerSearchResult(network_reply, reply_->errorString(), + buffer); emit SignalTaskShouldEnd(0); } diff --git a/src/ui/thread/KeyServerSearchTask.h b/src/ui/thread/KeyServerSearchTask.h index d602e537..df247761 100644 --- a/src/ui/thread/KeyServerSearchTask.h +++ b/src/ui/thread/KeyServerSearchTask.h @@ -60,7 +60,7 @@ class KeyServerSearchTask : public Thread::Task { * @param result */ void SignalKeyServerSearchResult(QNetworkReply::NetworkError reply, - QByteArray buffer); + QString err_string, QByteArray buffer); private slots: diff --git a/src/ui/widgets/KeyList.cpp b/src/ui/widgets/KeyList.cpp index c4a05edc..a9363e19 100644 --- a/src/ui/widgets/KeyList.cpp +++ b/src/ui/widgets/KeyList.cpp @@ -117,7 +117,7 @@ void KeyList::init() { : global_column_filter_ & ~GpgKeyTableColumn::kCREATE_DATE); }); - subkeys_number_column_action_ = new QAction("Subkey(s)", this); + subkeys_number_column_action_ = new QAction(tr("Subkey(s)"), this); subkeys_number_column_action_->setCheckable(true); subkeys_number_column_action_->setChecked( (global_column_filter_ & GpgKeyTableColumn::kSUBKEYS_NUMBER) != @@ -131,7 +131,7 @@ void KeyList::init() { : global_column_filter_ & ~GpgKeyTableColumn::kSUBKEYS_NUMBER); }); - comment_column_action_ = new QAction("Comment", this); + comment_column_action_ = new QAction(tr("Comment"), this); comment_column_action_->setCheckable(true); comment_column_action_->setChecked( (global_column_filter_ & GpgKeyTableColumn::kCOMMENT) != |