Blame qtools/qdir.cpp

Packit 1c1d7e
/****************************************************************************
Packit 1c1d7e
** 
Packit 1c1d7e
**
Packit 1c1d7e
** Implementation of QDir class
Packit 1c1d7e
**
Packit 1c1d7e
** Created : 950427
Packit 1c1d7e
**
Packit 1c1d7e
** Copyright (C) 1992-2000 Trolltech AS.  All rights reserved.
Packit 1c1d7e
**
Packit 1c1d7e
** This file is part of the tools module of the Qt GUI Toolkit.
Packit 1c1d7e
**
Packit 1c1d7e
** This file may be distributed under the terms of the Q Public License
Packit 1c1d7e
** as defined by Trolltech AS of Norway and appearing in the file
Packit 1c1d7e
** LICENSE.QPL included in the packaging of this file.
Packit 1c1d7e
**
Packit 1c1d7e
** This file may be distributed and/or modified under the terms of the
Packit 1c1d7e
** GNU General Public License version 2 as published by the Free Software
Packit 1c1d7e
** Foundation and appearing in the file LICENSE.GPL included in the
Packit 1c1d7e
** packaging of this file.
Packit 1c1d7e
**
Packit 1c1d7e
** Licensees holding valid Qt Enterprise Edition or Qt Professional Edition
Packit 1c1d7e
** licenses may use this file in accordance with the Qt Commercial License
Packit 1c1d7e
** Agreement provided with the Software.
Packit 1c1d7e
**
Packit 1c1d7e
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
Packit 1c1d7e
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
Packit 1c1d7e
**
Packit 1c1d7e
** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
Packit 1c1d7e
**   information about Qt Commercial License Agreements.
Packit 1c1d7e
** See http://www.trolltech.com/qpl/ for QPL licensing information.
Packit 1c1d7e
** See http://www.trolltech.com/gpl/ for GPL licensing information.
Packit 1c1d7e
**
Packit 1c1d7e
** Contact info@trolltech.com if any conditions of this licensing are
Packit 1c1d7e
** not clear to you.
Packit 1c1d7e
**
Packit 1c1d7e
**********************************************************************/
Packit 1c1d7e
Packit 1c1d7e
#include "qglobal.h"
Packit 1c1d7e
Packit 1c1d7e
#include "qdir.h"
Packit 1c1d7e
Packit 1c1d7e
#ifndef QT_NO_DIR
Packit 1c1d7e
#include "qfileinfo.h"
Packit 1c1d7e
#include "qfiledefs_p.h"
Packit 1c1d7e
#include "qregexp.h"
Packit 1c1d7e
#include "qstringlist.h"
Packit 1c1d7e
#include <stdlib.h>
Packit 1c1d7e
#include <ctype.h>
Packit 1c1d7e
Packit 1c1d7e
// NOT REVISED
Packit 1c1d7e
/*!
Packit 1c1d7e
  \class QDir qdir.h
Packit 1c1d7e
  \brief Traverses directory structures and contents in a
Packit 1c1d7e
	    platform-independent way.
Packit 1c1d7e
Packit 1c1d7e
  \ingroup io
Packit 1c1d7e
Packit 1c1d7e
  A QDir can point to a file using either a relative or an absolute file
Packit 1c1d7e
  path. Absolute file paths begin with the directory separator ('/') or a
Packit 1c1d7e
  drive specification (not applicable to UNIX).	 Relative file names begin
Packit 1c1d7e
  with a directory name or a file name and specify a path relative to the
Packit 1c1d7e
  current directory.
Packit 1c1d7e
Packit 1c1d7e
  An example of an absolute path is the string "/tmp/quartz", a relative
Packit 1c1d7e
  path might look like "src/fatlib". You can use the function isRelative()
Packit 1c1d7e
  to check if a QDir is using a relative or an absolute file path. You can
Packit 1c1d7e
  call the function convertToAbs() to convert a relative QDir to an
Packit 1c1d7e
  absolute one.
Packit 1c1d7e
Packit 1c1d7e
  The directory "example" under the current directory is checked for existence
Packit 1c1d7e
  in the example below:
Packit 1c1d7e
Packit 1c1d7e
  \code
Packit 1c1d7e
    QDir d( "example" );			// "./example"
Packit 1c1d7e
    if ( !d.exists() )
Packit 1c1d7e
	qWarning( "Cannot find the example directory" );
Packit 1c1d7e
  \endcode
Packit 1c1d7e
Packit 1c1d7e
  If you always use '/' as a directory separator, Qt will translate your
Packit 1c1d7e
  paths to conform to the underlying operating system.
Packit 1c1d7e
Packit 1c1d7e
  cd() and cdUp() can be used to navigate the directory tree. Note that the
Packit 1c1d7e
  logical cd and cdUp operations are not performed if the new directory does
Packit 1c1d7e
  not exist.
Packit 1c1d7e
Packit 1c1d7e
  Example:
Packit 1c1d7e
  \code
Packit 1c1d7e
    QDir d = QDir::root();			// "/"
Packit 1c1d7e
    if ( !d.cd("tmp") ) {			// "/tmp"
Packit 1c1d7e
	qWarning( "Cannot find the \"/tmp\" directory" );
Packit 1c1d7e
    } else {
Packit 1c1d7e
	QFile f( d.filePath("ex1.txt") );	// "/tmp/ex1.txt"
Packit 1c1d7e
	if ( !f.open(IO_ReadWrite) )
Packit 1c1d7e
	    qWarning( "Cannot create the file %s", f.name() );
Packit 1c1d7e
    }
Packit 1c1d7e
  \endcode
Packit 1c1d7e
Packit 1c1d7e
  To read the contents of a directory you can use the entryList() and
Packit 1c1d7e
  entryInfoList() functions.
Packit 1c1d7e
Packit 1c1d7e
  Example:
Packit 1c1d7e
  \code
Packit 1c1d7e
    #include <stdio.h>
Packit 1c1d7e
    #include <qdir.h>
Packit 1c1d7e
Packit 1c1d7e
    //
Packit 1c1d7e
    // This program scans the current directory and lists all files
Packit 1c1d7e
    // that are not symbolic links, sorted by size with the smallest files
Packit 1c1d7e
    // first.
Packit 1c1d7e
    //
Packit 1c1d7e
Packit 1c1d7e
    int main( int argc, char **argv )
Packit 1c1d7e
    {
Packit 1c1d7e
	QDir d;
Packit 1c1d7e
	d.setFilter( QDir::Files | QDir::Hidden | QDir::NoSymLinks );
Packit 1c1d7e
	d.setSorting( QDir::Size | QDir::Reversed );
Packit 1c1d7e
Packit 1c1d7e
	const QFileInfoList *list = d.entryInfoList();
Packit 1c1d7e
	QFileInfoListIterator it( *list );	// create list iterator
Packit 1c1d7e
	QFileInfo *fi;				// pointer for traversing
Packit 1c1d7e
Packit 1c1d7e
	printf( "     BYTES FILENAME\n" );	// print header
Packit 1c1d7e
	while ( (fi=it.current()) ) {		// for each file...
Packit 1c1d7e
	    printf( "%10li %s\n", fi->size(), fi->fileName().data() );
Packit 1c1d7e
	    ++it;				// goto next list element
Packit 1c1d7e
	}
Packit 1c1d7e
    }
Packit 1c1d7e
  \endcode
Packit 1c1d7e
*/
Packit 1c1d7e
Packit 1c1d7e
Packit 1c1d7e
/*!
Packit 1c1d7e
  Constructs a QDir pointing to the current directory.
Packit 1c1d7e
  \sa currentDirPath()
Packit 1c1d7e
*/
Packit 1c1d7e
Packit 1c1d7e
QDir::QDir()
Packit 1c1d7e
{
Packit 1c1d7e
    dPath = QString::fromLatin1(".");
Packit 1c1d7e
    init();
Packit 1c1d7e
}
Packit 1c1d7e
Packit 1c1d7e
/*!
Packit 1c1d7e
  Constructs a QDir.
Packit 1c1d7e
Packit 1c1d7e
  \arg \e path is the directory.
Packit 1c1d7e
  \arg \e nameFilter is the file name filter.
Packit 1c1d7e
  \arg \e sortSpec is the sort specification, which describes how to
Packit 1c1d7e
  sort the files in the directory.
Packit 1c1d7e
  \arg \e filterSpec is the filter specification, which describes how
Packit 1c1d7e
  to filter the files in the directory.
Packit 1c1d7e
Packit 1c1d7e
  Most of these arguments (except \e path) have optional values.
Packit 1c1d7e
Packit 1c1d7e
  Example:
Packit 1c1d7e
  \code
Packit 1c1d7e
    // lists all files in /tmp
Packit 1c1d7e
Packit 1c1d7e
    QDir d( "/tmp" );
Packit 1c1d7e
    for ( int i=0; i
Packit 1c1d7e
	printf( "%s\n", d[i] );
Packit 1c1d7e
  \endcode
Packit 1c1d7e
Packit 1c1d7e
  If \e path is "" or null, the directory is set to "." (the current
Packit 1c1d7e
  directory).  If \e nameFilter is "" or null, it is set to "*" (all
Packit 1c1d7e
  files).
Packit 1c1d7e
Packit 1c1d7e
  No check is made to ensure that the directory exists.
Packit 1c1d7e
Packit 1c1d7e
  \sa exists(), setPath(), setNameFilter(), setFilter(), setSorting()
Packit 1c1d7e
*/
Packit 1c1d7e
Packit 1c1d7e
QDir::QDir( const QString &path, const QString &nameFilter,
Packit 1c1d7e
	    int sortSpec, int filterSpec )
Packit 1c1d7e
{
Packit 1c1d7e
    init();
Packit 1c1d7e
    dPath = cleanDirPath( path );
Packit 1c1d7e
    if ( dPath.isEmpty() )
Packit 1c1d7e
	dPath = QString::fromLatin1(".");
Packit 1c1d7e
    nameFilt = nameFilter;
Packit 1c1d7e
    if ( nameFilt.isEmpty() )
Packit 1c1d7e
	nameFilt = QString::fromLatin1("*");
Packit 1c1d7e
    filtS = (FilterSpec)filterSpec;
Packit 1c1d7e
    sortS = (SortSpec)sortSpec;
Packit 1c1d7e
}
Packit 1c1d7e
Packit 1c1d7e
/*!
Packit 1c1d7e
  Constructs a QDir that is a copy of the given directory.
Packit 1c1d7e
  \sa operator=()
Packit 1c1d7e
*/
Packit 1c1d7e
Packit 1c1d7e
QDir::QDir( const QDir &d )
Packit 1c1d7e
{
Packit 1c1d7e
    dPath = d.dPath;
Packit 1c1d7e
    fList = 0;
Packit 1c1d7e
    fiList = 0;
Packit 1c1d7e
    nameFilt = d.nameFilt;
Packit 1c1d7e
    dirty = TRUE;
Packit 1c1d7e
    allDirs = d.allDirs;
Packit 1c1d7e
    filtS = d.filtS;
Packit 1c1d7e
    sortS = d.sortS;
Packit 1c1d7e
}
Packit 1c1d7e
Packit 1c1d7e
Packit 1c1d7e
void QDir::init()
Packit 1c1d7e
{
Packit 1c1d7e
    fList = 0;
Packit 1c1d7e
    fiList = 0;
Packit 1c1d7e
    nameFilt = QString::fromLatin1("*");
Packit 1c1d7e
    dirty = TRUE;
Packit 1c1d7e
    allDirs = FALSE;
Packit 1c1d7e
    filtS = All;
Packit 1c1d7e
    sortS = SortSpec(Name | IgnoreCase);
Packit 1c1d7e
}
Packit 1c1d7e
Packit 1c1d7e
/*!
Packit 1c1d7e
  Destructs the QDir and cleans up.
Packit 1c1d7e
*/
Packit 1c1d7e
Packit 1c1d7e
QDir::~QDir()
Packit 1c1d7e
{
Packit 1c1d7e
    if ( fList )
Packit 1c1d7e
       delete fList;
Packit 1c1d7e
    if ( fiList )
Packit 1c1d7e
       delete fiList;
Packit 1c1d7e
}
Packit 1c1d7e
Packit 1c1d7e
Packit 1c1d7e
/*!
Packit 1c1d7e
  Sets the path of the directory. The path is cleaned of redundant ".", ".."
Packit 1c1d7e
  and multiple separators. No check is made to ensure that a directory
Packit 1c1d7e
  with this path exists.
Packit 1c1d7e
Packit 1c1d7e
  The path can be either absolute or relative. Absolute paths begin with the
Packit 1c1d7e
  directory separator ('/') or a drive specification (not
Packit 1c1d7e
  applicable to UNIX).
Packit 1c1d7e
  Relative file names begin with a directory name or a file name and specify
Packit 1c1d7e
  a path relative to the current directory. An example of
Packit 1c1d7e
  an absolute path is the string "/tmp/quartz", a relative path might look like
Packit 1c1d7e
  "src/fatlib". You can use the function isRelative() to check if a QDir
Packit 1c1d7e
  is using a relative or an absolute file path. You can call the function
Packit 1c1d7e
  convertToAbs() to convert a relative QDir to an absolute one.
Packit 1c1d7e
Packit 1c1d7e
  \sa path(), absPath(), exists(), cleanDirPath(), dirName(),
Packit 1c1d7e
      absFilePath(), isRelative(), convertToAbs()
Packit 1c1d7e
*/
Packit 1c1d7e
Packit 1c1d7e
void QDir::setPath( const QString &path )
Packit 1c1d7e
{
Packit 1c1d7e
    dPath = cleanDirPath( path );
Packit 1c1d7e
    if ( dPath.isEmpty() )
Packit 1c1d7e
	dPath = QString::fromLatin1(".");
Packit 1c1d7e
    dirty = TRUE;
Packit 1c1d7e
}
Packit 1c1d7e
Packit 1c1d7e
/*!
Packit 1c1d7e
  \fn  QString QDir::path() const
Packit 1c1d7e
  Returns the path, this may contain symbolic links, but never contains
Packit 1c1d7e
  redundant ".", ".." or multiple separators.
Packit 1c1d7e
Packit 1c1d7e
  The returned path can be either absolute or relative (see setPath()).
Packit 1c1d7e
Packit 1c1d7e
  \sa setPath(), absPath(), exists(), cleanDirPath(), dirName(),
Packit 1c1d7e
  absFilePath(), convertSeparators()
Packit 1c1d7e
*/
Packit 1c1d7e
Packit 1c1d7e
/*!
Packit 1c1d7e
  Returns the absolute (a path that starts with '/') path, which may
Packit 1c1d7e
  contain symbolic links, but never contains redundant ".", ".." or
Packit 1c1d7e
  multiple separators.
Packit 1c1d7e
Packit 1c1d7e
  \sa setPath(), canonicalPath(), exists(),  cleanDirPath(), dirName(),
Packit 1c1d7e
  absFilePath()
Packit 1c1d7e
*/
Packit 1c1d7e
Packit 1c1d7e
QString QDir::absPath() const
Packit 1c1d7e
{
Packit 1c1d7e
    if ( QDir::isRelativePath(dPath) ) {
Packit 1c1d7e
	QString tmp = currentDirPath();
Packit 1c1d7e
	if ( tmp.right(1) != QString::fromLatin1("/") )
Packit 1c1d7e
	    tmp += '/';
Packit 1c1d7e
	tmp += dPath;
Packit 1c1d7e
	return cleanDirPath( tmp );
Packit 1c1d7e
    } else {
Packit 1c1d7e
	return cleanDirPath( dPath );
Packit 1c1d7e
    }
Packit 1c1d7e
}
Packit 1c1d7e
Packit 1c1d7e
/*!
Packit 1c1d7e
  Returns the name of the directory, this is NOT the same as the path, e.g.
Packit 1c1d7e
  a directory with the name "mail", might have the path "/var/spool/mail".
Packit 1c1d7e
  If the directory has no name (e.g. the root directory) a null string is
Packit 1c1d7e
  returned.
Packit 1c1d7e
Packit 1c1d7e
  No check is made to ensure that a directory with this name actually exists.
Packit 1c1d7e
Packit 1c1d7e
  \sa path(), absPath(), absFilePath(), exists(), QString::isNull()
Packit 1c1d7e
*/
Packit 1c1d7e
Packit 1c1d7e
QString QDir::dirName() const
Packit 1c1d7e
{
Packit 1c1d7e
    int pos = dPath.findRev( '/' );
Packit 1c1d7e
    if ( pos == -1  )
Packit 1c1d7e
	return dPath;
Packit 1c1d7e
    return dPath.right( dPath.length() - pos - 1 );
Packit 1c1d7e
}
Packit 1c1d7e
Packit 1c1d7e
/*!
Packit 1c1d7e
  Returns the path name of a file in the directory. Does NOT check if
Packit 1c1d7e
  the file actually exists in the directory. If the QDir is relative
Packit 1c1d7e
  the returned path name will also be relative. Redundant multiple separators
Packit 1c1d7e
  or "." and ".." directories in \e fileName will not be removed (see
Packit 1c1d7e
  cleanDirPath()).
Packit 1c1d7e
Packit 1c1d7e
  If \e acceptAbsPath is TRUE a \e fileName starting with a separator
Packit 1c1d7e
  ('/') will be returned without change.
Packit 1c1d7e
  If \e acceptAbsPath is FALSE an absolute path will be appended to
Packit 1c1d7e
  the directory path.
Packit 1c1d7e
Packit 1c1d7e
  \sa absFilePath(), isRelative(), canonicalPath()
Packit 1c1d7e
*/
Packit 1c1d7e
Packit 1c1d7e
QString QDir::filePath( const QString &fileName,
Packit 1c1d7e
			bool acceptAbsPath ) const
Packit 1c1d7e
{
Packit 1c1d7e
    if ( acceptAbsPath && !isRelativePath(fileName) )
Packit 1c1d7e
	return QString(fileName);
Packit 1c1d7e
Packit 1c1d7e
    QString tmp = dPath;
Packit 1c1d7e
    if ( tmp.isEmpty() || (tmp[(int)tmp.length()-1] != '/' && !!fileName &&
Packit 1c1d7e
			   fileName[0] != '/') )
Packit 1c1d7e
	tmp += '/';
Packit 1c1d7e
    tmp += fileName;
Packit 1c1d7e
    return tmp;
Packit 1c1d7e
}
Packit 1c1d7e
Packit 1c1d7e
/*!
Packit 1c1d7e
  Returns the absolute path name of a file in the directory. Does NOT check if
Packit 1c1d7e
  the file actually exists in the directory. Redundant multiple separators
Packit 1c1d7e
  or "." and ".." directories in \e fileName will NOT be removed (see
Packit 1c1d7e
  cleanDirPath()).
Packit 1c1d7e
Packit 1c1d7e
  If \e acceptAbsPath is TRUE a \e fileName starting with a separator
Packit 1c1d7e
  ('/') will be returned without change.
Packit 1c1d7e
  if \e acceptAbsPath is FALSE an absolute path will be appended to
Packit 1c1d7e
  the directory path.
Packit 1c1d7e
Packit 1c1d7e
  \sa filePath()
Packit 1c1d7e
*/
Packit 1c1d7e
Packit 1c1d7e
QString QDir::absFilePath( const QString &fileName,
Packit 1c1d7e
			   bool acceptAbsPath ) const
Packit 1c1d7e
{
Packit 1c1d7e
    if ( acceptAbsPath && !isRelativePath( fileName ) )
Packit 1c1d7e
	return fileName;
Packit 1c1d7e
Packit 1c1d7e
    QString tmp = absPath();
Packit 1c1d7e
    if ( tmp.isEmpty() || (tmp[(int)tmp.length()-1] != '/' && !!fileName &&
Packit 1c1d7e
			   fileName[0] != '/') )
Packit 1c1d7e
	tmp += '/';
Packit 1c1d7e
    tmp += fileName;
Packit 1c1d7e
    return tmp;
Packit 1c1d7e
}
Packit 1c1d7e
Packit 1c1d7e
Packit 1c1d7e
/*!
Packit 1c1d7e
  Converts the '/' separators in \a pathName to system native
Packit 1c1d7e
  separators.  Returns the translated string.
Packit 1c1d7e
Packit 1c1d7e
  On Windows, convertSeparators("c:/winnt/system32") returns
Packit 1c1d7e
  "c:\winnt\system32".
Packit 1c1d7e
Packit 1c1d7e
  No conversion is done on UNIX.
Packit 1c1d7e
*/
Packit 1c1d7e
Packit 1c1d7e
QString QDir::convertSeparators( const QString &pathName )
Packit 1c1d7e
{
Packit 1c1d7e
    QString n( pathName );
Packit 1c1d7e
#if defined(_OS_FATFS_) || defined(_OS_OS2EMX_)
Packit 1c1d7e
    for ( int i=0; i<(int)n.length(); i++ ) {
Packit 1c1d7e
	if ( n[i] == '/' )
Packit 1c1d7e
	    n[i] = '\\';
Packit 1c1d7e
    }
Packit 1c1d7e
#endif
Packit 1c1d7e
    return n;
Packit 1c1d7e
}
Packit 1c1d7e
Packit 1c1d7e
Packit 1c1d7e
/*!
Packit 1c1d7e
  Changes directory by descending into the given directory. Returns
Packit 1c1d7e
  TRUE if the new directory exists and is readable. Note that the logical
Packit 1c1d7e
  cd operation is NOT performed if the new directory does not exist.
Packit 1c1d7e
Packit 1c1d7e
  If \e acceptAbsPath is TRUE a path starting with a separator ('/')
Packit 1c1d7e
  will cd to the absolute directory, if \e acceptAbsPath is FALSE
Packit 1c1d7e
  any number of separators at the beginning of \e dirName will be removed.
Packit 1c1d7e
Packit 1c1d7e
  Example:
Packit 1c1d7e
  \code
Packit 1c1d7e
  QDir d = QDir::home();  // now points to home directory
Packit 1c1d7e
  if ( !d.cd("c++") ) {	  // now points to "c++" under home directory if OK
Packit 1c1d7e
      QFileInfo fi( d, "c++" );
Packit 1c1d7e
      if ( fi.exists() ) {
Packit 1c1d7e
	  if ( fi.isDir() )
Packit 1c1d7e
	      qWarning( "Cannot cd into \"%s\".", (char*)d.absFilePath("c++") );
Packit 1c1d7e
	  else
Packit 1c1d7e
	      qWarning( "Cannot create directory \"%s\"\n"
Packit 1c1d7e
		       "A file named \"c++\" already exists in \"%s\"",
Packit 1c1d7e
		       (const char *)d.absFilePath("c++"),
Packit 1c1d7e
		       (const char *)d.path() );
Packit 1c1d7e
	  return;
Packit 1c1d7e
      } else {
Packit 1c1d7e
	  qWarning( "Creating directory \"%s\"",
Packit 1c1d7e
		   (const char *) d.absFilePath("c++") );
Packit 1c1d7e
	  if ( !d.mkdir( "c++" ) ) {
Packit 1c1d7e
	      qWarning("Could not create directory \"%s\"",
Packit 1c1d7e
		      (const char *)d.absFilePath("c++") );
Packit 1c1d7e
	      return;
Packit 1c1d7e
	  }
Packit 1c1d7e
      }
Packit 1c1d7e
  }
Packit 1c1d7e
  \endcode
Packit 1c1d7e
Packit 1c1d7e
  Calling cd( ".." ) is equivalent to calling cdUp().
Packit 1c1d7e
Packit 1c1d7e
  \sa cdUp(), isReadable(), exists(), path()
Packit 1c1d7e
*/
Packit 1c1d7e
Packit 1c1d7e
bool QDir::cd( const QString &dirName, bool acceptAbsPath )
Packit 1c1d7e
{
Packit 1c1d7e
    if ( dirName.isEmpty() || dirName==QString::fromLatin1(".") )
Packit 1c1d7e
	return TRUE;
Packit 1c1d7e
    QString old = dPath;
Packit 1c1d7e
    if ( acceptAbsPath && !isRelativePath(dirName) ) {
Packit 1c1d7e
	dPath = cleanDirPath( dirName );
Packit 1c1d7e
    } else {
Packit 1c1d7e
	if ( !isRoot() )
Packit 1c1d7e
	    dPath += '/';
Packit 1c1d7e
	dPath += dirName;
Packit 1c1d7e
	if ( dirName.find('/') >= 0
Packit 1c1d7e
		|| old == QString::fromLatin1(".")
Packit 1c1d7e
		|| dirName == QString::fromLatin1("..") )
Packit 1c1d7e
	    dPath = cleanDirPath( dPath );
Packit 1c1d7e
    }
Packit 1c1d7e
    if ( !exists() ) {
Packit 1c1d7e
	dPath = old;			// regret
Packit 1c1d7e
	return FALSE;
Packit 1c1d7e
    }
Packit 1c1d7e
    dirty = TRUE;
Packit 1c1d7e
    return TRUE;
Packit 1c1d7e
}
Packit 1c1d7e
Packit 1c1d7e
/*!
Packit 1c1d7e
  Changes directory by moving one directory up the path followed to arrive
Packit 1c1d7e
  at the current directory.
Packit 1c1d7e
Packit 1c1d7e
  Returns TRUE if the new directory exists and is readable. Note that the
Packit 1c1d7e
  logical cdUp() operation is not performed if the new directory does not
Packit 1c1d7e
  exist.
Packit 1c1d7e
Packit 1c1d7e
  \sa cd(), isReadable(), exists(), path()
Packit 1c1d7e
*/
Packit 1c1d7e
Packit 1c1d7e
bool QDir::cdUp()
Packit 1c1d7e
{
Packit 1c1d7e
    return cd( QString::fromLatin1("..") );
Packit 1c1d7e
}
Packit 1c1d7e
Packit 1c1d7e
/*!
Packit 1c1d7e
  \fn QString QDir::nameFilter() const
Packit 1c1d7e
  Returns the string set by setNameFilter()
Packit 1c1d7e
*/
Packit 1c1d7e
Packit 1c1d7e
/*!
Packit 1c1d7e
  Sets the name filter used by entryList() and entryInfoList().
Packit 1c1d7e
Packit 1c1d7e
  The name filter is a wildcarding filter that understands "*" and "?"
Packit 1c1d7e
  wildcards, You may specify several filter entries separated by a " " or a ";". If
Packit 1c1d7e
  you want entryList() and entryInfoList() to list all files ending with
Packit 1c1d7e
  ".cpp" and all files ending with ".h", you simply call
Packit 1c1d7e
  dir.setNameFilter("*.cpp *.h") or dir.setNameFilter("*.cpp;*.h")
Packit 1c1d7e
Packit 1c1d7e
  \sa nameFilter(), setFilter()
Packit 1c1d7e
*/
Packit 1c1d7e
Packit 1c1d7e
void QDir::setNameFilter( const QString &nameFilter )
Packit 1c1d7e
{
Packit 1c1d7e
    nameFilt = nameFilter;
Packit 1c1d7e
    if ( nameFilt.isEmpty() )
Packit 1c1d7e
	nameFilt = QString::fromLatin1("*");
Packit 1c1d7e
    dirty = TRUE;
Packit 1c1d7e
}
Packit 1c1d7e
Packit 1c1d7e
/*!
Packit 1c1d7e
  \fn QDir::FilterSpec QDir::filter() const
Packit 1c1d7e
  Returns the value set by setFilter()
Packit 1c1d7e
*/
Packit 1c1d7e
Packit 1c1d7e
/*! \enum QDir::FilterSpec
Packit 1c1d7e
Packit 1c1d7e
  This enum describes how QDir is to select what entries in a
Packit 1c1d7e
  directory to return.  The filter value is specified by or-ing
Packit 1c1d7e
  together values from the following list: 
    Packit 1c1d7e
    Packit 1c1d7e
      
  • \c Dirs - List directories only
  • Packit 1c1d7e
      
  • \c Files - List files only
  • Packit 1c1d7e
    Packit 1c1d7e
      
  • \c Drives - List disk drives (does nothing under unix)
  • Packit 1c1d7e
      
  • \c NoSymLinks - Do not list symbolic links (where they exist)
  • Packit 1c1d7e
      
  • \c Readable - List files for which the application has read access.
  • Packit 1c1d7e
      
  • \c Writable - List files for which the application has write access.
  • Packit 1c1d7e
      
  • \c Executable - List files for which the application has execute access
  • Packit 1c1d7e
      
  • \c Modified - Only list files that have been modified (does nothing
  • Packit 1c1d7e
      under unix)
    Packit 1c1d7e
      
  • \c Hidden - List hidden files (on unix, files starting with a .)
  • Packit 1c1d7e
      
  • \c System - List system files (does nothing under unix)
  • Packit 1c1d7e
      
    Packit 1c1d7e
    Packit 1c1d7e
      If you do not set any of \c Readable, \c Writable or \c Executable,
    Packit 1c1d7e
      QDir will set all three of them.  This makes the default easy to
    Packit 1c1d7e
      write and at the same time useful.
    Packit 1c1d7e
    Packit 1c1d7e
      Examples: \c Readable|Writable means list all files for which the
    Packit 1c1d7e
      application has read access, write access or both.  \c Dirs|Drives
    Packit 1c1d7e
      means list drives, directories, all files that the application can
    Packit 1c1d7e
      read, write or execute, and also symlinks to such files/directories.
    Packit 1c1d7e
    */
    Packit 1c1d7e
    Packit 1c1d7e
    Packit 1c1d7e
    /*!
    Packit 1c1d7e
      Sets the filter used by entryList() and entryInfoList(). The filter is used
    Packit 1c1d7e
      to specify the kind of files that should be returned by entryList() and
    Packit 1c1d7e
      entryInfoList().
    Packit 1c1d7e
    Packit 1c1d7e
      \sa filter(), setNameFilter()
    Packit 1c1d7e
    */
    Packit 1c1d7e
    Packit 1c1d7e
    void QDir::setFilter( int filterSpec )
    Packit 1c1d7e
    {
    Packit 1c1d7e
        if ( filtS == (FilterSpec) filterSpec )
    Packit 1c1d7e
    	return;
    Packit 1c1d7e
        filtS = (FilterSpec) filterSpec;
    Packit 1c1d7e
        dirty = TRUE;
    Packit 1c1d7e
    }
    Packit 1c1d7e
    Packit 1c1d7e
    /*!
    Packit 1c1d7e
      \fn QDir::SortSpec QDir::sorting() const
    Packit 1c1d7e
    Packit 1c1d7e
      Returns the value set by setSorting()
    Packit 1c1d7e
    Packit 1c1d7e
      \sa setSorting()
    Packit 1c1d7e
    */
    Packit 1c1d7e
    Packit 1c1d7e
    /*! \enum QDir::SortSpec
    Packit 1c1d7e
    Packit 1c1d7e
      This enum describes how QDir is to sort entries in a directory when
    Packit 1c1d7e
      it returns a list of them.  The sort value is specified by or-ing
    Packit 1c1d7e
      together values from the following list: 
      Packit 1c1d7e
      Packit 1c1d7e
        
    • \c Name - sort by name
    • Packit 1c1d7e
        
    • \c Time - sort by time (modification time)
    • Packit 1c1d7e
        
    • \c Size - sort by file size
    • Packit 1c1d7e
        
    • \c Unsorted - do not sort
    • Packit 1c1d7e
      Packit 1c1d7e
        
    • \c DirsFirst - put all directories first in the list
    • Packit 1c1d7e
        
    • \c Reversed - reverse the sort order
    • Packit 1c1d7e
        
    • \c IgnoreCase - sort case-insensitively
    • Packit 1c1d7e
      Packit 1c1d7e
        
      Packit 1c1d7e
      Packit 1c1d7e
        You can only specify one of the first four.  If you specify both \c
      Packit 1c1d7e
        DirsFirst and \c Reversed, directories are still put first but the
      Packit 1c1d7e
        list is otherwise reversed.
      Packit 1c1d7e
      */
      Packit 1c1d7e
      Packit 1c1d7e
      // ### Unsorted+DirsFirst ? Unsorted+Reversed?
      Packit 1c1d7e
      Packit 1c1d7e
      /*!
      Packit 1c1d7e
        Sets the sorting order used by entryList() and entryInfoList().
      Packit 1c1d7e
      Packit 1c1d7e
        The \e sortSpec is specified by or-ing values from the enum
      Packit 1c1d7e
        SortSpec. The different values are:
      Packit 1c1d7e
      Packit 1c1d7e
        One of these:
      Packit 1c1d7e
        
      Packit 1c1d7e
        
      Name
      Sort by name (alphabetical order).
      Packit 1c1d7e
        
      Time
      Sort by time (most recent first).
      Packit 1c1d7e
        
      Size
      Sort by size (largest first).
      Packit 1c1d7e
        
      Unsorted
      Use the operating system order (UNIX does NOT sort
      Packit 1c1d7e
        alphabetically).
      Packit 1c1d7e
      Packit 1c1d7e
        ORed with zero or more of these:
      Packit 1c1d7e
      Packit 1c1d7e
        
      DirsFirst
      Always put directory names first.
      Packit 1c1d7e
        
      Reversed
      Reverse sort order.
      Packit 1c1d7e
        
      IgnoreCase
      Ignore case when sorting by name.
      Packit 1c1d7e
        
      Packit 1c1d7e
      */
      Packit 1c1d7e
      Packit 1c1d7e
      void QDir::setSorting( int sortSpec )
      Packit 1c1d7e
      {
      Packit 1c1d7e
          if ( sortS == (SortSpec) sortSpec )
      Packit 1c1d7e
      	return;
      Packit 1c1d7e
          sortS = (SortSpec) sortSpec;
      Packit 1c1d7e
          dirty = TRUE;
      Packit 1c1d7e
      }
      Packit 1c1d7e
      Packit 1c1d7e
      /*!
      Packit 1c1d7e
        \fn bool QDir::matchAllDirs() const
      Packit 1c1d7e
        Returns the value set by setMatchAllDirs()
      Packit 1c1d7e
      Packit 1c1d7e
        \sa setMatchAllDirs()
      Packit 1c1d7e
      */
      Packit 1c1d7e
      Packit 1c1d7e
      /*!
      Packit 1c1d7e
        If \e enable is TRUE, all directories will be listed (even if they do not
      Packit 1c1d7e
        match the filter or the name filter), otherwise only matched directories
      Packit 1c1d7e
        will be listed.
      Packit 1c1d7e
      Packit 1c1d7e
        \bug Currently, directories that do not match the filter will not be
      Packit 1c1d7e
        included (the name filter will be ignored as expected).
      Packit 1c1d7e
      Packit 1c1d7e
        \sa matchAllDirs()
      Packit 1c1d7e
      */
      Packit 1c1d7e
      Packit 1c1d7e
      void QDir::setMatchAllDirs( bool enable )
      Packit 1c1d7e
      {
      Packit 1c1d7e
          if ( (bool)allDirs == enable )
      Packit 1c1d7e
      	return;
      Packit 1c1d7e
          allDirs = enable;
      Packit 1c1d7e
          dirty = TRUE;
      Packit 1c1d7e
      }
      Packit 1c1d7e
      Packit 1c1d7e
      Packit 1c1d7e
      /*!
      Packit 1c1d7e
        Returns the number of files that was found.
      Packit 1c1d7e
        Equivalent to entryList().count().
      Packit 1c1d7e
        \sa operator[](), entryList()
      Packit 1c1d7e
      */
      Packit 1c1d7e
      Packit 1c1d7e
      uint QDir::count() const
      Packit 1c1d7e
      {
      Packit 1c1d7e
          return entryList().count();
      Packit 1c1d7e
      }
      Packit 1c1d7e
      Packit 1c1d7e
      /*!
      Packit 1c1d7e
        Returns the file name at position \e index in the list of found file
      Packit 1c1d7e
        names.
      Packit 1c1d7e
        Equivalent to entryList().at(index).
      Packit 1c1d7e
      Packit 1c1d7e
        Returns null if the \e index is out of range or if the entryList()
      Packit 1c1d7e
        function failed.
      Packit 1c1d7e
      Packit 1c1d7e
        \sa count(), entryList()
      Packit 1c1d7e
      */
      Packit 1c1d7e
      Packit 1c1d7e
      QString QDir::operator[]( int index ) const
      Packit 1c1d7e
      {
      Packit 1c1d7e
          entryList();
      Packit 1c1d7e
          return fList && index >= 0 && index < (int)fList->count() ?
      Packit 1c1d7e
      	(*fList)[index] : QString::null;
      Packit 1c1d7e
      }
      Packit 1c1d7e
      Packit 1c1d7e
      Packit 1c1d7e
      /*!
      Packit 1c1d7e
        This function is included to easy porting from Qt 1.x to Qt 2.0,
      Packit 1c1d7e
        it is the same as entryList(), but encodes the filenames as 8-bit
      Packit 1c1d7e
        strings using QFile::encodedName().
      Packit 1c1d7e
      Packit 1c1d7e
        It is more efficient to use entryList().
      Packit 1c1d7e
      */
      Packit 1c1d7e
      QStrList QDir::encodedEntryList( int filterSpec, int sortSpec ) const
      Packit 1c1d7e
      {
      Packit 1c1d7e
          QStrList r;
      Packit 1c1d7e
          QStringList l = entryList(filterSpec,sortSpec);
      Packit 1c1d7e
          for ( QStringList::Iterator it = l.begin(); it != l.end(); ++it ) {
      Packit 1c1d7e
      	r.append( QFile::encodeName(*it) );
      Packit 1c1d7e
          }
      Packit 1c1d7e
          return r;
      Packit 1c1d7e
      }
      Packit 1c1d7e
      Packit 1c1d7e
      /*!
      Packit 1c1d7e
        This function is included to easy porting from Qt 1.x to Qt 2.0,
      Packit 1c1d7e
        it is the same as entryList(), but encodes the filenames as 8-bit
      Packit 1c1d7e
        strings using QFile::encodedName().
      Packit 1c1d7e
      Packit 1c1d7e
        It is more efficient to use entryList().
      Packit 1c1d7e
      */
      Packit 1c1d7e
      QStrList QDir::encodedEntryList( const QString &nameFilter,
      Packit 1c1d7e
      			   int filterSpec,
      Packit 1c1d7e
      			   int sortSpec ) const
      Packit 1c1d7e
      {
      Packit 1c1d7e
          QStrList r;
      Packit 1c1d7e
          QStringList l = entryList(nameFilter,filterSpec,sortSpec);
      Packit 1c1d7e
          for ( QStringList::Iterator it = l.begin(); it != l.end(); ++it ) {
      Packit 1c1d7e
      	r.append( QFile::encodeName(*it) );
      Packit 1c1d7e
          }
      Packit 1c1d7e
          return r;
      Packit 1c1d7e
      }
      Packit 1c1d7e
      Packit 1c1d7e
      Packit 1c1d7e
      Packit 1c1d7e
      /*!
      Packit 1c1d7e
        Returns a list of the names of all files and directories in the directory
      Packit 1c1d7e
        indicated by the setSorting(), setFilter() and setNameFilter()
      Packit 1c1d7e
        specifications.
      Packit 1c1d7e
      Packit 1c1d7e
        The the filter and sorting specifications can be overridden using the
      Packit 1c1d7e
        \e filterSpec and \e sortSpec arguments.
      Packit 1c1d7e
      Packit 1c1d7e
        Returns an empty list if the directory is unreadable or does not exist.
      Packit 1c1d7e
      Packit 1c1d7e
        \sa entryInfoList(), setNameFilter(), setSorting(), setFilter(),
      Packit 1c1d7e
      	encodedEntryList()
      Packit 1c1d7e
      */
      Packit 1c1d7e
      Packit 1c1d7e
      QStringList QDir::entryList( int filterSpec, int sortSpec ) const
      Packit 1c1d7e
      {
      Packit 1c1d7e
          if ( !dirty && filterSpec == (int)DefaultFilter &&
      Packit 1c1d7e
      		   sortSpec   == (int)DefaultSort )
      Packit 1c1d7e
      	return *fList;
      Packit 1c1d7e
          return entryList( nameFilt, filterSpec, sortSpec );
      Packit 1c1d7e
      }
      Packit 1c1d7e
      Packit 1c1d7e
      /*!
      Packit 1c1d7e
        Returns a list of the names of all files and directories in the directory
      Packit 1c1d7e
        indicated by the setSorting(), setFilter() and setNameFilter()
      Packit 1c1d7e
        specifications.
      Packit 1c1d7e
      Packit 1c1d7e
        The the filter and sorting specifications can be overridden using the
      Packit 1c1d7e
        \e nameFilter, \e filterSpec and \e sortSpec arguments.
      Packit 1c1d7e
      Packit 1c1d7e
        Returns and empty list if the directory is unreadable or does not exist.
      Packit 1c1d7e
      Packit 1c1d7e
        \sa entryInfoList(), setNameFilter(), setSorting(), setFilter(),
      Packit 1c1d7e
      	encodedEntryList()
      Packit 1c1d7e
      */
      Packit 1c1d7e
      Packit 1c1d7e
      QStringList QDir::entryList( const QString &nameFilter,
      Packit 1c1d7e
      				 int filterSpec, int sortSpec ) const
      Packit 1c1d7e
      {
      Packit 1c1d7e
          if ( filterSpec == (int)DefaultFilter )
      Packit 1c1d7e
      	filterSpec = filtS;
      Packit 1c1d7e
          if ( sortSpec == (int)DefaultSort )
      Packit 1c1d7e
      	sortSpec = sortS;
      Packit 1c1d7e
          QDir *that = (QDir*)this;			// mutable function
      Packit 1c1d7e
          if ( that->readDirEntries(nameFilter, filterSpec, sortSpec) )
      Packit 1c1d7e
      	return *that->fList;
      Packit 1c1d7e
          else
      Packit 1c1d7e
      	return QStringList();
      Packit 1c1d7e
      }
      Packit 1c1d7e
      Packit 1c1d7e
      /*!
      Packit 1c1d7e
        Returns a list of QFileInfo objects for all files and directories in
      Packit 1c1d7e
        the directory pointed to using the setSorting(), setFilter() and
      Packit 1c1d7e
        setNameFilter() specifications.
      Packit 1c1d7e
      Packit 1c1d7e
        The the filter and sorting specifications can be overridden using the
      Packit 1c1d7e
        \e filterSpec and \e sortSpec arguments.
      Packit 1c1d7e
      Packit 1c1d7e
        Returns 0 if the directory is unreadable or does not exist.
      Packit 1c1d7e
      Packit 1c1d7e
        The returned pointer is a const pointer to a QFileInfoList. The list is
      Packit 1c1d7e
        owned by the QDir object and will be reused on the next call to
      Packit 1c1d7e
        entryInfoList() for the same QDir instance. If you want to keep the
      Packit 1c1d7e
        entries of the list after a subsequent call to this function you will
      Packit 1c1d7e
        need to copy them.
      Packit 1c1d7e
      Packit 1c1d7e
        \sa entryList(), setNameFilter(), setSorting(), setFilter()
      Packit 1c1d7e
      */
      Packit 1c1d7e
      Packit 1c1d7e
      const QFileInfoList *QDir::entryInfoList( int filterSpec, int sortSpec ) const
      Packit 1c1d7e
      {
      Packit 1c1d7e
          if ( !dirty && filterSpec == (int)DefaultFilter &&
      Packit 1c1d7e
      		   sortSpec   == (int)DefaultSort )
      Packit 1c1d7e
      	return fiList;
      Packit 1c1d7e
          return entryInfoList( nameFilt, filterSpec, sortSpec );
      Packit 1c1d7e
      }
      Packit 1c1d7e
      Packit 1c1d7e
      /*!
      Packit 1c1d7e
        Returns a list of QFileInfo objects for all files and directories in
      Packit 1c1d7e
        the directory pointed to using the setSorting(), setFilter() and
      Packit 1c1d7e
        setNameFilter() specifications.
      Packit 1c1d7e
      Packit 1c1d7e
        The the filter and sorting specifications can be overridden using the
      Packit 1c1d7e
        \e nameFilter, \e filterSpec and \e sortSpec arguments.
      Packit 1c1d7e
      Packit 1c1d7e
        Returns 0 if the directory is unreadable or does not exist.
      Packit 1c1d7e
      Packit 1c1d7e
        The returned pointer is a const pointer to a QFileInfoList. The list is
      Packit 1c1d7e
        owned by the QDir object and will be reused on the next call to
      Packit 1c1d7e
        entryInfoList() for the same QDir instance. If you want to keep the
      Packit 1c1d7e
        entries of the list after a subsequent call to this function you will
      Packit 1c1d7e
        need to copy them.
      Packit 1c1d7e
      Packit 1c1d7e
        \sa entryList(), setNameFilter(), setSorting(), setFilter()
      Packit 1c1d7e
      */
      Packit 1c1d7e
      Packit 1c1d7e
      const QFileInfoList *QDir::entryInfoList( const QString &nameFilter,
      Packit 1c1d7e
      					  int filterSpec, int sortSpec ) const
      Packit 1c1d7e
      {
      Packit 1c1d7e
          if ( filterSpec == (int)DefaultFilter )
      Packit 1c1d7e
      	filterSpec = filtS;
      Packit 1c1d7e
          if ( sortSpec == (int)DefaultSort )
      Packit 1c1d7e
      	sortSpec = sortS;
      Packit 1c1d7e
          QDir *that = (QDir*)this;			// mutable function
      Packit 1c1d7e
          if ( that->readDirEntries(nameFilter, filterSpec, sortSpec) )
      Packit 1c1d7e
      	return that->fiList;
      Packit 1c1d7e
          else
      Packit 1c1d7e
      	return 0;
      Packit 1c1d7e
      }
      Packit 1c1d7e
      Packit 1c1d7e
      /*!
      Packit 1c1d7e
        Returns TRUE if the directory exists. (If a file with the same
      Packit 1c1d7e
        name is found this function will of course return FALSE).
      Packit 1c1d7e
      Packit 1c1d7e
        \sa QFileInfo::exists(), QFile::exists()
      Packit 1c1d7e
      */
      Packit 1c1d7e
      Packit 1c1d7e
      bool QDir::exists() const
      Packit 1c1d7e
      {
      Packit 1c1d7e
          QFileInfo fi( dPath );
      Packit 1c1d7e
          return fi.exists() && fi.isDir();
      Packit 1c1d7e
      }
      Packit 1c1d7e
      Packit 1c1d7e
      /*!
      Packit 1c1d7e
        Returns TRUE if the directory path is relative to the current directory,
      Packit 1c1d7e
        FALSE if the path is absolute (e.g. under UNIX a path is relative if it
      Packit 1c1d7e
        does not start with a '/').
      Packit 1c1d7e
      Packit 1c1d7e
        According to Einstein this function should always return TRUE.
      Packit 1c1d7e
      Packit 1c1d7e
        \sa convertToAbs()
      Packit 1c1d7e
      */
      Packit 1c1d7e
      Packit 1c1d7e
      bool QDir::isRelative() const
      Packit 1c1d7e
      {
      Packit 1c1d7e
          return isRelativePath( dPath );
      Packit 1c1d7e
      }
      Packit 1c1d7e
      Packit 1c1d7e
      /*!
      Packit 1c1d7e
        Converts the directory path to an absolute path. If it is already
      Packit 1c1d7e
        absolute nothing is done.
      Packit 1c1d7e
      Packit 1c1d7e
        \sa isRelative()
      Packit 1c1d7e
      */
      Packit 1c1d7e
      Packit 1c1d7e
      void QDir::convertToAbs()
      Packit 1c1d7e
      {
      Packit 1c1d7e
          dPath = absPath();
      Packit 1c1d7e
      }
      Packit 1c1d7e
      Packit 1c1d7e
      /*!
      Packit 1c1d7e
        Makes a copy of d and assigns it to this QDir.
      Packit 1c1d7e
      */
      Packit 1c1d7e
      Packit 1c1d7e
      QDir &QDir::operator=( const QDir &d )
      Packit 1c1d7e
      {
      Packit 1c1d7e
          dPath    = d.dPath;
      Packit 1c1d7e
          delete fList;
      Packit 1c1d7e
          fList    = 0;
      Packit 1c1d7e
          delete fiList;
      Packit 1c1d7e
          fiList   = 0;
      Packit 1c1d7e
          nameFilt = d.nameFilt;
      Packit 1c1d7e
          dirty    = TRUE;
      Packit 1c1d7e
          allDirs  = d.allDirs;
      Packit 1c1d7e
          filtS    = d.filtS;
      Packit 1c1d7e
          sortS    = d.sortS;
      Packit 1c1d7e
          return *this;
      Packit 1c1d7e
      }
      Packit 1c1d7e
      Packit 1c1d7e
      /*!
      Packit 1c1d7e
        Sets the directory path to be the given path.
      Packit 1c1d7e
      */
      Packit 1c1d7e
      Packit 1c1d7e
      QDir &QDir::operator=( const QString &path )
      Packit 1c1d7e
      {
      Packit 1c1d7e
          dPath = cleanDirPath( path );
      Packit 1c1d7e
          dirty = TRUE;
      Packit 1c1d7e
          return *this;
      Packit 1c1d7e
      }
      Packit 1c1d7e
      Packit 1c1d7e
      Packit 1c1d7e
      /*!
      Packit 1c1d7e
        \fn bool QDir::operator!=( const QDir &d ) const
      Packit 1c1d7e
        Returns TRUE if the \e d and this dir have different path or
      Packit 1c1d7e
        different sort/filter settings, otherwise FALSE.
      Packit 1c1d7e
      */
      Packit 1c1d7e
      Packit 1c1d7e
      /*!
      Packit 1c1d7e
        Returns TRUE if the \e d and this dir have the same path and all sort
      Packit 1c1d7e
        and filter settings are equal, otherwise FALSE.
      Packit 1c1d7e
      */
      Packit 1c1d7e
      Packit 1c1d7e
      bool QDir::operator==( const QDir &d ) const
      Packit 1c1d7e
      {
      Packit 1c1d7e
          return dPath    == d.dPath &&
      Packit 1c1d7e
      	   nameFilt == d.nameFilt &&
      Packit 1c1d7e
      	   allDirs  == d.allDirs &&
      Packit 1c1d7e
      	   filtS    == d.filtS &&
      Packit 1c1d7e
      	   sortS    == d.sortS;
      Packit 1c1d7e
      }
      Packit 1c1d7e
      Packit 1c1d7e
      Packit 1c1d7e
      /*!
      Packit 1c1d7e
        Removes a file.
      Packit 1c1d7e
      Packit 1c1d7e
        If \e acceptAbsPath is TRUE a path starting with a separator ('/')
      Packit 1c1d7e
        will remove the file with the absolute path, if \e acceptAbsPath is FALSE
      Packit 1c1d7e
        any number of separators at the beginning of \e fileName will be removed.
      Packit 1c1d7e
      Packit 1c1d7e
        Returns TRUE if successful, otherwise FALSE.
      Packit 1c1d7e
      */
      Packit 1c1d7e
      Packit 1c1d7e
      bool QDir::remove( const QString &fileName, bool acceptAbsPath )
      Packit 1c1d7e
      {
      Packit 1c1d7e
          if ( fileName.isEmpty() ) {
      Packit 1c1d7e
      #if defined(CHECK_NULL)
      Packit 1c1d7e
      	qWarning( "QDir::remove: Empty or null file name" );
      Packit 1c1d7e
      #endif
      Packit 1c1d7e
      	return FALSE;
      Packit 1c1d7e
          }
      Packit 1c1d7e
          QString p = filePath( fileName, acceptAbsPath );
      Packit 1c1d7e
          return QFile::remove( p );
      Packit 1c1d7e
      }
      Packit 1c1d7e
      Packit 1c1d7e
      /*!
      Packit 1c1d7e
        Checks for existence of a file.
      Packit 1c1d7e
      Packit 1c1d7e
        If \e acceptAbsPaths is TRUE a path starting with a separator ('/')
      Packit 1c1d7e
        will check the file with the absolute path, if \e acceptAbsPath is FALSE
      Packit 1c1d7e
        any number of separators at the beginning of \e name will be removed.
      Packit 1c1d7e
      Packit 1c1d7e
        Returns TRUE if the file exists, otherwise FALSE.
      Packit 1c1d7e
      Packit 1c1d7e
        \sa QFileInfo::exists(), QFile::exists()
      Packit 1c1d7e
      */
      Packit 1c1d7e
      Packit 1c1d7e
      bool QDir::exists( const QString &name, bool acceptAbsPath )
      Packit 1c1d7e
      {
      Packit 1c1d7e
          if ( name.isEmpty() ) {
      Packit 1c1d7e
      #if defined(CHECK_NULL)
      Packit 1c1d7e
      	qWarning( "QDir::exists: Empty or null file name" );
      Packit 1c1d7e
      #endif
      Packit 1c1d7e
      	return FALSE;
      Packit 1c1d7e
          }
      Packit 1c1d7e
          QString tmp = filePath( name, acceptAbsPath );
      Packit 1c1d7e
          return QFile::exists( tmp );
      Packit 1c1d7e
      }
      Packit 1c1d7e
      Packit 1c1d7e
      /*!
      Packit 1c1d7e
        Returns the native directory separator; '/' under UNIX and '\' under
      Packit 1c1d7e
        MS-DOS, Windows NT and OS/2.
      Packit 1c1d7e
      Packit 1c1d7e
        You do not need to use this function to build file paths. If you always
      Packit 1c1d7e
        use '/', Qt will translate your paths to conform to the underlying
      Packit 1c1d7e
        operating system.
      Packit 1c1d7e
      */
      Packit 1c1d7e
      Packit 1c1d7e
      char QDir::separator()
      Packit 1c1d7e
      {
      Packit 1c1d7e
      #if defined(_OS_UNIX_)
      Packit 1c1d7e
          return '/';
      Packit 1c1d7e
      #elif defined (_OS_FATFS_)
      Packit 1c1d7e
          return '\\';
      Packit 1c1d7e
      #elif defined (_OS_MAC_)
      Packit 1c1d7e
          return ':';
      Packit 1c1d7e
      #else
      Packit 1c1d7e
          return '/';
      Packit 1c1d7e
      #endif
      Packit 1c1d7e
      }
      Packit 1c1d7e
      Packit 1c1d7e
      /*!
      Packit 1c1d7e
        Returns the current directory.
      Packit 1c1d7e
        \sa currentDirPath(), QDir::QDir()
      Packit 1c1d7e
      */
      Packit 1c1d7e
      Packit 1c1d7e
      QDir QDir::current()
      Packit 1c1d7e
      {
      Packit 1c1d7e
          return QDir( currentDirPath() );
      Packit 1c1d7e
      }
      Packit 1c1d7e
      Packit 1c1d7e
      /*!
      Packit 1c1d7e
        Returns the home directory.
      Packit 1c1d7e
        \sa homeDirPath()
      Packit 1c1d7e
      */
      Packit 1c1d7e
      Packit 1c1d7e
      QDir QDir::home()
      Packit 1c1d7e
      {
      Packit 1c1d7e
          return QDir( homeDirPath() );
      Packit 1c1d7e
      }
      Packit 1c1d7e
      Packit 1c1d7e
      /*!
      Packit 1c1d7e
        Returns the root directory.
      Packit 1c1d7e
        \sa rootDirPath() drives()
      Packit 1c1d7e
      */
      Packit 1c1d7e
      Packit 1c1d7e
      QDir QDir::root()
      Packit 1c1d7e
      {
      Packit 1c1d7e
          return QDir( rootDirPath() );
      Packit 1c1d7e
      }
      Packit 1c1d7e
      Packit 1c1d7e
      /*!
      Packit 1c1d7e
        \fn QString QDir::homeDirPath()
      Packit 1c1d7e
      Packit 1c1d7e
        Returns the absolute path for the user's home directory,
      Packit 1c1d7e
        \sa home()
      Packit 1c1d7e
      */
      Packit 1c1d7e
      Packit 1c1d7e
      QStringList qt_makeFilterList( const QString &filter )
      Packit 1c1d7e
      {
      Packit 1c1d7e
          if ( filter.isEmpty() )
      Packit 1c1d7e
      	return QStringList();
      Packit 1c1d7e
      Packit 1c1d7e
          QChar sep( ';' );
      Packit 1c1d7e
          int i = filter.find( sep, 0 );
      Packit 1c1d7e
          if ( i == -1 && filter.find( ' ', 0 ) != -1 )
      Packit 1c1d7e
      	sep = QChar( ' ' );
      Packit 1c1d7e
      Packit 1c1d7e
          QStringList lst = QStringList::split( sep, filter );
      Packit 1c1d7e
          QStringList lst2;
      Packit 1c1d7e
          QStringList::Iterator it = lst.begin();
      Packit 1c1d7e
      Packit 1c1d7e
          for ( ; it != lst.end(); ++it ) {
      Packit 1c1d7e
      	QString s = *it;
      Packit 1c1d7e
      	lst2 << s.stripWhiteSpace();
      Packit 1c1d7e
          }
      Packit 1c1d7e
          return lst2;
      Packit 1c1d7e
      }
      Packit 1c1d7e
      Packit 1c1d7e
      /*!
      Packit 1c1d7e
        Returns TRUE if the \e fileName matches one of the wildcards in the list \e filters.
      Packit 1c1d7e
        \sa QRegExp
      Packit 1c1d7e
      */
      Packit 1c1d7e
      Packit 1c1d7e
      bool QDir::match( const QStringList &filters, const QString &fileName )
      Packit 1c1d7e
      {
      Packit 1c1d7e
          QStringList::ConstIterator sit = filters.begin();
      Packit 1c1d7e
          bool matched = FALSE;
      Packit 1c1d7e
          for ( ; sit != filters.end(); ++sit ) {
      Packit 1c1d7e
      	QRegExp regexp( (*sit).data(), FALSE, TRUE );
      Packit 1c1d7e
      	if ( regexp.match( fileName.data() ) != -1 ) {
      Packit 1c1d7e
      	    matched = TRUE;
      Packit 1c1d7e
      	    break;
      Packit 1c1d7e
      	}
      Packit 1c1d7e
          }
      Packit 1c1d7e
      Packit 1c1d7e
          return matched;
      Packit 1c1d7e
      }
      Packit 1c1d7e
      Packit 1c1d7e
      /*!
      Packit 1c1d7e
        Returns TRUE if the \e fileName matches the wildcard \e filter.
      Packit 1c1d7e
        \a Filter may also contain multiple wildcards separated by spaces or
      Packit 1c1d7e
        semicolons.
      Packit 1c1d7e
        \sa QRegExp
      Packit 1c1d7e
      */
      Packit 1c1d7e
      Packit 1c1d7e
      bool QDir::match( const QString &filter, const QString &fileName )
      Packit 1c1d7e
      {
      Packit 1c1d7e
          QStringList lst = qt_makeFilterList( filter );
      Packit 1c1d7e
          return match( lst, fileName );
      Packit 1c1d7e
      }
      Packit 1c1d7e
      Packit 1c1d7e
      Packit 1c1d7e
      /*!
      Packit 1c1d7e
        Removes all multiple directory separators ('/') and resolves
      Packit 1c1d7e
        any "." or ".." found in the path.
      Packit 1c1d7e
      Packit 1c1d7e
        Symbolic links are kept.  This function does not return the
      Packit 1c1d7e
        canonical path, but rather the most simplified version of the input.
      Packit 1c1d7e
        "../stuff" becomes "stuff", "stuff/../nonsense" becomes "nonsense"
      Packit 1c1d7e
        and "\\stuff\\more\\..\\nonsense" becomes "\\stuff\\nonsense".
      Packit 1c1d7e
      Packit 1c1d7e
        \sa absPath() canonicalPath()
      Packit 1c1d7e
      */
      Packit 1c1d7e
      Packit 1c1d7e
      QString QDir::cleanDirPath( const QString &filePath )
      Packit 1c1d7e
      {
      Packit 1c1d7e
          QString name = filePath;
      Packit 1c1d7e
          QString newPath;
      Packit 1c1d7e
      Packit 1c1d7e
          if ( name.isEmpty() )
      Packit 1c1d7e
      	return name;
      Packit 1c1d7e
      Packit 1c1d7e
          slashify( name );
      Packit 1c1d7e
      Packit 1c1d7e
          bool addedSeparator;
      Packit 1c1d7e
          if ( isRelativePath(name) ) {
      Packit 1c1d7e
      	addedSeparator = TRUE;
      Packit 1c1d7e
      	name.insert( 0, '/' );
      Packit 1c1d7e
          } else {
      Packit 1c1d7e
      	addedSeparator = FALSE;
      Packit 1c1d7e
          }
      Packit 1c1d7e
      Packit 1c1d7e
          int ePos, pos, upLevel;
      Packit 1c1d7e
      Packit 1c1d7e
          pos = ePos = name.length();
      Packit 1c1d7e
          upLevel = 0;
      Packit 1c1d7e
          int len;
      Packit 1c1d7e
      Packit 1c1d7e
          while ( pos && (pos = name.findRev('/',--pos)) != -1 ) {
      Packit 1c1d7e
      	len = ePos - pos - 1;
      Packit 1c1d7e
      	if ( len == 2 && name.at(pos + 1) == '.'
      Packit 1c1d7e
      		      && name.at(pos + 2) == '.' ) {
      Packit 1c1d7e
      	    upLevel++;
      Packit 1c1d7e
      	} else {
      Packit 1c1d7e
      	    if ( len != 0 && (len != 1 || name.at(pos + 1) != '.') ) {
      Packit 1c1d7e
      		if ( !upLevel )
      Packit 1c1d7e
      		    newPath = QString::fromLatin1("/")
      Packit 1c1d7e
      			+ name.mid(pos + 1, len) + newPath;
      Packit 1c1d7e
      		else
      Packit 1c1d7e
      		    upLevel--;
      Packit 1c1d7e
      	    }
      Packit 1c1d7e
      	}
      Packit 1c1d7e
      	ePos = pos;
      Packit 1c1d7e
          }
      Packit 1c1d7e
          if ( addedSeparator ) {
      Packit 1c1d7e
      	while ( upLevel-- )
      Packit 1c1d7e
      	    newPath.insert( 0, QString::fromLatin1("/..") );
      Packit 1c1d7e
      	if ( !newPath.isEmpty() )
      Packit 1c1d7e
      	    newPath.remove( 0, 1 );
      Packit 1c1d7e
      	else
      Packit 1c1d7e
      	    newPath = QString::fromLatin1(".");
      Packit 1c1d7e
          } else {
      Packit 1c1d7e
      	if ( newPath.isEmpty() )
      Packit 1c1d7e
      	    newPath = QString::fromLatin1("/");
      Packit 1c1d7e
      #if defined(_OS_FATFS_) || defined(_OS_OS2EMX_)
      Packit 1c1d7e
      	if ( name[0] == '/' ) {
      Packit 1c1d7e
      	    if ( name[1] == '/' )		// "\\machine\x\ ..."
      Packit 1c1d7e
      		newPath.insert( 0, '/' );
      Packit 1c1d7e
      	} else {
      Packit 1c1d7e
      	    newPath = name.left(2) + newPath;
      Packit 1c1d7e
      	}
      Packit 1c1d7e
      #endif
      Packit 1c1d7e
          }
      Packit 1c1d7e
          return newPath;
      Packit 1c1d7e
      }
      Packit 1c1d7e
      Packit 1c1d7e
      int qt_cmp_si_sortSpec;
      Packit 1c1d7e
      Packit 1c1d7e
      #if defined(Q_C_CALLBACKS)
      Packit 1c1d7e
      extern "C" {
      Packit 1c1d7e
      #endif
      Packit 1c1d7e
      Packit 1c1d7e
      int qt_cmp_si( const void *n1, const void *n2 )
      Packit 1c1d7e
      {
      Packit 1c1d7e
          if ( !n1 || !n2 )
      Packit 1c1d7e
      	return 0;
      Packit 1c1d7e
      Packit 1c1d7e
          QDirSortItem* f1 = (QDirSortItem*)n1;
      Packit 1c1d7e
          QDirSortItem* f2 = (QDirSortItem*)n2;
      Packit 1c1d7e
      Packit 1c1d7e
          if ( qt_cmp_si_sortSpec & QDir::DirsFirst )
      Packit 1c1d7e
      	if ( f1->item->isDir() != f2->item->isDir() )
      Packit 1c1d7e
      	    return f1->item->isDir() ? -1 : 1;
      Packit 1c1d7e
      Packit 1c1d7e
          int r = 0;
      Packit 1c1d7e
          int sortBy = qt_cmp_si_sortSpec & QDir::SortByMask;
      Packit 1c1d7e
      Packit 1c1d7e
          switch ( sortBy ) {
      Packit 1c1d7e
            case QDir::Time:
      Packit 1c1d7e
      	r = f1->item->lastModified().secsTo(f2->item->lastModified());
      Packit 1c1d7e
      	break;
      Packit 1c1d7e
            case QDir::Size:
      Packit 1c1d7e
      	r = f2->item->size() - f1->item->size();
      Packit 1c1d7e
      	break;
      Packit 1c1d7e
            default:
      Packit 1c1d7e
      	;
      Packit 1c1d7e
          }
      Packit 1c1d7e
      Packit 1c1d7e
          if ( r == 0 && sortBy != QDir::Unsorted ) {
      Packit 1c1d7e
      	// Still not sorted - sort by name
      Packit 1c1d7e
      	bool ic = qt_cmp_si_sortSpec & QDir::IgnoreCase;
      Packit 1c1d7e
      Packit 1c1d7e
      	if ( f1->filename_cache.isNull() )
      Packit 1c1d7e
      	    f1->filename_cache = ic ? f1->item->fileName().lower()
      Packit 1c1d7e
      				    : f1->item->fileName();
      Packit 1c1d7e
      	if ( f2->filename_cache.isNull() )
      Packit 1c1d7e
      	    f2->filename_cache = ic ? f2->item->fileName().lower()
      Packit 1c1d7e
      				    : f2->item->fileName();
      Packit 1c1d7e
      Packit 1c1d7e
      	r = f1->filename_cache.compare(f2->filename_cache);
      Packit 1c1d7e
          }
      Packit 1c1d7e
      Packit 1c1d7e
          if ( r == 0 ) {
      Packit 1c1d7e
      	// Enforce an order - the order the items appear in the array
      Packit 1c1d7e
      	r = (int)((char*)n1 - (char*)n2);
      Packit 1c1d7e
          }
      Packit 1c1d7e
      Packit 1c1d7e
          if ( qt_cmp_si_sortSpec & QDir::Reversed )
      Packit 1c1d7e
      	return -r;
      Packit 1c1d7e
          else
      Packit 1c1d7e
      	return r;
      Packit 1c1d7e
      }
      Packit 1c1d7e
      Packit 1c1d7e
      #if defined(Q_C_CALLBACKS)
      Packit 1c1d7e
      }
      Packit 1c1d7e
      #endif
      Packit 1c1d7e
      Packit 1c1d7e
      #endif // QT_NO_DIR