Skip to content

Commit

Permalink
add detection of libz (optional, needs update for win32)
Browse files Browse the repository at this point in the history
  • Loading branch information
etiennesky committed Apr 11, 2012
1 parent 5e144ee commit e5775e7
Show file tree
Hide file tree
Showing 7 changed files with 94 additions and 34 deletions.
14 changes: 14 additions & 0 deletions CMakeLists.txt
Expand Up @@ -254,6 +254,20 @@ FIND_PROGRAM(QT_LRELEASE_EXECUTABLE
NO_DEFAULT_PATH
)


#############################################################
# search for zlib optional, used by quazip
# this uses script provided by cmake
# if WIN32 should use zlib from QT
FIND_PACKAGE(ZLIB)
IF (ZLIB_FOUND)
MESSAGE(STATUS "Found zlib: ${ZLIB_LIBRARIES}")
SET(HAVE_ZLIB TRUE)
ELSE (ZLIB_FOUND)
MESSAGE(STATUS "Could not find zlib (optional)")
ENDIF(ZLIB_FOUND)


#############################################################
# enable warnings

Expand Down
2 changes: 2 additions & 0 deletions cmake_templates/qgsconfig.h.in
Expand Up @@ -31,6 +31,8 @@

#cmakedefine HAVE_SPATIALITE

#cmakedefine HAVE_ZLIB

#cmakedefine HAVE_MSSQL

#cmakedefine HAVE_PYTHON
Expand Down
14 changes: 12 additions & 2 deletions src/app/qgsoptions.cpp
Expand Up @@ -46,6 +46,8 @@
#include <gdal.h>
#include <geos_c.h>

#include "qgsconfig.h"

/**
* \class QgsOptions - Set user options and preferences
* Constructor
Expand Down Expand Up @@ -205,10 +207,18 @@ QgsOptions::QgsOptions( QWidget *parent, Qt::WFlags fl ) :
// Scan for contents of compressed files (.zip) in browser dock
cmbScanZipInBrowser->clear();
cmbScanZipInBrowser->addItem( tr( "No" ) ); // 0
cmbScanZipInBrowser->addItem( tr( "Basic scan" ) ); // 1
cmbScanZipInBrowser->addItem( tr( "Passthru" ) ); // 2
cmbScanZipInBrowser->addItem( tr( "Passthru" ) ); // 1
// only add these options if zlib is available
#ifdef HAVE_ZLIB
cmbScanZipInBrowser->addItem( tr( "Basic scan" ) ); // 2
cmbScanZipInBrowser->addItem( tr( "Full scan" ) ); // 3
cmbScanZipInBrowser->setCurrentIndex( settings.value( "/qgis/scanZipInBrowser", 1 ).toInt() );
#else
if ( settings.value( "/qgis/scanZipInBrowser", 1 ) == 0 )
cmbScanZipInBrowser->setCurrentIndex( 0 );
else
cmbScanZipInBrowser->setCurrentIndex( 1 );
#endif

// set the display update threshold
spinBoxUpdateThreshold->setValue( settings.value( "/Map/updateThreshold" ).toInt() );
Expand Down
39 changes: 27 additions & 12 deletions src/core/CMakeLists.txt
Expand Up @@ -175,18 +175,23 @@ SET(QGIS_CORE_SRCS
symbology/qgssymbologyutils.cpp

qgsspatialindex.cpp

quazip/unzip.c
quazip/zip.c
quazip/JlCompress.cpp
quazip/qioapi.cpp
quazip/quaadler32.cpp
quazip/quacrc32.cpp
quazip/quazip.cpp
quazip/quazipfile.cpp
quazip/quazipnewinfo.cpp
)

IF(HAVE_ZLIB)
SET(QGIS_CORE_SRCS
${QGIS_CORE_SRCS}
quazip/unzip.c
quazip/zip.c
quazip/JlCompress.cpp
quazip/qioapi.cpp
quazip/quaadler32.cpp
quazip/quacrc32.cpp
quazip/quazip.cpp
quazip/quazipfile.cpp
quazip/quazipnewinfo.cpp
)
ENDIF(HAVE_ZLIB)

IF(WIN32)
SET(QGIS_CORE_SRCS
${QGIS_CORE_SRCS}
Expand Down Expand Up @@ -289,10 +294,16 @@ SET(QGIS_CORE_MOC_HDRS
gps/qgsgpsdconnection.h
gps/qextserialport/qextserialport.h
gps/qextserialport/qextserialenumerator.h

quazip/quazipfile.h
)

IF (HAVE_ZLIB)
SET(QGIS_CORE_MOC_HDRS
${QGIS_CORE_MOC_HDRS}
quazip/quazipfile.h
)
ENDIF(HAVE_ZLIB)


IF (QT_MOBILITY_LOCATION_FOUND)
SET(QGIS_CORE_MOC_HDRS
${QGIS_CORE_MOC_HDRS}
Expand Down Expand Up @@ -562,6 +573,10 @@ IF (NOT WITH_INTERNAL_SPATIALINDEX)
TARGET_LINK_LIBRARIES(qgis_core ${SPATIALINDEX_LIBRARY})
ENDIF (NOT WITH_INTERNAL_SPATIALINDEX)

IF (HAVE_ZLIB)
INCLUDE_DIRECTORIES(${ZLIB_INCLUDE_DIRS})
TARGET_LINK_LIBRARIES(qgis_core ${ZLIB_LIBRARIES})
ENDIF (HAVE_ZLIB)

IF (APPLE)
SET_TARGET_PROPERTIES(qgis_core PROPERTIES BUILD_WITH_INSTALL_RPATH TRUE )
Expand Down
51 changes: 35 additions & 16 deletions src/core/qgsdataitem.cpp
Expand Up @@ -34,10 +34,13 @@
#include "qgsdataprovider.h"
#include "qgslogger.h"
#include "qgsproviderregistry.h"
#include "qgsconfig.h"

// use internal quazip for /vsizip support
#ifdef HAVE_ZLIB
#define QUAZIP_STATIC
#include <quazip/quazip.h>
#endif

// shared icons
const QIcon &QgsLayerItem::iconPoint()
Expand Down Expand Up @@ -129,10 +132,10 @@ const QIcon &QgsDataCollectionItem::iconDir()
const QIcon &QgsFavouritesItem::iconFavourites()
{
static QIcon icon;

if ( icon.isNull() )
icon = QIcon( getThemePixmap( "/mIconFavourites.png" ) );

return icon;
}

Expand Down Expand Up @@ -777,25 +780,40 @@ QgsZipItem::~QgsZipItem()
QVector<QgsDataItem*> QgsZipItem::createChildren( )
{
QVector<QgsDataItem*> children;
QStringList fileList;
QStringList zipFileList;
QString tmpPath;
QString childPath;

QSettings settings;
int scanZipSetting = settings.value( "/qgis/scanZipInBrowser", 1 ).toInt();

QgsDebugMsg( QString( "path = %1 name= %2 scanZipSetting= %3" ).arg( path() ).arg( name() ).arg( scanZipSetting ) );

// if scanZipBrowser == 0 (No): skip to the next file
if ( scanZipSetting == 0 )
{
return children;
}
// if scanZipBrowser == "Passthru": do not scan zip and allow to open directly with /vsigzip/
if ( scanZipSetting == 2 )

#ifndef HAVE_ZLIB
// if zlib not available, only support Passthru
if ( scanZipSetting == 2 || scanZipSetting == 3 )
{
scanZipSetting = 1;
settings.setValue( "/qgis/scanZipInBrowser", 1 );
}
#endif

// if scanZipBrowser == 1 (Passthru): do not scan zip and allow to open directly with /vsigzip/
if ( scanZipSetting == 1 )
{
mPath = "/vsizip/" + path(); // should check for extension
QgsDebugMsg( "set path to " + path() );
return children;
}

#ifdef HAVE_ZLIB
QgsDebugMsg( QString( "Open file %1 with quazip" ).arg( path() ) );
// get list of files inside zip file
QuaZip zip( path() );
if ( ! zip.open( QuaZip::mdUnzip ) || ! zip.isOpen() )
Expand All @@ -806,22 +824,21 @@ QVector<QgsDataItem*> QgsZipItem::createChildren( )
{
for ( bool more = zip.goToFirstFile(); more; more = zip.goToNextFile() )
{
// tmpPath = "/vsizip/" + path() + "/" + zip.getCurrentFileName();
// QgsDebugMsg( QString( "file %1 - %2" ).arg( zip.getCurrentFileName() ).arg( tmpPath ) );
tmpPath = zip.getCurrentFileName();
// skip directories (files ending with /)
if ( tmpPath.right( 1 ) != "/" )
fileList << tmpPath;
zipFileList << tmpPath;
}
}
zip.close();
if ( zip.getZipError() != UNZ_OK )
{
QgsDebugMsg( QString( "Zip error: %1" ).arg( zip.getZipError() ) );
}
#endif

// loop over files inside zip
foreach( QString fileName, fileList )
foreach( QString fileName, zipFileList )
{
QFileInfo info( fileName );
tmpPath = "/vsizip/" + path() + "/" + fileName;
Expand All @@ -835,7 +852,7 @@ QVector<QgsDataItem*> QgsZipItem::createChildren( )
{
if ( info.suffix() == "dbf" )
{
if ( fileList.indexOf( fileName.left( fileName.count() - 4 ) + ".shp" ) != -1 )
if ( zipFileList.indexOf( fileName.left( fileName.count() - 4 ) + ".shp" ) != -1 )
continue;
}
if ( info.completeSuffix().toLower() == "shp.xml" )
Expand Down Expand Up @@ -886,15 +903,15 @@ QgsDataItem* QgsZipItem::itemFromPath( QgsDataItem* parent, QString path, QStrin
QString tmpPath = path;
QgsZipItem * zipItem = 0;

QgsDebugMsg( "path = " + path + " name= " + name );
QgsDebugMsg( QString( "path = %1 name= %2 scanZipSetting= %3" ).arg( path ).arg( name ).arg( scanZipSetting ) );

// if scanZipBrowser == 0 (No): skip to the next file
if ( scanZipSetting == 0 )
{
return 0;
}
// if scanZipBrowser == 2 (Passthru): do not scan zip and allow to open directly with /vsigzip/
else if ( scanZipSetting == 2 )
// if scanZipBrowser == 1 (Passthru): do not scan zip and allow to open directly with /vsigzip/
else if ( scanZipSetting == 1 )
{
tmpPath = "/vsizip/" + path;
zipItem = 0;
Expand All @@ -906,17 +923,19 @@ QgsDataItem* QgsZipItem::itemFromPath( QgsDataItem* parent, QString path, QStrin

if ( zipItem )
{
// force populate zipItem
zipItem->populate();
QgsDebugMsg( QString( "Got zipItem with %1 children, path=%2, name=%3" ).arg( zipItem->rowCount() ).arg( zipItem->path() ).arg( zipItem->name() ) );
}

// only display if has children
// other option would be to delay until item is opened, but we would be polluting the tree with empty items
// only display if has children
// other option would be to delay until item is opened, but we would be polluting the tree with empty items
if ( zipItem && zipItem->rowCount() > 1 )
{
QgsDebugMsg( "returning zipItem" );
return zipItem;
}
// if 1 or 0 child found, create a data item using the full path given by QgsZipItem
// if 1 or 0 child found, create a data item using the full path given by QgsZipItem
else
{
if ( zipItem )
Expand Down
4 changes: 2 additions & 2 deletions src/providers/gdal/qgsgdaldataitems.cpp
Expand Up @@ -166,8 +166,8 @@ QGISEXTERN QgsDataItem * dataItem( QString thePath, QgsDataItem* parentItem )
name = name.replace( "/vsizip/" + parentItem->path() + "/", "" );
}

// unless setting== 2 (passthru) or 3 (Full scan), return an item without testing
if ( scanZipSetting != 2 && scanZipSetting != 3 )
// if setting = 2 (Basic scan), return an item without testing
if ( scanZipSetting == 2 )
{
QStringList sublayers;
QgsDebugMsg( QString( "adding item name=%1 thePath=%2 uri=%3" ).arg( name ).arg( thePath ).arg( uri ) );
Expand Down
4 changes: 2 additions & 2 deletions src/providers/ogr/qgsogrdataitems.cpp
Expand Up @@ -292,8 +292,8 @@ QGISEXTERN QgsDataItem * dataItem( QString thePath, QgsDataItem* parentItem )
name = name.replace( "/vsizip/" + parentItem->path() + "/", "" );
}

// unless setting== 2 (Passthru) or 3 (Full scan), return an item without testing
if ( scanZipSetting != 2 && scanZipSetting != 3 )
// if setting== 2 (Basic scan), return an item without testing
if ( scanZipSetting == 2 )
{
QgsLayerItem * item = new QgsOgrLayerItem( parentItem, name, thePath, thePath, QgsLayerItem::Vector );
if ( item )
Expand Down

0 comments on commit e5775e7

Please sign in to comment.