diff --git a/src/commands/exportopenpgpcertstoservercommand.cpp b/src/commands/exportopenpgpcertstoservercommand.cpp index 9f185ddc6..af0430601 100644 --- a/src/commands/exportopenpgpcertstoservercommand.cpp +++ b/src/commands/exportopenpgpcertstoservercommand.cpp @@ -1,189 +1,177 @@ /* -*- mode: c++; c-basic-offset:4 -*- commands/exportopenpgpcertstoservercommand.cpp This file is part of Kleopatra, the KDE keymanager SPDX-FileCopyrightText: 2008 Klarälvdalens Datakonsult AB SPDX-License-Identifier: GPL-2.0-or-later */ #include #include "exportopenpgpcertstoservercommand.h" #include "command_p.h" #include #include #include #include #include #include #include using namespace Kleo; using namespace Kleo::Commands; using namespace GpgME; ExportOpenPGPCertsToServerCommand::ExportOpenPGPCertsToServerCommand(KeyListController *c) : GnuPGProcessCommand(c) { } ExportOpenPGPCertsToServerCommand::ExportOpenPGPCertsToServerCommand(QAbstractItemView *v, KeyListController *c) : GnuPGProcessCommand(v, c) { } ExportOpenPGPCertsToServerCommand::ExportOpenPGPCertsToServerCommand(const Key &key) : GnuPGProcessCommand(key) { } ExportOpenPGPCertsToServerCommand::ExportOpenPGPCertsToServerCommand(const std::vector &keys) : GnuPGProcessCommand(keys) { } ExportOpenPGPCertsToServerCommand::~ExportOpenPGPCertsToServerCommand() = default; static bool confirmExport(const std::vector &pgpKeys, QWidget *parentWidget) { auto notCertifiedKeys = std::accumulate(pgpKeys.cbegin(), pgpKeys.cend(), QStringList{}, [](auto keyNames, const auto &key) { const bool allValidUserIDsAreCertifiedByUser = Kleo::all_of(key.userIDs(), [](const UserID &userId) { return userId.isBad() || Kleo::userIDIsCertifiedByUser(userId); }); if (!allValidUserIDsAreCertifiedByUser) { keyNames.push_back(Formatting::formatForComboBox(key)); } return keyNames; }); if (!notCertifiedKeys.empty()) { if (pgpKeys.size() == 1) { const auto answer = KMessageBox::warningContinueCancel( // parentWidget, xi18nc("@info", "You haven't certified all valid user IDs of this certificate " "with an exportable certification. People relying on your certifications " "may not be able to verify the certificate." "Do you want to continue the export?"), i18nc("@title:window", "Confirm Certificate Export"), KGuiItem{i18ncp("@action:button", "Export Certificate", "Export Certificates", 1)}, KStandardGuiItem::cancel(), QStringLiteral("confirm-upload-of-uncertified-keys")); return answer == KMessageBox::Continue; } else { std::sort(notCertifiedKeys.begin(), notCertifiedKeys.end()); const auto answer = KMessageBox::warningContinueCancelList( // parentWidget, xi18nc("@info", "You haven't certified all valid user IDs of the certificates listed below " "with exportable certifications. People relying on your certifications " "may not be able to verify the certificates." "Do you want to continue the export?"), notCertifiedKeys, i18nc("@title:window", "Confirm Certificate Export"), KGuiItem{i18ncp("@action:button", "Export Certificate", "Export Certificates", pgpKeys.size())}, KStandardGuiItem::cancel(), QStringLiteral("confirm-upload-of-uncertified-keys")); return answer == KMessageBox::Continue; } } return true; } bool ExportOpenPGPCertsToServerCommand::preStartHook(QWidget *parent) const { if (!haveKeyserverConfigured()) { - if (KMessageBox::warningContinueCancel(parent, - xi18nc("@info", - "No OpenPGP directory services have been configured." - "Since none is configured, Kleopatra will use " - "keys.gnupg.net as the server to export to." - "You can configure OpenPGP directory servers in Kleopatra's " - "configuration dialog." - "Do you want to continue with keys.gnupg.net " - "as the server to export to?"), - i18nc("@title:window", "OpenPGP Certificate Export"), - KGuiItem{i18ncp("@action:button", "Export Certificate", "Export Certificates", d->keys().size())}, - KStandardGuiItem::cancel(), - QStringLiteral("warn-export-openpgp-missing-keyserver")) - != KMessageBox::Continue) { - return false; - } + d->error(i18ncp("@info", + "Exporting the certificate to a key server is not possible " + "because the usage of key servers has been disabled explicitly.", + "Exporting the certificates to a key server is not possible " + "because the usage of key servers has been disabled explicitly.", + d->keys().size())); + return false; } if (!confirmExport(d->keys(), parent)) { return false; } return KMessageBox::warningContinueCancel(parent, xi18nc("@info", "When OpenPGP certificates have been exported to a public directory server, " "it is nearly impossible to remove them again." "Before exporting your certificate to a public directory server, make sure that you " "have created a revocation certificate so you can revoke the certificate if needed later." "Are you sure you want to continue?"), i18nc("@title:window", "OpenPGP Certificate Export"), KGuiItem{i18ncp("@action:button", "Export Certificate", "Export Certificates", d->keys().size())}, KStandardGuiItem::cancel(), QStringLiteral("warn-export-openpgp-nonrevocable")) == KMessageBox::Continue; } QStringList ExportOpenPGPCertsToServerCommand::arguments() const { QStringList result; result << gpgPath(); - if (!haveKeyserverConfigured()) { - result << QStringLiteral("--keyserver") << QStringLiteral("keys.gnupg.net"); - } result << QStringLiteral("--send-keys"); const auto keys = d->keys(); for (const Key &key : keys) { result << QLatin1String(key.primaryFingerprint()); } return result; } QString ExportOpenPGPCertsToServerCommand::errorCaption() const { return i18nc("@title:window", "OpenPGP Certificate Export Error"); } QString ExportOpenPGPCertsToServerCommand::successCaption() const { return i18nc("@title:window", "OpenPGP Certificate Export Finished"); } QString ExportOpenPGPCertsToServerCommand::crashExitMessage(const QStringList &args) const { return xi18nc("@info", "The GPG process that tried to export OpenPGP certificates " "ended prematurely because of an unexpected error." "Please check the output of %1 for details.", args.join(QLatin1Char(' '))); } QString ExportOpenPGPCertsToServerCommand::errorExitMessage(const QStringList &args) const { // ki18n(" ") as initializer because initializing with empty string leads to // (I18N_EMPTY_MESSAGE) const auto errorLines = errorString().split(QLatin1Char{'\n'}); const auto errorText = std::accumulate(errorLines.begin(), errorLines.end(), KLocalizedString{ki18n(" ")}, [](KLocalizedString temp, const auto &line) { return kxi18nc("@info used for concatenating multiple lines of text with line breaks; most likely this shouldn't be translated", "%1%2") .subs(temp) .subs(line); }); return xi18nc("@info", "An error occurred while trying to export OpenPGP certificates. " "The output of %1 was:%2", args[0], errorText); } QString ExportOpenPGPCertsToServerCommand::successMessage(const QStringList &) const { return i18nc("@info", "OpenPGP certificates exported successfully."); } diff --git a/src/commands/refreshopenpgpcertscommand.cpp b/src/commands/refreshopenpgpcertscommand.cpp index 4eb0537b4..24f9f1f06 100644 --- a/src/commands/refreshopenpgpcertscommand.cpp +++ b/src/commands/refreshopenpgpcertscommand.cpp @@ -1,117 +1,103 @@ /* -*- mode: c++; c-basic-offset:4 -*- commands/refreshopenpgpcertscommand.cpp This file is part of Kleopatra, the KDE keymanager SPDX-FileCopyrightText: 2008 Klarälvdalens Datakonsult AB SPDX-License-Identifier: GPL-2.0-or-later */ #include #include "refreshopenpgpcertscommand.h" +#include "command_p.h" + #include #include #include using namespace Kleo; using namespace Kleo::Commands; RefreshOpenPGPCertsCommand::RefreshOpenPGPCertsCommand(KeyListController *c) : GnuPGProcessCommand(c) { setShowsOutputWindow(true); } RefreshOpenPGPCertsCommand::RefreshOpenPGPCertsCommand(QAbstractItemView *v, KeyListController *c) : GnuPGProcessCommand(v, c) { setShowsOutputWindow(true); } RefreshOpenPGPCertsCommand::~RefreshOpenPGPCertsCommand() { } bool RefreshOpenPGPCertsCommand::preStartHook(QWidget *parent) const { - if (!haveKeyserverConfigured()) - if (KMessageBox::warningContinueCancel(parent, - xi18nc("@info", - "No OpenPGP directory services have been configured." - "If not all of the certificates carry the name of their preferred " - "certificate server (few do), a fallback server is needed to fetch from." - "Since none is configured, Kleopatra will use " - "keys.gnupg.net as the fallback." - "You can configure OpenPGP directory servers in Kleopatra's " - "configuration dialog." - "Do you want to continue with keys.gnupg.net " - "as fallback server?"), - i18nc("@title:window", "OpenPGP Certificate Refresh"), - KStandardGuiItem::cont(), - KStandardGuiItem::cancel(), - QStringLiteral("warn-refresh-openpgp-missing-keyserver")) - != KMessageBox::Continue) { - return false; - } + if (!haveKeyserverConfigured()) { + d->error(i18nc("@info", + "Refreshing the OpenPGP certificates is not possible because " + "the usage of key servers has been disabled explicitly.")); + return false; + } return KMessageBox::warningContinueCancel(parent, xi18nc("@info", "Refreshing OpenPGP certificates implies downloading all certificates anew, " "to check if any of them have been revoked in the meantime." "This can put a severe strain on your own as well as other people's network " "connections, and can take up to an hour or more to complete, depending on " "your network connection, and the number of certificates to check. " "Are you sure you want to continue?"), i18nc("@title:window", "OpenPGP Certificate Refresh"), KStandardGuiItem::cont(), KStandardGuiItem::cancel(), QStringLiteral("warn-refresh-openpgp-expensive")) == KMessageBox::Continue; } QStringList RefreshOpenPGPCertsCommand::arguments() const { QStringList result; result << gpgPath(); - if (!haveKeyserverConfigured()) { - result << QStringLiteral("--keyserver") << QStringLiteral("keys.gnupg.net"); - } result << QStringLiteral("--refresh-keys"); return result; } QString RefreshOpenPGPCertsCommand::errorCaption() const { return i18nc("@title:window", "OpenPGP Certificate Refresh Error"); } QString RefreshOpenPGPCertsCommand::successCaption() const { return i18nc("@title:window", "OpenPGP Certificate Refresh Finished"); } QString RefreshOpenPGPCertsCommand::crashExitMessage(const QStringList &args) const { return xi18nc("@info", "The GPG process that tried to refresh OpenPGP certificates " "ended prematurely because of an unexpected error." "Please check the output of %1 for details.", args.join(QLatin1Char(' '))); } QString RefreshOpenPGPCertsCommand::errorExitMessage(const QStringList &args) const { return xi18nc("@info", "An error occurred while trying to refresh OpenPGP certificates. " "The output from %1 was: %2", args[0], errorString()); } QString RefreshOpenPGPCertsCommand::successMessage(const QStringList &) const { return i18nc("@info", "OpenPGP certificates refreshed successfully."); // ### --check-trustdb }