aboutsummaryrefslogtreecommitdiffstats
path: root/lang/qt/src/threadedjobmixin.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'lang/qt/src/threadedjobmixin.cpp')
-rw-r--r--lang/qt/src/threadedjobmixin.cpp84
1 files changed, 79 insertions, 5 deletions
diff --git a/lang/qt/src/threadedjobmixin.cpp b/lang/qt/src/threadedjobmixin.cpp
index 74755c55..cd7c494f 100644
--- a/lang/qt/src/threadedjobmixin.cpp
+++ b/lang/qt/src/threadedjobmixin.cpp
@@ -53,7 +53,68 @@
using namespace QGpgME;
using namespace GpgME;
-static const unsigned int GetAuditLogFlags = Context::AuditLogWithHelp | Context::HtmlAuditLog;
+#ifdef Q_OS_WIN
+#include <windows.h>
+
+static QString fromEncoding (unsigned int src_encoding, const char *data)
+{
+ int n = MultiByteToWideChar(src_encoding, 0, data, -1, NULL, 0);
+ if (n < 0) {
+ return QString();
+ }
+
+ wchar_t *result = (wchar_t *) malloc ((n+1) * sizeof *result);
+
+ n = MultiByteToWideChar(src_encoding, 0, data, -1, result, n);
+ if (n < 0) {
+ free(result);
+ return QString();
+ }
+ const auto ret = QString::fromWCharArray(result, n);
+ free(result);
+ return ret;
+}
+#endif
+
+static QString stringFromGpgOutput(const QByteArray &ba)
+{
+#ifdef Q_OS_WIN
+ /* Qt on Windows uses GetACP while GnuPG prefers
+ * GetConsoleOutputCP.
+ *
+ * As we are not a console application GetConsoleOutputCP
+ * usually returns 0.
+ * From experience the closest thing that let's us guess
+ * what GetConsoleOutputCP returns for a console application
+ * it appears to be the OEMCP.
+ */
+ unsigned int cpno = GetConsoleOutputCP ();
+ if (!cpno) {
+ cpno = GetOEMCP();
+ }
+ if (!cpno) {
+ cpno = GetACP();
+ }
+ if (!cpno) {
+ return QString();
+ }
+
+ return fromEncoding(cpno, ba.constData());
+#else
+ return QString::fromLocal8Bit(ba);
+#endif
+}
+
+static QString markupDiagnostics(const QString &data)
+{
+ // First ensure that we don't have html in the diag.
+ QString ret = QStringLiteral("<pre>%1</pre>").arg(data.toHtmlEscaped());
+
+ return ret;
+}
+
+static const unsigned int CMSAuditLogFlags = Context::AuditLogWithHelp | Context::HtmlAuditLog;
+static const unsigned int OpenPGPAuditLogFlags = Context::DiagnosticAuditLog;
QString _detail::audit_log_as_html(Context *ctx, GpgME::Error &err)
{
@@ -61,11 +122,24 @@ QString _detail::audit_log_as_html(Context *ctx, GpgME::Error &err)
QGpgME::QByteArrayDataProvider dp;
Data data(&dp);
assert(!data.isNull());
- if ((err = ctx->lastError()) || (err = ctx->getAuditLog(data, GetAuditLogFlags))) {
- return QString::fromLocal8Bit(err.asString());
+
+ if (ctx->protocol() == OpenPGP) {
+ if ((err = ctx->getAuditLog(data, OpenPGPAuditLogFlags))) {
+ return QString::fromLocal8Bit(err.asString());
+ }
+ const QByteArray ba = dp.data();
+ return markupDiagnostics(stringFromGpgOutput(ba));
}
- const QByteArray ba = dp.data();
- return QString::fromUtf8(ba.data(), ba.size());
+
+ if (ctx->protocol() == CMS) {
+ if ((err = ctx->lastError()) || (err = ctx->getAuditLog(data, CMSAuditLogFlags))) {
+ return QString::fromLocal8Bit(err.asString());
+ }
+ const QByteArray ba = dp.data();
+ return QString::fromUtf8(ba.data(), ba.size());
+ }
+
+ return QStringLiteral("Unsupported protocol for Audit Log");
}
static QList<QByteArray> from_sl(const QStringList &sl)