From 8fe15462829b5049137b3f631564b72c4f63c5e2 Mon Sep 17 00:00:00 2001 From: Andre Heinecke Date: Fri, 27 Aug 2021 13:00:22 +0200 Subject: [PATCH] qt: Expect UTF-8 on stderr on Windows * lang/qt/src/threadedjobmixin.cpp (stringFromGpgOutput): Expect UTF-8. -- In recent versions more and more output was changed to be UTF-8 on Windows. Werner advised to always expect UTF-8 diagnostics. --- lang/qt/src/threadedjobmixin.cpp | 45 +------------------------------- 1 file changed, 1 insertion(+), 44 deletions(-) diff --git a/lang/qt/src/threadedjobmixin.cpp b/lang/qt/src/threadedjobmixin.cpp index 3302918b..92e63849 100644 --- a/lang/qt/src/threadedjobmixin.cpp +++ b/lang/qt/src/threadedjobmixin.cpp @@ -53,53 +53,10 @@ using namespace QGpgME; using namespace GpgME; -#ifdef Q_OS_WIN -#include - -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()); + return QString::fromUtf8(ba); #else return QString::fromLocal8Bit(ba); #endif