aboutsummaryrefslogtreecommitdiffstats
path: root/src/ui
diff options
context:
space:
mode:
authorSaturn&Eric <[email protected]>2023-03-31 21:27:08 +0000
committerGitHub <[email protected]>2023-03-31 21:27:08 +0000
commit3cb863592a548edc074dde045493e0f83e5d694a (patch)
tree242534c257e723f49080428db22118c75706e233 /src/ui
parentMerge pull request #91 from saturneric/dev/2.0.10/main (diff)
parentfeat: add project security document (diff)
downloadGpgFrontend-2.1.0.tar.gz
GpgFrontend-2.1.0.zip
Merge pull request #93 from saturneric/dev/2.0.10/mainv2.1.0
Develop 2.1.0.2
Diffstat (limited to 'src/ui')
-rw-r--r--src/ui/GpgFrontendApplication.cpp2
-rw-r--r--src/ui/GpgFrontendUIInit.cpp61
-rw-r--r--src/ui/UserInterfaceUtils.cpp52
-rw-r--r--src/ui/dialog/GeneralDialog.cpp104
-rw-r--r--src/ui/dialog/details/VerifyDetailsDialog.h1
-rw-r--r--src/ui/dialog/help/AboutDialog.cpp11
-rw-r--r--src/ui/dialog/help/AboutDialog.h1
-rw-r--r--src/ui/dialog/help/GnupgTab.cpp7
-rw-r--r--src/ui/dialog/import_export/KeyImportDetailDialog.cpp41
-rw-r--r--src/ui/dialog/import_export/KeyServerImportDialog.cpp21
-rw-r--r--src/ui/dialog/key_generate/KeygenDialog.cpp29
-rw-r--r--src/ui/dialog/key_generate/KeygenDialog.h1
-rw-r--r--src/ui/dialog/key_generate/SubkeyGenerateDialog.cpp27
-rw-r--r--src/ui/dialog/key_generate/SubkeyGenerateDialog.h1
-rw-r--r--src/ui/dialog/keypair_details/KeyPairOperaTab.cpp32
-rw-r--r--src/ui/dialog/keypair_details/KeyPairSubkeyTab.cpp2
-rw-r--r--src/ui/dialog/keypair_details/KeySetExpireDateDialog.cpp2
-rw-r--r--src/ui/dialog/settings/SettingsGeneral.cpp29
-rw-r--r--src/ui/dialog/settings/SettingsKeyServer.cpp5
-rw-r--r--src/ui/dialog/settings/SettingsNetwork.cpp133
-rw-r--r--src/ui/main_window/KeyMgmt.cpp63
-rw-r--r--src/ui/main_window/MainWindow.cpp6
-rw-r--r--src/ui/main_window/MainWindow.h37
-rw-r--r--src/ui/main_window/MainWindowSlotFunction.cpp108
-rw-r--r--src/ui/main_window/MainWindowUI.cpp60
-rw-r--r--src/ui/thread/ProxyConnectionTestTask.cpp74
-rw-r--r--src/ui/thread/ProxyConnectionTestTask.h (renamed from src/ui/thread/ProxyConnectionTestThread.h)16
-rw-r--r--src/ui/thread/ProxyConnectionTestThread.cpp58
-rw-r--r--src/ui/widgets/TextEdit.cpp2
-rw-r--r--src/ui/widgets/VerifyKeyDetailBox.cpp20
30 files changed, 739 insertions, 267 deletions
diff --git a/src/ui/GpgFrontendApplication.cpp b/src/ui/GpgFrontendApplication.cpp
index 1b2bb9ad..3697adde 100644
--- a/src/ui/GpgFrontendApplication.cpp
+++ b/src/ui/GpgFrontendApplication.cpp
@@ -59,9 +59,11 @@ GpgFrontendApplication *GpgFrontendApplication::GetInstance(int argc,
if (new_instance || !instance) {
if (instance != nullptr) {
+ SPDLOG_DEBUG("old application exists, quitting...");
instance->quit();
delete instance;
}
+ SPDLOG_DEBUG("creating new application instance, argc: {}", argc);
instance = new GpgFrontendApplication(static_argc, static_argv);
}
return instance;
diff --git a/src/ui/GpgFrontendUIInit.cpp b/src/ui/GpgFrontendUIInit.cpp
index 6e41f81f..b90493a5 100644
--- a/src/ui/GpgFrontendUIInit.cpp
+++ b/src/ui/GpgFrontendUIInit.cpp
@@ -71,6 +71,63 @@ void InitGpgFrontendUI(QApplication* app) {
// init common utils
CommonUtils::GetInstance();
+ // application proxy configure
+
+ auto& settings = GlobalSettingStation::GetInstance().GetUISettings();
+ bool proxy_enable = false;
+ try {
+ proxy_enable = settings.lookup("proxy.enable");
+ } catch (...) {
+ SPDLOG_ERROR("setting operation error: proxy_enable");
+ }
+ SPDLOG_DEBUG("loading proxy configure, proxy_enable: {}", proxy_enable);
+
+ // if enable proxy for application
+ if (proxy_enable) {
+ try {
+ std::string proxy_type = settings.lookup("proxy.proxy_type");
+ std::string proxy_host = settings.lookup("proxy.proxy_host");
+ int proxy_port = settings.lookup("proxy.port");
+ std::string proxy_username = settings.lookup("proxy.username");
+ std::string proxy_password = settings.lookup("proxy.password");
+
+ SPDLOG_DEBUG("proxy settings: type {}, host {}, port: {}", proxy_type,
+ proxy_host, proxy_port);
+
+ QNetworkProxy::ProxyType proxy_type_qt = QNetworkProxy::NoProxy;
+ if (proxy_type == "HTTP") {
+ proxy_type_qt = QNetworkProxy::HttpProxy;
+ } else if (proxy_type == "Socks5") {
+ proxy_type_qt = QNetworkProxy::Socks5Proxy;
+ } else {
+ proxy_type_qt = QNetworkProxy::DefaultProxy;
+ }
+
+ // create proxy object and apply settings
+ QNetworkProxy proxy;
+ if (proxy_type_qt != QNetworkProxy::DefaultProxy) {
+ proxy.setType(proxy_type_qt);
+ proxy.setHostName(QString::fromStdString(proxy_host));
+ proxy.setPort(proxy_port);
+ if (!proxy_username.empty())
+ proxy.setUser(QString::fromStdString(proxy_username));
+ if (!proxy_password.empty())
+ proxy.setPassword(QString::fromStdString(proxy_password));
+ } else {
+ proxy.setType(proxy_type_qt);
+ }
+ QNetworkProxy::setApplicationProxy(proxy);
+
+ } catch (...) {
+ SPDLOG_ERROR("setting operation error: proxy setings");
+ // no proxy by default
+ QNetworkProxy::setApplicationProxy(QNetworkProxy::NoProxy);
+ }
+ } else {
+ // no proxy by default
+ QNetworkProxy::setApplicationProxy(QNetworkProxy::NoProxy);
+ }
+
// create the thread to load the gpg context
auto* init_ctx_task = new Thread::CtxCheckTask();
@@ -213,7 +270,7 @@ void init_locale() {
#ifndef WINDOWS
if (!lang.empty()) {
- std::string lc = lang.empty() ? "" : lang + ".UTF-8";
+ std::string lc = lang + ".UTF-8";
// set LC_ALL
auto* locale_name = setlocale(LC_ALL, lc.c_str());
@@ -229,7 +286,7 @@ void init_locale() {
}
#else
if (!lang.empty()) {
- std::string lc = lang.empty() ? "" : lang;
+ std::string lc = lang;
// set LC_ALL
auto* locale_name = setlocale(LC_ALL, lc.c_str());
diff --git a/src/ui/UserInterfaceUtils.cpp b/src/ui/UserInterfaceUtils.cpp
index f944e037..5a11e119 100644
--- a/src/ui/UserInterfaceUtils.cpp
+++ b/src/ui/UserInterfaceUtils.cpp
@@ -299,38 +299,36 @@ void CommonUtils::SlotExecuteGpgCommand(
void CommonUtils::SlotImportKeyFromKeyServer(
const KeyIdArgsList &key_ids, const ImportCallbackFunctiopn &callback) {
+ // target key server that we need to import key from it
std::string target_keyserver;
- if (target_keyserver.empty()) {
- try {
- auto &settings = GlobalSettingStation::GetInstance().GetUISettings();
- SettingsObject key_server_json("key_server");
+ try {
+ auto &settings = GlobalSettingStation::GetInstance().GetUISettings();
+ SettingsObject key_server_json("key_server");
- // get key servers from settings
- const auto key_server_list =
- key_server_json.Check("server_list", nlohmann::json::array());
- if (key_server_list.empty()) {
- throw std::runtime_error("No key server configured");
- }
+ // get key servers from settings
+ const auto key_server_list =
+ key_server_json.Check("server_list", nlohmann::json::array());
+ if (key_server_list.empty()) {
+ throw std::runtime_error("No key server configured");
+ }
- const int target_key_server_index =
- key_server_json.Check("default_server", 0);
- if (target_key_server_index >= key_server_list.size()) {
- throw std::runtime_error("default_server index out of range");
- }
- target_keyserver =
- key_server_list[target_key_server_index].get<std::string>();
-
- SPDLOG_DEBUG("set target key server to default Key Server: {}",
- target_keyserver);
- } catch (...) {
- SPDLOG_ERROR(_("Cannot read default_keyserver From Settings"));
- QMessageBox::critical(
- nullptr, _("Default Keyserver Not Found"),
- _("Cannot read default keyserver from your settings, "
- "please set a default keyserver first"));
- return;
+ const int target_key_server_index =
+ key_server_json.Check("default_server", 0);
+ if (target_key_server_index >= key_server_list.size()) {
+ throw std::runtime_error("default_server index out of range");
}
+ target_keyserver =
+ key_server_list[target_key_server_index].get<std::string>();
+
+ SPDLOG_DEBUG("set target key server to default Key Server: {}",
+ target_keyserver);
+ } catch (...) {
+ SPDLOG_ERROR(_("Cannot read default_keyserver From Settings"));
+ QMessageBox::critical(nullptr, _("Default Keyserver Not Found"),
+ _("Cannot read default keyserver from your settings, "
+ "please set a default keyserver first"));
+ return;
}
auto thread = QThread::create([target_keyserver, key_ids, callback]() {
diff --git a/src/ui/dialog/GeneralDialog.cpp b/src/ui/dialog/GeneralDialog.cpp
index 9367aa44..90c56b8a 100644
--- a/src/ui/dialog/GeneralDialog.cpp
+++ b/src/ui/dialog/GeneralDialog.cpp
@@ -57,53 +57,17 @@ void GpgFrontend::UI::GeneralDialog::slot_restore_settings() noexcept {
size_ = {width, height};
- if (this->parent() != nullptr) {
- QPoint parent_pos = {0, 0};
- QSize parent_size = {0, 0};
-
- auto *parent_widget = qobject_cast<QWidget *>(this->parent());
- if (parent_widget != nullptr) {
- parent_pos = parent_widget->pos();
- parent_size = parent_widget->size();
- }
-
- auto *parent_dialog = qobject_cast<QDialog *>(this->parent());
- if (parent_dialog != nullptr) {
- parent_pos = parent_dialog->pos();
- parent_size = parent_dialog->size();
- }
-
- auto *parent_window = qobject_cast<QMainWindow *>(this->parent());
- if (parent_window != nullptr) {
- parent_pos = parent_window->pos();
- parent_size = parent_window->size();
- }
-
- SPDLOG_DEBUG("parent pos x: {} y: {}", parent_pos.x(), parent_pos.y());
-
- SPDLOG_DEBUG("parent size width: {} height: {}", parent_size.width(),
- parent_size.height());
-
- SPDLOG_DEBUG("this dialog size width: {} height: {}", size_.width(),
- size_.height());
-
- if (parent_pos != QPoint{0, 0}) {
- QPoint parent_center{parent_pos.x() + parent_size.width() / 2,
- parent_pos.y() + parent_size.height() / 2};
-
- pos_ = {parent_center.x() - size_.width() / 2,
- parent_center.y() - size_.height() / 2};
-
- // record parent_pos_
- this->parent_pos_ = parent_pos;
- this->parent_size_ = parent_size;
- }
+ // check for valid
+ if (!pos_.isNull() && pos_.x() > 50 && pos_.y() > 50 && size_.isValid()) {
+ this->move(pos_);
+ this->resize(size_);
+ return;
}
-
- this->move(pos_);
- this->resize(size_);
}
+ // default action
+ movePosition2CenterOfParent();
+
} catch (...) {
SPDLOG_ERROR(name_, "error");
}
@@ -148,8 +112,56 @@ void GpgFrontend::UI::GeneralDialog::setPosCenterOfScreen() {
*
*/
void GpgFrontend::UI::GeneralDialog::movePosition2CenterOfParent() {
- SPDLOG_DEBUG("parent pos x: {} y: {}", parent_pos_.x(), parent_pos_.y());
+ // read pos and size from parent
+ if (this->parent() != nullptr) {
+ QPoint parent_pos = {0, 0};
+ QSize parent_size = {0, 0};
+
+ auto *parent_widget = qobject_cast<QWidget *>(this->parent());
+ if (parent_widget != nullptr) {
+ parent_pos = parent_widget->pos();
+ parent_size = parent_widget->size();
+ }
+
+ auto *parent_dialog = qobject_cast<QDialog *>(this->parent());
+ if (parent_dialog != nullptr) {
+ parent_pos = parent_dialog->pos();
+ parent_size = parent_dialog->size();
+ }
+
+ auto *parent_window = qobject_cast<QMainWindow *>(this->parent());
+ if (parent_window != nullptr) {
+ parent_pos = parent_window->pos();
+ parent_size = parent_window->size();
+ }
+
+ SPDLOG_DEBUG("parent pos x: {} y: {}", parent_pos.x(), parent_pos.y());
+ SPDLOG_DEBUG("parent size width: {} height: {}", parent_size.width(),
+ parent_size.height());
+
+ SPDLOG_DEBUG("this dialog size width: {} height: {}", size_.width(),
+ size_.height());
+
+ if (parent_pos != QPoint{0, 0}) {
+ QPoint parent_center{parent_pos.x() + parent_size.width() / 2,
+ parent_pos.y() + parent_size.height() / 2};
+
+ pos_ = {parent_center.x() - size_.width() / 2,
+ parent_center.y() - size_.height() / 2};
+
+ // record parent_pos_
+ this->parent_pos_ = parent_pos;
+ this->parent_size_ = parent_size;
+ }
+ } else {
+ // reset parent's pos and size
+ this->parent_pos_ = QPoint{0, 0};
+ this->parent_size_ = QSize{0, 0};
+ }
+
+ // log for debug
+ SPDLOG_DEBUG("parent pos x: {} y: {}", parent_pos_.x(), parent_pos_.y());
SPDLOG_DEBUG("parent size width: {}", parent_size_.width(),
"height:", parent_size_.height());
@@ -164,5 +176,7 @@ void GpgFrontend::UI::GeneralDialog::movePosition2CenterOfParent() {
pos_ = {parent_center.x() - size_.width() / 2,
parent_center.y() - size_.height() / 2};
this->move(pos_);
+ } else {
+ setPosCenterOfScreen();
}
} \ No newline at end of file
diff --git a/src/ui/dialog/details/VerifyDetailsDialog.h b/src/ui/dialog/details/VerifyDetailsDialog.h
index 97e2cc2d..5bc09884 100644
--- a/src/ui/dialog/details/VerifyDetailsDialog.h
+++ b/src/ui/dialog/details/VerifyDetailsDialog.h
@@ -60,7 +60,6 @@ class VerifyDetailsDialog : public QDialog {
void slot_refresh();
private:
- KeyList* key_list_; ///<
QHBoxLayout* main_layout_; ///<
QWidget* m_vbox_{}; ///<
QByteArray* input_data_{}; ///<
diff --git a/src/ui/dialog/help/AboutDialog.cpp b/src/ui/dialog/help/AboutDialog.cpp
index 3cf6c2a2..faf2b316 100644
--- a/src/ui/dialog/help/AboutDialog.cpp
+++ b/src/ui/dialog/help/AboutDialog.cpp
@@ -28,6 +28,8 @@
#include "AboutDialog.h"
+#include <openssl/opensslv.h>
+
#include "GpgFrontendBuildInfo.h"
#include "core/function/GlobalSettingStation.h"
#include "core/thread/TaskRunnerGetter.h"
@@ -83,9 +85,9 @@ InfoTab::InfoTab(QWidget* parent) : QWidget(parent) {
"<center><b>" + qApp->applicationVersion() + "</b></center>" +
"<center>" + GIT_VERSION + "</center>" + "<br><center>" +
_("GpgFrontend is an easy-to-use, compact, cross-platform, "
- "and installation-free gpg front-end tool."
- "It visualizes most of the common operations of gpg commands."
- "It's licensed under the GPL v3") +
+ "and installation-free GnuPG Frontend."
+ "It visualizes most of the common operations of GnuPG."
+ "GpgFrontend is licensed under the GPLv3") +
"<br><br>"
"<b>" +
_("Developer:") + "</b><br>" + "Saturneric" + "<br><br>" +
@@ -94,7 +96,8 @@ InfoTab::InfoTab(QWidget* parent) : QWidget(parent) {
" <a href=\"https://github.com/saturneric/GpgFrontend\">GitHub</a> " +
_("or send a mail to my mailing list at") + " <a " +
"href=\"mailto:[email protected]\">[email protected]</a>." + "<br><br> " +
- _("Built with Qt") + " " + qVersion() + " " + _("and GPGME") + " " +
+ _("Built with Qt") + " " + qVersion() + ", " + OPENSSL_VERSION_TEXT +
+ " " + _("and") + " " + "GPGME" + " " +
GpgFrontend::GpgContext::GetInstance()
.GetInfo(false)
.GpgMEVersion.c_str() +
diff --git a/src/ui/dialog/help/AboutDialog.h b/src/ui/dialog/help/AboutDialog.h
index 09a63734..6d7ce265 100644
--- a/src/ui/dialog/help/AboutDialog.h
+++ b/src/ui/dialog/help/AboutDialog.h
@@ -80,7 +80,6 @@ class UpdateTab : public QWidget {
QLabel* upgrade_label_; ///<
QProgressBar* pb_; ///<
QString current_version_; ///<
- QPushButton* download_button_; ///<
public:
/**
diff --git a/src/ui/dialog/help/GnupgTab.cpp b/src/ui/dialog/help/GnupgTab.cpp
index 2758cbe1..996d4ad9 100644
--- a/src/ui/dialog/help/GnupgTab.cpp
+++ b/src/ui/dialog/help/GnupgTab.cpp
@@ -42,7 +42,10 @@ GpgFrontend::UI::GnupgTab::GnupgTab(QWidget* parent)
QStringList components_column_titles;
components_column_titles << _("Name") << _("Description") << _("Version")
- << _("Checksum") << _("Path");
+ << _("Checksum") << _("Binary Path");
+
+ ui_->tabWidget->setTabText(0, _("Components"));
+ ui_->tabWidget->setTabText(1, _("Configurations"));
ui_->componentDetailsTable->setColumnCount(components_column_titles.length());
ui_->componentDetailsTable->setHorizontalHeaderLabels(
@@ -52,7 +55,7 @@ GpgFrontend::UI::GnupgTab::GnupgTab(QWidget* parent)
QAbstractItemView::SelectRows);
QStringList configurations_column_titles;
- configurations_column_titles << _("Name") << _("Path");
+ configurations_column_titles << _("Key") << _("Value");
ui_->configurationDetailsTable->setColumnCount(
configurations_column_titles.length());
diff --git a/src/ui/dialog/import_export/KeyImportDetailDialog.cpp b/src/ui/dialog/import_export/KeyImportDetailDialog.cpp
index e9b1af93..32ae63fa 100644
--- a/src/ui/dialog/import_export/KeyImportDetailDialog.cpp
+++ b/src/ui/dialog/import_export/KeyImportDetailDialog.cpp
@@ -124,7 +124,6 @@ void KeyImportDetailDialog::create_general_info_box() {
new QLabel(QString(_("Private Unchanged")) + ": "), row, 0);
generalInfoBoxLayout->addWidget(
new QLabel(QString::number(m_result_.secret_unchanged)), row, 1);
- row++;
}
}
@@ -162,36 +161,36 @@ void KeyImportDetailDialog::create_keys_table() {
keys_table_->resizeColumnsToContents();
}
-QString KeyImportDetailDialog::get_status_string(int keyStatus) {
- QString statusString;
+QString KeyImportDetailDialog::get_status_string(int key_status) {
+ QString status_string;
// keystatus is greater than 15, if key is private
- if (keyStatus > 15) {
- statusString.append(_("Private"));
- keyStatus = keyStatus - 16;
+ if (key_status > 15) {
+ status_string.append(_("Private"));
+ key_status = key_status - 16;
} else {
- statusString.append(_("Public"));
+ status_string.append(_("Public"));
}
- if (keyStatus == 0) {
- statusString.append(", " + QString(_("Unchanged")));
+ if (key_status == 0) {
+ status_string.append(", " + QString(_("Unchanged")));
} else {
- if (keyStatus == 1) {
- statusString.append(", " + QString(_("New Key")));
+ if (key_status == 1) {
+ status_string.append(", " + QString(_("New Key")));
} else {
- if (keyStatus > 7) {
- statusString.append(", " + QString(_("New Subkey")));
- keyStatus = keyStatus - 8;
+ if (key_status > 7) {
+ status_string.append(", " + QString(_("New Subkey")));
+ return status_string;
}
- if (keyStatus > 3) {
- statusString.append(", " + QString(_("New Signature")));
- keyStatus = keyStatus - 4;
+ if (key_status > 3) {
+ status_string.append(", " + QString(_("New Signature")));
+ return status_string;
}
- if (keyStatus > 1) {
- statusString.append(", " + QString(_("New UID")));
- keyStatus = keyStatus - 2;
+ if (key_status > 1) {
+ status_string.append(", " + QString(_("New UID")));
+ return status_string;
}
}
}
- return statusString;
+ return status_string;
}
void KeyImportDetailDialog::create_button_box() {
diff --git a/src/ui/dialog/import_export/KeyServerImportDialog.cpp b/src/ui/dialog/import_export/KeyServerImportDialog.cpp
index 713c5a58..5692f607 100644
--- a/src/ui/dialog/import_export/KeyServerImportDialog.cpp
+++ b/src/ui/dialog/import_export/KeyServerImportDialog.cpp
@@ -47,6 +47,23 @@ KeyServerImportDialog::KeyServerImportDialog(bool automatic, QWidget* parent)
// Layout for messagebox
auto* message_layout = new QHBoxLayout();
+ // get settings
+ auto& settings = GlobalSettingStation::GetInstance().GetUISettings();
+ // read settings
+ bool forbid_all_gnupg_connection = false;
+ try {
+ forbid_all_gnupg_connection =
+ settings.lookup("network.forbid_all_gnupg_connection");
+ } catch (...) {
+ SPDLOG_ERROR("setting operation error: forbid_all_gnupg_connection");
+ }
+
+ if (forbid_all_gnupg_connection) {
+ QMessageBox::critical(this, "Forbidden", "GnuPG is in offline mode now.");
+ this->close();
+ this->deleteLater();
+ }
+
if (automatic) {
setWindowFlags(Qt::Window | Qt::WindowTitleHint | Qt::CustomizeWindowHint);
} else {
@@ -249,6 +266,10 @@ void KeyServerImportDialog::slot_search() {
Thread::TaskRunnerGetter::GetInstance()
.GetTaskRunner(Thread::TaskRunnerGetter::kTaskRunnerType_Network)
->PostTask(task);
+
+ QEventLoop loop;
+ connect(task, &Thread::Task::SignalTaskEnd, &loop, &QEventLoop::quit);
+ loop.exec();
}
void KeyServerImportDialog::slot_search_finished(
diff --git a/src/ui/dialog/key_generate/KeygenDialog.cpp b/src/ui/dialog/key_generate/KeygenDialog.cpp
index d6f61215..ea874ed2 100644
--- a/src/ui/dialog/key_generate/KeygenDialog.cpp
+++ b/src/ui/dialog/key_generate/KeygenDialog.cpp
@@ -28,6 +28,8 @@
#include "KeygenDialog.h"
+#include <qobject.h>
+
#include "core/common/CoreCommonUtil.h"
#include "core/function/GlobalSettingStation.h"
#include "core/function/gpg/GpgKeyOpera.h"
@@ -53,6 +55,16 @@ KeyGenDialog::KeyGenDialog(QWidget* parent)
SPDLOG_ERROR("setting operation error: longer_expiration_date");
}
+ bool use_pinentry_as_password_input_dialog = false;
+ try {
+ use_pinentry_as_password_input_dialog =
+ settings.lookup("general.use_pinentry_as_password_input_dialog");
+ } catch (...) {
+ SPDLOG_ERROR(
+ "setting operation error: use_pinentry_as_password_input_dialog");
+ }
+ use_pinentry_ = use_pinentry_as_password_input_dialog;
+
max_date_time_ = longer_expiration_date
? QDateTime::currentDateTime().toLocalTime().addYears(30)
: QDateTime::currentDateTime().toLocalTime().addYears(2);
@@ -111,7 +123,8 @@ void KeyGenDialog::slot_key_gen_accept() {
error_stream << " " << _("Expiration time too long.") << std::endl;
}
- if (passphrase_edit_->isEnabled() && passphrase_edit_->text().size() == 0) {
+ if (!use_pinentry_ && passphrase_edit_->isEnabled() &&
+ passphrase_edit_->text().size() == 0) {
error_stream << " " << _("Password is empty.") << std::endl;
}
@@ -139,7 +152,7 @@ void KeyGenDialog::slot_key_gen_accept() {
#endif
}
- if (!gen_key_info_->IsNoPassPhrase()) {
+ if (!use_pinentry_ && !gen_key_info_->IsNoPassPhrase()) {
CoreCommonUtil::GetInstance()->SetTempCacheValue(
"__key_passphrase", this->passphrase_edit_->text().toStdString());
}
@@ -160,14 +173,14 @@ void KeyGenDialog::slot_key_gen_accept() {
dialog->close();
- if (!gen_key_info_->IsNoPassPhrase()) {
+ if (!use_pinentry_ && !gen_key_info_->IsNoPassPhrase()) {
CoreCommonUtil::GetInstance()->ResetTempCacheValue("__key_passphrase");
}
SPDLOG_DEBUG("generate done");
if (gpgme_err_code(error) == GPG_ERR_NO_ERROR) {
- auto* msg_box = new QMessageBox((QWidget*)this->parent());
+ auto* msg_box = new QMessageBox(qobject_cast<QWidget*>(this->parent()));
msg_box->setAttribute(Qt::WA_DeleteOnClose);
msg_box->setStandardButtons(QMessageBox::Ok);
msg_box->setWindowTitle(_("Success"));
@@ -391,6 +404,7 @@ QGroupBox* KeyGenDialog::create_basic_info_group_box() {
expire_check_box_->setCheckState(Qt::Unchecked);
passphrase_edit_->setEchoMode(QLineEdit::Password);
+ passphrase_edit_->setHidden(use_pinentry_);
no_pass_phrase_check_box_ = new QCheckBox(this);
no_pass_phrase_check_box_->setCheckState(Qt::Unchecked);
@@ -404,8 +418,9 @@ QGroupBox* KeyGenDialog::create_basic_info_group_box() {
vbox1->addWidget(new QLabel(QString(_("Never Expire")) + ": "), 3, 3);
vbox1->addWidget(new QLabel(QString(_("KeySize (in Bit)")) + ": "), 4, 0);
vbox1->addWidget(new QLabel(QString(_("Key Type")) + ": "), 5, 0);
- vbox1->addWidget(new QLabel(QString(_("Password")) + ": "), 6, 0);
- vbox1->addWidget(new QLabel(QString(_("Non Pass Phrase")) + ": "), 6, 3);
+ if (!use_pinentry_)
+ vbox1->addWidget(new QLabel(QString(_("Password")) + ": "), 6, 0);
+ vbox1->addWidget(new QLabel(QString(_("Non Pass Phrase"))), 6, 3);
vbox1->addWidget(name_edit_, 0, 1, 1, 3);
vbox1->addWidget(email_edit_, 1, 1, 1, 3);
@@ -414,7 +429,7 @@ QGroupBox* KeyGenDialog::create_basic_info_group_box() {
vbox1->addWidget(expire_check_box_, 3, 2);
vbox1->addWidget(key_size_spin_box_, 4, 1);
vbox1->addWidget(key_type_combo_box_, 5, 1);
- vbox1->addWidget(passphrase_edit_, 6, 1);
+ if (!use_pinentry_) vbox1->addWidget(passphrase_edit_, 6, 1);
vbox1->addWidget(no_pass_phrase_check_box_, 6, 2);
auto basicInfoGroupBox = new QGroupBox();
diff --git a/src/ui/dialog/key_generate/KeygenDialog.h b/src/ui/dialog/key_generate/KeygenDialog.h
index a1d7f39a..31b5f9c7 100644
--- a/src/ui/dialog/key_generate/KeygenDialog.h
+++ b/src/ui/dialog/key_generate/KeygenDialog.h
@@ -103,6 +103,7 @@ class KeyGenDialog : public GeneralDialog {
///< of the Key
QDateTime max_date_time_; ///<
std::vector<QCheckBox*> key_usage_check_boxes_; ///< ENCR, SIGN, CERT, AUTH
+ bool use_pinentry_ = false;
/**
* @brief
diff --git a/src/ui/dialog/key_generate/SubkeyGenerateDialog.cpp b/src/ui/dialog/key_generate/SubkeyGenerateDialog.cpp
index 50f38413..f4263962 100644
--- a/src/ui/dialog/key_generate/SubkeyGenerateDialog.cpp
+++ b/src/ui/dialog/key_generate/SubkeyGenerateDialog.cpp
@@ -52,6 +52,16 @@ SubkeyGenerateDialog::SubkeyGenerateDialog(const KeyId& key_id, QWidget* parent)
SPDLOG_ERROR("setting operation error: longer_expiration_date");
}
+ bool use_pinentry_as_password_input_dialog = false;
+ try {
+ use_pinentry_as_password_input_dialog =
+ settings.lookup("general.use_pinentry_as_password_input_dialog");
+ } catch (...) {
+ SPDLOG_ERROR(
+ "setting operation error: use_pinentry_as_password_input_dialog");
+ }
+ use_pinentry_ = use_pinentry_as_password_input_dialog;
+
max_date_time_ = longer_expiration_date
? QDateTime::currentDateTime().toLocalTime().addYears(30)
: QDateTime::currentDateTime().toLocalTime().addYears(2);
@@ -148,20 +158,24 @@ QGroupBox* SubkeyGenerateDialog::create_basic_info_group_box() {
expire_check_box_ = new QCheckBox(this);
expire_check_box_->setCheckState(Qt::Unchecked);
+ passphrase_edit_->setEchoMode(QLineEdit::Password);
+ passphrase_edit_->setHidden(use_pinentry_);
+
auto* vbox1 = new QGridLayout;
vbox1->addWidget(new QLabel(QString(_("Key Type")) + ": "), 0, 0);
vbox1->addWidget(new QLabel(QString(_("KeySize (in Bit)")) + ": "), 1, 0);
vbox1->addWidget(new QLabel(QString(_("Expiration Date")) + ": "), 2, 0);
vbox1->addWidget(new QLabel(QString(_("Never Expire"))), 2, 3);
- vbox1->addWidget(new QLabel(QString(_("Password")) + ": "), 3, 0);
+ if (!use_pinentry_)
+ vbox1->addWidget(new QLabel(QString(_("Password")) + ": "), 3, 0);
vbox1->addWidget(new QLabel(QString(_("Non Pass Phrase"))), 3, 3);
vbox1->addWidget(key_type_combo_box_, 0, 1);
vbox1->addWidget(key_size_spin_box_, 1, 1);
vbox1->addWidget(date_edit_, 2, 1);
vbox1->addWidget(expire_check_box_, 2, 2);
- vbox1->addWidget(passphrase_edit_, 3, 1);
+ if (!use_pinentry_) vbox1->addWidget(passphrase_edit_, 3, 1);
vbox1->addWidget(no_pass_phrase_check_box_, 3, 2);
auto basicInfoGroupBox = new QGroupBox();
@@ -265,7 +279,8 @@ void SubkeyGenerateDialog::slot_key_gen_accept() {
err_stream << " " << _("Expiration time no more than 2 years.") << " ";
}
- if (passphrase_edit_->isEnabled() && passphrase_edit_->text().size() == 0) {
+ if (!use_pinentry_ && passphrase_edit_->isEnabled() &&
+ passphrase_edit_->text().size() == 0) {
err_stream << " " << _("Password is empty.") << std::endl;
}
@@ -286,7 +301,7 @@ void SubkeyGenerateDialog::slot_key_gen_accept() {
#endif
}
- if (!gen_key_info_->IsNoPassPhrase()) {
+ if (!use_pinentry_ && !gen_key_info_->IsNoPassPhrase()) {
CoreCommonUtil::GetInstance()->SetTempCacheValue(
"__key_passphrase", this->passphrase_edit_->text().toStdString());
}
@@ -307,12 +322,12 @@ void SubkeyGenerateDialog::slot_key_gen_accept() {
}
waiting_dialog->close();
- if (!gen_key_info_->IsNoPassPhrase()) {
+ if (!use_pinentry_ && !gen_key_info_->IsNoPassPhrase()) {
CoreCommonUtil::GetInstance()->ResetTempCacheValue("__key_passphrase");
}
if (check_gpg_error_2_err_code(error) == GPG_ERR_NO_ERROR) {
- auto* msg_box = new QMessageBox((QWidget*)this->parent());
+ auto* msg_box = new QMessageBox(qobject_cast<QWidget*>(this->parent()));
msg_box->setAttribute(Qt::WA_DeleteOnClose);
msg_box->setStandardButtons(QMessageBox::Ok);
msg_box->setWindowTitle(_("Success"));
diff --git a/src/ui/dialog/key_generate/SubkeyGenerateDialog.h b/src/ui/dialog/key_generate/SubkeyGenerateDialog.h
index 731bb951..2b88bd61 100644
--- a/src/ui/dialog/key_generate/SubkeyGenerateDialog.h
+++ b/src/ui/dialog/key_generate/SubkeyGenerateDialog.h
@@ -74,6 +74,7 @@ class SubkeyGenerateDialog : public GeneralDialog {
std::vector<QCheckBox*> key_usage_check_boxes_; ///< ENCR, SIGN, CERT, AUTH
QDateTime max_date_time_; ///<
+ bool use_pinentry_ = false;
/**
* @brief Create a key usage group box object
diff --git a/src/ui/dialog/keypair_details/KeyPairOperaTab.cpp b/src/ui/dialog/keypair_details/KeyPairOperaTab.cpp
index a1452033..9be77923 100644
--- a/src/ui/dialog/keypair_details/KeyPairOperaTab.cpp
+++ b/src/ui/dialog/keypair_details/KeyPairOperaTab.cpp
@@ -27,6 +27,7 @@
#include "KeyPairOperaTab.h"
#include "KeySetExpireDateDialog.h"
+#include "core/function/GlobalSettingStation.h"
#include "core/function/gpg/GpgKeyImportExporter.h"
#include "core/function/gpg/GpgKeyOpera.h"
#include "ui/SignalStation.h"
@@ -73,10 +74,23 @@ KeyPairOperaTab::KeyPairOperaTab(const std::string& key_id, QWidget* parent)
}
auto advance_h_box_layout = new QHBoxLayout();
+
+ // get settings
+ auto& settings = GlobalSettingStation::GetInstance().GetUISettings();
+ // read settings
+ bool forbid_all_gnupg_connection = false;
+ try {
+ forbid_all_gnupg_connection =
+ settings.lookup("network.forbid_all_gnupg_connection");
+ } catch (...) {
+ SPDLOG_ERROR("setting operation error: forbid_all_gnupg_connection");
+ }
+
auto* key_server_opera_button =
new QPushButton(_("Key Server Operation (Pubkey)"));
key_server_opera_button->setStyleSheet("text-align:center;");
key_server_opera_button->setMenu(key_server_opera_menu_);
+ key_server_opera_button->setDisabled(forbid_all_gnupg_connection);
advance_h_box_layout->addWidget(key_server_opera_button);
if (m_key_.IsPrivateKey() && m_key_.IsHasMasterKey()) {
@@ -147,8 +161,13 @@ void KeyPairOperaTab::slot_export_public_key() {
}
// generate a file name
+#ifndef WINDOWS
auto file_string = m_key_.GetName() + "<" + m_key_.GetEmail() + ">(" +
m_key_.GetId() + ")_pub.asc";
+#else
+ auto file_string = m_key_.GetName() + "[" + m_key_.GetEmail() + "](" +
+ m_key_.GetId() + ")_pub.asc";
+#endif
std::replace(file_string.begin(), file_string.end(), ' ', '_');
auto file_name =
@@ -193,8 +212,14 @@ void KeyPairOperaTab::slot_export_short_private_key() {
return;
}
+ // generate a file name
+#ifndef WINDOWS
auto file_string = m_key_.GetName() + "<" + m_key_.GetEmail() + ">(" +
m_key_.GetId() + ")_short_secret.asc";
+#else
+ auto file_string = m_key_.GetName() + "[" + m_key_.GetEmail() + "](" +
+ m_key_.GetId() + ")_short_secret.asc";
+#endif
std::replace(file_string.begin(), file_string.end(), ' ', '_');
auto file_name =
@@ -235,8 +260,15 @@ void KeyPairOperaTab::slot_export_private_key() {
_("An error occurred during the export operation."));
return;
}
+
+ // generate a file name
+#ifndef WINDOWS
auto file_string = m_key_.GetName() + "<" + m_key_.GetEmail() + ">(" +
m_key_.GetId() + ")_full_secret.asc";
+#else
+ auto file_string = m_key_.GetName() + "[" + m_key_.GetEmail() + "](" +
+ m_key_.GetId() + ")_full_secret.asc";
+#endif
std::replace(file_string.begin(), file_string.end(), ' ', '_');
auto file_name =
diff --git a/src/ui/dialog/keypair_details/KeyPairSubkeyTab.cpp b/src/ui/dialog/keypair_details/KeyPairSubkeyTab.cpp
index d1367541..9c243a39 100644
--- a/src/ui/dialog/keypair_details/KeyPairSubkeyTab.cpp
+++ b/src/ui/dialog/keypair_details/KeyPairSubkeyTab.cpp
@@ -312,7 +312,7 @@ void KeyPairSubkeyTab::slot_refresh_subkey_detail() {
}
fingerprint_var_label_->setText(
- QString::fromStdString(subkey.GetFingerprint()));
+ QString::fromStdString(beautify_fingerprint(subkey.GetFingerprint())));
}
void KeyPairSubkeyTab::create_subkey_opera_menu() {
diff --git a/src/ui/dialog/keypair_details/KeySetExpireDateDialog.cpp b/src/ui/dialog/keypair_details/KeySetExpireDateDialog.cpp
index d09662e1..89d2ce74 100644
--- a/src/ui/dialog/keypair_details/KeySetExpireDateDialog.cpp
+++ b/src/ui/dialog/keypair_details/KeySetExpireDateDialog.cpp
@@ -79,7 +79,7 @@ void KeySetExpireDateDialog::slot_confirm() {
auto err = GpgKeyOpera::GetInstance().SetExpire(m_key_, m_subkey_, expires);
if (check_gpg_error_2_err_code(err) == GPG_ERR_NO_ERROR) {
- auto* msg_box = new QMessageBox((QWidget*)this->parent());
+ auto* msg_box = new QMessageBox(qobject_cast<QWidget*>(this->parent()));
msg_box->setAttribute(Qt::WA_DeleteOnClose);
msg_box->setStandardButtons(QMessageBox::Ok);
msg_box->setWindowTitle(_("Success"));
diff --git a/src/ui/dialog/settings/SettingsGeneral.cpp b/src/ui/dialog/settings/SettingsGeneral.cpp
index 7e48b4e1..17d9251c 100644
--- a/src/ui/dialog/settings/SettingsGeneral.cpp
+++ b/src/ui/dialog/settings/SettingsGeneral.cpp
@@ -47,7 +47,7 @@ GeneralTab::GeneralTab(QWidget* parent)
ui_->saveCheckedKeysCheckBox->setText(
_("Save checked private keys on exit and restore them on next start."));
ui_->clearGpgPasswordCacheCheckBox->setText(
- "Clear gpg password cache when closing GpgFrontend.");
+ _("Clear gpg password cache when closing GpgFrontend."));
ui_->importConfirmationBox->setTitle(_("Operation"));
ui_->longerKeyExpirationDateCheckBox->setText(
@@ -57,6 +57,8 @@ GeneralTab::GeneralTab(QWidget* parent)
ui_->gnupgDatabaseBox->setTitle(_("GnuPG"));
ui_->asciiModeCheckBox->setText(_("No ASCII Mode"));
+ ui_->usePinentryAsPasswordInputDialogCheckBox->setText(
+ _("Use Pinentry as Password Input Dialog"));
ui_->useCustomGnuPGInstallPathCheckBox->setText(_("Use Custom GnuPG"));
ui_->useCustomGnuPGInstallPathButton->setText(_("Select GnuPG Path"));
ui_->keyDatabseUseCustomCheckBox->setText(
@@ -167,6 +169,12 @@ GeneralTab::GeneralTab(QWidget* parent)
}
});
+ connect(ui_->usePinentryAsPasswordInputDialogCheckBox,
+ &QCheckBox::stateChanged, this, [=](int state) {
+ // announce the restart
+ this->slot_gnupg_stettings_changed();
+ });
+
SetSettings();
}
@@ -260,6 +268,16 @@ void GeneralTab::SetSettings() {
SPDLOG_ERROR("setting operation error: use_custom_gnupg_install_path");
}
+ try {
+ bool use_pinentry_as_password_input_dialog =
+ settings.lookup("general.use_pinentry_as_password_input_dialog");
+ if (use_pinentry_as_password_input_dialog)
+ ui_->usePinentryAsPasswordInputDialogCheckBox->setCheckState(Qt::Checked);
+ } catch (...) {
+ SPDLOG_ERROR(
+ "setting operation error: use_pinentry_as_password_input_dialog");
+ }
+
this->slot_update_custom_gnupg_install_path_label(
ui_->useCustomGnuPGInstallPathCheckBox->checkState());
}
@@ -343,6 +361,15 @@ void GeneralTab::ApplySettings() {
general["use_custom_gnupg_install_path"] =
ui_->useCustomGnuPGInstallPathCheckBox->isChecked();
}
+
+ if (!general.exists("use_pinentry_as_password_input_dialog"))
+ general.add("use_pinentry_as_password_input_dialog",
+ libconfig::Setting::TypeBoolean) =
+ ui_->usePinentryAsPasswordInputDialogCheckBox->isChecked();
+ else {
+ general["use_pinentry_as_password_input_dialog"] =
+ ui_->usePinentryAsPasswordInputDialogCheckBox->isChecked();
+ }
}
#ifdef MULTI_LANG_SUPPORT
diff --git a/src/ui/dialog/settings/SettingsKeyServer.cpp b/src/ui/dialog/settings/SettingsKeyServer.cpp
index 8719ab9a..83bd2c80 100644
--- a/src/ui/dialog/settings/SettingsKeyServer.cpp
+++ b/src/ui/dialog/settings/SettingsKeyServer.cpp
@@ -284,6 +284,11 @@ void KeyserverTab::slot_test_listed_key_server() {
Thread::TaskRunnerGetter::GetInstance()
.GetTaskRunner(Thread::TaskRunnerGetter::kTaskRunnerType_Network)
->PostTask(task);
+
+ QEventLoop loop;
+ connect(task, &Thread::Task::SignalTaskEnd, &loop, &QEventLoop::quit);
+ connect(waiting_dialog, &QProgressDialog::canceled, &loop, &QEventLoop::quit);
+ loop.exec();
}
void KeyserverTab::contextMenuEvent(QContextMenuEvent* event) {
diff --git a/src/ui/dialog/settings/SettingsNetwork.cpp b/src/ui/dialog/settings/SettingsNetwork.cpp
index fe3d450e..0713856d 100644
--- a/src/ui/dialog/settings/SettingsNetwork.cpp
+++ b/src/ui/dialog/settings/SettingsNetwork.cpp
@@ -29,7 +29,7 @@
#include "SettingsNetwork.h"
#include "core/function/GlobalSettingStation.h"
-#include "ui/thread/ProxyConnectionTestThread.h"
+#include "ui/thread/ProxyConnectionTestTask.h"
#include "ui_NetworkSettings.h"
GpgFrontend::UI::NetworkTab::NetworkTab(QWidget *parent)
@@ -37,7 +37,28 @@ GpgFrontend::UI::NetworkTab::NetworkTab(QWidget *parent)
ui_->setupUi(this);
connect(ui_->enableProxyCheckBox, &QCheckBox::stateChanged, this,
- [=](int state) { switch_ui_enabled(state == Qt::Checked); });
+ [=](int state) {
+ switch_ui_enabled(state == Qt::Checked);
+ // when selecting no proxy option, apply it immediately
+ if (state != Qt::Checked) apply_proxy_settings();
+ });
+
+ connect(
+ ui_->autoImportMissingKeyCheckBox, &QCheckBox::stateChanged, this,
+ [=](int state) {
+ ui_->forbidALLGnuPGNetworkConnectionCheckBox->setCheckState(
+ state == Qt::Checked
+ ? Qt::Unchecked
+ : ui_->forbidALLGnuPGNetworkConnectionCheckBox->checkState());
+ });
+
+ connect(ui_->forbidALLGnuPGNetworkConnectionCheckBox,
+ &QCheckBox::stateChanged, this, [=](int state) {
+ ui_->autoImportMissingKeyCheckBox->setCheckState(
+ state == Qt::Checked
+ ? Qt::Unchecked
+ : ui_->autoImportMissingKeyCheckBox->checkState());
+ });
connect(
ui_->proxyTypeComboBox, &QComboBox::currentTextChanged, this,
@@ -47,7 +68,7 @@ GpgFrontend::UI::NetworkTab::NetworkTab(QWidget *parent)
&NetworkTab::slot_test_proxy_connection_result);
ui_->proxyGroupBox->setTitle(_("Proxy"));
- ui_->capabilityGroupBox->setTitle(_("Network Capability"));
+ ui_->capabilityGroupBox->setTitle(_("Network Ability"));
ui_->operationsGroupBox->setTitle(_("Operations"));
ui_->enableProxyCheckBox->setText(_("Enable Proxy"));
@@ -59,12 +80,18 @@ GpgFrontend::UI::NetworkTab::NetworkTab(QWidget *parent)
ui_->usernameLabel->setText(_("Username"));
ui_->passwordLabel->setText(_("Password"));
- ui_->forbidALLCheckBox->setText(_("Forbid all network connection."));
- ui_->forbidALLCheckBox->setDisabled(true);
+ ui_->checkProxyConnectionButton->setText(
+ _("Apply Proxy Settings and Check Proxy Connection"));
+ ui_->forbidALLGnuPGNetworkConnectionCheckBox->setText(
+ _("Forbid all GnuPG network connection."));
ui_->prohibitUpdateCheck->setText(
_("Prohibit checking for version updates when the program starts."));
- ui_->checkProxyConnectionButton->setText(_("Check Proxy Connection"));
+ ui_->autoImportMissingKeyCheckBox->setText(
+ _("Automatically import a missing key for signature verification."));
+ ui_->networkAbilityTipsLabel->setText(
+ _("Tips: These Option Changes take effect only after the "
+ "application restart."));
SetSettings();
}
@@ -120,21 +147,17 @@ void GpgFrontend::UI::NetworkTab::SetSettings() {
SPDLOG_ERROR("setting operation error: proxy_enable");
}
- {
- auto state = ui_->enableProxyCheckBox->checkState();
- switch_ui_enabled(state == Qt::Checked);
- }
-
- ui_->forbidALLCheckBox->setCheckState(Qt::Unchecked);
+ ui_->forbidALLGnuPGNetworkConnectionCheckBox->setCheckState(Qt::Unchecked);
try {
- bool forbid_all_connection =
- settings.lookup("network.forbid_all_connection");
- if (forbid_all_connection)
- ui_->forbidALLCheckBox->setCheckState(Qt::Checked);
+ bool forbid_all_gnupg_connection =
+ settings.lookup("network.forbid_all_gnupg_connection");
+ if (forbid_all_gnupg_connection)
+ ui_->forbidALLGnuPGNetworkConnectionCheckBox->setCheckState(Qt::Checked);
else
- ui_->forbidALLCheckBox->setCheckState(Qt::Unchecked);
+ ui_->forbidALLGnuPGNetworkConnectionCheckBox->setCheckState(
+ Qt::Unchecked);
} catch (...) {
- SPDLOG_ERROR("setting operation error: forbid_all_connection");
+ SPDLOG_ERROR("setting operation error: forbid_all_gnupg_connection");
}
ui_->prohibitUpdateCheck->setCheckState(Qt::Unchecked);
@@ -148,6 +171,21 @@ void GpgFrontend::UI::NetworkTab::SetSettings() {
} catch (...) {
SPDLOG_ERROR("setting operation error: prohibit_update_checking");
}
+
+ ui_->autoImportMissingKeyCheckBox->setCheckState(Qt::Unchecked);
+ try {
+ bool auto_import_missing_key =
+ settings.lookup("network.auto_import_missing_key");
+ if (auto_import_missing_key)
+ ui_->autoImportMissingKeyCheckBox->setCheckState(Qt::Checked);
+ else
+ ui_->autoImportMissingKeyCheckBox->setCheckState(Qt::Unchecked);
+ } catch (...) {
+ SPDLOG_ERROR("setting operation error: auto_import_missing_key");
+ }
+
+ switch_ui_enabled(ui_->enableProxyCheckBox->isChecked());
+ switch_ui_proxy_type(ui_->proxyTypeComboBox->currentText());
}
void GpgFrontend::UI::NetworkTab::ApplySettings() {
@@ -207,11 +245,13 @@ void GpgFrontend::UI::NetworkTab::ApplySettings() {
auto &network = settings["network"];
- if (!network.exists("forbid_all_connection"))
- network.add("forbid_all_connection", libconfig::Setting::TypeBoolean) =
- ui_->forbidALLCheckBox->isChecked();
+ if (!network.exists("forbid_all_gnupg_connection"))
+ network.add("forbid_all_gnupg_connection",
+ libconfig::Setting::TypeBoolean) =
+ ui_->forbidALLGnuPGNetworkConnectionCheckBox->isChecked();
else {
- network["forbid_all_connection"] = ui_->forbidALLCheckBox->isChecked();
+ network["forbid_all_gnupg_connection"] =
+ ui_->forbidALLGnuPGNetworkConnectionCheckBox->isChecked();
}
if (!network.exists("prohibit_update_checking"))
@@ -221,6 +261,14 @@ void GpgFrontend::UI::NetworkTab::ApplySettings() {
network["prohibit_update_checking"] = ui_->prohibitUpdateCheck->isChecked();
}
+ if (!network.exists("auto_import_missing_key"))
+ network.add("auto_import_missing_key", libconfig::Setting::TypeBoolean) =
+ ui_->autoImportMissingKeyCheckBox->isChecked();
+ else {
+ network["auto_import_missing_key"] =
+ ui_->autoImportMissingKeyCheckBox->isChecked();
+ }
+
apply_proxy_settings();
}
@@ -232,9 +280,9 @@ void GpgFrontend::UI::NetworkTab::slot_test_proxy_connection_result() {
tr("Server Url"), QLineEdit::Normal,
"https://", &ok);
if (ok && !url.isEmpty()) {
- auto thread = new ProxyConnectionTestThread(url, 800, this);
- connect(thread,
- &GpgFrontend::UI::ProxyConnectionTestThread::
+ auto task = new ProxyConnectionTestTask(url, 800);
+ connect(task,
+ &GpgFrontend::UI::ProxyConnectionTestTask::
SignalProxyConnectionTestResult,
this, [=](const QString &result) {
if (result == "Reachable") {
@@ -248,7 +296,6 @@ void GpgFrontend::UI::NetworkTab::slot_test_proxy_connection_result() {
"proxy server. Proxy settings may be invalid."));
}
});
- connect(thread, &QThread::finished, thread, &QThread::deleteLater);
// Waiting Dialog
auto *waiting_dialog = new QProgressDialog(this);
@@ -261,43 +308,43 @@ void GpgFrontend::UI::NetworkTab::slot_test_proxy_connection_result() {
waiting_dialog_label->setWordWrap(true);
waiting_dialog->setLabel(waiting_dialog_label);
waiting_dialog->resize(420, 120);
- connect(thread, &QThread::finished, [=]() {
- waiting_dialog->finished(0);
+ connect(task, &Thread::Task::SignalTaskEnd, [=]() {
+ waiting_dialog->close();
waiting_dialog->deleteLater();
});
- connect(waiting_dialog, &QProgressDialog::canceled, [=]() {
- SPDLOG_DEBUG("cancel clicked");
- if (thread->isRunning()) thread->terminate();
- });
// Show Waiting Dialog
waiting_dialog->show();
waiting_dialog->setFocus();
- thread->start();
+ Thread::TaskRunnerGetter::GetInstance()
+ .GetTaskRunner(Thread::TaskRunnerGetter::kTaskRunnerType_Network)
+ ->PostTask(task);
+
QEventLoop loop;
- connect(thread, &QThread::finished, &loop, &QEventLoop::quit);
+ connect(task, &Thread::Task::SignalTaskEnd, &loop, &QEventLoop::quit);
+ connect(waiting_dialog, &QProgressDialog::canceled, &loop,
+ &QEventLoop::quit);
loop.exec();
}
}
void GpgFrontend::UI::NetworkTab::apply_proxy_settings() {
// apply settings
- QNetworkProxy _proxy;
+ QNetworkProxy proxy;
if (ui_->enableProxyCheckBox->isChecked() &&
proxy_type_ != QNetworkProxy::DefaultProxy) {
- _proxy.setType(proxy_type_);
- _proxy.setHostName(ui_->proxyServerAddressEdit->text());
- _proxy.setPort(ui_->portSpin->value());
+ proxy.setType(proxy_type_);
+ proxy.setHostName(ui_->proxyServerAddressEdit->text());
+ proxy.setPort(ui_->portSpin->value());
if (!ui_->usernameEdit->text().isEmpty()) {
- _proxy.setUser(ui_->usernameEdit->text());
- _proxy.setPassword(ui_->passwordEdit->text());
+ proxy.setUser(ui_->usernameEdit->text());
+ proxy.setPassword(ui_->passwordEdit->text());
}
} else {
- _proxy.setType(proxy_type_);
+ proxy.setType(proxy_type_);
}
-
- QNetworkProxy::setApplicationProxy(_proxy);
+ QNetworkProxy::setApplicationProxy(proxy);
}
void GpgFrontend::UI::NetworkTab::switch_ui_enabled(bool enabled) {
diff --git a/src/ui/main_window/KeyMgmt.cpp b/src/ui/main_window/KeyMgmt.cpp
index 9183d9d7..949ef071 100644
--- a/src/ui/main_window/KeyMgmt.cpp
+++ b/src/ui/main_window/KeyMgmt.cpp
@@ -91,7 +91,7 @@ KeyMgmt::KeyMgmt(QWidget* parent)
setCentralWidget(key_list_);
key_list_->SetDoubleClickedAction([this](const GpgKey& key, QWidget* parent) {
- new KeyDetailsDialog(key, parent);
+ new KeyDetailsDialog(key, this);
});
key_list_->SlotRefresh();
@@ -109,8 +109,10 @@ KeyMgmt::KeyMgmt(QWidget* parent)
this->statusBar()->show();
setWindowTitle(_("KeyPair Management"));
+
key_list_->AddMenuAction(generate_subkey_act_);
key_list_->AddMenuAction(delete_selected_keys_act_);
+ key_list_->AddSeparator();
key_list_->AddMenuAction(show_key_details_act_);
connect(this, &KeyMgmt::SignalKeyStatusUpdated, SignalStation::GetInstance(),
@@ -163,11 +165,23 @@ void KeyMgmt::create_actions() {
CommonUtils::GetInstance()->SlotImportKeyFromClipboard(this);
});
+ // get settings
+ auto& settings = GlobalSettingStation::GetInstance().GetUISettings();
+ // read settings
+ bool forbid_all_gnupg_connection = false;
+ try {
+ forbid_all_gnupg_connection =
+ settings.lookup("network.forbid_all_gnupg_connection");
+ } catch (...) {
+ SPDLOG_ERROR("setting operation error: forbid_all_gnupg_connection");
+ }
+
import_key_from_key_server_act_ = new QAction(_("Keyserver"), this);
import_key_from_key_server_act_->setIcon(
QIcon(":import_key_from_server.png"));
import_key_from_key_server_act_->setToolTip(
_("Import New Key From Keyserver"));
+ import_key_from_key_server_act_->setDisabled(forbid_all_gnupg_connection);
connect(import_key_from_key_server_act_, &QAction::triggered, this, [&]() {
CommonUtils::GetInstance()->SlotImportKeyFromKeyServer(this);
});
@@ -241,35 +255,28 @@ void KeyMgmt::create_menus() {
}
void KeyMgmt::create_tool_bars() {
- QToolBar* keyToolBar = addToolBar(_("Key"));
- keyToolBar->setObjectName("keytoolbar");
+ QToolBar* key_tool_bar = addToolBar(_("Key"));
+ key_tool_bar->setObjectName("keytoolbar");
- // add button with popup menu for import
- auto* generateToolButton = new QToolButton(this);
- generateToolButton->setMenu(generate_key_menu_);
- generateToolButton->setPopupMode(QToolButton::InstantPopup);
- generateToolButton->setIcon(QIcon(":key_generate.png"));
- generateToolButton->setText(_("Generate"));
- generateToolButton->setToolTip(_("Generate A New Keypair or Subkey"));
- generateToolButton->setToolButtonStyle(icon_style_);
- keyToolBar->addWidget(generateToolButton);
+ // genrate key pair
+ key_tool_bar->addAction(generate_key_pair_act_);
// add button with popup menu for import
- auto* toolButton = new QToolButton(this);
- toolButton->setMenu(import_key_menu_);
- toolButton->setPopupMode(QToolButton::InstantPopup);
- toolButton->setIcon(QIcon(":key_import.png"));
- toolButton->setToolTip(_("Import key"));
- toolButton->setText(_("Import Key"));
- toolButton->setToolButtonStyle(icon_style_);
- keyToolBar->addWidget(toolButton);
-
- keyToolBar->addSeparator();
- keyToolBar->addAction(delete_checked_keys_act_);
- keyToolBar->addSeparator();
- keyToolBar->addAction(export_key_to_file_act_);
- keyToolBar->addAction(export_key_to_clipboard_act_);
- keyToolBar->addAction(export_key_as_open_ssh_format_);
+ auto* tool_button = new QToolButton(this);
+ tool_button->setMenu(import_key_menu_);
+ tool_button->setPopupMode(QToolButton::InstantPopup);
+ tool_button->setIcon(QIcon(":key_import.png"));
+ tool_button->setToolTip(_("Import key"));
+ tool_button->setText(_("Import Key"));
+ tool_button->setToolButtonStyle(icon_style_);
+ key_tool_bar->addWidget(tool_button);
+
+ key_tool_bar->addSeparator();
+ key_tool_bar->addAction(delete_checked_keys_act_);
+ key_tool_bar->addSeparator();
+ key_tool_bar->addAction(export_key_to_file_act_);
+ key_tool_bar->addAction(export_key_to_clipboard_act_);
+ key_tool_bar->addAction(export_key_as_open_ssh_format_);
}
void KeyMgmt::SlotDeleteSelectedKeys() {
@@ -323,7 +330,7 @@ void KeyMgmt::SlotShowKeyDetails() {
return;
}
- new KeyDetailsDialog(key);
+ new KeyDetailsDialog(key, this);
}
void KeyMgmt::SlotExportKeyToKeyPackage() {
diff --git a/src/ui/main_window/MainWindow.cpp b/src/ui/main_window/MainWindow.cpp
index fff3ab63..b38646cf 100644
--- a/src/ui/main_window/MainWindow.cpp
+++ b/src/ui/main_window/MainWindow.cpp
@@ -84,7 +84,13 @@ void MainWindow::Init() noexcept {
});
m_key_list_->AddMenuAction(append_selected_keys_act_);
+ m_key_list_->AddMenuAction(append_key_create_date_to_editor_act_);
+ m_key_list_->AddMenuAction(append_key_expire_date_to_editor_act_);
+ m_key_list_->AddMenuAction(append_key_fingerprint_to_editor_act_);
+ m_key_list_->AddSeparator();
m_key_list_->AddMenuAction(copy_mail_address_to_clipboard_act_);
+ m_key_list_->AddMenuAction(copy_key_default_uid_to_clipboard_act_);
+ m_key_list_->AddMenuAction(copy_key_id_to_clipboard_act_);
m_key_list_->AddSeparator();
m_key_list_->AddMenuAction(show_key_details_act_);
diff --git a/src/ui/main_window/MainWindow.h b/src/ui/main_window/MainWindow.h
index e32a02ff..04a82759 100644
--- a/src/ui/main_window/MainWindow.h
+++ b/src/ui/main_window/MainWindow.h
@@ -225,12 +225,42 @@ class MainWindow : public GeneralMainWindow {
void slot_append_selected_keys();
/**
+ * @brief
+ *
+ */
+ void slot_append_keys_create_datetime();
+
+ /**
+ * @brief
+ *
+ */
+ void slot_append_keys_expire_datetime();
+
+ /**
+ * @brief
+ *
+ */
+ void slot_append_keys_fingerprint();
+
+ /**
* @details Copy the mailaddress of selected key to clipboard.
* Method for keylists contextmenu.
*/
void slot_copy_mail_address_to_clipboard();
/**
+ * @details Copy the mailaddress of selected key to clipboard.
+ * Method for keylists contextmenu.
+ */
+ void slot_copy_default_uid_to_clipboard();
+
+ /**
+ * @details Copy the mailaddress of selected key to clipboard.
+ * Method for keylists contextmenu.
+ */
+ void slot_copy_key_id_to_clipboard();
+
+ /**
* @details Open key management dialog.
*/
void slot_open_key_management();
@@ -376,8 +406,15 @@ class MainWindow : public GeneralMainWindow {
QAction*
append_selected_keys_act_{}; ///< Action to append selected keys to edit
+ QAction* append_key_fingerprint_to_editor_act_{}; ///<
+ QAction* append_key_create_date_to_editor_act_{}; ///<
+ QAction* append_key_expire_date_to_editor_act_{}; ///<
+
QAction* copy_mail_address_to_clipboard_act_{}; ///< Action to copy mail to
///< clipboard
+ QAction* copy_key_id_to_clipboard_act_{}; ///<
+ QAction* copy_key_default_uid_to_clipboard_act_{}; ///<
+
QAction* open_key_management_act_{}; ///< Action to open key management
QAction* copy_act_{}; ///< Action to copy text
QAction* quote_act_{}; ///< Action to quote text
diff --git a/src/ui/main_window/MainWindowSlotFunction.cpp b/src/ui/main_window/MainWindowSlotFunction.cpp
index 6f702e34..841c8680 100644
--- a/src/ui/main_window/MainWindowSlotFunction.cpp
+++ b/src/ui/main_window/MainWindowSlotFunction.cpp
@@ -26,12 +26,15 @@
*
*/
+#include <boost/date_time/posix_time/posix_time.hpp>
+#include <boost/date_time/posix_time/posix_time_io.hpp>
#include <memory>
#include <string>
#include <utility>
#include "MainWindow.h"
#include "core/GpgConstants.h"
+#include "core/GpgContext.h"
#include "core/GpgModel.h"
#include "core/function/gpg/GpgBasicOperator.h"
#include "core/function/gpg/GpgKeyGetter.h"
@@ -611,11 +614,88 @@ void MainWindow::slot_append_selected_keys() {
auto exported = std::make_unique<ByteArray>();
auto key_ids = m_key_list_->GetSelected();
- GpgKeyImportExporter::GetInstance().ExportKeys(key_ids, exported);
+ if (key_ids->empty()) {
+ SPDLOG_ERROR("no key is selected");
+ return;
+ }
+
+ if (!GpgKeyImportExporter::GetInstance().ExportKeys(key_ids, exported)) {
+ QMessageBox::critical(this, _("Error"), _("Key Export Operation Failed."));
+ return;
+ }
edit_->CurTextPage()->GetTextPage()->appendPlainText(
QString::fromStdString(*exported));
}
+void MainWindow::slot_append_keys_create_datetime() {
+ if (edit_->TabCount() == 0 || edit_->SlotCurPageTextEdit() == nullptr) {
+ return;
+ }
+
+ auto key_ids = m_key_list_->GetSelected();
+
+ if (key_ids->empty()) {
+ SPDLOG_ERROR("no key is selected");
+ return;
+ }
+
+ auto key = GpgKeyGetter::GetInstance().GetKey(key_ids->front());
+ if (!key.IsGood()) {
+ QMessageBox::critical(this, _("Error"), _("Key Not Found."));
+ return;
+ }
+
+ auto create_datetime_format_str =
+ boost::posix_time::to_iso_extended_string(key.GetCreateTime()) +
+ " (UTC) " + "\n";
+
+ edit_->CurTextPage()->GetTextPage()->appendPlainText(
+ QString::fromStdString(create_datetime_format_str));
+}
+
+void MainWindow::slot_append_keys_expire_datetime() {
+ if (edit_->TabCount() == 0 || edit_->SlotCurPageTextEdit() == nullptr) {
+ return;
+ }
+
+ auto key_ids = m_key_list_->GetSelected();
+
+ if (key_ids->empty()) {
+ SPDLOG_ERROR("no key is selected");
+ return;
+ }
+
+ auto key = GpgKeyGetter::GetInstance().GetKey(key_ids->front());
+ if (!key.IsGood()) {
+ QMessageBox::critical(this, _("Error"), _("Key Not Found."));
+ return;
+ }
+
+ auto create_datetime_format_str =
+ boost::posix_time::to_iso_extended_string(key.GetCreateTime()) +
+ " (UTC) " + "\n";
+
+ edit_->CurTextPage()->GetTextPage()->appendPlainText(
+ QString::fromStdString(create_datetime_format_str));
+}
+
+void MainWindow::slot_append_keys_fingerprint() {
+ auto key_ids = m_key_list_->GetSelected();
+ if (key_ids->empty()) return;
+
+ auto key = GpgKeyGetter::GetInstance().GetKey(key_ids->front());
+ if (!key.IsGood()) {
+ QMessageBox::critical(this, _("Error"), _("Key Not Found."));
+ return;
+ }
+
+ auto fingerprint_format_str =
+ beautify_fingerprint(key.GetFingerprint()) + "\n";
+
+ edit_->CurTextPage()->GetTextPage()->appendPlainText(
+ QString::fromStdString(fingerprint_format_str));
+}
+
void MainWindow::slot_copy_mail_address_to_clipboard() {
auto key_ids = m_key_list_->GetSelected();
if (key_ids->empty()) return;
@@ -629,6 +709,32 @@ void MainWindow::slot_copy_mail_address_to_clipboard() {
cb->setText(QString::fromStdString(key.GetEmail()));
}
+void MainWindow::slot_copy_default_uid_to_clipboard() {
+ auto key_ids = m_key_list_->GetSelected();
+ if (key_ids->empty()) return;
+
+ auto key = GpgKeyGetter::GetInstance().GetKey(key_ids->front());
+ if (!key.IsGood()) {
+ QMessageBox::critical(this, _("Error"), _("Key Not Found."));
+ return;
+ }
+ QClipboard* cb = QApplication::clipboard();
+ cb->setText(QString::fromStdString(key.GetUIDs()->front().GetUID()));
+}
+
+void MainWindow::slot_copy_key_id_to_clipboard() {
+ auto key_ids = m_key_list_->GetSelected();
+ if (key_ids->empty()) return;
+
+ auto key = GpgKeyGetter::GetInstance().GetKey(key_ids->front());
+ if (!key.IsGood()) {
+ QMessageBox::critical(this, _("Error"), _("Key Not Found."));
+ return;
+ }
+ QClipboard* cb = QApplication::clipboard();
+ cb->setText(QString::fromStdString(key.GetId()));
+}
+
void MainWindow::slot_show_key_details() {
auto key_ids = m_key_list_->GetSelected();
if (key_ids->empty()) return;
diff --git a/src/ui/main_window/MainWindowUI.cpp b/src/ui/main_window/MainWindowUI.cpp
index b9a01c15..1034df52 100644
--- a/src/ui/main_window/MainWindowUI.cpp
+++ b/src/ui/main_window/MainWindowUI.cpp
@@ -27,6 +27,7 @@
*/
#include "MainWindow.h"
+#include "core/function/GlobalSettingStation.h"
#include "core/function/gpg/GpgAdvancedOperator.h"
#include "ui/UserInterfaceUtils.h"
@@ -251,11 +252,23 @@ void MainWindow::create_actions() {
CommonUtils::GetInstance()->SlotImportKeyFromClipboard(this);
});
+ // get settings
+ auto& settings = GlobalSettingStation::GetInstance().GetUISettings();
+ // read settings
+ bool forbid_all_gnupg_connection = false;
+ try {
+ forbid_all_gnupg_connection =
+ settings.lookup("network.forbid_all_gnupg_connection");
+ } catch (...) {
+ SPDLOG_ERROR("setting operation error: forbid_all_gnupg_connection");
+ }
+
import_key_from_key_server_act_ = new QAction(_("Keyserver"), this);
import_key_from_key_server_act_->setIcon(
QIcon(":import_key_from_server.png"));
import_key_from_key_server_act_->setToolTip(
_("Import New Key From Keyserver"));
+ import_key_from_key_server_act_->setDisabled(forbid_all_gnupg_connection);
connect(import_key_from_key_server_act_, &QAction::triggered, this, [&]() {
CommonUtils::GetInstance()->SlotImportKeyFromKeyServer(this);
});
@@ -353,22 +366,53 @@ void MainWindow::create_actions() {
connect(start_wizard_act_, &QAction::triggered, this,
&MainWindow::slot_start_wizard);
- /* Popup-Menu-Action for KeyList
- */
- append_selected_keys_act_ = new QAction(_("Append To Text Editor"), this);
+ append_selected_keys_act_ =
+ new QAction(_("Append Public Key to Editor"), this);
append_selected_keys_act_->setToolTip(
- _("Append The Selected Public Key To Text in Editor"));
+ _("Append selected Keypair's Public Key to Editor"));
connect(append_selected_keys_act_, &QAction::triggered, this,
&MainWindow::slot_append_selected_keys);
+ append_key_create_date_to_editor_act_ =
+ new QAction(_("Append Create DateTime to Editor"), this);
+ append_key_create_date_to_editor_act_->setToolTip(
+ _("Append selected Key's creation date and time to Editor"));
+ connect(append_key_create_date_to_editor_act_, &QAction::triggered, this,
+ &MainWindow::slot_append_keys_create_datetime);
+
+ append_key_expire_date_to_editor_act_ =
+ new QAction(_("Append Expire DateTime to Editor"), this);
+ append_key_expire_date_to_editor_act_->setToolTip(
+ _("Append selected Key's expiration date and time to Editor"));
+ connect(append_key_expire_date_to_editor_act_, &QAction::triggered, this,
+ &MainWindow::slot_append_keys_expire_datetime);
+
+ append_key_fingerprint_to_editor_act_ =
+ new QAction(_("Append Fingerprint to Editor"), this);
+ append_key_expire_date_to_editor_act_->setToolTip(
+ _("Append selected Key's Fingerprint to Editor"));
+ connect(append_key_fingerprint_to_editor_act_, &QAction::triggered, this,
+ &MainWindow::slot_append_keys_fingerprint);
+
copy_mail_address_to_clipboard_act_ = new QAction(_("Copy Email"), this);
copy_mail_address_to_clipboard_act_->setToolTip(
- _("Copy selected Email to clipboard"));
+ _("Copy selected Keypair's to clipboard"));
connect(copy_mail_address_to_clipboard_act_, &QAction::triggered, this,
&MainWindow::slot_copy_mail_address_to_clipboard);
- // TODO: find central place for shared actions, to avoid code-duplication with
- // keymgmt.cpp
+ copy_key_default_uid_to_clipboard_act_ =
+ new QAction(_("Copy Default UID"), this);
+ copy_key_default_uid_to_clipboard_act_->setToolTip(
+ _("Copy selected Keypair's default UID to clipboard"));
+ connect(copy_key_default_uid_to_clipboard_act_, &QAction::triggered, this,
+ &MainWindow::slot_copy_default_uid_to_clipboard);
+
+ copy_key_id_to_clipboard_act_ = new QAction(_("Copy Key ID"), this);
+ copy_key_id_to_clipboard_act_->setToolTip(
+ _("Copy selected Keypair's ID to clipboard"));
+ connect(copy_key_id_to_clipboard_act_, &QAction::triggered, this,
+ &MainWindow::slot_copy_key_id_to_clipboard);
+
show_key_details_act_ = new QAction(_("Show Key Details"), this);
show_key_details_act_->setToolTip(_("Show Details for this Key"));
connect(show_key_details_act_, &QAction::triggered, this,
@@ -464,8 +508,8 @@ void MainWindow::create_menus() {
help_menu_->addAction(start_wizard_act_);
help_menu_->addSeparator();
help_menu_->addAction(check_update_act_);
- help_menu_->addAction(translate_act_);
help_menu_->addAction(gnupg_act_);
+ help_menu_->addAction(translate_act_);
help_menu_->addAction(about_act_);
}
diff --git a/src/ui/thread/ProxyConnectionTestTask.cpp b/src/ui/thread/ProxyConnectionTestTask.cpp
new file mode 100644
index 00000000..c7d623d7
--- /dev/null
+++ b/src/ui/thread/ProxyConnectionTestTask.cpp
@@ -0,0 +1,74 @@
+/**
+ * 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 <https://www.gnu.org/licenses/>.
+ *
+ * The initial version of the source code is inherited from
+ * the gpg4usb project, which is under GPL-3.0-or-later.
+ *
+ * The source code version of this software was modified and released
+ * by Saturneric<[email protected]><[email protected]> starting on May 12, 2021.
+ *
+ */
+
+#include "ProxyConnectionTestTask.h"
+
+GpgFrontend::UI::ProxyConnectionTestTask::ProxyConnectionTestTask(QString url,
+ int timeout)
+ : Task("proxy_connection_test_task"),
+ url_(std::move(url)),
+ timeout_(timeout),
+ network_manager_(new QNetworkAccessManager(this)) {}
+
+void GpgFrontend::UI::ProxyConnectionTestTask::run() {
+ SetFinishAfterRun(false);
+
+ auto* network_reply = network_manager_->get(QNetworkRequest{url_});
+ auto* timer = new QTimer(this);
+
+ connect(network_reply, &QNetworkReply::finished, this,
+ [this, network_reply]() {
+ SPDLOG_DEBUG("key server domain reply: {} received",
+ url_.toStdString());
+ this->slot_process_network_reply(network_reply);
+ });
+
+ connect(timer, &QTimer::timeout, this, [this, network_reply]() {
+ SPDLOG_DEBUG("timeout for key server: {}", url_.toStdString());
+ if (network_reply->isRunning()) {
+ network_reply->abort();
+ this->slot_process_network_reply(network_reply);
+ }
+ });
+
+ timer->start(timeout_);
+}
+
+void GpgFrontend::UI::ProxyConnectionTestTask::slot_process_network_reply(
+ QNetworkReply* reply) {
+ auto buffer = reply->readAll();
+ SPDLOG_DEBUG("key server domain reply: {}, buffer size: {}",
+ url_.toStdString(), buffer.size());
+
+ if (reply->error() == QNetworkReply::NoError && !buffer.isEmpty()) {
+ result_ = "Reachable";
+ } else {
+ result_ = "Not Reachable";
+ }
+
+ emit SignalProxyConnectionTestResult(result_);
+ emit SignalTaskRunnableEnd(0);
+}
diff --git a/src/ui/thread/ProxyConnectionTestThread.h b/src/ui/thread/ProxyConnectionTestTask.h
index 70757e03..38e78ae4 100644
--- a/src/ui/thread/ProxyConnectionTestThread.h
+++ b/src/ui/thread/ProxyConnectionTestTask.h
@@ -39,7 +39,7 @@ namespace GpgFrontend::UI {
* @brief
*
*/
-class ProxyConnectionTestThread : public QThread {
+class ProxyConnectionTestTask : public Thread::Task {
Q_OBJECT
public:
/**
@@ -49,9 +49,7 @@ class ProxyConnectionTestThread : public QThread {
* @param timeout
* @param parent
*/
- explicit ProxyConnectionTestThread(QString url, int timeout,
- QWidget* parent = nullptr)
- : QThread(parent), url_(std::move(url)), timeout_(timeout) {}
+ explicit ProxyConnectionTestTask(QString url, int timeout);
signals:
/**
@@ -68,10 +66,14 @@ class ProxyConnectionTestThread : public QThread {
*/
void run() override;
+ private slots:
+ void slot_process_network_reply(QNetworkReply* reply);
+
private:
- QString url_; ///<
- QString result_; ///<
- int timeout_ = 500; ///<
+ QString url_; ///<
+ QString result_; ///<
+ int timeout_ = 500; ///<
+ QNetworkAccessManager* network_manager_; ///<
};
} // namespace GpgFrontend::UI
diff --git a/src/ui/thread/ProxyConnectionTestThread.cpp b/src/ui/thread/ProxyConnectionTestThread.cpp
deleted file mode 100644
index 8b113453..00000000
--- a/src/ui/thread/ProxyConnectionTestThread.cpp
+++ /dev/null
@@ -1,58 +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 <https://www.gnu.org/licenses/>.
- *
- * The initial version of the source code is inherited from
- * the gpg4usb project, which is under GPL-3.0-or-later.
- *
- * The source code version of this software was modified and released
- * by Saturneric<[email protected]><[email protected]> starting on May 12, 2021.
- *
- */
-
-#include "ProxyConnectionTestThread.h"
-
-void GpgFrontend::UI::ProxyConnectionTestThread::run() {
- QNetworkProxyQuery npq({QUrl(url_)});
- auto proxies_list = QNetworkProxyFactory::systemProxyForQuery(npq);
-
- if (proxies_list.isEmpty()) {
- SPDLOG_DEBUG("no proxy applied");
- } else {
- SPDLOG_DEBUG("proxies list hostname: {}",
- proxies_list.front().hostName().toStdString());
- }
-
- SPDLOG_DEBUG("proxies list size: {}", proxies_list.size());
-
- auto manager = std::make_unique<QNetworkAccessManager>(nullptr);
- QNetworkRequest url_request;
- url_request.setUrl(QUrl(url_));
- auto _reply = manager->get(url_request);
-
- while (_reply->isRunning()) QApplication::processEvents();
- auto _buffer = _reply->readAll();
- if (_reply->error() == QNetworkReply::NoError && !_buffer.isEmpty()) {
- result_ = "Reachable";
- } else {
- result_ = "Not Reachable";
- }
-
- _reply->deleteLater();
-
- emit SignalProxyConnectionTestResult(result_);
-}
diff --git a/src/ui/widgets/TextEdit.cpp b/src/ui/widgets/TextEdit.cpp
index 4947e179..d22c091a 100644
--- a/src/ui/widgets/TextEdit.cpp
+++ b/src/ui/widgets/TextEdit.cpp
@@ -603,6 +603,7 @@ void TextEdit::slot_save_status_to_cache_for_revovery() {
text_page_data_modified_count_);
if (this->text_page_data_modified_count_++ % 3 != 0) return;
+#ifdef DEBUG
int tab_count = tab_widget_->count();
SPDLOG_DEBUG("current tabs count {}", tab_count);
@@ -635,6 +636,7 @@ void TextEdit::slot_save_status_to_cache_for_revovery() {
tab_title, raw_text.size());
unsaved_pages.push_back({i, tab_title, raw_text});
}
+#endif
}
} // namespace GpgFrontend::UI
diff --git a/src/ui/widgets/VerifyKeyDetailBox.cpp b/src/ui/widgets/VerifyKeyDetailBox.cpp
index c6c4982c..555414b4 100644
--- a/src/ui/widgets/VerifyKeyDetailBox.cpp
+++ b/src/ui/widgets/VerifyKeyDetailBox.cpp
@@ -28,6 +28,7 @@
#include "ui/widgets/VerifyKeyDetailBox.h"
+#include "core/function/GlobalSettingStation.h"
#include "core/function/gpg/GpgKeyGetter.h"
namespace GpgFrontend::UI {
@@ -40,8 +41,21 @@ VerifyKeyDetailBox::VerifyKeyDetailBox(const GpgSignature& signature,
switch (gpg_err_code(signature.GetStatus())) {
case GPG_ERR_NO_PUBKEY: {
this->setTitle("A Error Signature");
- auto* importButton = new QPushButton(_("Import from keyserver"));
- connect(importButton, &QPushButton::clicked, this,
+
+ // get settings
+ auto& settings = GlobalSettingStation::GetInstance().GetUISettings();
+ // read settings
+ bool forbid_all_gnupg_connection = false;
+ try {
+ forbid_all_gnupg_connection =
+ settings.lookup("network.forbid_all_gnupg_connection");
+ } catch (...) {
+ SPDLOG_ERROR("setting operation error: forbid_all_gnupg_connection");
+ }
+
+ auto* import_button = new QPushButton(_("Import from keyserver"));
+ import_button->setDisabled(forbid_all_gnupg_connection);
+ connect(import_button, &QPushButton::clicked, this,
&VerifyKeyDetailBox::slot_import_form_key_server);
this->setTitle(QString(_("Key not present with id 0x")) + fpr_.c_str());
@@ -52,7 +66,7 @@ VerifyKeyDetailBox::VerifyKeyDetailBox(const GpgSignature& signature,
// grid->addWidget(new QLabel(_("Fingerprint:")), 1, 0);
grid->addWidget(new QLabel(_("Key not present in key list")), 0, 1);
// grid->addWidget(new QLabel(signature->fpr), 1, 1);
- grid->addWidget(importButton, 2, 0, 2, 1);
+ grid->addWidget(import_button, 2, 0, 2, 1);
vbox->addLayout(grid);
break;