qt: Allow creation of default keys without name
authorAndre Heinecke <aheinecke@intevation.de>
Wed, 1 Mar 2017 10:14:07 +0000 (11:14 +0100)
committerAndre Heinecke <aheinecke@intevation.de>
Wed, 1 Mar 2017 10:14:07 +0000 (11:14 +0100)
* lang/qt/src/defaultkeygenerationjob.cpp
(DefaultKeyGenerationJob::start): Handle empty name and email.

lang/qt/src/defaultkeygenerationjob.cpp

index 020f4d2..f589384 100644 (file)
@@ -91,6 +91,11 @@ void DefaultKeyGenerationJob::slotCancel()
 
 GpgME::Error DefaultKeyGenerationJob::start(const QString &email, const QString &name)
 {
+    const QString namePart = name.isEmpty() ? QString() :
+                                QStringLiteral("name-real:     %1\n").arg(name);
+    const QString mailPart = email.isEmpty() ? QString() :
+                                QStringLiteral("name-email:    %1\n").arg(email);
+
     const QString args = QStringLiteral("<GnupgKeyParms format=\"internal\">\n"
                                         "%ask-passphrase\n"
                                         "key-type:      RSA\n"
@@ -99,9 +104,9 @@ GpgME::Error DefaultKeyGenerationJob::start(const QString &email, const QString
                                         "subkey-type:   RSA\n"
                                         "subkey-length: 2048\n"
                                         "subkey-usage:  encrypt\n"
-                                        "name-email:    %1\n"
-                                        "name-real:     %2\n"
-                                        "</GnupgKeyParms>").arg(email, name);
+                                        "%1"
+                                        "%2"
+                                        "</GnupgKeyParms>").arg(mailPart, namePart);
 
     d->job = openpgp()->keyGenerationJob();
     d->job->installEventFilter(this);