Commit b8bf6b65 authored by Laurent Montel's avatar Laurent Montel
Browse files

Port to QStringConverter

parent 5fb31c5c
Pipeline #246439 passed with stage
in 10 minutes
......@@ -63,9 +63,12 @@ void WebEnginePartHtmlWriter::end()
mTempFile = new QTemporaryFile(QDir::tempPath() + QLatin1String("/messageviewer_XXXXXX") + QLatin1String(".html"));
mTempFile->open();
QTextStream stream(mTempFile);
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
const QByteArray codecValue = Util::htmlCodec(data(), codec());
stream.setCodec(codecValue.constData());
#else
stream.setEncoding(Util::htmlEncoding(data(), codec()));
#endif
stream << data();
// Bug 387061
mHtmlView->load(QUrl::fromLocalFile(mTempFile->fileName()));
......
......@@ -761,6 +761,25 @@ QByteArray Util::htmlCodec(const QByteArray &data, const QByteArray &codec)
// qDebug() << " codec ******************************************: " << codec << " currentCodec : " <<currentCodec;
return currentCodec;
}
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
QStringConverter::Encoding Util::htmlEncoding(const QByteArray &data, const QByteArray &codec)
{
QByteArray currentCodec = codec;
if (currentCodec.isEmpty()) {
return QStringConverter::Utf8;
}
if (currentCodec == QByteArray("us-ascii")) {
return QStringConverter::Latin1;
}
if (data.contains("charset=\"utf-8\"") || data.contains("charset=\"UTF-8\"") || data.contains("charset=UTF-8")) {
return QStringConverter::Utf8;
}
// qDebug() << " codec ******************************************: " << codec << " currentCodec : " <<currentCodec;
// TODO verify
return QStringConverter::System;
}
#endif
QDebug operator<<(QDebug d, const Util::HtmlMessageInfo &t)
{
......
......@@ -41,7 +41,9 @@
#include <KMime/Content>
#include <KService>
#include <QTextCodec>
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
#include <QStringConverter>
#endif
class QUrl;
class QWidget;
class QActionGroup;
......@@ -74,7 +76,9 @@ Q_REQUIRED_RESULT MESSAGEVIEWER_EXPORT QAction *createAppAction(const KService::
/** Return a QTextCodec for the specified charset.
* This function is a bit more tolerant, than QTextCodec::codecForName */
MESSAGEVIEWER_EXPORT const QTextCodec *codecForName(const QByteArray &_str);
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
MESSAGEVIEWER_EXPORT QStringConverter::Encoding htmlEncoding(const QByteArray &data, const QByteArray &codec);
#endif
struct HtmlMessageInfo {
QString htmlSource;
QString extraHead;
......
  • If we have to expect arbitrary codecs here (ie. if this is received HTML, not something we generate) I think we instead need to drop using QTextStream here and manually push the data in blocks through QStringDecoder (since 6.4 that has a ctor for taking an arbitrary codec name).

    IIRC we did a similar change in KTextEditor, QTextStream unfortunately lost that feature.

Supports Markdown
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