diff --git a/src/core/function/KeyPackageOperator.cpp b/src/core/function/KeyPackageOperator.cpp index c5c573ce..ace277b8 100644 --- a/src/core/function/KeyPackageOperator.cpp +++ b/src/core/function/KeyPackageOperator.cpp @@ -51,10 +51,11 @@ auto KeyPackageOperator::GeneratePassphrase(const QString& phrase_path, void KeyPackageOperator::GenerateKeyPackage(const QString& key_package_path, const QString& key_package_name, + int channel, const KeyArgsList& keys, QString& phrase, bool secret, const OperationCallback& cb) { - GpgKeyImportExporter::GetInstance().ExportAllKeys( + GpgKeyImportExporter::GetInstance(channel).ExportAllKeys( keys, secret, true, [=](GpgError err, const DataObjectPtr& data_obj) { if (CheckGpgError(err) != GPG_ERR_NO_ERROR) { LOG_W() << "export keys error, reason: " @@ -86,6 +87,7 @@ void KeyPackageOperator::GenerateKeyPackage(const QString& key_package_path, void KeyPackageOperator::ImportKeyPackage(const QString& key_package_path, const QString& phrase_path, + int channel, const OperationCallback& cb) { RunOperaAsync( [=](const DataObjectPtr& data_object) -> GFError { @@ -120,7 +122,8 @@ void KeyPackageOperator::ImportKeyPackage(const QString& key_package_path, } auto import_info_ptr = - GpgKeyImportExporter::GetInstance().ImportKey(GFBuffer(key_data)); + GpgKeyImportExporter::GetInstance(channel).ImportKey( + GFBuffer(key_data)); if (import_info_ptr == nullptr) return GPG_ERR_NO_DATA; auto import_info = *import_info_ptr; diff --git a/src/core/function/KeyPackageOperator.h b/src/core/function/KeyPackageOperator.h index 33d389ea..82bb65c1 100644 --- a/src/core/function/KeyPackageOperator.h +++ b/src/core/function/KeyPackageOperator.h @@ -69,7 +69,7 @@ class GPGFRONTEND_CORE_EXPORT KeyPackageOperator { * @return false if key package was not generated */ static void GenerateKeyPackage(const QString &key_package_path, - const QString &key_package_name, + const QString &key_package_name, int channel, const KeyArgsList &keys, QString &phrase, bool secret, const OperationCallback &cb); @@ -83,7 +83,7 @@ class GPGFRONTEND_CORE_EXPORT KeyPackageOperator { * @return false if key package was not imported */ static void ImportKeyPackage(const QString &key_package_path, - const QString &phrase_path, + const QString &phrase_path, int channel, const OperationCallback &cb); private: diff --git a/src/core/function/gpg/GpgFileOpera.cpp b/src/core/function/gpg/GpgFileOpera.cpp index d2cdff9b..5d29364b 100644 --- a/src/core/function/gpg/GpgFileOpera.cpp +++ b/src/core/function/gpg/GpgFileOpera.cpp @@ -174,8 +174,7 @@ void GpgFileOpera::DecryptArchive(const QString& in_path, ArchiveFileOperator::ExtractArchiveFromDataExchanger( ex, out_path, [](GFError err, const DataObjectPtr&) { - FLOG_D("extract archive from data exchanger operation, err: %d", - err); + FLOG_D("extract archive from data exchanger operation, err: %d", err); }); RunGpgOperaAsync( @@ -201,7 +200,7 @@ void GpgFileOpera::SignFile(const KeyArgsList& keys, const QString& in_path, GpgError err; // Set Singers of this opera - GpgBasicOperator::GetInstance().SetSigners(keys, ascii); + GpgBasicOperator::GetInstance(GetChannel()).SetSigners(keys, ascii); GpgData data_in(in_path, true); GpgData data_out(out_path, false); @@ -226,7 +225,7 @@ auto GpgFileOpera::SignFileSync(const KeyArgsList& keys, const QString& in_path, GpgError err; // Set Singers of this opera - GpgBasicOperator::GetInstance().SetSigners(keys, ascii); + GpgBasicOperator::GetInstance(GetChannel()).SetSigners(keys, ascii); GpgData data_in(in_path, true); GpgData data_out(out_path, false); @@ -310,7 +309,8 @@ void GpgFileOpera::EncryptSignFile(const KeyArgsList& keys, // Last entry data_in array has to be nullptr recipients.emplace_back(nullptr); - GpgBasicOperator::GetInstance().SetSigners(signer_keys, ascii); + GpgBasicOperator::GetInstance(GetChannel()) + .SetSigners(signer_keys, ascii); GpgData data_in(in_path, true); GpgData data_out(out_path, false); @@ -341,7 +341,8 @@ auto GpgFileOpera::EncryptSignFileSync( // Last entry data_in array has to be nullptr recipients.emplace_back(nullptr); - GpgBasicOperator::GetInstance().SetSigners(signer_keys, ascii); + GpgBasicOperator::GetInstance(GetChannel()) + .SetSigners(signer_keys, ascii); GpgData data_in(in_path, true); GpgData data_out(out_path, false); @@ -376,7 +377,8 @@ void GpgFileOpera::EncryptSignDirectory(const KeyArgsList& keys, // Last entry data_in array has to be nullptr recipients.emplace_back(nullptr); - GpgBasicOperator::GetInstance().SetSigners(signer_keys, ascii); + GpgBasicOperator::GetInstance(GetChannel()) + .SetSigners(signer_keys, ascii); GpgData data_in(ex); GpgData data_out(out_path, false); diff --git a/src/ui/dialog/Wizard.cpp b/src/ui/dialog/Wizard.cpp index 10b2c449..3a3c0800 100644 --- a/src/ui/dialog/Wizard.cpp +++ b/src/ui/dialog/Wizard.cpp @@ -196,7 +196,7 @@ KeyGenPage::KeyGenPage(QWidget* parent) : QWizardPage(parent) { int KeyGenPage::nextId() const { return Wizard::Page_Conclusion; } void KeyGenPage::slot_generate_key_dialog() { - (new KeyGenDialog(this))->show(); + (new KeyGenDialog(kGpgFrontendDefaultChannel, this))->show(); wizard()->next(); } diff --git a/src/ui/dialog/import_export/ExportKeyPackageDialog.cpp b/src/ui/dialog/import_export/ExportKeyPackageDialog.cpp index c1923190..8c283f66 100644 --- a/src/ui/dialog/import_export/ExportKeyPackageDialog.cpp +++ b/src/ui/dialog/import_export/ExportKeyPackageDialog.cpp @@ -117,8 +117,9 @@ GpgFrontend::UI::ExportKeyPackageDialog::ExportKeyPackageDialog( CommonUtils::WaitForOpera( this, tr("Generating"), [this, keys](const OperaWaitingHd& op_hd) { KeyPackageOperator::GenerateKeyPackage( - ui_->outputPathLabel->text(), ui_->nameValueLabel->text(), *keys, - passphrase_, ui_->includeSecretKeyCheckBox->isChecked(), + ui_->outputPathLabel->text(), ui_->nameValueLabel->text(), + current_gpg_context_channel_, *keys, passphrase_, + ui_->includeSecretKeyCheckBox->isChecked(), [=](GFError err, const DataObjectPtr&) { // stop waiting op_hd(); diff --git a/src/ui/dialog/key_generate/KeygenDialog.cpp b/src/ui/dialog/key_generate/KeygenDialog.cpp index 37e2ff2c..e29f6b64 100644 --- a/src/ui/dialog/key_generate/KeygenDialog.cpp +++ b/src/ui/dialog/key_generate/KeygenDialog.cpp @@ -41,8 +41,9 @@ namespace GpgFrontend::UI { -KeyGenDialog::KeyGenDialog(QWidget* parent) - : GeneralDialog(typeid(KeyGenDialog).name(), parent) { +KeyGenDialog::KeyGenDialog(int channel, QWidget* parent) + : GeneralDialog(typeid(KeyGenDialog).name(), parent), + default_gpg_context_channel_(channel) { button_box_ = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel); @@ -426,6 +427,7 @@ auto KeyGenDialog::create_basic_info_group_box() -> QGroupBox* { gpg_contexts_combo_box_->addItem( QString("%1: %2").arg(channel).arg(database_name)); } + gpg_contexts_combo_box_->setCurrentIndex(default_gpg_context_channel_); for (const auto& algo : GenKeyInfo::GetSupportedKeyAlgo()) { key_type_combo_box_->addItem(std::get<0>(algo)); diff --git a/src/ui/dialog/key_generate/KeygenDialog.h b/src/ui/dialog/key_generate/KeygenDialog.h index b8d5a6da..8b9757d5 100644 --- a/src/ui/dialog/key_generate/KeygenDialog.h +++ b/src/ui/dialog/key_generate/KeygenDialog.h @@ -52,7 +52,7 @@ class KeyGenDialog : public GeneralDialog { * @param key The key to show details of * @param parent The parent of this widget */ - explicit KeyGenDialog(QWidget* parent = nullptr); + explicit KeyGenDialog(int channel, QWidget* parent = nullptr); signals: /** @@ -110,6 +110,8 @@ class KeyGenDialog : public GeneralDialog { std::vector key_usage_check_boxes_; ///< ENCR, SIGN, CERT, AUTH QComboBox* gpg_contexts_combo_box_{}; + int default_gpg_context_channel_; + /** * @brief * diff --git a/src/ui/dialog/keypair_details/KeyNewUIDDialog.cpp b/src/ui/dialog/keypair_details/KeyNewUIDDialog.cpp index 398dab40..76eb94c0 100644 --- a/src/ui/dialog/keypair_details/KeyNewUIDDialog.cpp +++ b/src/ui/dialog/keypair_details/KeyNewUIDDialog.cpp @@ -95,8 +95,8 @@ void KeyNewUIDDialog::slot_create_new_uid() { } auto error_string = error_stream.readAll(); if (error_string.isEmpty()) { - if (GpgUIDOperator::GetInstance().AddUID( - m_key_, name_->text(), comment_->text(), email_->text())) { + if (GpgUIDOperator::GetInstance(current_gpg_context_channel_) + .AddUID(m_key_, name_->text(), comment_->text(), email_->text())) { emit finished(1); emit SignalUIDCreated(); } else { diff --git a/src/ui/dialog/keypair_details/KeyPairOperaTab.cpp b/src/ui/dialog/keypair_details/KeyPairOperaTab.cpp index 9d40391a..b2978938 100644 --- a/src/ui/dialog/keypair_details/KeyPairOperaTab.cpp +++ b/src/ui/dialog/keypair_details/KeyPairOperaTab.cpp @@ -218,7 +218,8 @@ void KeyPairOperaTab::CreateOperaMenu() { void KeyPairOperaTab::slot_export_public_key() { auto [err, gf_buffer] = - GpgKeyImportExporter::GetInstance().ExportKey(m_key_, false, true, false); + GpgKeyImportExporter::GetInstance(current_gpg_context_channel_) + .ExportKey(m_key_, false, true, false); if (CheckGpgError(err) != GPG_ERR_NO_ERROR) { CommonUtils::RaiseMessageBox(this, err); return; @@ -265,7 +266,8 @@ void KeyPairOperaTab::slot_export_short_private_key() { // export key, if ok was clicked if (ret == QMessageBox::Ok) { auto [err, gf_buffer] = - GpgKeyImportExporter::GetInstance().ExportKey(m_key_, true, true, true); + GpgKeyImportExporter::GetInstance(current_gpg_context_channel_) + .ExportKey(m_key_, true, true, true); if (CheckGpgError(err) != GPG_ERR_NO_ERROR) { CommonUtils::RaiseMessageBox(this, err); return; @@ -308,8 +310,9 @@ void KeyPairOperaTab::slot_export_private_key() { // export key, if ok was clicked if (ret == QMessageBox::Ok) { - auto [err, gf_buffer] = GpgKeyImportExporter::GetInstance().ExportKey( - m_key_, true, true, false); + 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; @@ -386,8 +389,8 @@ void KeyPairOperaTab::slot_gen_revoke_cert() { } if (!m_output_file_name.isEmpty()) { - GpgKeyOpera::GetInstance().GenerateRevokeCert( - m_key_, m_output_file_name, code, text); + GpgKeyOpera::GetInstance(current_gpg_context_channel_) + .GenerateRevokeCert(m_key_, m_output_file_name, code, text); } }); @@ -395,8 +398,8 @@ void KeyPairOperaTab::slot_gen_revoke_cert() { } void KeyPairOperaTab::slot_modify_password() { - GpgKeyOpera::GetInstance().ModifyPassword( - m_key_, [this](GpgError err, const DataObjectPtr&) { + GpgKeyOpera::GetInstance(current_gpg_context_channel_) + .ModifyPassword(m_key_, [this](GpgError err, const DataObjectPtr&) { CommonUtils::RaiseMessageBox(this, err); }); } @@ -423,7 +426,8 @@ void KeyPairOperaTab::slot_modify_tofu_policy() { } else if (item == tr("Policy Unknown")) { tofu_policy = GPGME_TOFU_POLICY_UNKNOWN; } - auto err = GpgKeyOpera::GetInstance().ModifyTOFUPolicy(m_key_, tofu_policy); + auto err = GpgKeyOpera::GetInstance(current_gpg_context_channel_) + .ModifyTOFUPolicy(m_key_, tofu_policy); if (CheckGpgError(err) != GPG_ERR_NO_ERROR) { QMessageBox::critical(this, tr("Not Successful"), tr("Modify TOFU policy not successfully.")); @@ -508,8 +512,9 @@ void KeyPairOperaTab::slot_export_paper_key() { // export key, if ok was clicked if (ret == QMessageBox::Ok) { - auto [err, gf_buffer] = GpgKeyImportExporter::GetInstance().ExportKey( - m_key_, true, false, true); + auto [err, gf_buffer] = + GpgKeyImportExporter::GetInstance(current_gpg_context_channel_) + .ExportKey(m_key_, true, false, true); if (CheckGpgError(err) != GPG_ERR_NO_ERROR) { CommonUtils::RaiseMessageBox(this, err); return; @@ -562,7 +567,8 @@ void KeyPairOperaTab::slot_import_paper_key() { if (!Module::IsModuleActivate(kPaperKeyModuleID)) return; auto [err, gf_buffer] = - GpgKeyImportExporter::GetInstance().ExportKey(m_key_, false, false, true); + GpgKeyImportExporter::GetInstance(current_gpg_context_channel_) + .ExportKey(m_key_, false, false, true); if (CheckGpgError(err) != GPG_ERR_NO_ERROR) { CommonUtils::RaiseMessageBox(this, err); return; diff --git a/src/ui/dialog/keypair_details/KeyPairUIDTab.cpp b/src/ui/dialog/keypair_details/KeyPairUIDTab.cpp index 4846f58a..87f5e10e 100644 --- a/src/ui/dialog/keypair_details/KeyPairUIDTab.cpp +++ b/src/ui/dialog/keypair_details/KeyPairUIDTab.cpp @@ -389,7 +389,8 @@ void KeyPairUIDTab::slot_del_uid() { if (ret == QMessageBox::Yes) { for (const auto& uid : *selected_uids) { - if (!GpgUIDOperator::GetInstance().RevUID(m_key_, uid)) { + if (!GpgUIDOperator::GetInstance(current_gpg_context_channel_) + .RevUID(m_key_, uid)) { QMessageBox::critical( nullptr, tr("Operation Failed"), tr("An error occurred during the delete %1 operation.").arg(uid)); @@ -423,8 +424,8 @@ void KeyPairUIDTab::slot_set_primary_uid() { QMessageBox::No | QMessageBox::Yes); if (ret == QMessageBox::Yes) { - if (!GpgUIDOperator::GetInstance().SetPrimaryUID(m_key_, - selected_uids->front())) { + if (!GpgUIDOperator::GetInstance(current_gpg_context_channel_) + .SetPrimaryUID(m_key_, selected_uids->front())) { QMessageBox::critical(nullptr, tr("Operation Failed"), tr("An error occurred during the operation.")); } else { @@ -520,7 +521,8 @@ void KeyPairUIDTab::slot_del_uid_single() { QMessageBox::No | QMessageBox::Yes); if (ret == QMessageBox::Yes) { - if (!GpgUIDOperator::GetInstance().RevUID(m_key_, selected_uids->front())) { + if (!GpgUIDOperator::GetInstance(current_gpg_context_channel_) + .RevUID(m_key_, selected_uids->front())) { QMessageBox::critical(nullptr, tr("Operation Failed"), tr("An error occurred during the operation.")); } else { @@ -572,7 +574,8 @@ void KeyPairUIDTab::slot_del_sign() { QMessageBox::No | QMessageBox::Yes); if (ret == QMessageBox::Yes) { - if (!GpgKeyManager::GetInstance().RevSign(m_key_, selected_signs)) { + if (!GpgKeyManager::GetInstance(current_gpg_context_channel_) + .RevSign(m_key_, selected_signs)) { QMessageBox::critical(nullptr, tr("Operation Failed"), tr("An error occurred during the operation.")); } diff --git a/src/ui/dialog/keypair_details/KeySetExpireDateDialog.cpp b/src/ui/dialog/keypair_details/KeySetExpireDateDialog.cpp index 71963f99..d621e261 100644 --- a/src/ui/dialog/keypair_details/KeySetExpireDateDialog.cpp +++ b/src/ui/dialog/keypair_details/KeySetExpireDateDialog.cpp @@ -70,7 +70,8 @@ void KeySetExpireDateDialog::slot_confirm() { expires = std::make_unique(datetime.toLocalTime()); } - auto err = GpgKeyOpera::GetInstance().SetExpire(m_key_, m_subkey_, expires); + auto err = GpgKeyOpera::GetInstance(current_gpg_context_channel_) + .SetExpire(m_key_, m_subkey_, expires); if (CheckGpgError(err) == GPG_ERR_NO_ERROR) { auto* msg_box = new QMessageBox(qobject_cast(this->parent())); diff --git a/src/ui/dialog/keypair_details/KeyUIDSignDialog.cpp b/src/ui/dialog/keypair_details/KeyUIDSignDialog.cpp index 94194652..d34fb99a 100644 --- a/src/ui/dialog/keypair_details/KeyUIDSignDialog.cpp +++ b/src/ui/dialog/keypair_details/KeyUIDSignDialog.cpp @@ -116,7 +116,8 @@ void KeyUIDSignDialog::slot_sign_key(bool clicked) { for (const auto& uid : *m_uids_) { // Sign For mKey - if (!GpgKeyManager::GetInstance().SignKey(m_key_, *keys, uid, expires)) { + if (!GpgKeyManager::GetInstance(current_gpg_context_channel_) + .SignKey(m_key_, *keys, uid, expires)) { QMessageBox::critical( nullptr, tr("Unsuccessful Operation"), tr("Signature operation failed for UID %1").arg(uid)); diff --git a/src/ui/function/SetOwnerTrustLevel.cpp b/src/ui/function/SetOwnerTrustLevel.cpp index a15f3525..d3ca33b3 100644 --- a/src/ui/function/SetOwnerTrustLevel.cpp +++ b/src/ui/function/SetOwnerTrustLevel.cpp @@ -77,8 +77,8 @@ auto SetOwnerTrustLevel::Exec(int channel, const QString& key_id) -> bool { trust_level = 1; } - bool status = - GpgKeyManager::GetInstance().SetOwnerTrustLevel(key, trust_level); + bool status = GpgKeyManager::GetInstance(channel).SetOwnerTrustLevel( + key, trust_level); if (!status) { QMessageBox::critical(this, tr("Failed"), tr("Modify Owner Trust Level failed.")); diff --git a/src/ui/main_window/KeyMgmt.cpp b/src/ui/main_window/KeyMgmt.cpp index 343da2d9..022f3c9f 100644 --- a/src/ui/main_window/KeyMgmt.cpp +++ b/src/ui/main_window/KeyMgmt.cpp @@ -353,7 +353,8 @@ void KeyMgmt::delete_keys_with_warning(KeyIdArgsListPtr uidList) { QMessageBox::No | QMessageBox::Yes); if (ret == QMessageBox::Yes) { - GpgKeyOpera::GetInstance().DeleteKeys(std::move(uidList)); + GpgKeyOpera::GetInstance(key_list_->GetCurrentGpgContextChannel()) + .DeleteKeys(std::move(uidList)); emit SignalKeyStatusUpdated(); } } @@ -402,8 +403,9 @@ void KeyMgmt::SlotExportKeyToClipboard() { .GetKey(keys_checked->front()); assert(key.IsGood()); - auto [err, gf_buffer] = - GpgKeyImportExporter::GetInstance().ExportKey(key, false, true, false); + auto [err, gf_buffer] = GpgKeyImportExporter::GetInstance( + key_list_->GetCurrentGpgContextChannel()) + .ExportKey(key, false, true, false); if (CheckGpgError(err) != GPG_ERR_NO_ERROR) { CommonUtils::RaiseMessageBox(this, err); return; @@ -419,40 +421,42 @@ void KeyMgmt::SlotExportKeyToClipboard() { CommonUtils::WaitForOpera( this, tr("Exporting"), [=](const OperaWaitingHd& op_hd) { - GpgKeyImportExporter::GetInstance().ExportKeys( - *keys, false, true, false, false, - [=](GpgError err, const DataObjectPtr& data_obj) { - // stop waiting - op_hd(); + GpgKeyImportExporter::GetInstance( + key_list_->GetCurrentGpgContextChannel()) + .ExportKeys( + *keys, false, true, false, false, + [=](GpgError err, const DataObjectPtr& data_obj) { + // stop waiting + op_hd(); - if (CheckGpgError(err) == GPG_ERR_USER_1) { - QMessageBox::critical(this, tr("Error"), - tr("Unknown error occurred")); - return; - } + if (CheckGpgError(err) == GPG_ERR_USER_1) { + QMessageBox::critical(this, tr("Error"), + tr("Unknown error occurred")); + return; + } - if (CheckGpgError(err) != GPG_ERR_NO_ERROR) { - CommonUtils::RaiseMessageBox(this, err); - return; - } + if (CheckGpgError(err) != GPG_ERR_NO_ERROR) { + CommonUtils::RaiseMessageBox(this, err); + return; + } - if (data_obj == nullptr || !data_obj->Check()) { - FLOG_W("data object checking failed"); - QMessageBox::critical(this, tr("Error"), - tr("Unknown error occurred")); - return; - } + if (data_obj == nullptr || !data_obj->Check()) { + FLOG_W("data object checking failed"); + QMessageBox::critical(this, tr("Error"), + tr("Unknown error occurred")); + return; + } - auto gf_buffer = ExtractParams(data_obj, 0); - QApplication::clipboard()->setText( - gf_buffer.ConvertToQByteArray()); - }); + auto gf_buffer = ExtractParams(data_obj, 0); + QApplication::clipboard()->setText( + gf_buffer.ConvertToQByteArray()); + }); }); } } void KeyMgmt::SlotGenerateKeyDialog() { - (new KeyGenDialog(this))->exec(); + (new KeyGenDialog(key_list_->GetCurrentGpgContextChannel(), this))->exec(); this->raise(); } @@ -508,53 +512,56 @@ void KeyMgmt::SlotExportAsOpenSSHFormat() { CommonUtils::WaitForOpera( this, tr("Exporting"), [this, keys](const OperaWaitingHd& op_hd) { - GpgKeyImportExporter::GetInstance().ExportKeys( - *keys, false, true, false, true, - [=](GpgError err, const DataObjectPtr& data_obj) { - // stop waiting - op_hd(); + GpgKeyImportExporter::GetInstance( + key_list_->GetCurrentGpgContextChannel()) + .ExportKeys( + *keys, false, true, false, true, + [=](GpgError err, const DataObjectPtr& data_obj) { + // stop waiting + op_hd(); - if (CheckGpgError(err) == GPG_ERR_USER_1) { - QMessageBox::critical(this, tr("Error"), - tr("Unknown error occurred")); - return; - } + if (CheckGpgError(err) == GPG_ERR_USER_1) { + QMessageBox::critical(this, tr("Error"), + tr("Unknown error occurred")); + return; + } - if (CheckGpgError(err) != GPG_ERR_NO_ERROR) { - CommonUtils::RaiseMessageBox(this, err); - return; - } + if (CheckGpgError(err) != GPG_ERR_NO_ERROR) { + CommonUtils::RaiseMessageBox(this, err); + return; + } - if (data_obj == nullptr || !data_obj->Check()) { - QMessageBox::critical(this, tr("Error"), - tr("Unknown error occurred")); - return; - } + if (data_obj == nullptr || !data_obj->Check()) { + QMessageBox::critical(this, tr("Error"), + tr("Unknown error occurred")); + return; + } - auto gf_buffer = ExtractParams(data_obj, 0); - if (CheckGpgError(err) != GPG_ERR_NO_ERROR) { - CommonUtils::RaiseMessageBox(this, err); - return; - } + auto gf_buffer = ExtractParams(data_obj, 0); + if (CheckGpgError(err) != GPG_ERR_NO_ERROR) { + CommonUtils::RaiseMessageBox(this, err); + return; + } - if (gf_buffer.Empty()) { - QMessageBox::critical( - this, tr("Error"), - tr("This key may not be able to export as OpenSSH format. " - "Please check the key-size of the subkey(s) used to " - "sign.")); - return; - } + if (gf_buffer.Empty()) { + QMessageBox::critical( + this, tr("Error"), + tr("This key may not be able to export as OpenSSH " + "format. " + "Please check the key-size of the subkey(s) used to " + "sign.")); + return; + } - QString const file_name = QFileDialog::getSaveFileName( - this, tr("Export OpenSSH Key To File"), "authorized_keys", - tr("OpenSSH Public Key Files") + "All Files (*)"); + QString const file_name = QFileDialog::getSaveFileName( + this, tr("Export OpenSSH Key To File"), "authorized_keys", + tr("OpenSSH Public Key Files") + "All Files (*)"); - if (!file_name.isEmpty()) { - WriteFileGFBuffer(file_name, gf_buffer); - emit SignalStatusBarChanged(tr("key(s) exported")); - } - }); + if (!file_name.isEmpty()) { + WriteFileGFBuffer(file_name, gf_buffer); + emit SignalStatusBarChanged(tr("key(s) exported")); + } + }); }); } @@ -610,6 +617,7 @@ void KeyMgmt::SlotImportKeyPackage() { this, tr("Importing"), [=](const OperaWaitingHd& op_hd) { KeyPackageOperator::ImportKeyPackage( key_package_file_name, key_file_name, + key_list_->GetCurrentGpgContextChannel(), [=](GFError err, const DataObjectPtr& data_obj) { // stop waiting op_hd(); diff --git a/src/ui/widgets/KeyList.cpp b/src/ui/widgets/KeyList.cpp index d98081f3..5994abda 100644 --- a/src/ui/widgets/KeyList.cpp +++ b/src/ui/widgets/KeyList.cpp @@ -523,8 +523,8 @@ void KeyList::dragEnterEvent(QDragEnterEvent* event) { } void KeyList::import_keys(const QByteArray& in_buffer) { - auto result = - GpgKeyImportExporter::GetInstance().ImportKey(GFBuffer(in_buffer)); + auto result = GpgKeyImportExporter::GetInstance(current_gpg_context_channel_) + .ImportKey(GFBuffer(in_buffer)); (new KeyImportDetailDialog(current_gpg_context_channel_, result, this)); }