Commit e2658eef authored by Laurent Montel's avatar Laurent Montel 😁
Browse files

Extract code for allowing to autotest code

parent ffc72526
...@@ -20,7 +20,7 @@ ...@@ -20,7 +20,7 @@
#include "messageviewer_debug.h" #include "messageviewer_debug.h"
#include "viewer/webengine/mailwebengineview.h" #include "viewer/webengine/mailwebengineview.h"
#include "messageviewer/messageviewerutil.h"
#include <QUrl> #include <QUrl>
#include <cassert> #include <cassert>
...@@ -72,15 +72,8 @@ void WebEnginePartHtmlWriter::end() ...@@ -72,15 +72,8 @@ void WebEnginePartHtmlWriter::end()
mTempFile = new QTemporaryFile(QDir::tempPath() + QLatin1String("/messageviewer_XXXXXX")+ QLatin1String(".html")); mTempFile = new QTemporaryFile(QDir::tempPath() + QLatin1String("/messageviewer_XXXXXX")+ QLatin1String(".html"));
mTempFile->open(); mTempFile->open();
QTextStream stream(mTempFile); QTextStream stream(mTempFile);
//TODO we need to change codec when mail use different codec.
QByteArray codecValue = codec(); const QByteArray codecValue = Util::htmlCodec(data(), codec());
if (codecValue.isEmpty()) {
codecValue = QByteArray("UTF-8");
}
//qDebug() << " codecValue ******************************************: " << codecValue;
if (data().contains("<meta charset=\"utf-8\">")) {
codecValue = QByteArray("UTF-8");
}
stream.setCodec(codecValue.constData()); stream.setCodec(codecValue.constData());
stream << data(); stream << data();
......
...@@ -735,3 +735,17 @@ QString Util::processHtml(const QString &htmlSource, QString &extraHead) ...@@ -735,3 +735,17 @@ QString Util::processHtml(const QString &htmlSource, QString &extraHead)
s = textBeforeDoctype + s; s = textBeforeDoctype + s;
return s; return s;
} }
QByteArray Util::htmlCodec(const QByteArray &data, const QByteArray &codec)
{
QByteArray currentCodec = codec;
if (currentCodec.isEmpty()) {
currentCodec = QByteArray("UTF-8");
}
//qDebug() << " codecValue ******************************************: " << codecValue;
if (data.contains("<meta charset=\"utf-8\">")) {
currentCodec = QByteArray("UTF-8");
}
return currentCodec;
}
...@@ -73,6 +73,7 @@ Q_REQUIRED_RESULT MESSAGEVIEWER_EXPORT bool excludeExtraHeader(const QString &s) ...@@ -73,6 +73,7 @@ Q_REQUIRED_RESULT MESSAGEVIEWER_EXPORT bool excludeExtraHeader(const QString &s)
MESSAGEVIEWER_EXPORT const QTextCodec *codecForName(const QByteArray &_str); MESSAGEVIEWER_EXPORT const QTextCodec *codecForName(const QByteArray &_str);
Q_REQUIRED_RESULT MESSAGEVIEWER_EXPORT QString processHtml(const QString &htmlSource, QString &extraHead); Q_REQUIRED_RESULT MESSAGEVIEWER_EXPORT QString processHtml(const QString &htmlSource, QString &extraHead);
Q_REQUIRED_RESULT MESSAGEVIEWER_EXPORT QByteArray htmlCodec(const QByteArray &data, const QByteArray &currentCodec);
} }
} }
Q_DECLARE_METATYPE(KService::Ptr) Q_DECLARE_METATYPE(KService::Ptr)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment