diff options
author | Saturneric <[email protected]> | 2023-07-13 03:02:28 +0000 |
---|---|---|
committer | Saturneric <[email protected]> | 2023-07-13 03:02:28 +0000 |
commit | 5b635cf78c679f36cf47d18d8ba4e6967a7297f9 (patch) | |
tree | cbe42823440bcadd39572c4c19dee66d8d8c5b1e | |
parent | feat: support owner trust level settings of gpg key (diff) | |
download | GpgFrontend-5b635cf78c679f36cf47d18d8ba4e6967a7297f9.tar.gz GpgFrontend-5b635cf78c679f36cf47d18d8ba4e6967a7297f9.zip |
feat: improve ui of owner trust function
-rw-r--r-- | src/core/model/GpgKey.cpp | 18 | ||||
-rw-r--r-- | src/core/model/GpgKey.h | 7 | ||||
-rw-r--r-- | src/ui/dialog/keypair_details/KeyPairOperaTab.cpp | 23 |
3 files changed, 42 insertions, 6 deletions
diff --git a/src/core/model/GpgKey.cpp b/src/core/model/GpgKey.cpp index e2e7df6e..3a167b81 100644 --- a/src/core/model/GpgKey.cpp +++ b/src/core/model/GpgKey.cpp @@ -93,6 +93,24 @@ std::string GpgFrontend::GpgKey::GetOwnerTrust() const { return "Invalid"; } +int GpgFrontend::GpgKey::GetOwnerTrustLevel() const { + switch (key_ref_->owner_trust) { + case GPGME_VALIDITY_UNKNOWN: + return 0; + case GPGME_VALIDITY_UNDEFINED: + return 1; + case GPGME_VALIDITY_NEVER: + return 2; + case GPGME_VALIDITY_MARGINAL: + return 3; + case GPGME_VALIDITY_FULL: + return 4; + case GPGME_VALIDITY_ULTIMATE: + return 5; + } + return 0; +} + std::string GpgFrontend::GpgKey::GetPublicKeyAlgo() const { return gpgme_pubkey_algo_name(key_ref_->subkeys->pubkey_algo); } diff --git a/src/core/model/GpgKey.h b/src/core/model/GpgKey.h index 8c24ca5d..fb87b791 100644 --- a/src/core/model/GpgKey.h +++ b/src/core/model/GpgKey.h @@ -102,6 +102,13 @@ class GPGFRONTEND_CORE_EXPORT GpgKey { /** * @brief * + * @return int + */ + [[nodiscard]] int GetOwnerTrustLevel() const; + + /** + * @brief + * * @return std::string */ [[nodiscard]] std::string GetPublicKeyAlgo() const; diff --git a/src/ui/dialog/keypair_details/KeyPairOperaTab.cpp b/src/ui/dialog/keypair_details/KeyPairOperaTab.cpp index 34bd8534..13c857a0 100644 --- a/src/ui/dialog/keypair_details/KeyPairOperaTab.cpp +++ b/src/ui/dialog/keypair_details/KeyPairOperaTab.cpp @@ -405,13 +405,13 @@ void KeyPairOperaTab::slot_modify_tofu_policy() { void KeyPairOperaTab::slot_set_owner_trust_level() { QStringList items; - items << _("Ultimate") << _("Full") << _("Marginal") << _("Never") - << _("Undefined") << _("Unknown"); - + items << _("Unknown") << _("Undefined") << _("Never") << _("Marginal") + << _("Full") << _("Ultimate"); bool ok; - QString item = - QInputDialog::getItem(this, _("Modify Owner Trust Level"), - _("Trust for the Key Pair:"), items, 0, false, &ok); + QString item = QInputDialog::getItem(this, _("Modify Owner Trust Level"), + _("Trust for the Key Pair:"), items, + m_key_.GetOwnerTrustLevel(), false, &ok); + if (ok && !item.isEmpty()) { SPDLOG_DEBUG("selected policy: {}", item.toStdString()); int trust_level = 0; // Unknown Level @@ -426,12 +426,23 @@ void KeyPairOperaTab::slot_set_owner_trust_level() { } else if (item == _("Undefined")) { trust_level = 1; } + + if (trust_level == 0) { + QMessageBox::warning( + this, _("Warning"), + QString(_("Owner Trust Level cannot set to Unknown level, automately " + "changing it into Undefined level."))); + trust_level = 1; + } + bool status = GpgKeyManager::GetInstance().SetOwnerTrustLevel(m_key_, trust_level); if (!status) { QMessageBox::critical(this, _("Failed"), QString(_("Modify Owner Trust Level failed."))); } else { + QMessageBox::information(this, _("Success"), + QString(_("Set Owner Trust Level successful."))); // update key database and refresh ui emit SignalKeyDatabaseRefresh(); } |