diff options
Diffstat (limited to 'src/ui/dialog')
-rw-r--r-- | src/ui/dialog/ADSKsPicker.cpp | 3 | ||||
-rw-r--r-- | src/ui/dialog/controller/GnuPGControllerDialog.cpp | 3 | ||||
-rw-r--r-- | src/ui/dialog/controller/SmartCardControllerDialog.cpp | 73 | ||||
-rw-r--r-- | src/ui/dialog/key_generate/KeyGenerateDialog.cpp | 9 | ||||
-rw-r--r-- | src/ui/dialog/key_generate/SubkeyGenerateDialog.cpp | 7 | ||||
-rw-r--r-- | src/ui/dialog/keypair_details/KeyPairSubkeyTab.cpp | 15 | ||||
-rw-r--r-- | src/ui/dialog/keypair_details/KeyPairSubkeyTab.h | 100 |
7 files changed, 114 insertions, 96 deletions
diff --git a/src/ui/dialog/ADSKsPicker.cpp b/src/ui/dialog/ADSKsPicker.cpp index 878c5e96..56039a15 100644 --- a/src/ui/dialog/ADSKsPicker.cpp +++ b/src/ui/dialog/ADSKsPicker.cpp @@ -115,8 +115,7 @@ void ADSKsPicker::slot_add_adsk(const QContainer<GpgSubKey>& s_keys) { for (const auto& info : err_sub_key_infos) { failed_info.append(info); } - QString details = failed_info.join("\n\n"); - + auto 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() diff --git a/src/ui/dialog/controller/GnuPGControllerDialog.cpp b/src/ui/dialog/controller/GnuPGControllerDialog.cpp index 5dacae65..3f21b57b 100644 --- a/src/ui/dialog/controller/GnuPGControllerDialog.cpp +++ b/src/ui/dialog/controller/GnuPGControllerDialog.cpp @@ -333,7 +333,8 @@ auto GnuPGControllerDialog::check_custom_gnupg_path(QString path) -> bool { QMessageBox::critical(this, tr("Illegal GnuPG Path"), tr("Target GnuPG Path is not an absolute path.")); } -#ifdef __MINGW32__ + +#if defined(_WIN32) || defined(WIN32) QFileInfo const gpgconf_info(path + "/gpgconf.exe"); #else QFileInfo const gpgconf_info(path + "/gpgconf"); diff --git a/src/ui/dialog/controller/SmartCardControllerDialog.cpp b/src/ui/dialog/controller/SmartCardControllerDialog.cpp index 73dd48b9..797fe052 100644 --- a/src/ui/dialog/controller/SmartCardControllerDialog.cpp +++ b/src/ui/dialog/controller/SmartCardControllerDialog.cpp @@ -33,6 +33,7 @@ #include "core/function/gpg/GpgSmartCardManager.h" #include "core/utils/GpgUtils.h" #include "ui/UISignalStation.h" +#include "ui/UserInterfaceUtils.h" #include "ui/dialog/key_generate/GenerateCardKeyDialog.h" // @@ -110,18 +111,22 @@ SmartCardControllerDialog::SmartCardControllerDialog(QWidget* parent) [=](bool) { modify_key_pin("OPENPGP.2"); }); connect(ui_->restartGpgAgentButton, &QPushButton::clicked, this, [=](bool) { - GpgFrontend::GpgAdvancedOperator::RestartGpgComponents( - [=](int err, DataObjectPtr) { - if (err >= 0) { - QMessageBox::information( - this, tr("Successful Operation"), - tr("Restart all the GnuPG's components successfully")); - } else { - QMessageBox::critical( - this, tr("Failed Operation"), - tr("Failed to restart all or one of the GnuPG's component(s)")); - } - }); + bool ret = true; + const auto size = GpgContext::GetAllChannelId().size(); + for (auto i = 0; i < size; i++) { + ret = GpgAdvancedOperator::GetInstance().RestartGpgComponents(); + if (!ret) break; + } + + if (ret) { + QMessageBox::information( + this, tr("Successful Operation"), + tr("Restart all the GnuPG's components successfully")); + } else { + QMessageBox::critical( + this, tr("Failed Operation"), + tr("Failed to restart all or one of the GnuPG's component(s)")); + } }); connect(ui_->generateKeysButton, &QPushButton::clicked, this, [=](bool) { @@ -163,11 +168,13 @@ void SmartCardControllerDialog::select_smart_card_by_serial_number( return; } - auto [ret, err] = + auto [err, status] = GpgSmartCardManager::GetInstance(channel_).SelectCardBySerialNumber( serial_number); - if (!ret) { - LOG_E() << "select card by serial number failed: " << err; + if (err != GPG_ERR_NO_ERROR) { + LOG_E() << "select card by serial number failed, err:" << CheckGpgError(err) + << "status:" << status; + CommonUtils::RaiseFailureMessageBox(this, err, status); reset_status(); return; } @@ -188,6 +195,7 @@ void SmartCardControllerDialog::fetch_smart_card_info( GpgSmartCardManager::GetInstance(channel_).FetchCardInfoBySerialNumber( serial_number); if (card_info == nullptr) { + LOG_E() << "card info is nullptr, serial number:" << serial_number; reset_status(); return; } @@ -446,9 +454,14 @@ void SmartCardControllerDialog::slot_disable_controllers(bool disable) { void SmartCardControllerDialog::slot_fetch_smart_card_keys() { ui_->fetchButton->setDisabled(true); - GpgSmartCardManager::GetInstance().Fetch( + auto err = GpgSmartCardManager::GetInstance().Fetch( ui_->currentCardComboBox->currentText()); + if (err != GPG_ERR_NO_ERROR) { + CommonUtils::RaiseFailureMessageBox(this, err); + return; + } + QTimer::singleShot(1000, [=]() { GpgCommandExecutor::GetInstance(channel_).GpgExecuteSync( {{}, @@ -524,14 +537,13 @@ void SmartCardControllerDialog::modify_key_attribute(const QString& attr) { } } - auto [r, err] = + auto [err, status] = GpgSmartCardManager::GetInstance(channel_).ModifyAttr(attr, value); - if (!r) { - LOG_D() << "SCD SETATTR command failed for attr" << attr; - QMessageBox::critical( - this, tr("Failed"), - tr("Failed to set attribute '%1'. Reason: %2. ").arg(attr).arg(err)); + if (err != GPG_ERR_NO_ERROR) { + LOG_D() << "SCD SETATTR command failed for attr:" << attr + << ", err:" << CheckGpgError(err); + CommonUtils::RaiseFailureMessageBox(this, err, status); return; } QMessageBox::information(this, tr("Success"), @@ -540,22 +552,11 @@ void SmartCardControllerDialog::modify_key_attribute(const QString& attr) { } void SmartCardControllerDialog::modify_key_pin(const QString& pinref) { - auto [success, err] = + auto [err, status] = GpgSmartCardManager::GetInstance(channel_).ModifyPin(pinref); - if (!success) { - QString message; - if (pinref == "OPENPGP.3") { - message = tr("Failed to change Admin PIN."); - } else if (pinref == "OPENPGP.2") { - message = tr("Failed to set the Reset Code."); - } else { - message = tr("Failed to change PIN."); - } - - message += tr("Reason: ") + err; - - QMessageBox::critical(this, tr("Error"), message); + if (err != GPG_ERR_NO_ERROR) { + CommonUtils::RaiseFailureMessageBox(this, err, status); return; } diff --git a/src/ui/dialog/key_generate/KeyGenerateDialog.cpp b/src/ui/dialog/key_generate/KeyGenerateDialog.cpp index d738029d..df8b5232 100644 --- a/src/ui/dialog/key_generate/KeyGenerateDialog.cpp +++ b/src/ui/dialog/key_generate/KeyGenerateDialog.cpp @@ -49,8 +49,9 @@ KeyGenerateDialog::KeyGenerateDialog(int channel, QWidget* parent) ui_(QSharedPointer<Ui_KeyGenDialog>::create()), gen_key_info_(QSharedPointer<KeyGenerateInfo>::create()), gen_subkey_info_(nullptr), - supported_primary_key_algos_(KeyGenerateInfo::GetSupportedKeyAlgo()), - supported_subkey_algos_(KeyGenerateInfo::GetSupportedSubkeyAlgo()), + supported_primary_key_algos_( + KeyGenerateInfo::GetSupportedKeyAlgo(channel)), + supported_subkey_algos_(KeyGenerateInfo::GetSupportedSubkeyAlgo(channel)), channel_(channel) { ui_->setupUi(this); @@ -146,6 +147,10 @@ KeyGenerateDialog::KeyGenerateDialog(int channel, QWidget* parent) this->setWindowTitle(tr("Generate Key")); this->setAttribute(Qt::WA_DeleteOnClose); this->setModal(true); + + this->show(); + this->raise(); + this->activateWindow(); } void KeyGenerateDialog::slot_key_gen_accept() { diff --git a/src/ui/dialog/key_generate/SubkeyGenerateDialog.cpp b/src/ui/dialog/key_generate/SubkeyGenerateDialog.cpp index fd592733..68c68765 100644 --- a/src/ui/dialog/key_generate/SubkeyGenerateDialog.cpp +++ b/src/ui/dialog/key_generate/SubkeyGenerateDialog.cpp @@ -50,7 +50,8 @@ SubkeyGenerateDialog::SubkeyGenerateDialog(int channel, GpgKeyPtr key, current_gpg_context_channel_(channel), key_(std::move(key)), gen_subkey_info_(QSharedPointer<KeyGenerateInfo>::create(true)), - supported_subkey_algos_(KeyGenerateInfo::GetSupportedSubkeyAlgo()) { + supported_subkey_algos_(KeyGenerateInfo::GetSupportedSubkeyAlgo( + current_gpg_context_channel_)) { ui_->setupUi(this); assert(key_ != nullptr); @@ -88,6 +89,10 @@ SubkeyGenerateDialog::SubkeyGenerateDialog(int channel, GpgKeyPtr key, set_signal_slot_config(); refresh_widgets_state(); + + this->show(); + this->raise(); + this->activateWindow(); } void SubkeyGenerateDialog::set_signal_slot_config() { diff --git a/src/ui/dialog/keypair_details/KeyPairSubkeyTab.cpp b/src/ui/dialog/keypair_details/KeyPairSubkeyTab.cpp index 73e7f4e5..64e4d029 100644 --- a/src/ui/dialog/keypair_details/KeyPairSubkeyTab.cpp +++ b/src/ui/dialog/keypair_details/KeyPairSubkeyTab.cpp @@ -31,7 +31,6 @@ #include "core/function/gpg/GpgKeyGetter.h" #include "core/function/gpg/GpgKeyImportExporter.h" #include "core/function/gpg/GpgKeyManager.h" -#include "core/function/gpg/GpgKeyOpera.h" #include "core/utils/CommonUtils.h" #include "core/utils/GpgUtils.h" #include "core/utils/IOUtils.h" @@ -66,6 +65,11 @@ KeyPairSubkeyTab::KeyPairSubkeyTab(int channel, GpgKeyPtr key, QWidget* parent) add_adsk_button->hide(); } + if (!CheckGpgVersion(channel, "2.4.1")) { + add_adsk_button->setDisabled(true); + add_adsk_button->hide(); + } + uid_buttons_layout->addWidget(add_subkey_button, 0, 0); uid_buttons_layout->addWidget(add_adsk_button, 0, 1); @@ -277,9 +281,12 @@ void KeyPairSubkeyTab::slot_refresh_subkey_list() { } void KeyPairSubkeyTab::slot_add_subkey() { - auto* dialog = - new SubkeyGenerateDialog(current_gpg_context_channel_, key_, this); - dialog->show(); + if (!CheckGpgVersion(current_gpg_context_channel_, "2.2.0")) { + CommonUtils::RaiseMessageBoxNotSupported(this); + return; + } + + new SubkeyGenerateDialog(current_gpg_context_channel_, key_, this); } void KeyPairSubkeyTab::slot_add_adsk() { diff --git a/src/ui/dialog/keypair_details/KeyPairSubkeyTab.h b/src/ui/dialog/keypair_details/KeyPairSubkeyTab.h index 3d9eeb50..c7d7a08a 100644 --- a/src/ui/dialog/keypair_details/KeyPairSubkeyTab.h +++ b/src/ui/dialog/keypair_details/KeyPairSubkeyTab.h @@ -47,55 +47,13 @@ class KeyPairSubkeyTab : public QWidget { */ KeyPairSubkeyTab(int channel, GpgKeyPtr key, QWidget* parent); - private: - /** - * @brief Create a subkey list object - * - */ - void create_subkey_list(); - - /** - * @brief Create a subkey opera menu object - * - */ - void create_subkey_opera_menu(); - + protected: /** - * @brief Get the selected subkey object + * @brief * - * @return const GpgSubKey& + * @param event */ - auto get_selected_subkey() -> const GpgSubKey&; - - int current_gpg_context_channel_; - GpgKeyPtr key_; ///< - QTableWidget* subkey_list_{}; ///< - QContainer<GpgSubKey> buffered_subkeys_; ///< - - QGroupBox* list_box_; ///< - QGroupBox* detail_box_; ///< - - QMenu* subkey_opera_menu_{}; ///< - - QLabel* key_type_var_label_; - QLabel* key_size_var_label_; ///< Label containing the keys key size - QLabel* expire_var_label_; ///< Label containing the keys expiration date - QLabel* revoke_var_label_; - QLabel* created_var_label_; ///< Label containing the keys creation date - QLabel* algorithm_var_label_; ///< Label containing the keys algorithm - QLabel* algorithm_detail_var_label_; ///< - QLabel* key_id_var_label_; ///< Label containing the keys keyid - QLabel* fingerprint_var_label_; ///< Label containing the keys fingerprint - QLabel* usage_var_label_; ///< - QLabel* master_key_exist_var_label_; ///< - QLabel* card_key_label_; ///< - - QPushButton* export_subkey_button_; - QAction* export_subkey_act_; - - QAction* edit_subkey_act_; - QAction* delete_subkey_act_; - QAction* revoke_subkey_act_; + void contextMenuEvent(QContextMenuEvent* event) override; private slots: @@ -161,13 +119,55 @@ class KeyPairSubkeyTab : public QWidget { */ void SignalKeyDatabaseRefresh(); - protected: + private: + int current_gpg_context_channel_; + GpgKeyPtr key_; ///< + QTableWidget* subkey_list_{}; ///< + QContainer<GpgSubKey> buffered_subkeys_; ///< + + QGroupBox* list_box_; ///< + QGroupBox* detail_box_; ///< + + QMenu* subkey_opera_menu_{}; ///< + + QLabel* key_type_var_label_; + QLabel* key_size_var_label_; ///< Label containing the keys key size + QLabel* expire_var_label_; ///< Label containing the keys expiration date + QLabel* revoke_var_label_; + QLabel* created_var_label_; ///< Label containing the keys creation date + QLabel* algorithm_var_label_; ///< Label containing the keys algorithm + QLabel* algorithm_detail_var_label_; ///< + QLabel* key_id_var_label_; ///< Label containing the keys keyid + QLabel* fingerprint_var_label_; ///< Label containing the keys fingerprint + QLabel* usage_var_label_; ///< + QLabel* master_key_exist_var_label_; ///< + QLabel* card_key_label_; ///< + + QPushButton* export_subkey_button_; + QAction* export_subkey_act_; + + QAction* edit_subkey_act_; + QAction* delete_subkey_act_; + QAction* revoke_subkey_act_; + /** - * @brief + * @brief Create a subkey list object * - * @param event */ - void contextMenuEvent(QContextMenuEvent* event) override; + void create_subkey_list(); + + /** + * @brief Create a subkey opera menu object + * + */ + void create_subkey_opera_menu(); + + /** + * @brief Get the selected subkey object + * + * @return const GpgSubKey& + */ + auto get_selected_subkey() -> const GpgSubKey&; }; } // namespace GpgFrontend::UI |