File indexing completed on 2024-06-23 05:13:44

0001 /* -*- mode: c++; c-basic-offset:4 -*-
0002     commands/refreshopenpgpcertscommand.cpp
0003 
0004     This file is part of Kleopatra, the KDE keymanager
0005     SPDX-FileCopyrightText: 2008 Klarälvdalens Datakonsult AB
0006 
0007     SPDX-License-Identifier: GPL-2.0-or-later
0008 */
0009 
0010 #include <config-kleopatra.h>
0011 
0012 #include "refreshopenpgpcertscommand.h"
0013 
0014 #include "command_p.h"
0015 
0016 #include <Libkleo/GnuPG>
0017 
0018 #include <KLocalizedString>
0019 #include <KMessageBox>
0020 
0021 using namespace Kleo;
0022 using namespace Kleo::Commands;
0023 
0024 RefreshOpenPGPCertsCommand::RefreshOpenPGPCertsCommand(KeyListController *c)
0025     : GnuPGProcessCommand(c)
0026 {
0027     setShowsOutputWindow(true);
0028 }
0029 
0030 RefreshOpenPGPCertsCommand::RefreshOpenPGPCertsCommand(QAbstractItemView *v, KeyListController *c)
0031     : GnuPGProcessCommand(v, c)
0032 {
0033     setShowsOutputWindow(true);
0034 }
0035 
0036 RefreshOpenPGPCertsCommand::~RefreshOpenPGPCertsCommand()
0037 {
0038 }
0039 
0040 bool RefreshOpenPGPCertsCommand::preStartHook(QWidget *parent) const
0041 {
0042     if (!haveKeyserverConfigured()) {
0043         d->error(i18nc("@info",
0044                        "Refreshing the OpenPGP certificates is not possible because "
0045                        "the usage of key servers has been disabled explicitly."));
0046         return false;
0047     }
0048     return KMessageBox::warningContinueCancel(parent,
0049                                               xi18nc("@info",
0050                                                      "<para>Refreshing OpenPGP certificates implies downloading all certificates anew, "
0051                                                      "to check if any of them have been revoked in the meantime.</para>"
0052                                                      "<para>This can put a severe strain on your own as well as other people's network "
0053                                                      "connections, and can take up to an hour or more to complete, depending on "
0054                                                      "your network connection, and the number of certificates to check.</para> "
0055                                                      "<para>Are you sure you want to continue?</para>"),
0056                                               i18nc("@title:window", "OpenPGP Certificate Refresh"),
0057                                               KStandardGuiItem::cont(),
0058                                               KStandardGuiItem::cancel(),
0059                                               QStringLiteral("warn-refresh-openpgp-expensive"))
0060         == KMessageBox::Continue;
0061 }
0062 
0063 QStringList RefreshOpenPGPCertsCommand::arguments() const
0064 {
0065     QStringList result;
0066     result << gpgPath();
0067     result << QStringLiteral("--refresh-keys");
0068     return result;
0069 }
0070 
0071 QString RefreshOpenPGPCertsCommand::errorCaption() const
0072 {
0073     return i18nc("@title:window", "OpenPGP Certificate Refresh Error");
0074 }
0075 
0076 QString RefreshOpenPGPCertsCommand::successCaption() const
0077 {
0078     return i18nc("@title:window", "OpenPGP Certificate Refresh Finished");
0079 }
0080 
0081 QString RefreshOpenPGPCertsCommand::crashExitMessage(const QStringList &args) const
0082 {
0083     return xi18nc("@info",
0084                   "<para>The GPG process that tried to refresh OpenPGP certificates "
0085                   "ended prematurely because of an unexpected error.</para>"
0086                   "<para>Please check the output of <icode>%1</icode> for details.</para>",
0087                   args.join(QLatin1Char(' ')));
0088 }
0089 
0090 QString RefreshOpenPGPCertsCommand::errorExitMessage(const QStringList &args) const
0091 {
0092     return xi18nc("@info",
0093                   "<para>An error occurred while trying to refresh OpenPGP certificates.</para> "
0094                   "<para>The output from <command>%1</command> was: <bcode>%2</bcode></para>",
0095                   args[0],
0096                   errorString());
0097 }
0098 
0099 QString RefreshOpenPGPCertsCommand::successMessage(const QStringList &) const
0100 {
0101     return i18nc("@info", "OpenPGP certificates refreshed successfully.");
0102     // ### --check-trustdb
0103 }
0104 
0105 #include "moc_refreshopenpgpcertscommand.cpp"