Remove QTextCodec dependency from QMimeData
We already assumed that 8bit data is utf8 encoded in all cases but for HTML. Handle HTML through QStringDecoder now. This removes support for encodings other than UTF based one and Latin1. This is ok, as HTML should nowadays always be encoded in utf8 as well (anything else is strongly discouraged by the HTML spec). In addition, utf-8 and latin1 together seem to cover ~98% of all HTML data. Change-Id: I7e7165edd38cfac395faf72681e5715b6d014c14 Reviewed-by: David Faure <david.faure@kdab.com>
This commit is contained in:
parent
124d587bb9
commit
7e65f6a45d
@ -42,9 +42,7 @@
|
||||
#include "private/qobject_p.h"
|
||||
#include "qurl.h"
|
||||
#include "qstringlist.h"
|
||||
#if QT_CONFIG(textcodec)
|
||||
#include "qtextcodec.h"
|
||||
#endif
|
||||
#include "qstringconverter.h"
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
|
||||
@ -157,15 +155,18 @@ QVariant QMimeDataPrivate::retrieveTypedData(const QString &format, QMetaType::T
|
||||
if (data.userType() == QMetaType::QByteArray) {
|
||||
// see if we can convert to the requested type
|
||||
switch(type) {
|
||||
#if QT_CONFIG(textcodec)
|
||||
case QMetaType::QString: {
|
||||
const QByteArray ba = data.toByteArray();
|
||||
QTextCodec *codec = QTextCodec::codecForName("utf-8");
|
||||
if (format == QLatin1String("text/html"))
|
||||
codec = QTextCodec::codecForHtml(ba, codec);
|
||||
return codec->toUnicode(ba);
|
||||
if (format == QLatin1String("text/html")) {
|
||||
auto encoding = QStringConverter::encodingForHtml(ba.constData(), ba.size());
|
||||
if (encoding) {
|
||||
QStringDecoder toUtf16(*encoding);
|
||||
return QString(toUtf16(ba));
|
||||
}
|
||||
// fall back to utf8
|
||||
}
|
||||
return QString::fromUtf8(ba);
|
||||
}
|
||||
#endif // textcodec
|
||||
case QMetaType::QColor: {
|
||||
QVariant newData = data;
|
||||
newData.convert(QMetaType::QColor);
|
||||
|
Loading…
Reference in New Issue
Block a user