18 #include <QApplication>
23 #include <QMouseEvent>
24 #include <QTreeWidget>
25 #include <QTreeWidgetItem>
36 #include "qgsconfig.h"
40 #include "cpl_string.h"
120 QStyle *style = QApplication::style();
121 icon = QIcon( style->standardPixmap( QStyle::SP_DirClosedIcon ) );
122 icon.addPixmap( style->standardPixmap( QStyle::SP_DirOpenIcon ),
123 QIcon::Normal, QIcon::On );
153 : QObject(), mType( type ), mParent( parent ), mPopulated( false ), mName( name ), mPath( path )
181 return QVector<QgsDataItem*>();
191 QApplication::setOverrideCursor( Qt::WaitCursor );
201 QApplication::restoreOverrideCursor();
289 for (
int i = 0; i < items.size(); i++ )
292 if ( items[i]->
equal( item ) )
302 QApplication::setOverrideCursor( Qt::WaitCursor );
307 QVector<QgsDataItem*>
remove;
310 if (
findItem( items, child ) >= 0 )
312 remove.append( child );
331 QApplication::restoreOverrideCursor();
336 if ( metaObject()->className() == other->metaObject()->className() &&
348 , mProviderKey( providerKey )
350 , mLayerType( layerType )
396 QgsDebugMsgLevel( QString(
"delete child = 0x%0" ).arg(( qlonglong )i, 8, 16, QLatin1Char(
'0' ) ), 2 );
415 QStringList::const_iterator i;
416 for ( i = keys.begin(); i != keys.end(); ++i )
425 if ( !dataCapabilities )
427 QgsDebugMsg( library->fileName() +
" does not have dataCapabilities" );
432 QgsDebugMsg( library->fileName() +
" has NoDataCapabilities" );
436 QgsDebugMsg( QString(
"%1 dataCapabilities : %2" ).arg( library->fileName() ).arg( dataCapabilities() ) );
457 QStringList entries = dir.entryList( QDir::AllDirs | QDir::NoDotAndDotDot, QDir::Name | QDir::IgnoreCase );
458 foreach ( QString subdir, entries )
460 QString subdirPath = dir.absoluteFilePath( subdir );
466 children.append( item );
469 QStringList fileEntries = dir.entryList( QDir::Dirs | QDir::NoDotAndDotDot | QDir::Files, QDir::Name );
470 foreach ( QString
name, fileEntries )
472 QString
path = dir.absoluteFilePath( name );
473 QFileInfo fileInfo( path );
481 children.append( item );
492 if ( !dataCapabilities )
508 QgsDebugMsg( library->fileName() +
" does not have dataItem" );
515 children.append( item );
539 : QTreeWidget( parent )
541 setRootIsDecorated(
false );
546 labels <<
tr(
"Name" ) <<
tr(
"Size" ) <<
tr(
"Date" ) <<
tr(
"Permissions" ) <<
tr(
"Owner" ) <<
tr(
"Group" ) <<
tr(
"Type" );
547 setHeaderLabels( labels );
549 QStyle* style = QApplication::style();
550 QIcon iconDirectory = QIcon( style->standardPixmap( QStyle::SP_DirClosedIcon ) );
551 QIcon iconFile = QIcon( style->standardPixmap( QStyle::SP_FileIcon ) );
552 QIcon iconLink = QIcon( style->standardPixmap( QStyle::SP_FileLinkIcon ) );
554 QList<QTreeWidgetItem *> items;
557 QStringList entries = dir.entryList( QDir::AllEntries | QDir::NoDotAndDotDot, QDir::Name | QDir::IgnoreCase );
558 foreach ( QString name, entries )
560 QFileInfo fi( dir.absoluteFilePath( name ) );
564 if ( fi.size() > 1024 )
566 size = size.sprintf(
"%.1f KiB", fi.size() / 1024.0 );
568 else if ( fi.size() > 1.048576e6 )
570 size = size.sprintf(
"%.1f MiB", fi.size() / 1.048576e6 );
574 size = QString(
"%1 B" ).arg( fi.size() );
577 texts << fi.lastModified().toString( Qt::SystemLocaleShortDate );
579 perm += fi.permission( QFile::ReadOwner ) ?
'r' :
'-';
580 perm += fi.permission( QFile::WriteOwner ) ?
'w' :
'-';
581 perm += fi.permission( QFile::ExeOwner ) ?
'x' :
'-';
583 perm += fi.permission( QFile::ReadGroup ) ?
'r' :
'-';
584 perm += fi.permission( QFile::WriteGroup ) ?
'w' :
'-';
585 perm += fi.permission( QFile::ExeGroup ) ?
'x' :
'-';
586 perm += fi.permission( QFile::ReadOther ) ?
'r' :
'-';
587 perm += fi.permission( QFile::WriteOther ) ?
'w' :
'-';
588 perm += fi.permission( QFile::ExeOther ) ?
'x' :
'-';
598 type =
tr(
"folder" );
599 icon = iconDirectory;
601 else if ( fi.isFile() )
606 else if ( fi.isSymLink() )
614 QTreeWidgetItem *item =
new QTreeWidgetItem( texts );
615 item->setIcon( 0, icon );
619 addTopLevelItems( items );
623 QList<QVariant> lst = settings.value(
"/dataitem/directoryHiddenColumns" ).toList();
624 foreach ( QVariant colVariant, lst )
626 setColumnHidden( colVariant.toInt(), true );
632 if ( event->button() == Qt::RightButton )
638 labels <<
tr(
"Name" ) <<
tr(
"Size" ) <<
tr(
"Date" ) <<
tr(
"Permissions" ) <<
tr(
"Owner" ) <<
tr(
"Group" ) <<
tr(
"Type" );
639 for (
int i = 0; i < labels.count(); i++ )
641 QAction* action = popupMenu.addAction( labels[i],
this, SLOT(
showHideColumn() ) );
642 action->setObjectName( QString::number( i ) );
643 action->setCheckable(
true );
644 action->setChecked( !isColumnHidden( i ) );
647 popupMenu.exec( event->globalPos() );
653 QAction* action = qobject_cast<QAction*>( sender() );
657 int columnIndex = action->objectName().toInt();
658 setColumnHidden( columnIndex, !isColumnHidden( columnIndex ) );
663 for (
int i = 0; i < columnCount(); i++ )
665 if ( isColumnHidden( i ) )
666 lst.append( QVariant( i ) );
668 settings.setValue(
"/dataitem/directoryHiddenColumns", lst );
700 QStringList favDirs = settings.value(
"/browser/favourites", QVariant() ).toStringList();
702 foreach ( QString favDir, favDirs )
707 children.append( item );
717 QStringList favDirs = settings.value(
"/browser/favourites" ).toStringList();
718 favDirs.append( favDir );
719 settings.setValue(
"/browser/favourites", favDirs );
730 QStringList favDirs = settings.value(
"/browser/favourites" ).toStringList();
731 favDirs.removeAll( item->
path() );
732 settings.setValue(
"/browser/favourites", favDirs );
737 QgsDebugMsg( QString(
"favourites item %1 not found" ).arg( item->
path() ) );
762 keys <<
"gdal" <<
"ogr";
764 QStringList::const_iterator i;
765 for ( i = keys.begin(); i != keys.end(); ++i )
775 if ( !dataCapabilities )
777 QgsDebugMsg( library->fileName() +
" does not have dataCapabilities" );
782 QgsDebugMsg( library->fileName() +
" has NoDataCapabilities" );
785 QgsDebugMsg( QString(
"%1 dataCapabilities : %2" ).arg( library->fileName() ).arg( dataCapabilities() ) );
790 QgsDebugMsg( library->fileName() +
" does not have dataItem" );
817 char **papszOFiles = NULL;
818 char **papszFiles1 = NULL;
819 char **papszFiles2 = NULL;
820 VSIStatBufL psStatBuf;
821 CPLString osTemp1, osTemp2;
823 int nCount1, nCount2;
826 papszFiles1 = VSIReadDir( pszPath );
831 nCount1 = CSLCount( papszFiles1 );
832 for ( i = 0; i < nCount1; i++ )
836 osTemp1.append( pszPath );
837 osTemp1.append(
"/" );
838 osTemp1.append( papszFiles1[i] );
841 if ( VSIStatL( osTemp1.c_str(), &psStatBuf ) == 0 &&
842 VSI_ISREG( psStatBuf.st_mode ) )
845 papszOFiles = CSLAddString( papszOFiles, papszFiles1[i] );
847 else if ( VSIStatL( osTemp1.c_str(), &psStatBuf ) == 0 &&
848 VSI_ISDIR( psStatBuf.st_mode ) )
852 osTemp2.append( papszFiles1[i] );
853 osTemp2.append(
"/" );
855 papszOFiles = CSLAddString( papszOFiles, osTemp2.c_str() );
861 nCount2 = CSLCount( papszFiles2 );
862 for ( j = 0; j < nCount2; j++ )
865 osTemp2.append( papszFiles1[i] );
866 osTemp2.append(
"/" );
867 osTemp2.append( papszFiles2[j] );
869 papszOFiles = CSLAddString( papszOFiles, osTemp2.c_str() );
871 CSLDestroy( papszFiles2 );
875 CSLDestroy( papszFiles1 );
887 QString scanZipSetting = settings.value(
"/qgis/scanZipInBrowser2",
"basic" ).toString();
894 if ( scanZipSetting ==
"no" )
905 QFileInfo info( fileName );
915 if ( info.suffix().toLower() ==
"dbf" )
917 if (
mZipFileList.indexOf( fileName.left( fileName.count() - 4 ) +
".shp" ) != -1 )
920 if ( info.completeSuffix().toLower() ==
"shp.xml" )
936 children.append( item );
948 if ( children.size() == 1 )
959 if ( path.startsWith(
"/vsizip/", Qt::CaseInsensitive ) ||
960 path.endsWith(
".zip", Qt::CaseInsensitive ) )
962 else if ( path.startsWith(
"/vsitar/", Qt::CaseInsensitive ) ||
963 path.endsWith(
".tar", Qt::CaseInsensitive ) ||
964 path.endsWith(
".tar.gz", Qt::CaseInsensitive ) ||
965 path.endsWith(
".tgz", Qt::CaseInsensitive ) )
967 else if ( path.startsWith(
"/vsigzip/", Qt::CaseInsensitive ) ||
968 path.endsWith(
".gz", Qt::CaseInsensitive ) )
977 QString scanZipSetting = settings.value(
"/qgis/scanZipInBrowser2",
"basic" ).toString();
978 QString vsiPath =
path;
979 int zipFileCount = 0;
980 QStringList zipFileList;
981 QFileInfo fileInfo( path );
984 bool populated =
false;
986 QgsDebugMsgLevel( QString(
"path = %1 name= %2 scanZipSetting= %3 vsiPrefix= %4" ).arg( path ).arg( name ).arg( scanZipSetting ).arg( vsiPrefix ), 3 );
989 if ( scanZipSetting ==
"no" )
993 if (( vsiPrefix !=
"/vsizip/" && vsiPrefix !=
"/vsitar/" ) )
996 zipItem =
new QgsZipItem( parent, name, path );
1006 if ( path.endsWith(
".zip", Qt::CaseInsensitive ) ||
1007 path.endsWith(
".tar", Qt::CaseInsensitive ) )
1012 if ( zipFileList.count() > 0 && zipFileList.count() <= 10 )
1016 QgsDebugMsgLevel( QString(
"Got zipItem with %1 children, path=%2, name=%3" ).arg( zipItem->
rowCount() ).arg( zipItem->
path() ).arg( zipItem->
name() ), 3 );
1020 QgsDebugMsgLevel( QString(
"Delaying populating zipItem with path=%1, name=%2" ).arg( zipItem->
path() ).arg( zipItem->
name() ), 3 );
1025 if ( zipItem && ( !populated || zipItem->
rowCount() > 1 ) )
1035 vsiPath = zipItem->
path();
1036 zipFileCount = zipFileList.count();
1040 QgsDebugMsgLevel( QString(
"will try to create a normal dataItem from path= %2 or %3" ).arg( path ).arg( vsiPath ), 3 );
1054 item = dataItem( path, parent );
1057 item = dataItem( vsiPath, parent );
1074 QString scanZipSetting = settings.value(
"/qgis/scanZipInBrowser2",
"basic" ).toString();
1079 if ( scanZipSetting ==
"no" )
1087 if ( papszSiblingFiles )
1089 for (
int i = 0; i < CSLCount( papszSiblingFiles ); i++ )
1091 tmpPath = papszSiblingFiles[i];
1094 if ( tmpPath.right( 1 ) !=
"/" )
1097 CSLDestroy( papszSiblingFiles );