RagePhoto: Qt6 support added
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Syping 2020-11-11 17:58:15 +01:00
parent e34ee22ed9
commit 6befe33596
3 changed files with 41 additions and 4 deletions

View file

@ -18,9 +18,11 @@
#include "RagePhoto.h"
#include <QJsonDocument>
#include <QTextCodec>
#include <QBuffer>
#include <QFile>
#if QT_VERSION < 0x060000
#include <QTextCodec>
#endif
RagePhoto::RagePhoto()
{
@ -92,7 +94,7 @@ bool RagePhoto::load()
size = dataBuffer.read(photoHeader, 256);
if (size != 256)
return false;
for (const QChar &photoChar : QTextCodec::codecForName("UTF-16LE")->toUnicode(photoHeader, 256)) {
for (const QChar &photoChar : utf16LEToString(photoHeader, 256)) {
if (photoChar.isNull())
break;
p_photoString += photoChar;
@ -608,7 +610,7 @@ void RagePhoto::save(QIODevice *ioDevice, PhotoFormat photoFormat)
uInt32ToCharLE(&format, uInt32Buffer);
ioDevice->write(uInt32Buffer, 4);
QByteArray photoHeader = QTextCodec::codecForName("UTF-16LE")->fromUnicode(p_photoString);
QByteArray photoHeader = stringToUtf16LE(p_photoString);
if (photoHeader.left(2) == "\xFF\xFE") {
photoHeader.remove(0, 2);
}
@ -727,3 +729,33 @@ void RagePhoto::uInt32ToCharLE(quint32 *x, char *y)
y[2] = (*x >> 16) & 0xFF;
y[3] = (*x >> 24) & 0xFF;
}
QByteArray RagePhoto::stringToUtf16LE(const QString &string)
{
#if QT_VERSION >= 0x060000
QStringEncoder stringEncoder = QStringEncoder(QStringEncoder::Utf16LE);
return stringEncoder(string);
#else
return QTextCodec::codecForName("UTF-16LE")->fromUnicode(string);
#endif
}
QString RagePhoto::utf16LEToString(const QByteArray &data)
{
#if QT_VERSION >= 0x060000
QStringDecoder stringDecoder = QStringDecoder(QStringDecoder::Utf16LE);
return stringDecoder(data);
#else
return QTextCodec::codecForName("UTF-16LE")->toUnicode(data);
#endif
}
QString RagePhoto::utf16LEToString(const char *data, int size)
{
#if QT_VERSION >= 0x060000
QStringDecoder stringDecoder = QStringDecoder(QStringDecoder::Utf16LE);
return stringDecoder(QByteArray::fromRawData(data, size));
#else
return QTextCodec::codecForName("UTF-16LE")->toUnicode(data, size);
#endif
}

View file

@ -80,6 +80,9 @@ private:
inline quint32 charToUInt32LE(char *x);
inline void uInt32ToCharBE(quint32 *x, char *y);
inline void uInt32ToCharLE(quint32 *x, char *y);
inline QByteArray stringToUtf16LE(const QString &string);
inline QString utf16LEToString(const QByteArray &data);
inline QString utf16LEToString(const char *data, int size);
PhotoFormat p_photoFormat;
QJsonObject p_jsonObject;
QByteArray p_fileData;

View file

@ -48,7 +48,9 @@ QString StandardPaths::cacheLocation()
QString StandardPaths::dataLocation()
{
#if QT_VERSION >= 0x050000
#if QT_VERSION >= 0x060000
return QStandardPaths::writableLocation(QStandardPaths::AppLocalDataLocation);
#elif QT_VERSION >= 0x050000
return QStandardPaths::writableLocation(QStandardPaths::DataLocation);
#else
return QDesktopServices::storageLocation(QDesktopServices::DataLocation);