diff options
Diffstat (limited to 'src/ui/dialog')
-rw-r--r-- | src/ui/dialog/ADSKsPicker.cpp | 55 | ||||
-rw-r--r-- | src/ui/dialog/ADSKsPicker.h | 13 | ||||
-rw-r--r-- | src/ui/dialog/KeyGroupCreationDialog.cpp | 31 | ||||
-rw-r--r-- | src/ui/dialog/KeyGroupManageDialog.cpp | 28 | ||||
-rw-r--r-- | src/ui/dialog/KeyGroupManageDialog.h | 12 | ||||
-rw-r--r-- | src/ui/dialog/import_export/KeyImportDetailDialog.cpp | 12 | ||||
-rw-r--r-- | src/ui/dialog/import_export/KeyServerImportDialog.cpp | 12 | ||||
-rw-r--r-- | src/ui/dialog/import_export/KeyUploadDialog.cpp | 1 | ||||
-rw-r--r-- | src/ui/dialog/key_generate/SubkeyGenerateDialog.cpp | 1 | ||||
-rw-r--r-- | src/ui/dialog/keypair_details/KeyNewUIDDialog.cpp | 2 | ||||
-rw-r--r-- | src/ui/dialog/keypair_details/KeyPairDetailTab.cpp | 2 | ||||
-rw-r--r-- | src/ui/dialog/keypair_details/KeyPairOperaTab.cpp | 148 | ||||
-rw-r--r-- | src/ui/dialog/keypair_details/KeyPairOperaTab.h | 11 | ||||
-rw-r--r-- | src/ui/dialog/keypair_details/KeyPairSubkeyTab.cpp | 51 | ||||
-rw-r--r-- | src/ui/dialog/keypair_details/KeyPairUIDTab.cpp | 2 | ||||
-rw-r--r-- | src/ui/dialog/keypair_details/KeySetExpireDateDialog.cpp | 2 |
16 files changed, 207 insertions, 176 deletions
diff --git a/src/ui/dialog/ADSKsPicker.cpp b/src/ui/dialog/ADSKsPicker.cpp index 9d9fa4c3..09648355 100644 --- a/src/ui/dialog/ADSKsPicker.cpp +++ b/src/ui/dialog/ADSKsPicker.cpp @@ -28,12 +28,14 @@ #include "ADSKsPicker.h" -#include "core/GpgModel.h" +#include "core/function/gpg/GpgKeyOpera.h" +#include "core/utils/GpgUtils.h" +#include "ui/UISignalStation.h" #include "ui/widgets/KeyTreeView.h" namespace GpgFrontend::UI { -ADSKsPicker::ADSKsPicker(int channel, +ADSKsPicker::ADSKsPicker(int channel, GpgKeyPtr key, const GpgKeyTreeProxyModel::KeyFilter& filter, QWidget* parent) : GeneralDialog(typeid(ADSKsPicker).name(), parent), @@ -47,14 +49,22 @@ ADSKsPicker::ADSKsPicker(int channel, (k->KeyType() == GpgAbstractKeyType::kGPG_SUBKEY && k->IsHasEncrCap())) && filter(k); - })) { + })), + channel_(channel), + key_(std::move(key)) { auto* confirm_button = new QPushButton(tr("Confirm")); auto* cancel_button = new QPushButton(tr("Cancel")); connect(confirm_button, &QPushButton::clicked, this, [=]() { - emit SignalSubkeyChecked(tree_view_->GetAllCheckedSubKey()); + if (tree_view_->GetAllCheckedSubKey().isEmpty()) { + QMessageBox::information(this, tr("No Subkeys Selected"), + tr("Please select at least one s_key.")); + + return; + } + slot_add_adsk(tree_view_->GetAllCheckedSubKey()); + accept(); }); - connect(confirm_button, &QPushButton::clicked, this, &QDialog::accept); connect(cancel_button, &QPushButton::clicked, this, &QDialog::reject); tree_view_->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); @@ -88,4 +98,39 @@ ADSKsPicker::ADSKsPicker(int channel, this->activateWindow(); } +void ADSKsPicker::slot_add_adsk(const QContainer<GpgSubKey>& s_keys) { + QContainer<QString> err_sub_key_infos; + for (const auto& s_key : s_keys) { + auto [err, data_object] = + GpgKeyOpera::GetInstance(channel_).AddADSKSync(key_, s_key); + if (CheckGpgError(err) == GPG_ERR_NO_ERROR) continue; + + err_sub_key_infos.append(tr("Key ID: %1 Reason: %2") + .arg(s_key.ID()) + .arg(DescribeGpgErrCode(err).second)); + } + + if (!err_sub_key_infos.isEmpty()) { + QStringList failed_info; + for (const auto& info : err_sub_key_infos) { + failed_info.append(info); + } + QString details = failed_info.join("\n\n"); + + auto* msg_box = new QMessageBox(nullptr); + msg_box->setIcon(QMessageBox::Warning); + msg_box->setWindowTitle(err_sub_key_infos.size() == s_keys.size() + ? tr("Failed") + : tr("Partially Failed")); + msg_box->setText(err_sub_key_infos.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->show(); + + return; + } + + emit UISignalStation::GetInstance() -> SignalKeyDatabaseRefresh(); +} } // namespace GpgFrontend::UI diff --git a/src/ui/dialog/ADSKsPicker.h b/src/ui/dialog/ADSKsPicker.h index 59c7b06b..577ac06a 100644 --- a/src/ui/dialog/ADSKsPicker.h +++ b/src/ui/dialog/ADSKsPicker.h @@ -50,16 +50,23 @@ class ADSKsPicker : public GeneralDialog { * * @param parent */ - explicit ADSKsPicker(int channel, + explicit ADSKsPicker(int channel, GpgKeyPtr key, const GpgKeyTreeProxyModel::KeyFilter& filter, QWidget* parent = nullptr); - signals: - void SignalSubkeyChecked(QContainer<GpgSubKey>); + private slots: + /** + * @brief + * + * @param s_keys + */ + void slot_add_adsk(const QContainer<GpgSubKey>& s_keys); private: KeyTreeView* tree_view_; ///< bool accepted_ = false; + int channel_; + GpgKeyPtr key_; }; } // namespace GpgFrontend::UI diff --git a/src/ui/dialog/KeyGroupCreationDialog.cpp b/src/ui/dialog/KeyGroupCreationDialog.cpp index 506c173d..16e34536 100644 --- a/src/ui/dialog/KeyGroupCreationDialog.cpp +++ b/src/ui/dialog/KeyGroupCreationDialog.cpp @@ -46,20 +46,29 @@ KeyGroupCreationDialog::KeyGroupCreationDialog(int channel, QStringList key_ids, email_->setMinimumWidth(240); comment_ = new QLineEdit(); comment_->setMinimumWidth(240); - create_button_ = new QPushButton("Create"); + create_button_ = new QPushButton(tr("Create")); error_label_ = new QLabel(); auto* grid_layout = new QGridLayout(); - grid_layout->addWidget(new QLabel(tr("Name")), 0, 0); - grid_layout->addWidget(new QLabel(tr("Email")), 1, 0); - grid_layout->addWidget(new QLabel(tr("Comment")), 2, 0); - grid_layout->addWidget(name_, 0, 1); - grid_layout->addWidget(email_, 1, 1); - grid_layout->addWidget(comment_, 2, 1); + auto* description_label = new QLabel(tr( + "A Key Group is a collection of keys. It allows you to encrypt data for " + "multiple recipients at once by grouping their public keys together.")); + description_label->setWordWrap(true); + description_label->setStyleSheet("color: gray; font-size: 11px;"); - grid_layout->addWidget(create_button_, 3, 0, 1, 2); - grid_layout->addWidget(error_label_, 4, 0, 1, 2); + grid_layout->addWidget(description_label, 0, 0, 2, 2); + + grid_layout->addWidget(new QLabel(tr("Name")), 2, 0); + grid_layout->addWidget(new QLabel(tr("Email")), 3, 0); + grid_layout->addWidget(new QLabel(tr("Comment")), 4, 0); + + grid_layout->addWidget(name_, 2, 1); + grid_layout->addWidget(email_, 3, 1); + grid_layout->addWidget(comment_, 4, 1); + + grid_layout->addWidget(create_button_, 5, 0, 1, 2); + grid_layout->addWidget(error_label_, 6, 0, 1, 2); connect(create_button_, &QPushButton::clicked, this, &KeyGroupCreationDialog::slot_create_new_uid); @@ -68,8 +77,10 @@ KeyGroupCreationDialog::KeyGroupCreationDialog(int channel, QStringList key_ids, UISignalStation::GetInstance(), &UISignalStation::SignalKeyDatabaseRefresh); + setMinimumHeight(250); + this->setLayout(grid_layout); - this->setWindowTitle(tr("Create New Key Group")); + this->setWindowTitle(tr("New Key Group")); this->setAttribute(Qt::WA_DeleteOnClose, true); this->setModal(true); } diff --git a/src/ui/dialog/KeyGroupManageDialog.cpp b/src/ui/dialog/KeyGroupManageDialog.cpp index cbd70b61..88892ada 100644 --- a/src/ui/dialog/KeyGroupManageDialog.cpp +++ b/src/ui/dialog/KeyGroupManageDialog.cpp @@ -54,7 +54,8 @@ KeyGroupManageDialog::KeyGroupManageDialog( ui_->keyGroupKeyList->Init( channel, KeyMenuAbility::kCOLUMN_FILTER | KeyMenuAbility::kSEARCH_BAR, GpgKeyTableColumn::kTYPE | GpgKeyTableColumn::kNAME | - GpgKeyTableColumn::kEMAIL_ADDRESS | GpgKeyTableColumn::kKEY_ID); + GpgKeyTableColumn::kEMAIL_ADDRESS | GpgKeyTableColumn::kKEY_ID | + GpgKeyTableColumn::kUSAGE); ui_->keyGroupKeyList->AddListGroupTab( tr("Key Group"), "key-group", GpgKeyTableDisplayMode::kPRIVATE_KEY | @@ -78,6 +79,14 @@ KeyGroupManageDialog::KeyGroupManageDialog( }); ui_->keyList->SlotRefresh(); + connect(ui_->keyList, &KeyList::SignalKeyChecked, this, + &KeyGroupManageDialog::slot_set_add_button_state); + connect(ui_->keyGroupKeyList, &KeyList::SignalKeyChecked, this, + &KeyGroupManageDialog::slot_set_remove_button_state); + + ui_->addButton->setDisabled(true); + ui_->removeButton->setDisabled(true); + QTimer::singleShot(200, [=]() { slot_notify_invalid_key_ids(); }); this->setModal(true); @@ -104,6 +113,8 @@ void KeyGroupManageDialog::slot_add_to_key_group() { ui_->keyGroupKeyList->RefreshKeyTable(0); ui_->keyList->RefreshKeyTable(0); + slot_set_add_button_state(); + slot_set_remove_button_state(); if (!failed_keys.isEmpty()) { QStringList failed_ids; @@ -127,6 +138,8 @@ void KeyGroupManageDialog::slot_remove_from_key_group() { ui_->keyGroupKeyList->RefreshKeyTable(0); ui_->keyList->RefreshKeyTable(0); + slot_set_add_button_state(); + slot_set_remove_button_state(); } void KeyGroupManageDialog::slot_notify_invalid_key_ids() { @@ -138,9 +151,7 @@ void KeyGroupManageDialog::slot_notify_invalid_key_ids() { if (key == nullptr) invalid_key_ids.push_back(key_id); } - if (invalid_key_ids.isEmpty()) { - return; - } + if (invalid_key_ids.isEmpty()) return; const QString id_list = invalid_key_ids.join(", "); const auto message = @@ -163,4 +174,13 @@ void KeyGroupManageDialog::slot_notify_invalid_key_ids() { emit UISignalStation::GetInstance() -> SignalKeyDatabaseRefresh(); } + +void KeyGroupManageDialog::slot_set_add_button_state() { + ui_->addButton->setDisabled(ui_->keyList->GetCheckedKeys().isEmpty()); +} + +void KeyGroupManageDialog::slot_set_remove_button_state() { + ui_->removeButton->setDisabled( + ui_->keyGroupKeyList->GetCheckedKeys().isEmpty()); +} } // namespace GpgFrontend::UI diff --git a/src/ui/dialog/KeyGroupManageDialog.h b/src/ui/dialog/KeyGroupManageDialog.h index 66211d28..902bbb59 100644 --- a/src/ui/dialog/KeyGroupManageDialog.h +++ b/src/ui/dialog/KeyGroupManageDialog.h @@ -74,6 +74,18 @@ class KeyGroupManageDialog : public GeneralDialog { */ void slot_notify_invalid_key_ids(); + /** + * @brief + * + */ + void slot_set_add_button_state(); + + /** + * @brief + * + */ + void slot_set_remove_button_state(); + private: QSharedPointer<Ui_KeyGroupManageDialog> ui_; ///< int channel_; diff --git a/src/ui/dialog/import_export/KeyImportDetailDialog.cpp b/src/ui/dialog/import_export/KeyImportDetailDialog.cpp index 24062796..92e45eb6 100644 --- a/src/ui/dialog/import_export/KeyImportDetailDialog.cpp +++ b/src/ui/dialog/import_export/KeyImportDetailDialog.cpp @@ -28,7 +28,7 @@ #include "KeyImportDetailDialog.h" -#include "core/function/gpg/GpgKeyGetter.h" +#include "core/function/gpg/GpgAbstractKeyGetter.h" #include "core/model/GpgImportInformation.h" namespace GpgFrontend::UI { @@ -147,11 +147,13 @@ void KeyImportDetailDialog::create_keys_table() { int row = 0; for (const auto& imp_key : m_result_->imported_keys) { keys_table_->setRowCount(row + 1); - auto key = GpgKeyGetter::GetInstance(current_gpg_context_channel_) + + auto key = GpgAbstractKeyGetter::GetInstance(current_gpg_context_channel_) .GetKey(imp_key.fpr); - if (!key.IsGood()) continue; - keys_table_->setItem(row, 0, new QTableWidgetItem(key.Name())); - keys_table_->setItem(row, 1, new QTableWidgetItem(key.Email())); + if (key == nullptr) continue; + + keys_table_->setItem(row, 0, new QTableWidgetItem(key->Name())); + keys_table_->setItem(row, 1, new QTableWidgetItem(key->Email())); keys_table_->setItem( row, 2, new QTableWidgetItem(get_status_string(imp_key.import_status))); keys_table_->setItem(row, 3, new QTableWidgetItem(imp_key.fpr)); diff --git a/src/ui/dialog/import_export/KeyServerImportDialog.cpp b/src/ui/dialog/import_export/KeyServerImportDialog.cpp index 03ee6c4a..8e01bd4b 100644 --- a/src/ui/dialog/import_export/KeyServerImportDialog.cpp +++ b/src/ui/dialog/import_export/KeyServerImportDialog.cpp @@ -422,10 +422,14 @@ void KeyServerImportDialog::slot_import_finished( // refresh the key database emit SignalKeyImported(); - // show details - (new KeyImportDetailDialog(current_gpg_context_channel_, std::move(info), - this)) - ->exec(); + auto* connection = new QMetaObject::Connection; + *connection = connect( + UISignalStation::GetInstance(), + &UISignalStation::SignalKeyDatabaseRefreshDone, this, [=]() { + (new KeyImportDetailDialog(current_gpg_context_channel_, info, this)); + QObject::disconnect(*connection); + delete connection; + }); } void KeyServerImportDialog::set_loading(bool status) { diff --git a/src/ui/dialog/import_export/KeyUploadDialog.cpp b/src/ui/dialog/import_export/KeyUploadDialog.cpp index 346be765..8abcc8de 100644 --- a/src/ui/dialog/import_export/KeyUploadDialog.cpp +++ b/src/ui/dialog/import_export/KeyUploadDialog.cpp @@ -29,7 +29,6 @@ #include "KeyUploadDialog.h" #include <QtNetwork> -#include <utility> #include "core/function/gpg/GpgKeyImportExporter.h" #include "core/model/SettingsObject.h" diff --git a/src/ui/dialog/key_generate/SubkeyGenerateDialog.cpp b/src/ui/dialog/key_generate/SubkeyGenerateDialog.cpp index 662ac77a..b182e017 100644 --- a/src/ui/dialog/key_generate/SubkeyGenerateDialog.cpp +++ b/src/ui/dialog/key_generate/SubkeyGenerateDialog.cpp @@ -30,7 +30,6 @@ #include <cassert> #include <cstddef> -#include <utility> #include "core/function/gpg/GpgKeyOpera.h" #include "core/utils/GpgUtils.h" 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" |