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.
This commit is contained in:
parent
bc774104bb
commit
8fe1546282
@ -53,53 +53,10 @@
|
|||||||
using namespace QGpgME;
|
using namespace QGpgME;
|
||||||
using namespace GpgME;
|
using namespace GpgME;
|
||||||
|
|
||||||
#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)
|
static QString stringFromGpgOutput(const QByteArray &ba)
|
||||||
{
|
{
|
||||||
#ifdef Q_OS_WIN
|
#ifdef Q_OS_WIN
|
||||||
/* Qt on Windows uses GetACP while GnuPG prefers
|
return QString::fromUtf8(ba);
|
||||||
* 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
|
#else
|
||||||
return QString::fromLocal8Bit(ba);
|
return QString::fromLocal8Bit(ba);
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
Reference in New Issue
Block a user