From 8c44e10ae48a88ed2ea885f432c65a0859013011 Mon Sep 17 00:00:00 2001
From: Petr Vanek <petr@yarpen.cz>
Date: Thu, 29 Oct 2020 18:19:02 +0100
Subject: [PATCH] fixed #569 Build fails with quazip 1.0

---
 ImageLounge/cmake/Unix.cmake                | 28 +++++++++++++++------
 ImageLounge/src/DkCore/DkBasicLoader.cpp    |  4 +++
 ImageLounge/src/DkCore/DkImageContainer.cpp |  4 +++
 ImageLounge/src/DkCore/DkImageLoader.cpp    |  6 ++++-
 ImageLounge/src/DkGui/DkDialog.cpp          |  4 +++
 5 files changed, 37 insertions(+), 9 deletions(-)

diff --git a/ImageLounge/cmake/Unix.cmake b/ImageLounge/cmake/Unix.cmake
index 5567084b..c90ba320 100644
--- a/ImageLounge/cmake/Unix.cmake
+++ b/ImageLounge/cmake/Unix.cmake
@@ -102,14 +102,26 @@ unset(QT_ROOT CACHE)
 
 if(ENABLE_QUAZIP)
   if(USE_SYSTEM_QUAZIP)
-    SET(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
-
-    find_package(QuaZip5 QUIET)
-    if(NOT QUAZIP_FOUND)
-	    message(FATAL_ERROR "QUAZIP not found. It's mandatory when used with ENABLE_QUAZIP enabled, you can also disable USE_SYSTEM_QUAZIP")
-    else()
-	    add_definitions(-DWITH_QUAZIP)
-    endif()
+    # Let's try QuaZip1 first (it's the bright future)
+    find_package(QuaZip-Qt5 QUIET)
+    if (QuaZip-Qt5_FOUND)
+      message(STATUS "QUAZIP: QuaZip-1 for Qt5 found")
+      set(QUAZIP_LIBRARIES QuaZip::QuaZip)
+      add_definitions(-DWITH_QUAZIP1)
+    else ()
+      message(WARNING "QUAZIP: 1.x not found. Trying to find 0.x")
+      # QuaZip < 1.0. This leg can be removed (including cmake/FindQuaZip5.cmake)
+      # ater the final migration to 1.x in Linux distros
+      SET(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
+
+      find_package(QuaZip5 QUIET)
+      if(NOT QUAZIP_FOUND)
+        message(FATAL_ERROR "QUAZIP: even 0.x not found. It's mandatory when used with ENABLE_QUAZIP enabled, you can also disable USE_SYSTEM_QUAZIP")
+      endif()
+
+    endif (QuaZip-Qt5_FOUND)
+    # we have any QuaZip after all
+    add_definitions(-DWITH_QUAZIP)
   else()
     find_package(ZLIB REQUIRED)
     set(QUAZIP_INCLUDE_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/3rdparty/quazip-0.7/quazip ${CMAKE_CURRENT_SOURCE_DIR}/3rdparty/quazip-0.7/)
diff --git a/ImageLounge/src/DkCore/DkBasicLoader.cpp b/ImageLounge/src/DkCore/DkBasicLoader.cpp
index 7f9e889c..b7edfd43 100644
--- a/ImageLounge/src/DkCore/DkBasicLoader.cpp
+++ b/ImageLounge/src/DkCore/DkBasicLoader.cpp
@@ -54,8 +54,12 @@
 
 // quazip
 #ifdef WITH_QUAZIP
+#ifdef WITH_QUAZIP1
+#include <quazip/JlCompress.h>
+#else
 #include <quazip5/JlCompress.h>
 #endif
+#endif
 
 // opencv
 #ifdef WITH_OPENCV
diff --git a/ImageLounge/src/DkCore/DkImageContainer.cpp b/ImageLounge/src/DkCore/DkImageContainer.cpp
index 810994d3..150da9c2 100644
--- a/ImageLounge/src/DkCore/DkImageContainer.cpp
+++ b/ImageLounge/src/DkCore/DkImageContainer.cpp
@@ -41,8 +41,12 @@
 
 // quazip
 #ifdef WITH_QUAZIP
+#ifdef WITH_QUAZIP1
+#include <quazip/JlCompress.h>
+#else
 #include <quazip5/JlCompress.h>
 #endif
+#endif
 #pragma warning(pop)		// no warnings from includes - end
 
 #pragma warning(disable: 4251)	// TODO: remove
diff --git a/ImageLounge/src/DkCore/DkImageLoader.cpp b/ImageLounge/src/DkCore/DkImageLoader.cpp
index 09d25d23..e4186f2b 100644
--- a/ImageLounge/src/DkCore/DkImageLoader.cpp
+++ b/ImageLounge/src/DkCore/DkImageLoader.cpp
@@ -79,8 +79,12 @@
 
 // quazip
 #ifdef WITH_QUAZIP
+#ifdef WITH_QUAZIP1
+#include <quazip/JlCompress.h>
+#else
 #include <quazip5/JlCompress.h>
 #endif
+#endif
 
 // opencv
 #ifdef WITH_OPENCV
@@ -2212,4 +2216,4 @@ QString DkImageLoader::fileName() const {
 	return mCurrentImage->fileName();
 }
 
-}
\ No newline at end of file
+}
diff --git a/ImageLounge/src/DkGui/DkDialog.cpp b/ImageLounge/src/DkGui/DkDialog.cpp
index 008c9a3b..85842eca 100644
--- a/ImageLounge/src/DkGui/DkDialog.cpp
+++ b/ImageLounge/src/DkGui/DkDialog.cpp
@@ -97,8 +97,12 @@
 
 // quazip
 #ifdef WITH_QUAZIP
+#ifdef WITH_QUAZIP1
+#include <quazip/JlCompress.h>
+#else
 #include <quazip5/JlCompress.h>
 #endif
+#endif
 
 #pragma warning(pop)		// no warnings from includes - end
 
