[pim/kleopatra] src/crypto: Fix result message if not signing with detached signature

Ingo Klöcker <[email protected]>
Newsgroups gmane.comp.kde.cvs
Message-ID <[email protected]>
Git commit 40715b1f403dbeb1812af2a86583d6b5bd991d59 by Ingo Klöcker, on behalf of Ingo Klöcker.
Committed on 10/08/2026 at 10:04.
Pushed by kloecker into branch 'master'.

Fix result message if not signing with detached signature

If a single file was signed we need to check the used signature mode.
Otherwise, Kleopatra always creates a signed archive so that we don't
need to check for detached signature mode. Archives are always signed
with a "normal" signature.

GnuPG-bug-id: 8349

M  +24   -12   src/crypto/signencrypttask.cpp

https://invent.kde.org/pim/kleopatra/-/commit/40715b1f403dbeb1812af2a86583d6b5bd991d59

diff --git a/src/crypto/signencrypttask.cpp b/src/crypto/signencrypttask.cpp
index 33e180e15..4a68c2a73 100644
--- a/src/crypto/signencrypttask.cpp
+++ b/src/crypto/signencrypttask.cpp
@@ -131,7 +131,8 @@ static QString formatResultLine(const QStringList &inputs,
                                 bool encrypt,
                                 bool signingFailed,
                                 bool encryptionFailed,
-                                const GpgME::Error &error)
+                                const GpgME::Error &error,
+                                const GpgME::SignatureMode signatureMode)
 {
     Q_ASSERT(inputs.size() > 0);
     Q_ASSERT(sign || encrypt);
@@ -237,21 +238,28 @@ static QString formatResultLine(const QStringList &inputs,
 
     if (sign) {
         if (inputs.size() == 1) {
-            return xi18nc("@info Successfully signed <file> and saved the signature in <file>.",
-                          "Successfully signed <filename>%1</filename> and saved the signature in <filename>%2</filename>.",
-                          inputs[0],
-                          output);
+            if (signatureMode == SignatureMode::Detached) {
+                return xi18nc("@info Successfully signed <file> and saved the signature in <file>.",
+                              "Successfully signed <filename>%1</filename> and saved the signature in <filename>%2</filename>.",
+                              inputs[0],
+                              output);
+            } else {
+                return xi18nc("@info Successfully signed <file> and saved it as <file>.",
+                              "Successfully signed <filename>%1</filename> and saved it as <filename>%2</filename>.",
+                              inputs[0],
+                              output);
+            }
         }
         if (inputs.size() == 2) {
-            return xi18nc("@info Successfully signed <file> and <file> and saved the signature in <file>.",
-                          "Successfully signed <filename>%1</filename> and <filename>%2</filename> and saved the signature in <filename>%3</filename>.",
+            return xi18nc("@info Successfully signed <file> and <file> and saved them as <file>.",
+                          "Successfully signed <filename>%1</filename> and <filename>%2</filename> and saved them as <filename>%3</filename>.",
                           inputs[0],
                           inputs[1],
                           output);
         }
-        return xi18ncp("@info Successfully signed <file> and <n> other(s) and saved the signature in <file>.",
-                       "Successfully signed <filename>%2</filename> and %1 other and saved the signature in <filename>%3</filename>.",
-                       "Successfully signed <filename>%2</filename> and %1 others and saved the signature in <filename>%3</filename>.",
+        return xi18ncp("@info Successfully signed <file> and <n> other(s) and saved them as <file>.",
+                       "Successfully signed <filename>%2</filename> and %1 other and saved them as <filename>%3</filename>.",
+                       "Successfully signed <filename>%2</filename> and %1 others and saved them as <filename>%3</filename>.",
                        inputs.size() - 1,
                        inputs[0],
                        output);
@@ -324,7 +332,7 @@ QString ErrorResult::overview() const
     Q_ASSERT(m_error || m_error.isCanceled());
     Q_ASSERT(m_sign || m_encrypt);
 
-    return formatResultLine(m_input.fileNames, m_outputLabel, m_sign, m_encrypt, true, true, m_error);
+    return formatResultLine(m_input.fileNames, m_outputLabel, m_sign, m_encrypt, true, true, m_error, SignatureMode::NormalSignatureMode);
 }
 
 QString ErrorResult::details() const
@@ -1018,13 +1026,17 @@ QString SignEncryptTaskResult::overview() const
         return {};
     }
 
+    const auto signatures = d->m_sresult.isNull() ? std::vector<CreatedSignature>{} : d->m_sresult.createdSignatures();
+    const SignatureMode sigMode = signatures.empty() ? SignatureMode::NormalSignatureMode : signatures.front().mode();
+
     return formatResultLine(d->m_input.fileNames,
                             d->m_output.label,
                             !d->m_sresult.isNull(),
                             !d->m_eresult.isNull(),
                             d->m_sresult.error().isError(),
                             d->m_eresult.error().isError(),
-                            !d->m_sresult.error().isSuccess() ? d->m_sresult.error() : d->m_eresult.error());
+                            !d->m_sresult.error().isSuccess() ? d->m_sresult.error() : d->m_eresult.error(),
+                            sigMode);
 }
 
 QString SignEncryptTaskResult::details() const
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.