aboutsummaryrefslogtreecommitdiffstats
path: root/src/ui
diff options
context:
space:
mode:
Diffstat (limited to 'src/ui')
-rw-r--r--src/ui/GpgFrontendUIInit.cpp10
-rw-r--r--src/ui/GpgFrontendUIInit.h5
-rw-r--r--src/ui/SignalStation.cpp2
-rw-r--r--src/ui/SignalStation.h6
-rw-r--r--src/ui/UserInterfaceUtils.cpp165
-rw-r--r--src/ui/UserInterfaceUtils.h18
-rw-r--r--src/ui/import_export/KeyServerImportDialog.cpp20
-rw-r--r--src/ui/key_generate/KeygenDialog.cpp12
-rw-r--r--src/ui/key_generate/SubkeyGenerateDialog.cpp21
-rw-r--r--src/ui/keypair_details/KeyPairDetailTab.cpp12
-rw-r--r--src/ui/keypair_details/KeyPairSubkeyTab.cpp4
-rw-r--r--src/ui/keypair_details/KeyPairUIDTab.cpp4
-rw-r--r--src/ui/keypair_details/KeySetExpireDateDialog.cpp16
-rw-r--r--src/ui/main_window/MainWindowSlotFunction.cpp3
-rw-r--r--src/ui/widgets/KeyList.cpp24
15 files changed, 204 insertions, 118 deletions
diff --git a/src/ui/GpgFrontendUIInit.cpp b/src/ui/GpgFrontendUIInit.cpp
index 82746551..49f16ec5 100644
--- a/src/ui/GpgFrontendUIInit.cpp
+++ b/src/ui/GpgFrontendUIInit.cpp
@@ -28,6 +28,8 @@
#include "GpgFrontendUIInit.h"
+#include "SignalStation.h"
+#include "UserInterfaceUtils.h"
#include "core/function/GlobalSettingStation.h"
// init easyloggingpp library
@@ -35,6 +37,14 @@ INITIALIZE_EASYLOGGINGPP
namespace GpgFrontend::UI {
+extern void init_logging();
+
+void InitGpgFrontendUI() {
+ init_logging();
+ SignalStation::GetInstance();
+ CommonUtils::GetInstance();
+}
+
void init_logging() {
using namespace boost::posix_time;
using namespace boost::gregorian;
diff --git a/src/ui/GpgFrontendUIInit.h b/src/ui/GpgFrontendUIInit.h
index ddb791c3..6518256b 100644
--- a/src/ui/GpgFrontendUIInit.h
+++ b/src/ui/GpgFrontendUIInit.h
@@ -34,9 +34,10 @@
namespace GpgFrontend::UI {
/**
- * @brief
+ * @brief init the UI library
+ *
*/
-void init_logging();
+void InitGpgFrontendUI();
}; // namespace GpgFrontend::UI
diff --git a/src/ui/SignalStation.cpp b/src/ui/SignalStation.cpp
index 045b63f5..c1f1238f 100644
--- a/src/ui/SignalStation.cpp
+++ b/src/ui/SignalStation.cpp
@@ -28,6 +28,8 @@
#include "SignalStation.h"
+#include "UserInterfaceUtils.h"
+
namespace GpgFrontend::UI {
std::unique_ptr<SignalStation> SignalStation::_instance = nullptr;
diff --git a/src/ui/SignalStation.h b/src/ui/SignalStation.h
index dbf978be..eb7b3f74 100644
--- a/src/ui/SignalStation.h
+++ b/src/ui/SignalStation.h
@@ -60,6 +60,12 @@ class SignalStation : public QObject {
/**
* @brief
*
+ */
+ void SignalKeyDatabaseRefreshDone();
+
+ /**
+ * @brief
+ *
* @param text
* @param verify_label_status
*/
diff --git a/src/ui/UserInterfaceUtils.cpp b/src/ui/UserInterfaceUtils.cpp
index 52b7eb28..9859ff65 100644
--- a/src/ui/UserInterfaceUtils.cpp
+++ b/src/ui/UserInterfaceUtils.cpp
@@ -29,10 +29,13 @@
#include "UserInterfaceUtils.h"
#include <utility>
+#include <vector>
#include "core/common/CoreCommonUtil.h"
#include "core/function/FileOperator.h"
#include "core/function/GlobalSettingStation.h"
+#include "core/function/gpg/GpgKeyGetter.h"
+#include "easylogging++.h"
#include "ui/SignalStation.h"
#include "ui/dialog/WaitingDialog.h"
#include "ui/widgets/TextEdit.h"
@@ -129,11 +132,24 @@ CommonUtils *CommonUtils::GetInstance() {
}
CommonUtils::CommonUtils() : QWidget(nullptr) {
+ LOG(INFO) << "common utils created";
+
connect(CoreCommonUtil::GetInstance(), &CoreCommonUtil::SignalGnupgNotInstall,
this, &CommonUtils::SignalGnupgNotInstall);
connect(this, &CommonUtils::SignalKeyStatusUpdated,
SignalStation::GetInstance(),
&SignalStation::SignalKeyDatabaseRefresh);
+ connect(this, &CommonUtils::SignalKeyDatabaseRefreshDone,
+ SignalStation::GetInstance(),
+ &SignalStation::SignalKeyDatabaseRefreshDone);
+
+ // directly connect to SignalKeyStatusUpdated
+ // to avoid the delay of signal emitting
+ // when the key database is refreshed
+ connect(SignalStation::GetInstance(),
+ &SignalStation::SignalKeyDatabaseRefresh, this,
+ &CommonUtils::slot_update_key_status);
+
connect(this, &CommonUtils::SignalGnupgNotInstall, this, []() {
QMessageBox::critical(
nullptr, _("ENV Loading Failed"),
@@ -227,8 +243,7 @@ void CommonUtils::SlotExecuteGpgCommand(
}
void CommonUtils::SlotImportKeyFromKeyServer(
- const KeyIdArgsList &key_ids,
- const ImportCallbackFunctiopn &callback) {
+ const KeyIdArgsList &key_ids, const ImportCallbackFunctiopn &callback) {
std::string target_keyserver;
if (target_keyserver.empty()) {
try {
@@ -248,71 +263,95 @@ void CommonUtils::SlotImportKeyFromKeyServer(
}
}
- auto thread =
- QThread::create([target_keyserver, key_ids, callback]() {
- QUrl target_keyserver_url(target_keyserver.c_str());
-
- auto network_manager = std::make_unique<QNetworkAccessManager>();
- // LOOP
- decltype(key_ids.size()) current_index = 1, all_index = key_ids.size();
- for (const auto &key_id : key_ids) {
- // New Req Url
- QUrl req_url(target_keyserver_url.scheme() + "://" +
- target_keyserver_url.host() +
- "/pks/lookup?op=get&search=0x" + key_id.c_str() +
- "&options=mr");
-
- LOG(INFO) << "request url" << req_url.toString().toStdString();
-
- // Waiting for reply
- QNetworkReply *reply = network_manager->get(QNetworkRequest(req_url));
- QEventLoop loop;
- connect(reply, &QNetworkReply::finished, &loop, &QEventLoop::quit);
- loop.exec();
-
- // Get Data
- auto key_data = reply->readAll();
- auto key_data_ptr =
- std::make_unique<ByteArray>(key_data.data(), key_data.size());
-
- // Detect status
- std::string status;
- auto error = reply->error();
- if (error != QNetworkReply::NoError) {
- switch (error) {
- case QNetworkReply::ContentNotFoundError:
- status = _("Key Not Found");
- break;
- case QNetworkReply::TimeoutError:
- status = _("Timeout");
- break;
- case QNetworkReply::HostNotFoundError:
- status = _("Key Server Not Found");
- break;
- default:
- status = _("Connection Error");
- }
- }
-
- reply->deleteLater();
-
- // Try importing
- GpgImportInformation result =
- GpgKeyImportExporter::GetInstance()
- .ImportKey(std::move(key_data_ptr));
-
- if (result.imported == 1) {
- status = _("The key has been updated");
- } else {
- status = _("No need to update the key");
- }
- callback(key_id, status, current_index, all_index);
- current_index++;
+ auto thread = QThread::create([target_keyserver, key_ids, callback]() {
+ QUrl target_keyserver_url(target_keyserver.c_str());
+
+ auto network_manager = std::make_unique<QNetworkAccessManager>();
+ // LOOP
+ decltype(key_ids.size()) current_index = 1, all_index = key_ids.size();
+ for (const auto &key_id : key_ids) {
+ // New Req Url
+ QUrl req_url(
+ target_keyserver_url.scheme() + "://" + target_keyserver_url.host() +
+ "/pks/lookup?op=get&search=0x" + key_id.c_str() + "&options=mr");
+
+ LOG(INFO) << "request url" << req_url.toString().toStdString();
+
+ // Waiting for reply
+ QNetworkReply *reply = network_manager->get(QNetworkRequest(req_url));
+ QEventLoop loop;
+ connect(reply, &QNetworkReply::finished, &loop, &QEventLoop::quit);
+ loop.exec();
+
+ // Get Data
+ auto key_data = reply->readAll();
+ auto key_data_ptr =
+ std::make_unique<ByteArray>(key_data.data(), key_data.size());
+
+ // Detect status
+ std::string status;
+ auto error = reply->error();
+ if (error != QNetworkReply::NoError) {
+ switch (error) {
+ case QNetworkReply::ContentNotFoundError:
+ status = _("Key Not Found");
+ break;
+ case QNetworkReply::TimeoutError:
+ status = _("Timeout");
+ break;
+ case QNetworkReply::HostNotFoundError:
+ status = _("Key Server Not Found");
+ break;
+ default:
+ status = _("Connection Error");
}
- });
+ }
+
+ reply->deleteLater();
+
+ // Try importing
+ GpgImportInformation result =
+ GpgKeyImportExporter::GetInstance().ImportKey(
+ std::move(key_data_ptr));
+
+ if (result.imported == 1) {
+ status = _("The key has been updated");
+ } else {
+ status = _("No need to update the key");
+ }
+ callback(key_id, status, current_index, all_index);
+ current_index++;
+ }
+ });
connect(thread, &QThread::finished, thread, &QThread::deleteLater);
thread->start();
}
+void CommonUtils::slot_update_key_status() {
+ LOG(INFO) << "called";
+
+ std::vector<QThread *> threads;
+
+ // flush key cache for all GpgKeyGetter Intances.
+ for (const auto &channel_id : GpgKeyGetter::GetAllChannelId()) {
+ // multi threading
+ auto *thread = QThread::create([channel_id]() {
+ LOG(INFO) << "thread start"
+ << "channel:" << channel_id;
+ GpgKeyGetter::GetInstance(channel_id).FlushKeyCache();
+ });
+ thread->start();
+ threads.push_back(thread);
+ }
+
+ for (auto *thread : threads) {
+ thread->wait();
+ thread->deleteLater();
+ }
+
+ emit SignalKeyDatabaseRefreshDone();
+ LOG(INFO) << "finished";
+}
+
} // namespace GpgFrontend::UI \ No newline at end of file
diff --git a/src/ui/UserInterfaceUtils.h b/src/ui/UserInterfaceUtils.h
index a7f20f10..85ef012b 100644
--- a/src/ui/UserInterfaceUtils.h
+++ b/src/ui/UserInterfaceUtils.h
@@ -59,8 +59,8 @@ void show_verify_details(QWidget* parent, InfoBoardWidget* info_board,
* @param parent
* @param verify_res
*/
-void import_unknown_key_from_keyserver(QWidget* parent,
- const GpgVerifyResultAnalyse& verify_res);
+void import_unknown_key_from_keyserver(
+ QWidget* parent, const GpgVerifyResultAnalyse& verify_res);
/**
* @brief
@@ -144,6 +144,12 @@ class CommonUtils : public QWidget {
*/
void SignalGnupgNotInstall();
+ /**
+ * @brief emit when the key database is refreshed
+ *
+ */
+ void SignalKeyDatabaseRefreshDone();
+
public slots:
/**
* @brief
@@ -195,6 +201,14 @@ class CommonUtils : public QWidget {
const QStringList& arguments,
const std::function<void(QProcess*)>& interact_func);
+ private slots:
+
+ /**
+ * @brief update the key status when signal is emitted
+ *
+ */
+ void slot_update_key_status();
+
private:
static std::unique_ptr<CommonUtils> instance_; ///<
};
diff --git a/src/ui/import_export/KeyServerImportDialog.cpp b/src/ui/import_export/KeyServerImportDialog.cpp
index c35e3db7..2d30c021 100644
--- a/src/ui/import_export/KeyServerImportDialog.cpp
+++ b/src/ui/import_export/KeyServerImportDialog.cpp
@@ -30,9 +30,9 @@
#include <utility>
+#include "core/function/GlobalSettingStation.h"
#include "core/function/gpg/GpgKeyImportExporter.h"
#include "ui/SignalStation.h"
-#include "core/function/GlobalSettingStation.h"
namespace GpgFrontend::UI {
@@ -47,12 +47,15 @@ KeyServerImportDialog::KeyServerImportDialog(bool automatic, QWidget* parent)
// Buttons
close_button_ = new QPushButton(_("Close"));
- connect(close_button_, &QPushButton::clicked, this, &KeyServerImportDialog::close);
+ connect(close_button_, &QPushButton::clicked, this,
+ &KeyServerImportDialog::close);
import_button_ = new QPushButton(_("Import ALL"));
- connect(import_button_, &QPushButton::clicked, this, &KeyServerImportDialog::slot_import);
+ connect(import_button_, &QPushButton::clicked, this,
+ &KeyServerImportDialog::slot_import);
import_button_->setDisabled(true);
search_button_ = new QPushButton(_("Search"));
- connect(search_button_, &QPushButton::clicked, this, &KeyServerImportDialog::slot_search);
+ connect(search_button_, &QPushButton::clicked, this,
+ &KeyServerImportDialog::slot_search);
// Line edits for search string
search_label_ = new QLabel(QString(_("Search String")) + _(": "));
@@ -139,11 +142,13 @@ KeyServerImportDialog::KeyServerImportDialog(bool automatic, QWidget* parent)
this->setModal(true);
- connect(this, &KeyServerImportDialog::SignalKeyImported, SignalStation::GetInstance(),
+ connect(this, &KeyServerImportDialog::SignalKeyImported,
+ SignalStation::GetInstance(),
&SignalStation::SignalKeyDatabaseRefresh);
// save window pos and size to configure file
- connect(this, &KeyServerImportDialog::finished, this, &KeyServerImportDialog::slot_save_window_state);
+ connect(this, &KeyServerImportDialog::finished, this,
+ &KeyServerImportDialog::slot_save_window_state);
}
QComboBox* KeyServerImportDialog::create_comboBox() {
@@ -222,7 +227,8 @@ void KeyServerImportDialog::slot_search() {
QNetworkReply* reply =
network_access_manager_->get(QNetworkRequest(url_from_remote));
- connect(reply, &QNetworkReply::finished, this, &KeyServerImportDialog::slot_search_finished);
+ connect(reply, &QNetworkReply::finished, this,
+ &KeyServerImportDialog::slot_search_finished);
set_loading(true);
this->search_button_->setDisabled(true);
diff --git a/src/ui/key_generate/KeygenDialog.cpp b/src/ui/key_generate/KeygenDialog.cpp
index 6df0bcf0..676539c7 100644
--- a/src/ui/key_generate/KeygenDialog.cpp
+++ b/src/ui/key_generate/KeygenDialog.cpp
@@ -28,10 +28,10 @@
#include "ui/key_generate/KeygenDialog.h"
-#include "dialog/WaitingDialog.h"
+#include "core/function/GlobalSettingStation.h"
#include "core/function/gpg/GpgKeyOpera.h"
+#include "dialog/WaitingDialog.h"
#include "ui/SignalStation.h"
-#include "core/function/GlobalSettingStation.h"
namespace GpgFrontend::UI {
@@ -144,15 +144,19 @@ void KeyGenDialog::slot_key_gen_accept() {
dialog->close();
+ LOG(INFO) << "generate done";
+
if (gpgme_err_code(error) == GPG_ERR_NO_ERROR) {
- auto* msg_box = new QMessageBox(nullptr);
+ auto* msg_box = new QMessageBox((QWidget*)this->parent());
msg_box->setAttribute(Qt::WA_DeleteOnClose);
msg_box->setStandardButtons(QMessageBox::Ok);
msg_box->setWindowTitle(_("Success"));
msg_box->setText(_("The new key pair has been generated."));
- msg_box->setModal(false);
+ msg_box->setModal(true);
msg_box->open();
+ LOG(INFO) << "generate success";
+
emit SignalKeyGenerated();
this->close();
} else {
diff --git a/src/ui/key_generate/SubkeyGenerateDialog.cpp b/src/ui/key_generate/SubkeyGenerateDialog.cpp
index 4eb041aa..451c6521 100644
--- a/src/ui/key_generate/SubkeyGenerateDialog.cpp
+++ b/src/ui/key_generate/SubkeyGenerateDialog.cpp
@@ -26,11 +26,11 @@
#include "ui/key_generate/SubkeyGenerateDialog.h"
-#include "dialog/WaitingDialog.h"
+#include "core/function/GlobalSettingStation.h"
#include "core/function/gpg/GpgKeyGetter.h"
#include "core/function/gpg/GpgKeyOpera.h"
+#include "dialog/WaitingDialog.h"
#include "ui/SignalStation.h"
-#include "core/function/GlobalSettingStation.h"
namespace GpgFrontend::UI {
@@ -73,7 +73,8 @@ SubkeyGenerateDialog::SubkeyGenerateDialog(const KeyId& key_id, QWidget* parent)
this->setLayout(vbox2);
this->setModal(true);
- connect(this, &SubkeyGenerateDialog::SignalSubKeyGenerated, SignalStation::GetInstance(),
+ connect(this, &SubkeyGenerateDialog::SignalSubKeyGenerated,
+ SignalStation::GetInstance(),
&SignalStation::SignalKeyDatabaseRefresh);
set_signal_slot();
@@ -156,8 +157,10 @@ QGroupBox* SubkeyGenerateDialog::create_basic_info_group_box() {
}
void SubkeyGenerateDialog::set_signal_slot() {
- connect(button_box_, &QDialogButtonBox::accepted, this, &SubkeyGenerateDialog::slot_key_gen_accept);
- connect(button_box_, &QDialogButtonBox::rejected, this, &SubkeyGenerateDialog::reject);
+ connect(button_box_, &QDialogButtonBox::accepted, this,
+ &SubkeyGenerateDialog::slot_key_gen_accept);
+ connect(button_box_, &QDialogButtonBox::rejected, this,
+ &SubkeyGenerateDialog::reject);
connect(expire_check_box_, &QCheckBox::stateChanged, this,
&SubkeyGenerateDialog::slot_expire_box_changed);
@@ -171,8 +174,8 @@ void SubkeyGenerateDialog::set_signal_slot() {
connect(key_usage_check_boxes_[3], &QCheckBox::stateChanged, this,
&SubkeyGenerateDialog::slot_authentication_box_changed);
- connect(key_type_combo_box_, qOverload<int>(&QComboBox::currentIndexChanged), this,
- &SubkeyGenerateDialog::slot_activated_key_type);
+ connect(key_type_combo_box_, qOverload<int>(&QComboBox::currentIndexChanged),
+ this, &SubkeyGenerateDialog::slot_activated_key_type);
}
void SubkeyGenerateDialog::slot_expire_box_changed() {
@@ -271,12 +274,12 @@ void SubkeyGenerateDialog::slot_key_gen_accept() {
dialog->close();
if (check_gpg_error_2_err_code(error) == GPG_ERR_NO_ERROR) {
- auto* msg_box = new QMessageBox(nullptr);
+ auto* msg_box = new QMessageBox((QWidget*)this->parent());
msg_box->setAttribute(Qt::WA_DeleteOnClose);
msg_box->setStandardButtons(QMessageBox::Ok);
msg_box->setWindowTitle(_("Success"));
msg_box->setText(_("The new subkey has been generated."));
- msg_box->setModal(false);
+ msg_box->setModal(true);
msg_box->open();
emit SignalSubKeyGenerated();
diff --git a/src/ui/keypair_details/KeyPairDetailTab.cpp b/src/ui/keypair_details/KeyPairDetailTab.cpp
index 6174e67b..76f316e9 100644
--- a/src/ui/keypair_details/KeyPairDetailTab.cpp
+++ b/src/ui/keypair_details/KeyPairDetailTab.cpp
@@ -26,9 +26,9 @@
#include "ui/keypair_details/KeyPairDetailTab.h"
-#include "dialog/WaitingDialog.h"
#include "core/function/gpg/GpgKeyGetter.h"
#include "core/function/gpg/GpgKeyImportExporter.h"
+#include "dialog/WaitingDialog.h"
#include "ui/SignalStation.h"
namespace GpgFrontend::UI {
@@ -152,7 +152,8 @@ KeyPairDetailTab::KeyPairDetailTab(const std::string& key_id, QWidget* parent)
mvbox->setContentsMargins(0, 0, 0, 0);
// when key database updated
- connect(SignalStation::GetInstance(), &SignalStation::SignalKeyDatabaseRefresh, this,
+ connect(SignalStation::GetInstance(),
+ &SignalStation::SignalKeyDatabaseRefreshDone, this,
&KeyPairDetailTab::slot_refresh_key);
slot_refresh_key_info();
@@ -169,11 +170,12 @@ void KeyPairDetailTab::slot_copy_fingerprint() {
void KeyPairDetailTab::slot_refresh_key_info() {
// Show the situation that primary key not exists.
- primary_key_exist_var_label_->setText(key_.IsHasMasterKey() ? _("Exists")
- : _("Not Exists"));
+ primary_key_exist_var_label_->setText(
+ key_.IsHasMasterKey() ? _("Exists") : _("Not Exists"));
if (!key_.IsHasMasterKey()) {
auto palette_expired = primary_key_exist_var_label_->palette();
- palette_expired.setColor(primary_key_exist_var_label_->foregroundRole(), Qt::red);
+ palette_expired.setColor(primary_key_exist_var_label_->foregroundRole(),
+ Qt::red);
primary_key_exist_var_label_->setPalette(palette_expired);
} else {
auto palette_valid = primary_key_exist_var_label_->palette();
diff --git a/src/ui/keypair_details/KeyPairSubkeyTab.cpp b/src/ui/keypair_details/KeyPairSubkeyTab.cpp
index 067ce110..46de550c 100644
--- a/src/ui/keypair_details/KeyPairSubkeyTab.cpp
+++ b/src/ui/keypair_details/KeyPairSubkeyTab.cpp
@@ -124,10 +124,10 @@ KeyPairSubkeyTab::KeyPairSubkeyTab(const std::string& key_id, QWidget* parent)
// key database refresh signal
connect(SignalStation::GetInstance(),
- &SignalStation::SignalKeyDatabaseRefresh, this,
+ &SignalStation::SignalKeyDatabaseRefreshDone, this,
&KeyPairSubkeyTab::slot_refresh_key_info);
connect(SignalStation::GetInstance(),
- &SignalStation::SignalKeyDatabaseRefresh, this,
+ &SignalStation::SignalKeyDatabaseRefreshDone, this,
&KeyPairSubkeyTab::slot_refresh_subkey_list);
baseLayout->setContentsMargins(0, 0, 0, 0);
diff --git a/src/ui/keypair_details/KeyPairUIDTab.cpp b/src/ui/keypair_details/KeyPairUIDTab.cpp
index 81d34684..4cc835a8 100644
--- a/src/ui/keypair_details/KeyPairUIDTab.cpp
+++ b/src/ui/keypair_details/KeyPairUIDTab.cpp
@@ -102,7 +102,7 @@ KeyPairUIDTab::KeyPairUIDTab(const std::string& key_id, QWidget* parent)
// Key Database Refresh
connect(SignalStation::GetInstance(),
- &SignalStation::SignalKeyDatabaseRefresh, this,
+ &SignalStation::SignalKeyDatabaseRefreshDone, this,
&KeyPairUIDTab::slot_refresh_key);
connect(this, &KeyPairUIDTab::SignalUpdateUIDInfo,
@@ -419,7 +419,7 @@ void KeyPairUIDTab::slot_set_primary_uid() {
if (ret == QMessageBox::Yes) {
if (!GpgUIDOperator::GetInstance().SetPrimaryUID(m_key_,
- selected_uids->front())) {
+ selected_uids->front())) {
QMessageBox::critical(nullptr, _("Operation Failed"),
_("An error occurred during the operation."));
} else {
diff --git a/src/ui/keypair_details/KeySetExpireDateDialog.cpp b/src/ui/keypair_details/KeySetExpireDateDialog.cpp
index 79325e8b..785dce14 100644
--- a/src/ui/keypair_details/KeySetExpireDateDialog.cpp
+++ b/src/ui/keypair_details/KeySetExpireDateDialog.cpp
@@ -30,10 +30,10 @@
#include <utility>
+#include "core/function/GlobalSettingStation.h"
#include "core/function/gpg/GpgKeyGetter.h"
#include "core/function/gpg/GpgKeyOpera.h"
#include "ui/SignalStation.h"
-#include "core/function/GlobalSettingStation.h"
#include "ui_ModifiedExpirationDateTime.h"
namespace GpgFrontend::UI {
@@ -72,21 +72,20 @@ 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(nullptr);
+ auto* msg_box = new QMessageBox((QWidget*)this->parent());
msg_box->setAttribute(Qt::WA_DeleteOnClose);
msg_box->setStandardButtons(QMessageBox::Ok);
msg_box->setWindowTitle(_("Success"));
msg_box->setText(_("The expire date of the key pair has been updated."));
- msg_box->setModal(false);
+ msg_box->setModal(true);
msg_box->open();
emit SignalKeyExpireDateUpdated();
+ this->close();
} else {
QMessageBox::critical(this, _("Failure"), _(gpgme_strerror(err)));
}
-
- this->close();
}
void KeySetExpireDateDialog::init() {
@@ -113,8 +112,11 @@ void KeySetExpireDateDialog::init() {
ui_->dateEdit->setMaximumDateTime(max_date_time);
ui_->dateEdit->setMinimumDateTime(min_date_time);
- ui_->dateEdit->setDateTime(max_date_time);
- ui_->timeEdit->setDateTime(max_date_time);
+ // set default date time to expire date time
+ auto current_expire_time =
+ QDateTime::fromTime_t(to_time_t(m_key_.GetExpireTime()));
+ ui_->dateEdit->setDateTime(current_expire_time);
+ ui_->timeEdit->setDateTime(current_expire_time);
connect(ui_->noExpirationCheckBox, &QCheckBox::stateChanged, this,
&KeySetExpireDateDialog::slot_non_expired_checked);
diff --git a/src/ui/main_window/MainWindowSlotFunction.cpp b/src/ui/main_window/MainWindowSlotFunction.cpp
index 0a322f6a..a1db4d61 100644
--- a/src/ui/main_window/MainWindowSlotFunction.cpp
+++ b/src/ui/main_window/MainWindowSlotFunction.cpp
@@ -27,7 +27,6 @@
*/
#include "MainWindow.h"
-
#include "core/function/GlobalSettingStation.h"
#include "core/function/gpg/GpgBasicOperator.h"
#include "core/function/gpg/GpgKeyGetter.h"
@@ -74,7 +73,7 @@ void MainWindow::slot_encrypt() {
}
});
} else {
- auto key_getter = GpgFrontend::GpgKeyGetter::GetInstance();
+ auto& key_getter = GpgFrontend::GpgKeyGetter::GetInstance();
auto keys = GpgKeyGetter::GetInstance().GetKeys(key_ids);
for (const auto& key : *keys) {
if (!key.IsHasActualEncryptionCapability()) {
diff --git a/src/ui/widgets/KeyList.cpp b/src/ui/widgets/KeyList.cpp
index 6292c1a9..237576ad 100644
--- a/src/ui/widgets/KeyList.cpp
+++ b/src/ui/widgets/KeyList.cpp
@@ -29,6 +29,7 @@
#include "ui/widgets/KeyList.h"
#include <boost/format.hpp>
+#include <mutex>
#include <utility>
#include "core/GpgCoreInit.h"
@@ -63,7 +64,7 @@ void KeyList::init() {
connect(this, &KeyList::SignalRefreshDatabase, SignalStation::GetInstance(),
&SignalStation::SignalKeyDatabaseRefresh);
connect(SignalStation::GetInstance(),
- &SignalStation::SignalKeyDatabaseRefresh, this,
+ &SignalStation::SignalKeyDatabaseRefreshDone, this,
&KeyList::SlotRefresh);
connect(ui_->refreshKeyListButton, &QPushButton::clicked, this,
&KeyList::SlotRefresh);
@@ -154,19 +155,15 @@ void KeyList::AddListGroupTab(
}
void KeyList::SlotRefresh() {
- LOG(INFO) << _("Called");
- emit SignalRefreshStatusBar(_("Refreshing Key List..."), 3000);
- auto thread = QThread::create([this]() {
- std::lock_guard<std::mutex> guard(buffered_key_list_mutex_);
- buffered_keys_list_ = nullptr;
- // buffered keys list
- buffered_keys_list_ = GpgKeyGetter::GetInstance().FetchKey();
- });
- connect(thread, &QThread::finished, this, &KeyList::slot_refresh_ui);
- connect(thread, &QThread::finished, thread, &QThread::deleteLater);
+ LOG(INFO) << _("Called") << "address" << this;
+
ui_->refreshKeyListButton->setDisabled(true);
ui_->syncButton->setDisabled(true);
- thread->start();
+
+ emit SignalRefreshStatusBar(_("Refreshing Key List..."), 3000);
+
+ this->buffered_keys_list_ = GpgKeyGetter::GetInstance().FetchKey();
+ this->slot_refresh_ui();
}
KeyIdArgsListPtr KeyList::GetChecked(const KeyTable& key_table) {
@@ -424,7 +421,8 @@ void KeyList::slot_refresh_ui() {
if (buffered_keys_list_ != nullptr) {
std::lock_guard<std::mutex> guard(buffered_key_list_mutex_);
for (auto& key_table : m_key_tables_) {
- key_table.Refresh(GpgKeyGetter::GetKeysCopy(buffered_keys_list_));
+ key_table.Refresh(
+ GpgKeyGetter::GetInstance().GetKeysCopy(buffered_keys_list_));
}
}
emit SignalRefreshStatusBar(_("Key List Refreshed."), 1000);