diff --git a/src/aboutdata.cpp b/src/aboutdata.cpp index 9d926901e..c6df6bf6e 100644 --- a/src/aboutdata.cpp +++ b/src/aboutdata.cpp @@ -1,131 +1,131 @@ /* aboutdata.cpp This file is part of Kleopatra, the KDE keymanager SPDX-FileCopyrightText: 2001, 2002, 2004 Klarälvdalens Datakonsult AB SPDX-License-Identifier: GPL-2.0-or-later */ #include #include #include "aboutdata.h" #include #include -#include "ki18n_version.h" +#include #if KI18N_VERSION >= QT_VERSION_CHECK(5, 89, 0) -#include +#include #undef I18N_NOOP #define I18N_NOOP kli18n #endif static const char kleopatra_version[] = KLEOPATRA_VERSION_STRING; struct about_data { #if KI18N_VERSION < QT_VERSION_CHECK(5, 89, 0) const char *name; const char *desc; #else const KLazyLocalizedString name; const KLazyLocalizedString desc; #endif const char *email; const char *web; }; static const about_data authors[] = { { I18N_NOOP("Andre Heinecke"), I18N_NOOP("Current Maintainer"), "aheinecke@gnupg.org", nullptr }, { I18N_NOOP("Marc Mutz"), I18N_NOOP("Former Maintainer"), "mutz@kde.org", nullptr }, { I18N_NOOP("Steffen Hansen"), I18N_NOOP("Former Maintainer"), "hansen@kde.org", nullptr }, { I18N_NOOP("Matthias Kalle Dalheimer"), I18N_NOOP("Original Author"), "kalle@kde.org", nullptr }, }; static const about_data credits[] = { { I18N_NOOP("David Faure"), I18N_NOOP("Backend configuration framework, KIO integration"), "faure@kde.org", nullptr }, { I18N_NOOP("Michel Boyer de la Giroday"), I18N_NOOP("Key-state dependent colors and fonts in the certificates list"), "michel@klaralvdalens-datakonsult.se", nullptr }, { I18N_NOOP("Thomas Moenicke"), I18N_NOOP("Artwork"), "tm@php-qt.org", nullptr }, { I18N_NOOP("Frank Osterfeld"), I18N_NOOP("Resident gpgme/win wrangler, UI Server commands and dialogs"), "osterfeld@kde.org", nullptr }, { I18N_NOOP("Karl-Heinz Zimmer"), I18N_NOOP("DN display ordering support, infrastructure"), "khz@kde.org", nullptr }, { I18N_NOOP("Laurent Montel"), I18N_NOOP("Qt5 port, general code maintenance"), "montel@kde.org", nullptr }, }; AboutData::AboutData() : KAboutData(QStringLiteral("kleopatra"), i18n("Kleopatra"), #ifdef Q_OS_WIN Kleo::gpg4winVersion(), Kleo::gpg4winDescription(), #else QLatin1String(kleopatra_version), i18n("Certificate Manager and Unified Crypto GUI"), #endif KAboutLicense::GPL, i18n("(c) 2002 Steffen\u00A0Hansen, Matthias\u00A0Kalle\u00A0" "Dalheimer, Klar\u00E4lvdalens\u00A0" "Datakonsult\u00A0" "AB\n" "(c) 2004, 2007, 2008, 2009 Marc\u00A0Mutz, Klar\u00E4lvdalens\u00A0" "Datakonsult\u00A0" "AB") + QLatin1Char('\n') + i18n("(c) 2010-2021 The Kleopatra developers, g10 Code GmbH, Intevation GmbH") #ifdef Q_OS_WIN , Kleo::gpg4winLongDescription() #endif ) { using ::authors; using ::credits; #if KI18N_VERSION < QT_VERSION_CHECK(5, 89, 0) for (unsigned int i = 0; i < sizeof authors / sizeof * authors; ++i) { addAuthor(i18n(authors[i].name), i18n(authors[i].desc), QLatin1String(authors[i].email), QLatin1String(authors[i].web)); } for (unsigned int i = 0; i < sizeof credits / sizeof * credits; ++i) { addCredit(i18n(credits[i].name), i18n(credits[i].desc), QLatin1String(credits[i].email), QLatin1String(credits[i].web)); } #else for (unsigned int i = 0; i < sizeof authors / sizeof * authors; ++i) { addAuthor(KLocalizedString(authors[i].name).toString(), KLocalizedString(authors[i].desc).toString(), QLatin1String(authors[i].email), QLatin1String(authors[i].web)); } for (unsigned int i = 0; i < sizeof credits / sizeof * credits; ++i) { addCredit(KLocalizedString(credits[i].name).toString(), KLocalizedString(credits[i].desc).toString(), QLatin1String(credits[i].email), QLatin1String(credits[i].web)); } #endif const auto backendVersions = Kleo::backendVersionInfo(); if (!backendVersions.empty()) { setOtherText(i18nc("Preceeds a list of applications/libraries used by Kleopatra", "Uses:") + QLatin1String{"
  • "} + backendVersions.join(QLatin1String{"
  • "}) + QLatin1String{"
"} + otherText()); } #ifdef Q_OS_WIN setBugAddress("https://dev.gnupg.org/u/rgpg4win"); #endif } diff --git a/src/commands/deletecertificatescommand.cpp b/src/commands/deletecertificatescommand.cpp index f6948ee1f..d00a57049 100644 --- a/src/commands/deletecertificatescommand.cpp +++ b/src/commands/deletecertificatescommand.cpp @@ -1,450 +1,450 @@ /* -*- mode: c++; c-basic-offset:4 -*- deleteCertificatescommand.cpp This file is part of Kleopatra, the KDE keymanager SPDX-FileCopyrightText: 2007 Klarälvdalens Datakonsult AB SPDX-License-Identifier: GPL-2.0-or-later */ #include #include "deletecertificatescommand.h" #include "command_p.h" #include #include #include #include #include #include #include #include #include #include #include #include #include -#include "ki18n_version.h" +#include #if KI18N_VERSION >= QT_VERSION_CHECK(5, 89, 0) -#include +#include #undef I18N_NOOP #define I18N_NOOP kli18n #define I18N_NOOP_EMPTY KLazyLocalizedString() #else #define I18N_NOOP_EMPTY "" #endif using namespace GpgME; using namespace Kleo; using namespace Kleo::Dialogs; using namespace QGpgME; class DeleteCertificatesCommand::Private : public Command::Private { friend class ::Kleo::DeleteCertificatesCommand; DeleteCertificatesCommand *q_func() const { return static_cast(q); } public: explicit Private(DeleteCertificatesCommand *qq, KeyListController *c); ~Private() override; void startDeleteJob(GpgME::Protocol protocol); void cancelJobs(); void pgpDeleteResult(const GpgME::Error &); void cmsDeleteResult(const GpgME::Error &); void showErrorsAndFinish(); bool canDelete(GpgME::Protocol proto) const { if (const auto cbp = (proto == GpgME::OpenPGP ? QGpgME::openpgp() : QGpgME::smime())) if (DeleteJob *const job = cbp->deleteJob()) { job->slotCancel(); return true; } return false; } void ensureDialogCreated() { if (dialog) { return; } dialog = new DeleteCertificatesDialog; applyWindowID(dialog); dialog->setAttribute(Qt::WA_DeleteOnClose); dialog->setWindowTitle(i18nc("@title:window", "Delete Certificates")); connect(dialog, SIGNAL(accepted()), q_func(), SLOT(slotDialogAccepted())); connect(dialog, SIGNAL(rejected()), q_func(), SLOT(slotDialogRejected())); } void ensureDialogShown() { if (dialog) { dialog->show(); } } void slotDialogAccepted(); void slotDialogRejected() { canceled(); } private: QPointer dialog; QPointer cmsJob, pgpJob; GpgME::Error cmsError, pgpError; std::vector cmsKeys, pgpKeys; }; DeleteCertificatesCommand::Private *DeleteCertificatesCommand::d_func() { return static_cast(d.get()); } const DeleteCertificatesCommand::Private *DeleteCertificatesCommand::d_func() const { return static_cast(d.get()); } #define d d_func() #define q q_func() DeleteCertificatesCommand::Private::Private(DeleteCertificatesCommand *qq, KeyListController *c) : Command::Private(qq, c) { } DeleteCertificatesCommand::Private::~Private() {} DeleteCertificatesCommand::DeleteCertificatesCommand(KeyListController *p) : Command(new Private(this, p)) { } DeleteCertificatesCommand::DeleteCertificatesCommand(QAbstractItemView *v, KeyListController *p) : Command(v, new Private(this, p)) { } DeleteCertificatesCommand::~DeleteCertificatesCommand() {} namespace { enum Action { Nothing = 0, Failure = 1, ClearCMS = 2, ClearPGP = 4 }; // const unsigned int errorCase = // openpgp.empty() << 3U | d->canDelete( OpenPGP ) << 2U | // cms.empty() << 1U | d->canDelete( CMS ) << 0U ; static const struct { #if KI18N_VERSION < QT_VERSION_CHECK(5, 89, 0) const char *text; #else const KLazyLocalizedString text; #endif Action actions; } deletionErrorCases[16] = { // if havePGP // if cantPGP // if haveCMS { I18N_NOOP("Neither the OpenPGP nor the CMS " "backends support certificate deletion.\n" "Check your installation."), Failure }, // cantCMS { I18N_NOOP("The OpenPGP backend does not support " "certificate deletion.\n" "Check your installation.\n" "Only the selected CMS certificates " "will be deleted."), ClearPGP }, // canCMS // if !haveCMS { I18N_NOOP("The OpenPGP backend does not support " "certificate deletion.\n" "Check your installation."), Failure }, { I18N_NOOP("The OpenPGP backend does not support " "certificate deletion.\n" "Check your installation."), Failure }, // if canPGP // if haveCMS { I18N_NOOP("The CMS backend does not support " "certificate deletion.\n" "Check your installation.\n" "Only the selected OpenPGP certificates " "will be deleted."), ClearCMS }, // cantCMS { I18N_NOOP_EMPTY, Nothing }, // canCMS // if !haveCMS { I18N_NOOP_EMPTY, Nothing }, // cantCMS { I18N_NOOP_EMPTY, Nothing }, // canCMS // if !havePGP // if cantPGP // if haveCMS { I18N_NOOP("The CMS backend does not support " "certificate deletion.\n" "Check your installation."), Failure }, // cantCMS { I18N_NOOP_EMPTY, Nothing }, // canCMS // if !haveCMS { I18N_NOOP_EMPTY, Nothing }, // cantCMS { I18N_NOOP_EMPTY, Nothing }, // canCMS // if canPGP // if haveCMS { I18N_NOOP("The CMS backend does not support " "certificate deletion.\n" "Check your installation."), Failure }, // cantCMS { I18N_NOOP_EMPTY, Nothing }, // canCMS // if !haveCMS { I18N_NOOP_EMPTY, Nothing }, // cantCMS { I18N_NOOP_EMPTY, Nothing }, // canCMS }; } // anon namespace void DeleteCertificatesCommand::doStart() { std::vector selected = d->keys(); if (selected.empty()) { d->finished(); return; } std::sort(selected.begin(), selected.end(), _detail::ByFingerprint()); // Calculate the closure of the selected keys (those that need to // be deleted with them, though not selected themselves): std::vector toBeDeleted = KeyCache::instance()->findSubjects(selected); std::sort(toBeDeleted.begin(), toBeDeleted.end(), _detail::ByFingerprint()); std::vector unselected; unselected.reserve(toBeDeleted.size()); std::set_difference(toBeDeleted.begin(), toBeDeleted.end(), selected.begin(), selected.end(), std::back_inserter(unselected), _detail::ByFingerprint()); d->ensureDialogCreated(); d->dialog->setSelectedKeys(selected); d->dialog->setUnselectedKeys(unselected); d->ensureDialogShown(); } void DeleteCertificatesCommand::Private::slotDialogAccepted() { std::vector keys = dialog->keys(); Q_ASSERT(!keys.empty()); auto pgpBegin = keys.begin(); auto pgpEnd = std::stable_partition(pgpBegin, keys.end(), [](const GpgME::Key &key) { return key.protocol() != GpgME::CMS; }); auto cmsBegin = pgpEnd; auto cmsEnd = keys.end(); std::vector openpgp(pgpBegin, pgpEnd); std::vector cms(cmsBegin, cmsEnd); const unsigned int errorCase = openpgp.empty() << 3U | canDelete(OpenPGP) << 2U | cms.empty() << 1U | canDelete(CMS) << 0U; if (const unsigned int actions = deletionErrorCases[errorCase].actions) { #if KI18N_VERSION < QT_VERSION_CHECK(5, 89, 0) information(i18n(deletionErrorCases[errorCase].text), (actions & Failure) ? i18n("Certificate Deletion Failed") : i18n("Certificate Deletion Problem")); #else information(KLocalizedString(deletionErrorCases[errorCase].text).toString(), (actions & Failure) ? i18n("Certificate Deletion Failed") : i18n("Certificate Deletion Problem")); #endif if (actions & ClearCMS) { cms.clear(); } if (actions & ClearPGP) { openpgp.clear(); } if (actions & Failure) { canceled(); return; } } Q_ASSERT(!openpgp.empty() || !cms.empty()); pgpKeys.swap(openpgp); cmsKeys.swap(cms); if (!pgpKeys.empty()) { startDeleteJob(GpgME::OpenPGP); } if (!cmsKeys.empty()) { startDeleteJob(GpgME::CMS); } if ((pgpKeys.empty() || pgpError.code()) && (cmsKeys.empty() || cmsError.code())) { showErrorsAndFinish(); } } void DeleteCertificatesCommand::Private::startDeleteJob(GpgME::Protocol protocol) { Q_ASSERT(protocol != GpgME::UnknownProtocol); const std::vector &keys = protocol == CMS ? cmsKeys : pgpKeys; const auto backend = (protocol == GpgME::OpenPGP) ? QGpgME::openpgp() : QGpgME::smime(); Q_ASSERT(backend); std::unique_ptr job(new MultiDeleteJob(backend)); if (protocol == CMS) connect(job.get(), SIGNAL(result(GpgME::Error,GpgME::Key)), q_func(), SLOT(cmsDeleteResult(GpgME::Error))); else connect(job.get(), SIGNAL(result(GpgME::Error,GpgME::Key)), q_func(), SLOT(pgpDeleteResult(GpgME::Error))); connect(job.get(), &Job::progress, q, &Command::progress); if (const Error err = job->start(keys, true /*allowSecretKeyDeletion*/)) { (protocol == CMS ? cmsError : pgpError) = err; } else { (protocol == CMS ? cmsJob : pgpJob) = job.release(); } } void DeleteCertificatesCommand::Private::showErrorsAndFinish() { Q_ASSERT(!pgpJob); Q_ASSERT(!cmsJob); if (pgpError || cmsError) { QString pgpErrorString; if (pgpError) { pgpErrorString = i18n("OpenPGP backend: %1", QString::fromLocal8Bit(pgpError.asString())); } QString cmsErrorString; if (cmsError) { cmsErrorString = i18n("CMS backend: %1", QString::fromLocal8Bit(cmsError.asString())); } const QString msg = i18n("

An error occurred while trying to delete " "the certificate:

" "

%1

", pgpError ? cmsError ? pgpErrorString + QLatin1String("
") + cmsErrorString : pgpErrorString : cmsErrorString); error(msg, i18n("Certificate Deletion Failed")); } else if (!pgpError.isCanceled() && !cmsError.isCanceled()) { std::vector keys = pgpKeys; keys.insert(keys.end(), cmsKeys.begin(), cmsKeys.end()); KeyCache::mutableInstance()->remove(keys); } finished(); } void DeleteCertificatesCommand::doCancel() { d->cancelJobs(); } void DeleteCertificatesCommand::Private::pgpDeleteResult(const Error &err) { pgpError = err; pgpJob = nullptr; if (!cmsJob) { showErrorsAndFinish(); } } void DeleteCertificatesCommand::Private::cmsDeleteResult(const Error &err) { cmsError = err; cmsJob = nullptr; if (!pgpJob) { showErrorsAndFinish(); } } void DeleteCertificatesCommand::Private::cancelJobs() { if (cmsJob) { cmsJob->slotCancel(); } if (pgpJob) { pgpJob->slotCancel(); } } #undef d #undef q #include "moc_deletecertificatescommand.cpp"