diff --git a/src/ui/keyselectiondialog.cpp b/src/ui/keyselectiondialog.cpp --- a/src/ui/keyselectiondialog.cpp +++ b/src/ui/keyselectiondialog.cpp @@ -83,55 +83,69 @@ #include #include -static bool checkKeyUsage(const GpgME::Key &key, unsigned int keyUsage) +static bool checkKeyUsage(const GpgME::Key &key, unsigned int keyUsage, QString *statusString = Q_NULLPTR) { + auto setStatusString = [statusString](const QString &status) { + if (statusString) { + *statusString = status; + } + }; if (keyUsage & Kleo::KeySelectionDialog::ValidKeys) { if (key.isInvalid()) { if (key.keyListMode() & GpgME::Validate) { qCDebug(KLEO_UI_LOG) << "key is invalid"; + setStatusString(i18n("The key is not valid.")); return false; } else { qCDebug(KLEO_UI_LOG) << "key is invalid - ignoring"; } } if (key.isExpired()) { qCDebug(KLEO_UI_LOG) << "key is expired"; + setStatusString(i18n("The key is expired.")); return false; } else if (key.isRevoked()) { qCDebug(KLEO_UI_LOG) << "key is revoked"; + setStatusString(i18n("The key is revoked.")); return false; } else if (key.isDisabled()) { qCDebug(KLEO_UI_LOG) << "key is disabled"; + setStatusString(i18n("The key is disabled.")); return false; } } if (keyUsage & Kleo::KeySelectionDialog::EncryptionKeys && !key.canEncrypt()) { qCDebug(KLEO_UI_LOG) << "key can't encrypt"; + setStatusString(i18n("The key is not designated for encryption.")); return false; } if (keyUsage & Kleo::KeySelectionDialog::SigningKeys && !key.canSign()) { qCDebug(KLEO_UI_LOG) << "key can't sign"; + setStatusString(i18n("The key is not designated for signing.")); return false; } if (keyUsage & Kleo::KeySelectionDialog::CertificationKeys && !key.canCertify()) { qCDebug(KLEO_UI_LOG) << "key can't certify"; + setStatusString(i18n("The key is not designated for certifying.")); return false; } if (keyUsage & Kleo::KeySelectionDialog::AuthenticationKeys && !key.canAuthenticate()) { qCDebug(KLEO_UI_LOG) << "key can't authenticate"; + setStatusString(i18n("The key is not designated for authentication.")); return false; } if (keyUsage & Kleo::KeySelectionDialog::SecretKeys && !(keyUsage & Kleo::KeySelectionDialog::PublicKeys) && !key.hasSecret()) { qCDebug(KLEO_UI_LOG) << "key isn't secret"; + setStatusString(i18n("The key is not secret.")); return false; } @@ -146,11 +160,13 @@ return true; } qCDebug(KLEO_UI_LOG) << "key has no UIDs with validity >= Marginal"; + setStatusString(i18n("The key is not trusted enough.")); return false; } // X.509 keys are always trusted, else they won't be the keybox. // PENDING(marc) check that this ^ is correct + setStatusString(i18n("The key can be used.")); return true; } @@ -262,24 +278,33 @@ const GpgME::Subkey subkey = key.subkey(0); const QString expiry = subkey.neverExpires() ? i18n("never") : time_t2string(subkey.expirationTime()); const QString creation = time_t2string(subkey.creationTime()); - if (key.protocol() == GpgME::OpenPGP) - return i18n("OpenPGP key for %1\n" - "Created: %2\n" - "Expiry: %3\n" - "Fingerprint: %4", - uid ? QString::fromUtf8(uid) : i18n("unknown"), - creation, expiry, - fpr ? QString::fromLatin1(fpr) : i18n("unknown")); - else - return i18n("S/MIME key for %1\n" - "Created: %2\n" - "Expiry: %3\n" - "Fingerprint: %4\n" - "Issuer: %5", - uid ? Kleo::DN(uid).prettyDN() : i18n("unknown"), - creation, expiry, - fpr ? QString::fromLatin1(fpr) : i18n("unknown"), - issuer ? Kleo::DN(issuer).prettyDN() : i18n("unknown")); + QString keyStatusString; + if (!checkKeyUsage(key, mKeyUsage, &keyStatusString)) { + // Show the status in bold if there is a problem + keyStatusString = QLatin1String("") % keyStatusString % QLatin1String(""); + } + + QString html = QStringLiteral("

"); + if (key.protocol() == GpgME::OpenPGP) { + html += i18n("OpenPGP key for %1", uid ? QString::fromUtf8(uid) : i18n("unknown")); + } else { + html += i18n("S/MIME key for %1", uid ? Kleo::DN(uid).prettyDN() : i18n("unknown")); + } + html += QStringLiteral("

"); + + const auto addRow = [&html](const QString &name, const QString &value) { + html += QStringLiteral("").arg(name, value); + }; + addRow(i18nc("Key creation date", "Created"), creation); + addRow(i18nc("Key Expiration date", "Expiry"), expiry); + addRow(i18nc("Key fingerprint", "Fingerprint"), fpr ? QString::fromLatin1(fpr) : i18n("unknown")); + if (key.protocol() != GpgME::OpenPGP) { + addRow(i18nc("Key issuer", "Issuer"), issuer ? Kleo::DN(issuer).prettyDN() : i18n("unknown")); + } + addRow(i18nc("Key status", "Status"), keyStatusString); + html += QStringLiteral("
%1: %2
"); + + return html; } QIcon ColumnStrategy::icon(const GpgME::Key &key, int col) const