aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorsaturneric <[email protected]>2024-01-16 17:41:52 +0000
committersaturneric <[email protected]>2024-01-16 17:41:52 +0000
commit5bcf07c5f6a3429bc787c31d26edd796c8cad9c6 (patch)
treef473d3c278b64396852403e5e334f87f02f5505a
parentfix: slove some issues and update translations (diff)
downloadGpgFrontend-5bcf07c5f6a3429bc787c31d26edd796c8cad9c6.tar.gz
GpgFrontend-5bcf07c5f6a3429bc787c31d26edd796c8cad9c6.zip
fix: solve discovered issues
-rw-r--r--src/core/GpgCoreInit.cpp6
-rw-r--r--src/core/function/DataObjectOperator.cpp2
-rw-r--r--src/core/function/GlobalSettingStation.cpp3
-rw-r--r--src/core/function/gpg/GpgAdvancedOperator.cpp176
-rw-r--r--src/core/function/gpg/GpgAdvancedOperator.h14
-rw-r--r--src/core/thread/Task.cpp5
-rw-r--r--src/ui/main_window/MainWindow.cpp9
-rw-r--r--src/ui/main_window/MainWindowUI.cpp38
-rw-r--r--ui/FilePage.ui6
9 files changed, 96 insertions, 163 deletions
diff --git a/src/core/GpgCoreInit.cpp b/src/core/GpgCoreInit.cpp
index 74e944f8..1790776e 100644
--- a/src/core/GpgCoreInit.cpp
+++ b/src/core/GpgCoreInit.cpp
@@ -235,7 +235,8 @@ void InitGpgFrontendCore(CoreInitArgs args) {
QString gnupg_install_fs_path;
// user defined
- if (!custom_gnupg_install_path.isEmpty()) {
+ if (use_custom_gnupg_install_path &&
+ !custom_gnupg_install_path.isEmpty()) {
// check gpgconf path
gnupg_install_fs_path = custom_gnupg_install_path;
#ifdef WINDOWS
@@ -265,7 +266,8 @@ void InitGpgFrontendCore(CoreInitArgs args) {
// check key database path
QString key_database_fs_path;
// user defined
- if (!custom_key_database_path.isEmpty()) {
+ if (use_custom_key_database_path &&
+ !custom_key_database_path.isEmpty()) {
key_database_fs_path = custom_key_database_path;
if (VerifyKeyDatabasePath(QFileInfo(key_database_fs_path))) {
GF_CORE_LOG_ERROR(
diff --git a/src/core/function/DataObjectOperator.cpp b/src/core/function/DataObjectOperator.cpp
index 1d4d2c4a..e1d8b4da 100644
--- a/src/core/function/DataObjectOperator.cpp
+++ b/src/core/function/DataObjectOperator.cpp
@@ -45,7 +45,7 @@ void DataObjectOperator::init_app_secure_key() {
DataObjectOperator::DataObjectOperator(int channel)
: SingletonFunctionObject<DataObjectOperator>(channel) {
- if (!QDir(app_secure_path_).exists()) QDir(app_secure_path_).mkdir(".");
+ if (!QDir(app_secure_path_).exists()) QDir(app_secure_path_).mkpath(".");
if (!QFileInfo(app_secure_key_path_).exists()) init_app_secure_key();
QByteArray key;
diff --git a/src/core/function/GlobalSettingStation.cpp b/src/core/function/GlobalSettingStation.cpp
index a25bb52c..04129186 100644
--- a/src/core/function/GlobalSettingStation.cpp
+++ b/src/core/function/GlobalSettingStation.cpp
@@ -158,8 +158,7 @@ class GlobalSettingStation::Impl {
QString working_path_ = QDir::currentPath();
QString app_data_path_ = QString{QStandardPaths::writableLocation(
- QStandardPaths::AppLocalDataLocation)} +
- "/GpgFrontend"; ///< Program Data Location
+ QStandardPaths::AppLocalDataLocation)}; ///< Program Data Location
QString app_log_path_ = app_data_path_ + "/logs"; ///< Program Data Location
diff --git a/src/core/function/gpg/GpgAdvancedOperator.cpp b/src/core/function/gpg/GpgAdvancedOperator.cpp
index ce08e03a..8b60003c 100644
--- a/src/core/function/gpg/GpgAdvancedOperator.cpp
+++ b/src/core/function/gpg/GpgAdvancedOperator.cpp
@@ -35,57 +35,47 @@
#include "core/function/gpg/GpgCommandExecutor.h"
#include "core/module/ModuleManager.h"
-auto GpgFrontend::GpgAdvancedOperator::ClearGpgPasswordCache() -> bool {
- bool success = false;
-
+void GpgFrontend::GpgAdvancedOperator::ClearGpgPasswordCache(
+ OperationCallback cb) {
const auto gpgconf_path = Module::RetrieveRTValueTypedOrDefault<>(
"core", "gpgme.ctx.gpgconf_path", QString{});
GF_CORE_LOG_DEBUG("got gpgconf path from rt: {}", gpgconf_path);
if (gpgconf_path.isEmpty()) {
GF_CORE_LOG_ERROR("cannot get valid gpgconf path from rt, abort.");
- return false;
+ cb(-1, TransferParams());
+ return;
}
GpgFrontend::GpgCommandExecutor::ExecuteSync(
{gpgconf_path,
{"--reload", "gpg-agent"},
- [&](int exit_code, const QString & /*p_out*/,
+ [=](int exit_code, const QString & /*p_out*/,
const QString & /*p_err*/) {
- if (exit_code == 0) {
- GF_CORE_LOG_DEBUG("gpgconf reload exit code: {}", exit_code);
- success = true;
- }
+ GF_CORE_LOG_DEBUG("gpgconf reload exit code: {}", exit_code);
+ cb(exit_code == 0 ? 0 : -1, TransferParams());
}});
- return success;
}
-auto GpgFrontend::GpgAdvancedOperator::ReloadGpgComponents() -> bool {
- bool success = false;
-
+void GpgFrontend::GpgAdvancedOperator::ReloadGpgComponents(
+ OperationCallback cb) {
const auto gpgconf_path = Module::RetrieveRTValueTypedOrDefault<>(
"core", "gpgme.ctx.gpgconf_path", QString{});
GF_CORE_LOG_DEBUG("got gpgconf path from rt: {}", gpgconf_path);
if (gpgconf_path.isEmpty()) {
GF_CORE_LOG_ERROR("cannot get valid gpgconf path from rt, abort.");
- return false;
+ cb(-1, TransferParams());
+ return;
}
GpgFrontend::GpgCommandExecutor::ExecuteSync(
{gpgconf_path,
{"--reload"},
- [&](int exit_code, const QString &p_out, const QString &p_err) {
- if (exit_code == 0) {
- success = true;
- } else {
- GF_CORE_LOG_ERROR(
- "gpgconf execute error, process stderr: {}, process stdout: {}",
- p_err, p_out);
- return;
- }
+ [=](int exit_code, const QString &, const QString &) {
+ GF_CORE_LOG_DEBUG("gpgconf reload exit code: {}", exit_code);
+ cb(exit_code == 0 ? 0 : -1, TransferParams());
}});
- return success;
}
void GpgFrontend::GpgAdvancedOperator::RestartGpgComponents() {
@@ -101,7 +91,7 @@ void GpgFrontend::GpgAdvancedOperator::RestartGpgComponents() {
GpgFrontend::GpgCommandExecutor::ExecuteSync(
{gpgconf_path,
{"--verbose", "--kill", "all"},
- [&](int exit_code, const QString &p_out, const QString &p_err) {
+ [=](int exit_code, const QString &p_out, const QString &p_err) {
GF_CORE_LOG_DEBUG("gpgconf --kill all command got exit code: {}",
exit_code);
bool success = true;
@@ -122,64 +112,37 @@ void GpgFrontend::GpgAdvancedOperator::RestartGpgComponents() {
return;
}
- success &= StartGpgAgent();
-
- if (!success) {
- GF_CORE_LOG_ERROR("start gpg agent after core initilized failed");
- return;
- }
-
- success &= StartDirmngr();
-
- if (!success) {
- GF_CORE_LOG_ERROR("start dirmngr after core initilized failed");
- return;
- }
-
- success &= StartKeyBoxd();
-
- if (!success) {
- GF_CORE_LOG_ERROR("start keyboxd after core initilized failed");
- return;
- }
-
- Module::UpsertRTValue(
- "core", "gpg_advanced_operator.restart_gpg_components", true);
+ StartGpgAgent([](int err, DataObjectPtr) {
+ if (err >= 0) {
+ Module::UpsertRTValue(
+ "core", "gpg_advanced_operator.restart_gpg_components", true);
+ return;
+ }
+ });
}});
}
-auto GpgFrontend::GpgAdvancedOperator::ResetConfigures() -> bool {
- bool success = false;
-
+void GpgFrontend::GpgAdvancedOperator::ResetConfigures(OperationCallback cb) {
const auto gpgconf_path = Module::RetrieveRTValueTypedOrDefault<>(
"core", "gpgme.ctx.gpgconf_path", QString{});
GF_CORE_LOG_DEBUG("got gpgconf path from rt: {}", gpgconf_path);
if (gpgconf_path.isEmpty()) {
GF_CORE_LOG_ERROR("cannot get valid gpgconf path from rt, abort.");
- return false;
+ cb(-1, TransferParams());
+ return;
}
GpgFrontend::GpgCommandExecutor::ExecuteSync(
{gpgconf_path,
{"--apply-defaults"},
- [&](int exit_code, const QString &p_out, const QString &p_err) {
- if (exit_code == 0) {
- success = true;
- } else {
- GF_CORE_LOG_ERROR(
- "gpgconf execute error, process stderr: {}, process stdout: {}",
- p_err, p_out);
- return;
- }
+ [=](int exit_code, const QString &, const QString &) {
+ GF_CORE_LOG_DEBUG("gpgconf apply-defaults exit code: {}", exit_code);
+ cb(exit_code == 0 ? 0 : -1, TransferParams());
}});
-
- return success;
}
-auto GpgFrontend::GpgAdvancedOperator::StartGpgAgent() -> bool {
- bool success = false;
-
+void GpgFrontend::GpgAdvancedOperator::StartGpgAgent(OperationCallback cb) {
const auto gpg_agent_path = Module::RetrieveRTValueTypedOrDefault<>(
"com.bktus.gpgfrontend.module.integrated.gnupg-info-gathering",
"gnupg.gpg_agent_path", QString{});
@@ -192,37 +155,20 @@ auto GpgFrontend::GpgAdvancedOperator::StartGpgAgent() -> bool {
if (gpg_agent_path.isEmpty()) {
GF_CORE_LOG_ERROR("cannot get valid gpg agent path from rt, abort.");
- return false;
+ cb(-1, TransferParams());
+ return;
}
GpgFrontend::GpgCommandExecutor::ExecuteSync(
{gpg_agent_path,
{"--homedir", home_path, "--daemon"},
- [&](int exit_code, const QString &p_out, const QString &p_err) {
- if (exit_code == 0) {
- success = true;
- GF_CORE_LOG_INFO("start gpg-agent successfully");
- return;
- }
-
- if (exit_code == 2) {
- success = true;
- GF_CORE_LOG_INFO("gpg-agent already started");
- return;
- }
-
- GF_CORE_LOG_ERROR(
- "gpg-agent execute error, "
- "process stderr: {}, process stdout: {}",
- p_err, p_out);
+ [=](int exit_code, const QString &, const QString &) {
+ GF_CORE_LOG_DEBUG("gpgconf daemon exit code: {}", exit_code);
+ cb(exit_code >= 0 ? 0 : -1, TransferParams());
}});
-
- return success;
}
-auto GpgFrontend::GpgAdvancedOperator::StartDirmngr() -> bool {
- bool success = false;
-
+void GpgFrontend::GpgAdvancedOperator::StartDirmngr(OperationCallback cb) {
const auto dirmngr_path = Module::RetrieveRTValueTypedOrDefault<>(
"com.bktus.gpgfrontend.module.integrated.gnupg-info-gathering",
"gnupg.dirmngr_path", QString{});
@@ -235,36 +181,20 @@ auto GpgFrontend::GpgAdvancedOperator::StartDirmngr() -> bool {
if (dirmngr_path.isEmpty()) {
GF_CORE_LOG_ERROR("cannot get valid dirmngr path from rt, abort.");
- return false;
+ cb(-1, TransferParams());
+ return;
}
GpgFrontend::GpgCommandExecutor::ExecuteSync(
{dirmngr_path,
{"--homedir", home_path, "--daemon"},
- [&](int exit_code, const QString &p_out, const QString &p_err) {
- if (exit_code == 0) {
- success = true;
- GF_CORE_LOG_INFO("start dirmngr successfully");
- return;
- }
-
- if (exit_code == 2) {
- success = true;
- GF_CORE_LOG_INFO("dirmngr already started");
- return;
- }
-
- GF_CORE_LOG_ERROR(
- "dirmngr execute error, process stderr: {}, process stdout: {}",
- p_err, p_out);
+ [=](int exit_code, const QString &, const QString &) {
+ GF_CORE_LOG_DEBUG("gpgconf daemon exit code: {}", exit_code);
+ cb(exit_code >= 0 ? 0 : -1, TransferParams());
}});
-
- return success;
}
-auto GpgFrontend::GpgAdvancedOperator::StartKeyBoxd() -> bool {
- auto success = false;
-
+void GpgFrontend::GpgAdvancedOperator::StartKeyBoxd(OperationCallback cb) {
const auto keyboxd_path = Module::RetrieveRTValueTypedOrDefault<>(
"com.bktus.gpgfrontend.module.integrated.gnupg-info-gathering",
"gnupg.keyboxd_path", QString{});
@@ -277,29 +207,15 @@ auto GpgFrontend::GpgAdvancedOperator::StartKeyBoxd() -> bool {
if (keyboxd_path.isEmpty()) {
GF_CORE_LOG_ERROR("cannot get valid keyboxd path from rt, abort.");
- return false;
+ cb(-1, TransferParams());
+ return;
}
GpgFrontend::GpgCommandExecutor::ExecuteSync(
{keyboxd_path,
{"--homedir", home_path, "--daemon"},
- [&](int exit_code, const QString &p_out, const QString &p_err) {
- if (exit_code == 0) {
- success = true;
- GF_CORE_LOG_INFO("start keyboxd successfully");
- return;
- }
-
- if (exit_code == 2) {
- success = true;
- GF_CORE_LOG_INFO("keyboxd already started");
- return;
- }
-
- GF_CORE_LOG_ERROR(
- "keyboxd execute error, process stderr: {}, process stdout: {}",
- p_err, p_out);
+ [=](int exit_code, const QString &, const QString &) {
+ GF_CORE_LOG_DEBUG("gpgconf daemon exit code: {}", exit_code);
+ cb(exit_code >= 0 ? 0 : -1, TransferParams());
}});
-
- return success;
}
diff --git a/src/core/function/gpg/GpgAdvancedOperator.h b/src/core/function/gpg/GpgAdvancedOperator.h
index fbd6f6ef..4f6ba8bb 100644
--- a/src/core/function/gpg/GpgAdvancedOperator.h
+++ b/src/core/function/gpg/GpgAdvancedOperator.h
@@ -32,6 +32,8 @@
#pragma once
+#include "core/typedef/CoreTypedef.h"
+
namespace GpgFrontend {
class GPGFRONTEND_CORE_EXPORT GpgAdvancedOperator {
@@ -42,7 +44,7 @@ class GPGFRONTEND_CORE_EXPORT GpgAdvancedOperator {
* @return true
* @return false
*/
- static auto ClearGpgPasswordCache() -> bool;
+ static void ClearGpgPasswordCache(OperationCallback);
/**
* @brief
@@ -50,7 +52,7 @@ class GPGFRONTEND_CORE_EXPORT GpgAdvancedOperator {
* @return true
* @return false
*/
- static auto ReloadGpgComponents() -> bool;
+ static void ReloadGpgComponents(OperationCallback cb);
/**
* @brief
@@ -66,7 +68,7 @@ class GPGFRONTEND_CORE_EXPORT GpgAdvancedOperator {
* @return true
* @return false
*/
- static auto ResetConfigures() -> bool;
+ static void ResetConfigures(OperationCallback cb);
/**
* @brief
@@ -74,7 +76,7 @@ class GPGFRONTEND_CORE_EXPORT GpgAdvancedOperator {
* @return true
* @return false
*/
- static auto StartGpgAgent() -> bool;
+ static void StartGpgAgent(OperationCallback cb);
/**
* @brief
@@ -82,7 +84,7 @@ class GPGFRONTEND_CORE_EXPORT GpgAdvancedOperator {
* @return true
* @return false
*/
- static auto StartDirmngr() -> bool;
+ static void StartDirmngr(OperationCallback cb);
/**
* @brief
@@ -90,7 +92,7 @@ class GPGFRONTEND_CORE_EXPORT GpgAdvancedOperator {
* @return true
* @return false
*/
- static auto StartKeyBoxd() -> bool;
+ static void StartKeyBoxd(OperationCallback cb);
};
} // namespace GpgFrontend
diff --git a/src/core/thread/Task.cpp b/src/core/thread/Task.cpp
index 249d898f..1d251520 100644
--- a/src/core/thread/Task.cpp
+++ b/src/core/thread/Task.cpp
@@ -146,8 +146,11 @@ class Task::Impl {
//
connect(parent_, &Task::SignalRun, parent_, &Task::slot_exception_safe_run);
+ auto *callback_thread = callback_thread_ != nullptr
+ ? callback_thread_
+ : QCoreApplication::instance()->thread();
//
- connect(parent_, &Task::SignalTaskShouldEnd, QThread::currentThread(),
+ connect(parent_, &Task::SignalTaskShouldEnd, callback_thread,
[this](int rtn) {
// set task returning code
SetRTN(rtn);
diff --git a/src/ui/main_window/MainWindow.cpp b/src/ui/main_window/MainWindow.cpp
index 31d53bd1..7f75574e 100644
--- a/src/ui/main_window/MainWindow.cpp
+++ b/src/ui/main_window/MainWindow.cpp
@@ -131,11 +131,10 @@ void MainWindow::Init() noexcept {
.GetSettings()
.value("basic/clear_gpg_password_cache", false)
.toBool()) {
- if (GpgFrontend::GpgAdvancedOperator::ClearGpgPasswordCache()) {
- GF_UI_LOG_DEBUG("clear gpg password cache done");
- } else {
- GF_UI_LOG_ERROR("clear gpg password cache error");
- }
+ GpgFrontend::GpgAdvancedOperator::ClearGpgPasswordCache(
+ [](int, DataObjectPtr) {
+
+ });
}
});
diff --git a/src/ui/main_window/MainWindowUI.cpp b/src/ui/main_window/MainWindowUI.cpp
index f62f6d9f..39ef9aed 100644
--- a/src/ui/main_window/MainWindowUI.cpp
+++ b/src/ui/main_window/MainWindowUI.cpp
@@ -347,28 +347,34 @@ void MainWindow::create_actions() {
clean_gpg_password_cache_act_->setToolTip(
tr("Clear Password Cache of GnuPG"));
connect(clean_gpg_password_cache_act_, &QAction::triggered, this, [=]() {
- if (GpgFrontend::GpgAdvancedOperator::ClearGpgPasswordCache()) {
- QMessageBox::information(this, tr("Successful Operation"),
- tr("Clear password cache successfully"));
- } else {
- QMessageBox::critical(this, tr("Failed Operation"),
- tr("Failed to clear password cache of GnuPG"));
- }
+ GpgFrontend::GpgAdvancedOperator::ClearGpgPasswordCache([=](int err,
+ DataObjectPtr) {
+ if (err >= 0) {
+ QMessageBox::information(this, tr("Successful Operation"),
+ tr("Clear password cache successfully"));
+ } else {
+ QMessageBox::critical(this, tr("Failed Operation"),
+ tr("Failed to clear password cache of GnuPG"));
+ }
+ });
});
reload_components_act_ = new QAction(tr("Reload All Components"), this);
reload_components_act_->setIcon(QIcon(":/icons/configure.png"));
reload_components_act_->setToolTip(tr("Reload All GnuPG's Components"));
connect(reload_components_act_, &QAction::triggered, this, [=]() {
- if (GpgFrontend::GpgAdvancedOperator::ReloadGpgComponents()) {
- QMessageBox::information(
- this, tr("Successful Operation"),
- tr("Reload all the GnuPG's components successfully"));
- } else {
- QMessageBox::critical(
- this, tr("Failed Operation"),
- tr("Failed to reload all or one of the GnuPG's component(s)"));
- }
+ GpgFrontend::GpgAdvancedOperator::ReloadGpgComponents(
+ [=](int err, DataObjectPtr) {
+ if (err >= 0) {
+ QMessageBox::information(
+ this, tr("Successful Operation"),
+ tr("Reload all the GnuPG's components successfully"));
+ } else {
+ QMessageBox::critical(
+ this, tr("Failed Operation"),
+ tr("Failed to reload all or one of the GnuPG's component(s)"));
+ }
+ });
});
restart_components_act_ = new QAction(tr("Restart All Components"), this);
diff --git a/ui/FilePage.ui b/ui/FilePage.ui
index 70028e16..5ee3058e 100644
--- a/ui/FilePage.ui
+++ b/ui/FilePage.ui
@@ -62,9 +62,15 @@
<property name="leftMargin">
<number>5</number>
</property>
+ <property name="topMargin">
+ <number>5</number>
+ </property>
<property name="rightMargin">
<number>5</number>
</property>
+ <property name="bottomMargin">
+ <number>5</number>
+ </property>
<item>
<widget class="QToolButton" name="newDirButton">
<property name="sizePolicy">