forked from qt-creator/qt-creator
Squish: Fix object map handling on Windows
Ensure we are using UTF8 all over the place especially when using external tools and their stdin or stdout streams. This fixes bad encoding issues on Windows when having unicode characters inside the objects map file. Change-Id: Ic8e66a876abe0903308002cd25315b1eaa3788b1 Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
@@ -12,7 +12,7 @@
|
||||
#include <utils/fileutils.h>
|
||||
#include <utils/qtcprocess.h>
|
||||
|
||||
#include <QDir>
|
||||
#include <QtCore5Compat/QTextCodec>
|
||||
|
||||
namespace Squish {
|
||||
namespace Internal {
|
||||
@@ -187,13 +187,13 @@ Core::IDocument::OpenResult ObjectsMapDocument::openImpl(QString *error,
|
||||
if (fileName.isEmpty())
|
||||
return OpenResult::CannotHandle;
|
||||
|
||||
QString text;
|
||||
QByteArray text;
|
||||
if (realFileName.fileName() == "objects.map") {
|
||||
Utils::FileReader reader;
|
||||
if (!reader.fetch(realFileName, QIODevice::Text, error))
|
||||
return OpenResult::ReadError;
|
||||
|
||||
text = QString::fromLocal8Bit(reader.data());
|
||||
text = reader.data();
|
||||
} else {
|
||||
const Utils::FilePath base = SquishPlugin::squishSettings()->squishPath.filePath();
|
||||
if (base.isEmpty()) {
|
||||
@@ -212,11 +212,12 @@ Core::IDocument::OpenResult ObjectsMapDocument::openImpl(QString *error,
|
||||
Utils::QtcProcess objectMapReader;
|
||||
objectMapReader.setCommand({exe, {"--scriptMap", "--mode", "read",
|
||||
"--scriptedObjectMapPath", realFileName.toUserOutput()}});
|
||||
objectMapReader.setCodec(QTextCodec::codecForName("UTF-8"));
|
||||
objectMapReader.start();
|
||||
objectMapReader.waitForFinished();
|
||||
text = objectMapReader.cleanedStdOut();
|
||||
text = objectMapReader.cleanedStdOut().toUtf8();
|
||||
}
|
||||
if (!setContents(text.toUtf8())) {
|
||||
if (!setContents(text)) {
|
||||
if (error)
|
||||
error->append(Tr::tr("Failure while parsing objects.map content."));
|
||||
return OpenResult::ReadError;
|
||||
|
@@ -346,7 +346,7 @@ void ObjectsMapEditorWidget::onPropertiesContentModified(const QString &text)
|
||||
|
||||
const QModelIndex &idx = m_objMapFilterModel->mapToSource(selected.first());
|
||||
if (auto item = static_cast<ObjectsMapTreeItem *>(m_document->model()->itemForIndex(idx)))
|
||||
item->setPropertiesContent(text.toLocal8Bit().trimmed());
|
||||
item->setPropertiesContent(text.toUtf8().trimmed());
|
||||
}
|
||||
|
||||
void ObjectsMapEditorWidget::onJumpToSymbolicNameClicked()
|
||||
|
@@ -130,19 +130,20 @@ bool ObjectsMapTreeItem::parseProperties(const QByteArray &properties)
|
||||
if (properties.isEmpty() || properties.at(0) != '{')
|
||||
return false;
|
||||
|
||||
QString p = QString::fromUtf8(properties);
|
||||
ParseState state = None;
|
||||
QByteArray name;
|
||||
QByteArray value;
|
||||
QByteArray oper;
|
||||
QString name;
|
||||
QString value;
|
||||
QString oper;
|
||||
bool masquerading = false;
|
||||
for (char c : properties) {
|
||||
for (QChar c : p) {
|
||||
if (masquerading) {
|
||||
value.append('\\').append(c);
|
||||
masquerading = false;
|
||||
continue;
|
||||
}
|
||||
|
||||
switch (c) {
|
||||
switch (c.unicode()) {
|
||||
case '=':
|
||||
if (state == Value) {
|
||||
value.append(c);
|
||||
@@ -172,7 +173,7 @@ bool ObjectsMapTreeItem::parseProperties(const QByteArray &properties)
|
||||
} else if (state == Value) {
|
||||
state = None;
|
||||
Property prop;
|
||||
if (!prop.set(QLatin1String(name), QLatin1String(oper), QLatin1String(value))) {
|
||||
if (!prop.set(name, oper, value)) {
|
||||
propertyRoot->removeChildren();
|
||||
return false;
|
||||
}
|
||||
@@ -214,7 +215,7 @@ bool ObjectsMapTreeItem::parseProperties(const QByteArray &properties)
|
||||
}
|
||||
break;
|
||||
default:
|
||||
if (QChar::isSpace(c)) {
|
||||
if (c.isSpace()) {
|
||||
if (state == Value) {
|
||||
value.append(c);
|
||||
} else if (state == Name) {
|
||||
|
@@ -10,6 +10,7 @@ QtcPlugin {
|
||||
Depends { name: "Utils" }
|
||||
|
||||
Depends { name: "Qt.widgets" }
|
||||
Depends { name: "Qt.core5compat" }
|
||||
|
||||
files: [
|
||||
"deletesymbolicnamedialog.cpp",
|
||||
|
Reference in New Issue
Block a user