1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
|
From 654188c2806c376a4c2b9cdf44e48172c2255a18 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Jan=20Kundr=C3=A1t?= <jkt@kde.org>
Date: Mon, 3 Oct 2016 22:09:17 +0200
Subject: [PATCH] GUI: Prevent excessive newlines in the PartStatusWidget
crypto messages
Previously, there were extra newlines in certain scenarios. The long
text should never begin with a stray newline.
This might make it easier to see the linked bug.
Change-Id: I72188b08f1562b6cdd30849f9958fdcc9f0504b7
CCBUG: 369832
---
src/Cryptography/GpgMe++.cpp | 65 ++++++++++++++++++++++++------------
1 file changed, 44 insertions(+), 21 deletions(-)
diff --git a/src/Cryptography/GpgMe++.cpp b/src/Cryptography/GpgMe++.cpp
index 54275f73..e2fcdfe7 100644
--- a/src/Cryptography/GpgMe++.cpp
+++ b/src/Cryptography/GpgMe++.cpp
@@ -290,6 +290,8 @@ QVariant GpgMePart::data(int role) const
}
}
+#define ENSURE_LINE_LF(X) do { if (!X.isEmpty()) { X += LF; } } while (0)
+
void GpgMePart::extractSignatureStatus(std::shared_ptr<GpgME::Context> ctx, const GpgME::Signature &sig,
const std::vector<std::string> messageUids, const bool wasSigned, const bool wasEncrypted,
bool &sigOkDisregardingTrust, bool &sigValidVerified,
@@ -447,30 +449,38 @@ void GpgMePart::extractSignatureStatus(std::shared_ptr<GpgME::Context> ctx, cons
// extract the individual error bits
if (sig.summary() & GpgME::Signature::KeyRevoked) {
- longStatus += LF + tr("The key or at least one certificate has been revoked.");
+ ENSURE_LINE_LF(longStatus);
+ longStatus += tr("The key or at least one certificate has been revoked.");
}
if (sig.summary() & GpgME::Signature::KeyExpired) {
// FIXME: how to get the expiration date?
- longStatus += LF + tr("The key or one of the certificates has expired.");
+ ENSURE_LINE_LF(longStatus);
+ longStatus += tr("The key or one of the certificates has expired.");
}
if (sig.summary() & GpgME::Signature::SigExpired) {
- longStatus += LF + tr("Signature expired on %1.")
+ ENSURE_LINE_LF(longStatus);
+ longStatus += tr("Signature expired on %1.")
.arg(QDateTime::fromTime_t(sig.expirationTime()).toString(Qt::DefaultLocaleShortDate));
}
if (sig.summary() & GpgME::Signature::KeyMissing) {
- longStatus += LF + tr("Can't verify due to a missing key or certificate.");
+ ENSURE_LINE_LF(longStatus);
+ longStatus += tr("Can't verify due to a missing key or certificate.");
}
if (sig.summary() & GpgME::Signature::CrlMissing) {
- longStatus += LF + tr("The CRL (or an equivalent mechanism) is not available.");
+ ENSURE_LINE_LF(longStatus);
+ longStatus += tr("The CRL (or an equivalent mechanism) is not available.");
}
if (sig.summary() & GpgME::Signature::CrlTooOld) {
- longStatus += LF + tr("Available CRL is too old.");
+ ENSURE_LINE_LF(longStatus);
+ longStatus += tr("Available CRL is too old.");
}
if (sig.summary() & GpgME::Signature::BadPolicy) {
- longStatus += LF + tr("A policy requirement was not met.");
+ ENSURE_LINE_LF(longStatus);
+ longStatus += tr("A policy requirement was not met.");
}
if (sig.summary() & GpgME::Signature::SysError) {
- longStatus += LF + tr("A system error occurred. %1")
+ ENSURE_LINE_LF(longStatus);
+ longStatus += tr("A system error occurred. %1")
.arg(QString::fromUtf8(sig.status().asString()));
}
@@ -478,22 +488,28 @@ void GpgMePart::extractSignatureStatus(std::shared_ptr<GpgME::Context> ctx, cons
// Extract signature validity
switch (sig.validity()) {
case GpgME::Signature::Undefined:
- longStatus += LF + tr("Signature validity is undefined.");
+ ENSURE_LINE_LF(longStatus);
+ longStatus += tr("Signature validity is undefined.");
break;
case GpgME::Signature::Never:
- longStatus += LF + tr("Signature validity is never to be trusted.");
+ ENSURE_LINE_LF(longStatus);
+ longStatus += tr("Signature validity is never to be trusted.");
break;
case GpgME::Signature::Marginal:
- longStatus += LF + tr("Signature validity is marginal.");
+ ENSURE_LINE_LF(longStatus);
+ longStatus += tr("Signature validity is marginal.");
break;
case GpgME::Signature::Full:
- longStatus += LF + tr("Signature validity is full.");
+ ENSURE_LINE_LF(longStatus);
+ longStatus += tr("Signature validity is full.");
break;
case GpgME::Signature::Ultimate:
- longStatus += LF + tr("Signature validity is ultimate.");
+ ENSURE_LINE_LF(longStatus);
+ longStatus += tr("Signature validity is ultimate.");
break;
case GpgME::Signature::Unknown:
- longStatus += LF + tr("Signature validity is unknown.");
+ ENSURE_LINE_LF(longStatus);
+ longStatus += tr("Signature validity is unknown.");
break;
}
}
@@ -844,7 +860,8 @@ void GpgMeEncrypted::handleDataChanged(const QModelIndex &topLeft, const QModelI
if (tldr.isEmpty()) {
tldr = tr("Broken encrypted message");
}
- longStatus += LF + tr("Decryption error: %1").arg(QString::fromUtf8(combinedResult.first.error().asString()));
+ ENSURE_LINE_LF(longStatus);
+ longStatus += tr("Decryption error: %1").arg(QString::fromUtf8(combinedResult.first.error().asString()));
icon = QStringLiteral("emblem-error");
} else if (tldr.isEmpty()) {
tldr = tr("Encrypted message");
@@ -852,29 +869,35 @@ void GpgMeEncrypted::handleDataChanged(const QModelIndex &topLeft, const QModelI
}
if (combinedResult.first.isWrongKeyUsage()) {
- longStatus += LF + tr("Wrong key usage, not for encryption");
+ ENSURE_LINE_LF(longStatus);
+ longStatus += tr("Wrong key usage, not for encryption");
}
if (auto msg = combinedResult.first.unsupportedAlgorithm()) {
- longStatus += LF + tr("Unsupported algorithm: %1").arg(QString::fromUtf8(msg));
+ ENSURE_LINE_LF(longStatus);
+ longStatus += tr("Unsupported algorithm: %1").arg(QString::fromUtf8(msg));
}
for (const auto &recipient: combinedResult.first.recipients()) {
GpgME::Error keyError;
auto key = ctx->key(recipient.keyID(), keyError, false);
if (keyError) {
- longStatus += LF + tr("Cannot extract recipient %1: %2")
+ ENSURE_LINE_LF(longStatus);
+ longStatus += tr("Cannot extract recipient %1: %2")
.arg(QString::fromUtf8(recipient.keyID()), QString::fromUtf8(keyError.asString()));
} else {
if (key.numUserIDs()) {
- longStatus += LF + tr("Encrypted to %1 (%2)")
+ ENSURE_LINE_LF(longStatus);
+ longStatus += tr("Encrypted to %1 (%2)")
.arg(QString::fromUtf8(key.userID(0).id()), QString::fromUtf8(recipient.keyID()));
} else {
- longStatus += LF + tr("Encrypted to %1").arg(QString::fromUtf8(recipient.keyID()));
+ ENSURE_LINE_LF(longStatus);
+ longStatus += tr("Encrypted to %1").arg(QString::fromUtf8(recipient.keyID()));
}
}
}
if (auto fname = combinedResult.first.fileName()) {
- longStatus += LF + tr("Original filename: %1").arg(QString::fromUtf8(fname));
+ ENSURE_LINE_LF(longStatus);
+ longStatus += tr("Original filename: %1").arg(QString::fromUtf8(fname));
}
if (p) {
--
GitLab
|