summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMitch Curtis <mitch.curtis@digia.com>2013-04-17 12:45:24 +0200
committerThe Qt Project <gerrit-noreply@qt-project.org>2013-04-18 17:22:17 +0200
commit6626e5f41712723405c110a4f11ad650116f7523 (patch)
treea8f28aab50b73091a7f6aa8314d5692e42cfb241
parent7d9f5d1925cdc03a7fd1293fd02bf0cf72191867 (diff)
Make linguist's source viewer respect the encoding of files.
It currently loads source files as latin1, which means other encodings are not supported. Qt 5 change: c4f1ac0fbcd452f440aee4a3304574cb7fbca0ce Task-number: QTBUG-27238 Change-Id: Ieb4de351d93bd5ac2939692c5c53bd681fea4386 Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@digia.com>
-rw-r--r--tools/linguist/linguist/mainwindow.cpp1
-rw-r--r--tools/linguist/linguist/messagemodel.h1
-rw-r--r--tools/linguist/linguist/sourcecodeview.cpp10
-rw-r--r--tools/linguist/linguist/sourcecodeview.h2
4 files changed, 13 insertions, 1 deletions
diff --git a/tools/linguist/linguist/mainwindow.cpp b/tools/linguist/linguist/mainwindow.cpp
index 210169ce9c..285a4a2f87 100644
--- a/tools/linguist/linguist/mainwindow.cpp
+++ b/tools/linguist/linguist/mainwindow.cpp
@@ -1531,6 +1531,7 @@ void MainWindow::selectedMessageChanged(const QModelIndex &sortedIndex, const QM
QDir dir = QFileInfo(m_dataModel->srcFileName(model)).dir();
QString fileName = QDir::cleanPath(dir.absoluteFilePath(m->fileName()));
m_sourceCodeView->setSourceContext(fileName, m->lineNumber());
+ m_sourceCodeView->setCodecName(m_dataModel->model(model)->codecName());
}
m_errorsView->setEnabled(true);
} else {
diff --git a/tools/linguist/linguist/messagemodel.h b/tools/linguist/linguist/messagemodel.h
index 8f620cc7f9..3af25318f7 100644
--- a/tools/linguist/linguist/messagemodel.h
+++ b/tools/linguist/linguist/messagemodel.h
@@ -216,6 +216,7 @@ public:
void setSourceLanguageAndCountry(QLocale::Language lang, QLocale::Country country);
QLocale::Language sourceLanguage() const { return m_sourceLanguage; }
QLocale::Country sourceCountry() const { return m_sourceCountry; }
+ QByteArray codecName() const { return m_codecName; }
const QString &localizedLanguage() const { return m_localizedLanguage; }
const QStringList &numerusForms() const { return m_numerusForms; }
diff --git a/tools/linguist/linguist/sourcecodeview.cpp b/tools/linguist/linguist/sourcecodeview.cpp
index aead2076e9..f549d30c19 100644
--- a/tools/linguist/linguist/sourcecodeview.cpp
+++ b/tools/linguist/linguist/sourcecodeview.cpp
@@ -43,6 +43,7 @@
#include <QtCore/QFile>
#include <QtCore/QFileInfo>
+#include <QtCore/QTextCodec>
#include <QtCore/QTextStream>
#include <QtGui/QTextCharFormat>
@@ -79,6 +80,11 @@ void SourceCodeView::setSourceContext(const QString &fileName, const int lineNum
}
}
+void SourceCodeView::setCodecName(const QByteArray &codecName)
+{
+ m_codecName = codecName;
+}
+
void SourceCodeView::setActivated(bool activated)
{
m_isActive = activated;
@@ -108,7 +114,9 @@ void SourceCodeView::showSourceCode(const QString &absFileName, const int lineNu
appendHtml(tr("<i>File %1 not readable</i>").arg(absFileName));
return;
}
- fileText = QString::fromLatin1(file.readAll());
+ const QTextCodec *codec = QTextCodec::codecForName(m_codecName);
+ const QByteArray contents = file.readAll();
+ fileText = codec ? codec->toUnicode(contents) : QString::fromUtf8(contents);
fileHash.insert(absFileName, fileText);
}
diff --git a/tools/linguist/linguist/sourcecodeview.h b/tools/linguist/linguist/sourcecodeview.h
index 41b08282cf..303e57c8d0 100644
--- a/tools/linguist/linguist/sourcecodeview.h
+++ b/tools/linguist/linguist/sourcecodeview.h
@@ -54,6 +54,7 @@ class SourceCodeView : public QPlainTextEdit
public:
SourceCodeView(QWidget *parent = 0);
void setSourceContext(const QString &fileName, const int lineNum);
+ void setCodecName(const QByteArray &codecName);
public slots:
void setActivated(bool activated);
@@ -65,6 +66,7 @@ private:
QString m_fileToLoad;
int m_lineNumToLoad;
QString m_currentFileName;
+ QByteArray m_codecName;
QHash<QString, QString> fileHash;
};