aboutsummaryrefslogtreecommitdiffstats
path: root/src/ui/dialog/keypair_details
diff options
context:
space:
mode:
Diffstat (limited to 'src/ui/dialog/keypair_details')
-rw-r--r--src/ui/dialog/keypair_details/KeyNewUIDDialog.cpp2
-rw-r--r--src/ui/dialog/keypair_details/KeyPairDetailTab.cpp2
-rw-r--r--src/ui/dialog/keypair_details/KeyPairOperaTab.cpp148
-rw-r--r--src/ui/dialog/keypair_details/KeyPairOperaTab.h11
-rw-r--r--src/ui/dialog/keypair_details/KeyPairSubkeyTab.cpp51
-rw-r--r--src/ui/dialog/keypair_details/KeyPairUIDTab.cpp2
-rw-r--r--src/ui/dialog/keypair_details/KeySetExpireDateDialog.cpp2
7 files changed, 75 insertions, 143 deletions
diff --git a/src/ui/dialog/keypair_details/KeyNewUIDDialog.cpp b/src/ui/dialog/keypair_details/KeyNewUIDDialog.cpp
index d05154d5..6a6745da 100644
--- a/src/ui/dialog/keypair_details/KeyNewUIDDialog.cpp
+++ b/src/ui/dialog/keypair_details/KeyNewUIDDialog.cpp
@@ -28,8 +28,6 @@
#include "KeyNewUIDDialog.h"
-#include <utility>
-
#include "core/function/gpg/GpgUIDOperator.h"
#include "ui/UISignalStation.h"
diff --git a/src/ui/dialog/keypair_details/KeyPairDetailTab.cpp b/src/ui/dialog/keypair_details/KeyPairDetailTab.cpp
index fcdc139e..b5a6c1d2 100644
--- a/src/ui/dialog/keypair_details/KeyPairDetailTab.cpp
+++ b/src/ui/dialog/keypair_details/KeyPairDetailTab.cpp
@@ -28,8 +28,6 @@
#include "KeyPairDetailTab.h"
-#include <utility>
-
#include "core/function/GlobalSettingStation.h"
#include "core/function/gpg/GpgKeyGetter.h"
#include "core/model/GpgKey.h"
diff --git a/src/ui/dialog/keypair_details/KeyPairOperaTab.cpp b/src/ui/dialog/keypair_details/KeyPairOperaTab.cpp
index dddbb545..a06ec835 100644
--- a/src/ui/dialog/keypair_details/KeyPairOperaTab.cpp
+++ b/src/ui/dialog/keypair_details/KeyPairOperaTab.cpp
@@ -34,6 +34,7 @@
#include "core/function/gpg/GpgKeyOpera.h"
#include "core/model/GpgKey.h"
#include "core/module/ModuleManager.h"
+#include "core/thread/TaskRunnerGetter.h"
#include "core/typedef/GpgTypedef.h"
#include "core/utils/GpgUtils.h"
#include "core/utils/IOUtils.h"
@@ -131,8 +132,9 @@ KeyPairOperaTab::KeyPairOperaTab(int channel, GpgKeyPtr key, QWidget* parent)
opera_key_box->setLayout(vbox_p_k);
m_vbox->addWidget(opera_key_box);
// modify owner trust of public key
- if (!m_key_->IsPrivateKey())
+ if (!m_key_->IsPrivateKey()) {
vbox_p_k->addWidget(set_owner_trust_level_button);
+ }
vbox_p_k->addWidget(modify_tofu_button);
m_vbox->addStretch(0);
@@ -212,37 +214,68 @@ void KeyPairOperaTab::CreateOperaMenu() {
rev_cert_opera_menu_->addAction(rev_cert_gen_action);
}
-void KeyPairOperaTab::slot_export_public_key() {
- auto [err, gf_buffer] =
- GpgKeyImportExporter::GetInstance(current_gpg_context_channel_)
- .ExportKey(m_key_, false, true, false);
- if (CheckGpgError(err) != GPG_ERR_NO_ERROR) {
- CommonUtils::RaiseMessageBox(this, err);
- return;
- }
+void KeyPairOperaTab::slot_export_key(bool secret, bool ascii, bool shortest,
+ const QString& type) {
+ auto* task = new Thread::Task(
+ [=](const DataObjectPtr& data_object) -> int {
+ auto [err, gf_buffer] =
+ GpgKeyImportExporter::GetInstance(current_gpg_context_channel_)
+ .ExportKey(m_key_, secret, ascii, shortest);
+ data_object->Swap({err, gf_buffer});
+ return 0;
+ },
+ "key_export", TransferParams(),
+ [=](int ret, const DataObjectPtr& data_object) {
+ if (ret < 0) {
+ QMessageBox::critical(
+ this, tr("Unknown Error"),
+ tr("Caught unknown error while exporting the key."));
+ return;
+ }
- // generate a file name
+ // generate a file name
#if defined(_WIN32) || defined(WIN32)
-
- auto file_string = m_key_->Name() + "[" + m_key_->Email() + "](" +
- m_key_->ID() + ")_pub.asc";
+ auto file_name = QString("%1[%2](%3)_%4.asc");
#else
- auto file_string = m_key_->Name() + "<" + m_key_->Email() + ">(" +
- m_key_->ID() + ")_pub.asc";
+ auto file_name = QString("%1<%2[(%3)_%4.asc");
#endif
- std::replace(file_string.begin(), file_string.end(), ' ', '_');
- auto file_name = QFileDialog::getSaveFileName(
- this, tr("Export Key To File"), file_string,
- tr("Key Files") + " (*.asc *.txt);;All Files (*)");
+ file_name =
+ file_name.arg(m_key_->Name(), m_key_->Email(), m_key_->ID(), type);
- if (file_name.isEmpty()) return;
+ if (!data_object->Check<GpgError, GFBuffer>()) return;
- if (!WriteFileGFBuffer(file_name, gf_buffer)) {
- QMessageBox::critical(this, tr("Export Error"),
- tr("Couldn't open %1 for writing").arg(file_name));
- return;
- }
+ auto err = ExtractParams<GpgError>(data_object, 0);
+ auto gf_buffer = ExtractParams<GFBuffer>(data_object, 1);
+
+ if (CheckGpgError(err) != GPG_ERR_NO_ERROR) {
+ CommonUtils::RaiseMessageBox(this, err);
+ return;
+ }
+
+ file_name.replace(' ', '_');
+
+ auto filepath = QFileDialog::getSaveFileName(
+ this, tr("Export Key To File"), file_name,
+ tr("Key Files") + " (*.asc *.txt);;All Files (*)");
+
+ if (filepath.isEmpty()) return;
+
+ if (!WriteFileGFBuffer(filepath, gf_buffer)) {
+ QMessageBox::critical(
+ this, tr("Export Error"),
+ tr("Couldn't open %1 for writing").arg(file_name));
+ return;
+ }
+ });
+
+ Thread::TaskRunnerGetter::GetInstance()
+ .GetTaskRunner(Thread::TaskRunnerGetter::kTaskRunnerType_GPG)
+ ->PostTask(task);
+}
+
+void KeyPairOperaTab::slot_export_public_key() {
+ slot_export_key(false, true, false, "pub");
}
void KeyPairOperaTab::slot_export_short_private_key() {
@@ -261,38 +294,9 @@ void KeyPairOperaTab::slot_export_short_private_key() {
QMessageBox::Cancel | QMessageBox::Ok);
// export key, if ok was clicked
- if (ret == QMessageBox::Ok) {
- auto [err, gf_buffer] =
- GpgKeyImportExporter::GetInstance(current_gpg_context_channel_)
- .ExportKey(m_key_, true, true, true);
- if (CheckGpgError(err) != GPG_ERR_NO_ERROR) {
- CommonUtils::RaiseMessageBox(this, err);
- return;
- }
-
- // generate a file name
-#if defined(_WIN32) || defined(WIN32)
-
- auto file_string = m_key_->Name() + "[" + m_key_->Email() + "](" +
- m_key_->ID() + ")_short_secret.asc";
-#else
- auto file_string = m_key_->Name() + "<" + m_key_->Email() + ">(" +
- m_key_->ID() + ")_short_secret.asc";
-#endif
- std::replace(file_string.begin(), file_string.end(), ' ', '_');
-
- auto file_name = QFileDialog::getSaveFileName(
- this, tr("Export Key To File"), file_string,
- tr("Key Files") + " (*.asc *.txt);;All Files (*)");
-
- if (file_name.isEmpty()) return;
+ if (ret != QMessageBox::Ok) return;
- if (!WriteFileGFBuffer(file_name, gf_buffer)) {
- QMessageBox::critical(this, tr("Export Error"),
- tr("Couldn't open %1 for writing").arg(file_name));
- return;
- }
- }
+ slot_export_key(true, true, false, "short_secret");
}
void KeyPairOperaTab::slot_export_private_key() {
@@ -313,37 +317,9 @@ void KeyPairOperaTab::slot_export_private_key() {
QMessageBox::Cancel | QMessageBox::Ok);
// export key, if ok was clicked
- if (ret == QMessageBox::Ok) {
- auto [err, gf_buffer] =
- GpgKeyImportExporter::GetInstance(current_gpg_context_channel_)
- .ExportKey(m_key_, true, true, false);
- if (CheckGpgError(err) != GPG_ERR_NO_ERROR) {
- CommonUtils::RaiseMessageBox(this, err);
- return;
- }
-
- // generate a file name
-#if defined(_WIN32) || defined(WIN32)
- auto file_string = m_key_->Name() + "[" + m_key_->Email() + "](" +
- m_key_->ID() + ")_full_secret.asc";
-#else
- auto file_string = m_key_->Name() + "<" + m_key_->Email() + ">(" +
- m_key_->ID() + ")_full_secret.asc";
-#endif
- std::replace(file_string.begin(), file_string.end(), ' ', '_');
-
- auto file_name = QFileDialog::getSaveFileName(
- this, tr("Export Key To File"), file_string,
- tr("Key Files") + " (*.asc *.txt);;All Files (*)");
-
- if (file_name.isEmpty()) return;
+ if (ret != QMessageBox::Ok) return;
- if (!WriteFileGFBuffer(file_name, gf_buffer)) {
- QMessageBox::critical(this, tr("Export Error"),
- tr("Couldn't open %1 for writing").arg(file_name));
- return;
- }
- }
+ slot_export_key(true, true, false, "full_secret");
}
void KeyPairOperaTab::slot_modify_edit_datetime() {
diff --git a/src/ui/dialog/keypair_details/KeyPairOperaTab.h b/src/ui/dialog/keypair_details/KeyPairOperaTab.h
index 729a7d74..02566b61 100644
--- a/src/ui/dialog/keypair_details/KeyPairOperaTab.h
+++ b/src/ui/dialog/keypair_details/KeyPairOperaTab.h
@@ -138,6 +138,17 @@ class KeyPairOperaTab : public QWidget {
*/
void slot_import_paper_key();
+ /**
+ * @brief
+ *
+ * @param secret
+ * @param ascii
+ * @param shortest
+ * @param type
+ */
+ void slot_export_key(bool secret, bool ascii, bool shortest,
+ const QString& type);
+
private:
int current_gpg_context_channel_;
GpgKeyPtr m_key_; ///<
diff --git a/src/ui/dialog/keypair_details/KeyPairSubkeyTab.cpp b/src/ui/dialog/keypair_details/KeyPairSubkeyTab.cpp
index fa0c5c34..90bd3537 100644
--- a/src/ui/dialog/keypair_details/KeyPairSubkeyTab.cpp
+++ b/src/ui/dialog/keypair_details/KeyPairSubkeyTab.cpp
@@ -28,8 +28,6 @@
#include "KeyPairSubkeyTab.h"
-#include <utility>
-
#include "core/function/gpg/GpgKeyGetter.h"
#include "core/function/gpg/GpgKeyImportExporter.h"
#include "core/function/gpg/GpgKeyManager.h"
@@ -291,57 +289,12 @@ void KeyPairSubkeyTab::slot_add_adsk() {
except_key_ids.append(s_key.ID());
}
- auto* dialog = new ADSKsPicker(
- current_gpg_context_channel_,
+ new ADSKsPicker(
+ current_gpg_context_channel_, key_,
[=](const GpgAbstractKey* key) {
return !except_key_ids.contains(key->ID());
},
this);
-
- connect(dialog, &ADSKsPicker::SignalSubkeyChecked, this,
- [=](const QContainer<GpgSubKey>& s_keys) {
- if (s_keys.isEmpty()) {
- QMessageBox::information(this, tr("No Subkeys Selected"),
- tr("Please select at least one s_key."));
-
- return;
- }
-
- QContainer<GpgSubKey> err_sub_keys;
- for (const auto& s_key : s_keys) {
- auto [err, data_object] =
- GpgKeyOpera::GetInstance(current_gpg_context_channel_)
- .AddADSKSync(key_, s_key);
- if (CheckGpgError(err) == GPG_ERR_NO_ERROR) continue;
-
- err_sub_keys.append(s_key);
- }
-
- if (!err_sub_keys.isEmpty()) {
- QStringList failed_info;
- for (const auto& s_key : err_sub_keys) {
- QString key_id = s_key.ID();
- failed_info << tr("Key ID: %1").arg(key_id);
- }
-
- QString details = failed_info.join("\n\n");
-
- QMessageBox msg_box(this);
- msg_box.setIcon(QMessageBox::Warning);
- msg_box.setWindowTitle(err_sub_keys.size() == s_keys.size()
- ? tr("Failed")
- : tr("Partially Failed"));
- msg_box.setText(
- err_sub_keys.size() == s_keys.size()
- ? tr("Failed to add all selected subkeys.")
- : tr("Some subkeys failed to be added as ADSKs."));
- msg_box.setDetailedText(details);
- msg_box.exec();
- }
-
- emit SignalKeyDatabaseRefresh();
- });
- dialog->show();
}
void KeyPairSubkeyTab::slot_refresh_subkey_detail() {
diff --git a/src/ui/dialog/keypair_details/KeyPairUIDTab.cpp b/src/ui/dialog/keypair_details/KeyPairUIDTab.cpp
index e720b9b0..bc9e422c 100644
--- a/src/ui/dialog/keypair_details/KeyPairUIDTab.cpp
+++ b/src/ui/dialog/keypair_details/KeyPairUIDTab.cpp
@@ -28,8 +28,6 @@
#include "KeyPairUIDTab.h"
-#include <utility>
-
#include "core/function/gpg/GpgKeyGetter.h"
#include "core/function/gpg/GpgKeyManager.h"
#include "core/function/gpg/GpgUIDOperator.h"
diff --git a/src/ui/dialog/keypair_details/KeySetExpireDateDialog.cpp b/src/ui/dialog/keypair_details/KeySetExpireDateDialog.cpp
index b2d8d424..b1a33450 100644
--- a/src/ui/dialog/keypair_details/KeySetExpireDateDialog.cpp
+++ b/src/ui/dialog/keypair_details/KeySetExpireDateDialog.cpp
@@ -28,8 +28,6 @@
#include "KeySetExpireDateDialog.h"
-#include <utility>
-
#include "core/function/GlobalSettingStation.h"
#include "core/function/gpg/GpgKeyOpera.h"
#include "core/utils/GpgUtils.h"