[symmy] /: Show an error if gpg-agent is not running

Elvis Angelaccio null at kde.org
Thu Nov 23 12:21:28 UTC 2017


Git commit 11c066946f59dd15586d7867f8d36a53a5fdb6f6 by Elvis Angelaccio.
Committed on 23/11/2017 at 12:19.
Pushed by elvisangelaccio into branch 'master'.

Show an error if gpg-agent is not running

In the encryption case, this is the main reason why the operation could
fail. In the decryption case, it's hard to distinguish between wrong
passphrase and broken GPG setup, but if at least one file was decrypted
then we are sure gpg-agent is up and running.

M  +6    -0    doc/index.docbook
M  +14   -11   src/compositejob.cpp
M  +1    -1    src/encryptjob.cpp

https://commits.kde.org/symmy/11c066946f59dd15586d7867f8d36a53a5fdb6f6

diff --git a/doc/index.docbook b/doc/index.docbook
index 5ee9b99..7dfa11b 100644
--- a/doc/index.docbook
+++ b/doc/index.docbook
@@ -80,6 +80,12 @@
         If you need to send the key to another person, you should do so over a secure channel (for example, by meeting in person).
       </para>
     </sect2>
+    <sect2 id="gpg-requirement">
+      <title>GPG Requirement</title>
+      <para>
+      &symmy; uses GPG to perform the actual encryption, so it assumes that the <application>gpg-agent</application> process is running and properly configured.
+      </para>
+    </sect2>
     <sect2 id="managing_encryption">
       <title>Manage an Encryption Operation</title>
       <para>
diff --git a/src/compositejob.cpp b/src/compositejob.cpp
index bd4e72e..2f42cf6 100644
--- a/src/compositejob.cpp
+++ b/src/compositejob.cpp
@@ -62,11 +62,17 @@ bool CompositeJob::doKill()
 
 void CompositeJob::slotResult(KJob *job)
 {
-    if (job->error() and task() == Task::Decryption) {
-        qCDebug(SYMMY) << "Job failed with code" << job->error() << "and error" << job->errorText();
-        auto decryptJob = qobject_cast<Symmy::DecryptJob*>(job);
+    if (job->error() == KJob::UserDefinedError) {
+        qCDebug(SYMMY) << "Job failed:" << job->errorText();
+        if (task() == Task::Encryption) {
+            setError(KJob::UserDefinedError);
+            KMessageBox::error(nullptr, xi18nc("@info", "Encryption operation failed. Please check whether the <application>gpg-agent</application> process is running."));
+            emitResult();
+            return;
+        }
 
-        if (decryptJob and decryptJob->error() != KJob::KilledJobError) {
+        auto decryptJob = qobject_cast<Symmy::DecryptJob*>(job);
+        if (decryptJob) {
             qCDebug(SYMMY) << "Subjob failed to decrypt" << decryptJob->ciphertextFilename();
             m_failedDecryptions << decryptJob->ciphertextFilename();
         }
@@ -83,16 +89,13 @@ void CompositeJob::slotResult(KJob *job)
     qCDebug(SYMMY) << "Composite job finished";
 
     if (!m_failedDecryptions.isEmpty()) {
-        if (m_failedDecryptions.size() == 1) {
-            KMessageBox::error(nullptr, xi18nc("@info", "Could not decrypt the following ciphertext:<nl/><filename>%1</filename>", m_failedDecryptions.at(0)));
-        } else {
-            KMessageBox::errorList(nullptr, i18n("Could not decrypt the following ciphertexts:"), m_failedDecryptions);
-        }
-
         // Nothing was decrypted, mark the composite job as failed.
         if (m_failedDecryptions.size() == filenames().size()) {
             setError(KJob::UserDefinedError);
-            setErrorText(i18n("Wrong decryption key."));
+            KMessageBox::error(nullptr, xi18nc("@info", "Decryption operation failed. Please check whether the decryption key is correct.<nl/>"
+                                                        "You should also check whether the <application>gpg-agent</application> process is running."));
+        } else {
+            KMessageBox::errorList(nullptr, xi18nc("@info", "Could not decrypt the following ciphertexts.<nl/>Please check whether the decryption key is correct."), m_failedDecryptions);
         }
     }
 
diff --git a/src/encryptjob.cpp b/src/encryptjob.cpp
index d5c7ebc..402995d 100644
--- a/src/encryptjob.cpp
+++ b/src/encryptjob.cpp
@@ -91,7 +91,7 @@ void EncryptJob::slotResult(const EncryptionResult &, const QByteArray &, const
     qCDebug(SYMMY) << "Encryption job finished, ciphertext size:" << m_ciphertext->size();
 
     if (m_ciphertext->size() == 0) {
-        setError(KilledJobError);
+        setError(UserDefinedError);
         emitResult();
         return;
     }


More information about the kde-doc-english mailing list