Skip to content

Commit

Permalink
fix: use fixed byte detection encoding.
Browse files Browse the repository at this point in the history
Change-Id: I7ecc6f9864e909124ba51ecc238b7e66a84b6fc5
  • Loading branch information
rekols committed Sep 29, 2018
1 parent 2cc814b commit a0dd1cb
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
2 changes: 2 additions & 0 deletions src/editwrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,8 @@ void EditWrapper::handleFileLoadFinished(const QByteArray &encode, const QString
// restore mouse style.
// QApplication::restoreOverrideCursor();

qDebug() << "load finished: " << m_textEdit->filepath << ", " << encode;

m_isLoadFinished = true;
m_fileEncode = encode;

Expand Down
7 changes: 5 additions & 2 deletions src/fileloadthread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,12 @@ void FileLoadThread::run()
if (file.open(QIODevice::ReadOnly)) {
// reads all remaining data from the file.
QByteArray fileContent = file.readAll();

QByteArray detectArray = fileContent;
detectArray.truncate(fileContent.size() / 10);

if (fileContent.size() > 1000) {
// use fixed byte detection encoding.
detectArray.truncate(1000);
}

// read the encode.
QByteArray encode = Utils::detectEncode(detectArray, m_filePath);
Expand Down
2 changes: 1 addition & 1 deletion src/utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,7 @@ QVariantMap Utils::getThemeMapFromPath(const QString &filepath)

bool Utils::isMimeTypeSupport(const QString &filepath)
{
auto mimeType = QMimeDatabase().mimeTypeForFile(filepath).name();
QString mimeType = QMimeDatabase().mimeTypeForFile(filepath).name();
qDebug() << "detect mime type: " << filepath << mimeType;

if (mimeType.startsWith("text/")) {
Expand Down

0 comments on commit a0dd1cb

Please sign in to comment.