Propose better file names for export

This makes it clearer what is exported and avoids
just having cryptic names in the home directory
that have the fingerprint.

It also should help to avoid that users send their
secret key out instead of the public one.

GnuPG-Bug-Id: T4995
parent 0a6e22af
Pipeline #27411 passed with stage
in 23 minutes and 35 seconds
......@@ -42,6 +42,7 @@
#include <utils/filedialog.h>
#include <Libkleo/Classify>
#include <Libkleo/Formatting>
#include <QGpgME/Protocol>
#include <QGpgME/ExportJob>
......@@ -211,13 +212,17 @@ bool ExportCertificateCommand::Private::requestFileNames(GpgME::Protocol protoco
QString proposedFileName;
if (keys().size() == 1) {
const bool usePGPFileExt = FileOperationsPreferences().usePGPFileExt();
proposedFileName
= QString::fromLatin1(keys().front().primaryFingerprint())
+ QLatin1Char('.')
+ QString::fromLatin1(outputFileExtension(protocol == OpenPGP
? Class::OpenPGP | Class::Ascii | Class::Certificate
: Class::CMS | Class::Ascii | Class::Certificate, usePGPFileExt))
;
const auto key = keys().front();
auto name = Formatting::prettyName(key);
if (name.isEmpty()) {
name = Formatting::prettyEMail(key);
}
/* Not translated so it's better to use in tutorials etc. */
proposedFileName = QStringLiteral("%1_%2_public.%3").arg(name).arg(
Formatting::prettyKeyID(key.shortKeyID())).arg(
QString::fromLatin1(outputFileExtension(protocol == OpenPGP
? Class::OpenPGP | Class::Ascii | Class::Certificate
: Class::CMS | Class::Ascii | Class::Certificate, usePGPFileExt)));
}
const QString fname = FileDialog::getSaveFileNameEx(parentWidgetOrView(),
......
......@@ -42,6 +42,7 @@
#include <utils/filedialog.h>
#include <Libkleo/Classify>
#include <Libkleo/Formatting>
#include <gpgme++/key.h>
......@@ -85,13 +86,16 @@ bool ExportSecretKeyCommand::preStartHook(QWidget *parent) const
QString proposedFileName;
const bool usePGPFileExt = FileOperationsPreferences().usePGPFileExt();
proposedFileName
= QString::fromLatin1(key.primaryFingerprint())
+ QLatin1Char('.')
+ QString::fromLatin1(outputFileExtension(protocol == OpenPGP
auto name = Formatting::prettyName(key);
if (name.isEmpty()) {
name = Formatting::prettyEMail(key);
}
/* Not translated so it's better to use in tutorials etc. */
proposedFileName = QStringLiteral("%1_%2_SECRET.%3").arg(name).arg(
Formatting::prettyKeyID(key.shortKeyID())).arg(
QString::fromLatin1(outputFileExtension(protocol == OpenPGP
? Class::OpenPGP | Class::Ascii | Class::Certificate
: Class::CMS | Class::Binary | Class::ExportedPSM, usePGPFileExt))
;
: Class::CMS | Class::Binary | Class::ExportedPSM, usePGPFileExt)));
m_filename = FileDialog::getSaveFileNameEx(parent ? parent : d->parentWidgetOrView(),
i18n("Export Secret Key"),
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment