diff --git a/RagePhoto.cpp b/RagePhoto.cpp index f85e24d..fe3cac2 100644 --- a/RagePhoto.cpp +++ b/RagePhoto.cpp @@ -18,9 +18,11 @@ #include "RagePhoto.h" #include -#include #include #include +#if QT_VERSION < 0x060000 +#include +#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 +} diff --git a/RagePhoto.h b/RagePhoto.h index 4dc9bef..5a3d592 100644 --- a/RagePhoto.h +++ b/RagePhoto.h @@ -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; diff --git a/StandardPaths.cpp b/StandardPaths.cpp index af0176d..3f466ab 100644 --- a/StandardPaths.cpp +++ b/StandardPaths.cpp @@ -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);