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 <QStandardPaths>
|
||||||
#include <QStorageInfo>
|
#include <QStorageInfo>
|
||||||
#include <QTemporaryFile>
|
#include <QTemporaryFile>
|
||||||
|
#include <QTextCodec>
|
||||||
#include <QThread>
|
#include <QThread>
|
||||||
|
|
||||||
#ifdef Q_OS_WIN
|
#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."));
|
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::UnavailableDeviceFileAccess() = default;
|
UnavailableDeviceFileAccess::UnavailableDeviceFileAccess() = default;
|
||||||
@@ -1183,6 +1196,18 @@ Utils::expected_str<std::unique_ptr<FilePathWatcher>> DesktopDeviceFileAccess::w
|
|||||||
return make_unexpected(watcher->error());
|
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
|
QDateTime DesktopDeviceFileAccess::lastModified(const FilePath &filePath) const
|
||||||
{
|
{
|
||||||
return QFileInfo(filePath.path()).lastModified();
|
return QFileInfo(filePath.path()).lastModified();
|
||||||
|
@@ -10,6 +10,10 @@
|
|||||||
|
|
||||||
class tst_unixdevicefileaccess; // For testing.
|
class tst_unixdevicefileaccess; // For testing.
|
||||||
|
|
||||||
|
QT_BEGIN_NAMESPACE
|
||||||
|
class QTextCodec;
|
||||||
|
QT_END_NAMESPACE
|
||||||
|
|
||||||
namespace Utils {
|
namespace Utils {
|
||||||
|
|
||||||
class CommandLine;
|
class CommandLine;
|
||||||
@@ -77,6 +81,9 @@ protected:
|
|||||||
virtual expected_str<FilePath> createTempFile(const FilePath &filePath);
|
virtual expected_str<FilePath> createTempFile(const FilePath &filePath);
|
||||||
|
|
||||||
virtual Utils::expected_str<std::unique_ptr<FilePathWatcher>> watch(const FilePath &path) const;
|
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
|
class QTCREATOR_UTILS_EXPORT UnavailableDeviceFileAccess : public DeviceFileAccess
|
||||||
@@ -194,6 +201,9 @@ protected:
|
|||||||
expected_str<FilePath> createTempFile(const FilePath &filePath) override;
|
expected_str<FilePath> createTempFile(const FilePath &filePath) override;
|
||||||
|
|
||||||
Utils::expected_str<std::unique_ptr<FilePathWatcher>> watch(const FilePath &path) const 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
|
class QTCREATOR_UTILS_EXPORT UnixDeviceFileAccess : public DeviceFileAccess
|
||||||
|
@@ -2155,6 +2155,16 @@ QChar FilePath::pathListSeparator() const
|
|||||||
return osType() == OsTypeWindows ? u';' : u':';
|
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.
|
\brief Recursively resolves symlinks if this is a symlink.
|
||||||
|
|
||||||
|
@@ -24,6 +24,7 @@ QT_BEGIN_NAMESPACE
|
|||||||
class QDateTime;
|
class QDateTime;
|
||||||
class QDebug;
|
class QDebug;
|
||||||
class QFileInfo;
|
class QFileInfo;
|
||||||
|
class QTextCodec;
|
||||||
class QUrl;
|
class QUrl;
|
||||||
QT_END_NAMESPACE
|
QT_END_NAMESPACE
|
||||||
|
|
||||||
@@ -191,6 +192,9 @@ public:
|
|||||||
QChar pathComponentSeparator() const;
|
QChar pathComponentSeparator() const;
|
||||||
QChar pathListSeparator() const;
|
QChar pathListSeparator() const;
|
||||||
|
|
||||||
|
QTextCodec *processStdOutCodec() const;
|
||||||
|
QTextCodec *processStdErrCodec() const;
|
||||||
|
|
||||||
void clear();
|
void clear();
|
||||||
bool isEmpty() const;
|
bool isEmpty() const;
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user