forked from qt-creator/qt-creator
Utils: Add FilePath::processStd{Out,Err}Codec()
Allows in principle each executable to declare their output encoding. For now use the usual codecForLocale() on desktop and UTF-8 everywhere else. Change-Id: I040e9c0fca929fcccce0bf7746864bb9e3dac33b Reviewed-by: Marcus Tillmanns <marcus.tillmanns@qt.io>
This commit is contained in:
@@ -24,6 +24,7 @@
|
||||
#include <QStandardPaths>
|
||||
#include <QStorageInfo>
|
||||
#include <QTemporaryFile>
|
||||
#include <QTextCodec>
|
||||
#include <QThread>
|
||||
|
||||
#ifdef Q_OS_WIN
|
||||
@@ -400,6 +401,18 @@ Utils::expected_str<std::unique_ptr<FilePathWatcher>> DeviceFileAccess::watch(
|
||||
return make_unexpected(Tr::tr("watch is not implemented."));
|
||||
}
|
||||
|
||||
QTextCodec *DeviceFileAccess::processStdOutCodec(const FilePath &executable) const
|
||||
{
|
||||
Q_UNUSED(executable)
|
||||
return QTextCodec::codecForName("UTF-8"); // Good default nowadays.
|
||||
}
|
||||
|
||||
QTextCodec *DeviceFileAccess::processStdErrCodec(const FilePath &executable) const
|
||||
{
|
||||
Q_UNUSED(executable)
|
||||
return QTextCodec::codecForName("UTF-8"); // Good default nowadays.
|
||||
}
|
||||
|
||||
// UnavailableDeviceFileAccess
|
||||
|
||||
UnavailableDeviceFileAccess::UnavailableDeviceFileAccess() = default;
|
||||
@@ -1183,6 +1196,18 @@ Utils::expected_str<std::unique_ptr<FilePathWatcher>> DesktopDeviceFileAccess::w
|
||||
return make_unexpected(watcher->error());
|
||||
}
|
||||
|
||||
QTextCodec *DesktopDeviceFileAccess::processStdOutCodec(const FilePath &executable) const
|
||||
{
|
||||
Q_UNUSED(executable);
|
||||
return QTextCodec::codecForLocale();
|
||||
}
|
||||
|
||||
QTextCodec *DesktopDeviceFileAccess::processStdErrCodec(const FilePath &executable) const
|
||||
{
|
||||
Q_UNUSED(executable);
|
||||
return QTextCodec::codecForLocale();
|
||||
}
|
||||
|
||||
QDateTime DesktopDeviceFileAccess::lastModified(const FilePath &filePath) const
|
||||
{
|
||||
return QFileInfo(filePath.path()).lastModified();
|
||||
|
@@ -10,6 +10,10 @@
|
||||
|
||||
class tst_unixdevicefileaccess; // For testing.
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
class QTextCodec;
|
||||
QT_END_NAMESPACE
|
||||
|
||||
namespace Utils {
|
||||
|
||||
class CommandLine;
|
||||
@@ -77,6 +81,9 @@ protected:
|
||||
virtual expected_str<FilePath> createTempFile(const FilePath &filePath);
|
||||
|
||||
virtual Utils::expected_str<std::unique_ptr<FilePathWatcher>> watch(const FilePath &path) const;
|
||||
|
||||
virtual QTextCodec *processStdOutCodec(const FilePath &executable) const;
|
||||
virtual QTextCodec *processStdErrCodec(const FilePath &executable) const;
|
||||
};
|
||||
|
||||
class QTCREATOR_UTILS_EXPORT UnavailableDeviceFileAccess : public DeviceFileAccess
|
||||
@@ -194,6 +201,9 @@ protected:
|
||||
expected_str<FilePath> createTempFile(const FilePath &filePath) override;
|
||||
|
||||
Utils::expected_str<std::unique_ptr<FilePathWatcher>> watch(const FilePath &path) const override;
|
||||
|
||||
QTextCodec *processStdOutCodec(const FilePath &executable) const override;
|
||||
QTextCodec *processStdErrCodec(const FilePath &executable) const override;
|
||||
};
|
||||
|
||||
class QTCREATOR_UTILS_EXPORT UnixDeviceFileAccess : public DeviceFileAccess
|
||||
|
@@ -2155,6 +2155,16 @@ QChar FilePath::pathListSeparator() const
|
||||
return osType() == OsTypeWindows ? u';' : u':';
|
||||
}
|
||||
|
||||
QTextCodec *FilePath::processStdOutCodec() const
|
||||
{
|
||||
return fileAccess()->processStdOutCodec(*this);
|
||||
}
|
||||
|
||||
QTextCodec *FilePath::processStdErrCodec() const
|
||||
{
|
||||
return fileAccess()->processStdErrCodec(*this);
|
||||
}
|
||||
|
||||
/*!
|
||||
\brief Recursively resolves symlinks if this is a symlink.
|
||||
|
||||
|
@@ -24,6 +24,7 @@ QT_BEGIN_NAMESPACE
|
||||
class QDateTime;
|
||||
class QDebug;
|
||||
class QFileInfo;
|
||||
class QTextCodec;
|
||||
class QUrl;
|
||||
QT_END_NAMESPACE
|
||||
|
||||
@@ -191,6 +192,9 @@ public:
|
||||
QChar pathComponentSeparator() const;
|
||||
QChar pathListSeparator() const;
|
||||
|
||||
QTextCodec *processStdOutCodec() const;
|
||||
QTextCodec *processStdErrCodec() const;
|
||||
|
||||
void clear();
|
||||
bool isEmpty() const;
|
||||
|
||||
|
Reference in New Issue
Block a user