Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove dependency on QTextCodec for qt6 #199

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,6 @@
cmake-*
CMakeUserPresets.json
vcpkg_installed/
Testing/
Testing/
CMakeFiles/
CMakeCache.txt
27 changes: 24 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,13 @@ set(QUAZIP_DIR_NAME QuaZip-Qt${QUAZIP_QT_MAJOR_VERSION}-${QUAZIP_LIB_VERSION})
set(QUAZIP_PACKAGE_NAME QuaZip-Qt${QUAZIP_QT_MAJOR_VERSION})

if(QUAZIP_QT_MAJOR_VERSION EQUAL 6)
find_package(Qt6 REQUIRED COMPONENTS Core Core5Compat
find_package(Qt6 REQUIRED COMPONENTS Core
OPTIONAL_COMPONENTS Network Test)
message(STATUS "Found Qt version ${Qt6_VERSION} at ${Qt6_DIR}")
set(QUAZIP_QT_ZLIB_COMPONENT BundledZLIB)
set(QUAZIP_QT_ZLIB_HEADER_COMPONENT ZlibPrivate)
set(QUAZIP_LIB_LIBRARIES Qt6::Core Qt6::Core5Compat)
set(QUAZIP_TEST_QT_LIBRARIES Qt6::Core Qt6::Core5Compat Qt6::Network Qt6::Test)
set(QUAZIP_LIB_LIBRARIES Qt6::Core )
set(QUAZIP_TEST_QT_LIBRARIES Qt6::Core Qt6::Network Qt6::Test)
set(QUAZIP_PKGCONFIG_REQUIRES "zlib, Qt6Core")
elseif(QUAZIP_QT_MAJOR_VERSION EQUAL 5)
find_package(Qt5 REQUIRED COMPONENTS Core
Expand Down Expand Up @@ -225,6 +225,27 @@ if(QUAZIP_BZIP2)
endif()
endif()

#issue Qt5/Qt6 / Core5Compat and QTextCodec


if(${QT_VERSION} VERSION_GREATER_EQUAL 6.0.0)

find_package(Qt6 OPTIONAL_COMPONENTS Core5Compat)

if(Qt6Core5Compat_FOUND)
set(QUAZIP_LIB_LIBRARIES ${QUAZIP_LIB_LIBRARIES} Qt6::Core5Compat)
set(QUAZIP_TEST_QT_LIBRARIES ${QUAZIP_TEST_QT_LIBRARIES} Qt6::Core5Compat)

add_compile_definitions( QUAZIP_CAN_USE_QTEXTCODEC)
message("-- Quazip use QTextCodec")

endif()
else()
add_compile_definitions( QUAZIP_CAN_USE_QTEXTCODEC)
message("-- Quazip use QTextCodec")
endif()


add_subdirectory(quazip)

if(QUAZIP_ENABLE_TESTS)
Expand Down
6 changes: 6 additions & 0 deletions quazip/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ set(QUAZIP_HEADERS
quazip.h
quazip_global.h
quazip_qt_compat.h

quazip_textcodec.h

quazipdir.h
quazipfile.h
quazipfileinfo.h
Expand All @@ -36,6 +39,9 @@ set(QUAZIP_SOURCES
quagzipfile.cpp
quaziodevice.cpp
quazip.cpp

quazip_textcodec.cpp

quazipdir.cpp
quazipfile.cpp
quazipfileinfo.cpp
Expand Down
6 changes: 3 additions & 3 deletions quazip/JlCompress.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -350,8 +350,8 @@ QStringList JlCompress::extractFiles(QuaZip &zip, const QStringList &files, cons
return extracted;
}

QStringList JlCompress::extractDir(QString fileCompressed, QTextCodec* fileNameCodec, QString dir) {
// Open zip
QStringList JlCompress::extractDir(QString fileCompressed, QuazipTextCodec* fileNameCodec, QString dir) {
// Apro lo zip
QuaZip zip(fileCompressed);
if (fileNameCodec)
zip.setFileNameCodec(fileNameCodec);
Expand Down Expand Up @@ -434,7 +434,7 @@ QStringList JlCompress::getFileList(QuaZip *zip)
return lst;
}

QStringList JlCompress::extractDir(QIODevice* ioDevice, QTextCodec* fileNameCodec, QString dir)
QStringList JlCompress::extractDir(QIODevice* ioDevice, QuazipTextCodec* fileNameCodec, QString dir)
{
QuaZip zip(ioDevice);
if (fileNameCodec)
Expand Down
4 changes: 2 additions & 2 deletions quazip/JlCompress.h
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ class QUAZIP_EXPORT JlCompress {
left empty.
\return The list of the full paths of the files extracted, empty on failure.
*/
static QStringList extractDir(QString fileCompressed, QTextCodec* fileNameCodec, QString dir = QString());
static QStringList extractDir(QString fileCompressed, QuazipTextCodec* fileNameCodec, QString dir = QString());
/// Get the file list.
/**
\return The list of the files in the archive, or, more precisely, the
Expand Down Expand Up @@ -202,7 +202,7 @@ class QUAZIP_EXPORT JlCompress {
left empty.
\return The list of the full paths of the files extracted, empty on failure.
*/
static QStringList extractDir(QIODevice* ioDevice, QTextCodec* fileNameCodec, QString dir = QString());
static QStringList extractDir(QIODevice* ioDevice, QuazipTextCodec* fileNameCodec, QString dir = QString());
/// Get the file list.
/**
\return The list of the files in the archive, or, more precisely, the
Expand Down
36 changes: 19 additions & 17 deletions quazip/quazip.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ quazip/(un)zip.h files for details, basically it's zlib license.

#include "quazip.h"

#include "quazip_textcodec.h"

#define QUAZIP_OS_UNIX 3u

/// All the internal stuff for the QuaZip class.
Expand All @@ -45,9 +47,9 @@ class QuaZipPrivate {
/// The pointer to the corresponding QuaZip instance.
QuaZip *q;
/// The codec for file names (used when UTF-8 is not enabled).
QTextCodec *fileNameCodec;
QuazipTextCodec *fileNameCodec;
/// The codec for comments (used when UTF-8 is not enabled).
QTextCodec *commentCodec;
QuazipTextCodec *commentCodec;
/// The archive file name.
QString zipName;
/// The device to access the archive.
Expand Down Expand Up @@ -76,18 +78,18 @@ class QuaZipPrivate {
bool utf8;
/// The OS code.
uint osCode;
inline QTextCodec *getDefaultFileNameCodec()
inline QuazipTextCodec *getDefaultFileNameCodec()
{
if (defaultFileNameCodec == nullptr) {
return QTextCodec::codecForLocale();
return QuazipTextCodec::codecForLocale();
}
return defaultFileNameCodec;
}
/// The constructor for the corresponding QuaZip constructor.
inline QuaZipPrivate(QuaZip *q):
q(q),
fileNameCodec(getDefaultFileNameCodec()),
commentCodec(QTextCodec::codecForLocale()),
commentCodec(QuazipTextCodec::codecForLocale()),
ioDevice(nullptr),
mode(QuaZip::mdNotOpen),
hasCurrentFile_f(false),
Expand All @@ -107,7 +109,7 @@ class QuaZipPrivate {
inline QuaZipPrivate(QuaZip *q, const QString &zipName):
q(q),
fileNameCodec(getDefaultFileNameCodec()),
commentCodec(QTextCodec::codecForLocale()),
commentCodec(QuazipTextCodec::codecForLocale()),
zipName(zipName),
ioDevice(nullptr),
mode(QuaZip::mdNotOpen),
Expand All @@ -128,7 +130,7 @@ class QuaZipPrivate {
inline QuaZipPrivate(QuaZip *q, QIODevice *ioDevice):
q(q),
fileNameCodec(getDefaultFileNameCodec()),
commentCodec(QTextCodec::codecForLocale()),
commentCodec(QuazipTextCodec::codecForLocale()),
ioDevice(ioDevice),
mode(QuaZip::mdNotOpen),
hasCurrentFile_f(false),
Expand All @@ -155,11 +157,11 @@ class QuaZipPrivate {
QHash<QString, unz64_file_pos> directoryCaseSensitive;
QHash<QString, unz64_file_pos> directoryCaseInsensitive;
unz64_file_pos lastMappedDirectoryEntry;
static QTextCodec *defaultFileNameCodec;
static QuazipTextCodec *defaultFileNameCodec;
static uint defaultOsCode;
};

QTextCodec *QuaZipPrivate::defaultFileNameCodec = nullptr;
QuazipTextCodec *QuaZipPrivate::defaultFileNameCodec = nullptr;
uint QuaZipPrivate::defaultOsCode = QUAZIP_OS_UNIX;

void QuaZipPrivate::clearDirectoryMap()
Expand Down Expand Up @@ -588,14 +590,14 @@ QString QuaZip::getCurrentFileName()const
return result;
}

void QuaZip::setFileNameCodec(QTextCodec *fileNameCodec)
void QuaZip::setFileNameCodec(QuazipTextCodec *fileNameCodec)
{
p->fileNameCodec=fileNameCodec;
}

void QuaZip::setFileNameCodec(const char *fileNameCodecName)
{
p->fileNameCodec=QTextCodec::codecForName(fileNameCodecName);
p->fileNameCodec=QuazipTextCodec::codecForName(fileNameCodecName);
}

void QuaZip::setOsCode(uint osCode)
Expand All @@ -608,22 +610,22 @@ uint QuaZip::getOsCode() const
return p->osCode;
}

QTextCodec *QuaZip::getFileNameCodec()const
QuazipTextCodec *QuaZip::getFileNameCodec()const
{
return p->fileNameCodec;
}

void QuaZip::setCommentCodec(QTextCodec *commentCodec)
void QuaZip::setCommentCodec(QuazipTextCodec *commentCodec)
{
p->commentCodec=commentCodec;
}

void QuaZip::setCommentCodec(const char *commentCodecName)
{
p->commentCodec=QTextCodec::codecForName(commentCodecName);
p->commentCodec=QuazipTextCodec::codecForName(commentCodecName);
}

QTextCodec *QuaZip::getCommentCodec()const
QuazipTextCodec *QuaZip::getCommentCodec()const
{
return p->commentCodec;
}
Expand Down Expand Up @@ -783,14 +785,14 @@ Qt::CaseSensitivity QuaZip::convertCaseSensitivity(QuaZip::CaseSensitivity cs)
}
}

void QuaZip::setDefaultFileNameCodec(QTextCodec *codec)
void QuaZip::setDefaultFileNameCodec(QuazipTextCodec *codec)
{
QuaZipPrivate::defaultFileNameCodec = codec;
}

void QuaZip::setDefaultFileNameCodec(const char *codecName)
{
setDefaultFileNameCodec(QTextCodec::codecForName(codecName));
setDefaultFileNameCodec(QuazipTextCodec::codecForName(codecName));
}

void QuaZip::setDefaultOsCode(uint osCode)
Expand Down
22 changes: 12 additions & 10 deletions quazip/quazip.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,16 @@ quazip/(un)zip.h files for details, basically it's zlib license.

#include <QtCore/QString>
#include <QtCore/QStringList>
#include "quazip_qt_compat.h"


#include "zip.h"
#include "unzip.h"

#include "quazip_global.h"
#include "quazipfileinfo.h"

#include "quazip_textcodec.h"

// just in case it will be defined in the later versions of the ZIP/UNZIP
#ifndef UNZ_OPENERROR
// define additional error code
Expand Down Expand Up @@ -226,10 +228,10 @@ class QUAZIP_EXPORT QuaZip {
* example, file names with cyrillic letters will be in \c IBM866
* encoding.
**/
void setFileNameCodec(QTextCodec *fileNameCodec);
void setFileNameCodec(QuazipTextCodec *fileNameCodec);
/// Sets the codec used to encode/decode file names inside archive.
/** \overload
* Equivalent to calling setFileNameCodec(QTextCodec::codecForName(codecName));
* Equivalent to calling setFileNameCodec(QuazipTextCodec::codecForName(codecName));
**/
void setFileNameCodec(const char *fileNameCodecName);
/// Sets the OS code (highest 8 bits of the “version made by” field) for new files.
Expand All @@ -241,18 +243,18 @@ class QUAZIP_EXPORT QuaZip {
/// Returns the OS code for new files.
uint getOsCode() const;
/// Returns the codec used to encode/decode comments inside archive.
QTextCodec* getFileNameCodec() const;
QuazipTextCodec* getFileNameCodec() const;
/// Sets the codec used to encode/decode comments inside archive.
/** This codec defaults to locale codec, which is probably ok.
**/
void setCommentCodec(QTextCodec *commentCodec);
void setCommentCodec(QuazipTextCodec *commentCodec);
/// Sets the codec used to encode/decode comments inside archive.
/** \overload
* Equivalent to calling setCommentCodec(QTextCodec::codecForName(codecName));
* Equivalent to calling setCommentCodec(QuazipTextCodec::codecForName(codecName));
**/
void setCommentCodec(const char *commentCodecName);
/// Returns the codec used to encode/decode comments inside archive.
QTextCodec* getCommentCodec() const;
QuazipTextCodec* getCommentCodec() const;
/// Returns the name of the ZIP file.
/** Returns null string if no ZIP file name has been set, for
* example when the QuaZip instance is set up to use a QIODevice
Expand Down Expand Up @@ -570,7 +572,7 @@ class QUAZIP_EXPORT QuaZip {
* won't affect the QuaZip instances already created at that moment.
*
* The codec specified here can be overriden by calling setFileNameCodec().
* If neither function is called, QTextCodec::codecForLocale() will be used
* If neither function is called, QuazipTextCodec::codecForLocale() will be used
* to decode or encode file names. Use this function with caution if
* the application uses other libraries that depend on QuaZip. Those
* libraries can either call this function by themselves, thus overriding
Expand All @@ -594,11 +596,11 @@ class QUAZIP_EXPORT QuaZip {
*
* @param codec The codec to use by default. If null, resets to default.
*/
static void setDefaultFileNameCodec(QTextCodec *codec);
static void setDefaultFileNameCodec(QuazipTextCodec *codec);
/**
* @overload
* Equivalent to calling
* setDefaultFileNameCodec(QTextCodec::codecForName(codecName)).
* setDefaultFileNameCodec(QuazipTextCodec::codecForName(codecName)).
*/
static void setDefaultFileNameCodec(const char *codecName);
/// Sets default OS code.
Expand Down
8 changes: 1 addition & 7 deletions quazip/quazip_qt_compat.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,7 @@
#include <QtCore/Qt>
#include <QtCore/QtGlobal>

// Legacy encodings are still everywhere, but the Qt team decided we
// don't need them anymore and moved them out of Core in Qt 6.
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
# include <QtCore5Compat/QTextCodec>
#else
# include <QtCore/QTextCodec>
#endif
class QuazipTextCodec;

// QSaveFile terribly breaks the is-a idiom (Liskov substitution principle):
// QSaveFile is-a QIODevice, but it makes close() private and aborts
Expand Down
Loading