| 1 | /****************************************************************************
|
|---|
| 2 | ** $Id: qdir.h 2 2005-11-16 15:49:26Z dmik $
|
|---|
| 3 | **
|
|---|
| 4 | ** Definition of QDir class
|
|---|
| 5 | **
|
|---|
| 6 | ** Created : 950427
|
|---|
| 7 | **
|
|---|
| 8 | ** Copyright (C) 1992-2002 Trolltech AS. All rights reserved.
|
|---|
| 9 | **
|
|---|
| 10 | ** This file is part of the tools module of the Qt GUI Toolkit.
|
|---|
| 11 | **
|
|---|
| 12 | ** This file may be distributed under the terms of the Q Public License
|
|---|
| 13 | ** as defined by Trolltech AS of Norway and appearing in the file
|
|---|
| 14 | ** LICENSE.QPL included in the packaging of this file.
|
|---|
| 15 | **
|
|---|
| 16 | ** This file may be distributed and/or modified under the terms of the
|
|---|
| 17 | ** GNU General Public License version 2 as published by the Free Software
|
|---|
| 18 | ** Foundation and appearing in the file LICENSE.GPL included in the
|
|---|
| 19 | ** packaging of this file.
|
|---|
| 20 | **
|
|---|
| 21 | ** Licensees holding valid Qt Enterprise Edition or Qt Professional Edition
|
|---|
| 22 | ** licenses may use this file in accordance with the Qt Commercial License
|
|---|
| 23 | ** Agreement provided with the Software.
|
|---|
| 24 | **
|
|---|
| 25 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
|
|---|
| 26 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
|---|
| 27 | **
|
|---|
| 28 | ** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
|
|---|
| 29 | ** information about Qt Commercial License Agreements.
|
|---|
| 30 | ** See http://www.trolltech.com/qpl/ for QPL licensing information.
|
|---|
| 31 | ** See http://www.trolltech.com/gpl/ for GPL licensing information.
|
|---|
| 32 | **
|
|---|
| 33 | ** Contact info@trolltech.com if any conditions of this licensing are
|
|---|
| 34 | ** not clear to you.
|
|---|
| 35 | **
|
|---|
| 36 | **********************************************************************/
|
|---|
| 37 |
|
|---|
| 38 | #ifndef QDIR_H
|
|---|
| 39 | #define QDIR_H
|
|---|
| 40 |
|
|---|
| 41 | #ifndef QT_H
|
|---|
| 42 | #include "qglobal.h"
|
|---|
| 43 | #include "qstrlist.h"
|
|---|
| 44 | #include "qfileinfo.h"
|
|---|
| 45 | #endif // QT_H
|
|---|
| 46 |
|
|---|
| 47 |
|
|---|
| 48 | #ifndef QT_NO_DIR
|
|---|
| 49 | typedef QPtrList<QFileInfo> QFileInfoList;
|
|---|
| 50 | typedef QPtrListIterator<QFileInfo> QFileInfoListIterator;
|
|---|
| 51 | class QStringList;
|
|---|
| 52 | template <class T> class QDeepCopy;
|
|---|
| 53 |
|
|---|
| 54 |
|
|---|
| 55 | class Q_EXPORT QDir
|
|---|
| 56 | {
|
|---|
| 57 | public:
|
|---|
| 58 | enum FilterSpec { Dirs = 0x001,
|
|---|
| 59 | Files = 0x002,
|
|---|
| 60 | Drives = 0x004,
|
|---|
| 61 | NoSymLinks = 0x008,
|
|---|
| 62 | All = 0x007,
|
|---|
| 63 | TypeMask = 0x00F,
|
|---|
| 64 |
|
|---|
| 65 | Readable = 0x010,
|
|---|
| 66 | Writable = 0x020,
|
|---|
| 67 | Executable = 0x040,
|
|---|
| 68 | RWEMask = 0x070,
|
|---|
| 69 |
|
|---|
| 70 | Modified = 0x080,
|
|---|
| 71 | Hidden = 0x100,
|
|---|
| 72 | System = 0x200,
|
|---|
| 73 | AccessMask = 0x3F0,
|
|---|
| 74 |
|
|---|
| 75 | DefaultFilter = -1 };
|
|---|
| 76 |
|
|---|
| 77 | enum SortSpec { Name = 0x00,
|
|---|
| 78 | Time = 0x01,
|
|---|
| 79 | Size = 0x02,
|
|---|
| 80 | Unsorted = 0x03,
|
|---|
| 81 | SortByMask = 0x03,
|
|---|
| 82 |
|
|---|
| 83 | DirsFirst = 0x04,
|
|---|
| 84 | Reversed = 0x08,
|
|---|
| 85 | IgnoreCase = 0x10,
|
|---|
| 86 | DefaultSort = -1 };
|
|---|
| 87 |
|
|---|
| 88 | QDir();
|
|---|
| 89 | QDir( const QString &path, const QString &nameFilter = QString::null,
|
|---|
| 90 | int sortSpec = Name | IgnoreCase, int filterSpec = All );
|
|---|
| 91 | QDir( const QDir & );
|
|---|
| 92 |
|
|---|
| 93 | virtual ~QDir();
|
|---|
| 94 |
|
|---|
| 95 | QDir &operator=( const QDir & );
|
|---|
| 96 | QDir &operator=( const QString &path );
|
|---|
| 97 |
|
|---|
| 98 | virtual void setPath( const QString &path );
|
|---|
| 99 | virtual QString path() const;
|
|---|
| 100 | virtual QString absPath() const;
|
|---|
| 101 | virtual QString canonicalPath() const;
|
|---|
| 102 |
|
|---|
| 103 | virtual QString dirName() const;
|
|---|
| 104 | virtual QString filePath( const QString &fileName,
|
|---|
| 105 | bool acceptAbsPath = TRUE ) const;
|
|---|
| 106 | virtual QString absFilePath( const QString &fileName,
|
|---|
| 107 | bool acceptAbsPath = TRUE ) const;
|
|---|
| 108 |
|
|---|
| 109 | static QString convertSeparators( const QString &pathName );
|
|---|
| 110 |
|
|---|
| 111 | virtual bool cd( const QString &dirName, bool acceptAbsPath = TRUE );
|
|---|
| 112 | virtual bool cdUp();
|
|---|
| 113 |
|
|---|
| 114 | QString nameFilter() const;
|
|---|
| 115 | virtual void setNameFilter( const QString &nameFilter );
|
|---|
| 116 | FilterSpec filter() const;
|
|---|
| 117 | virtual void setFilter( int filterSpec );
|
|---|
| 118 | SortSpec sorting() const;
|
|---|
| 119 | virtual void setSorting( int sortSpec );
|
|---|
| 120 |
|
|---|
| 121 | bool matchAllDirs() const;
|
|---|
| 122 | virtual void setMatchAllDirs( bool );
|
|---|
| 123 |
|
|---|
| 124 | uint count() const;
|
|---|
| 125 | QString operator[]( int ) const;
|
|---|
| 126 |
|
|---|
| 127 | virtual QStrList encodedEntryList( int filterSpec = DefaultFilter,
|
|---|
| 128 | int sortSpec = DefaultSort ) const;
|
|---|
| 129 | virtual QStrList encodedEntryList( const QString &nameFilter,
|
|---|
| 130 | int filterSpec = DefaultFilter,
|
|---|
| 131 | int sortSpec = DefaultSort ) const;
|
|---|
| 132 | virtual QStringList entryList( int filterSpec = DefaultFilter,
|
|---|
| 133 | int sortSpec = DefaultSort ) const;
|
|---|
| 134 | virtual QStringList entryList( const QString &nameFilter,
|
|---|
| 135 | int filterSpec = DefaultFilter,
|
|---|
| 136 | int sortSpec = DefaultSort ) const;
|
|---|
| 137 |
|
|---|
| 138 | virtual const QFileInfoList *entryInfoList( int filterSpec = DefaultFilter,
|
|---|
| 139 | int sortSpec = DefaultSort ) const;
|
|---|
| 140 | virtual const QFileInfoList *entryInfoList( const QString &nameFilter,
|
|---|
| 141 | int filterSpec = DefaultFilter,
|
|---|
| 142 | int sortSpec = DefaultSort ) const;
|
|---|
| 143 |
|
|---|
| 144 | static const QFileInfoList *drives();
|
|---|
| 145 |
|
|---|
| 146 | virtual bool mkdir( const QString &dirName,
|
|---|
| 147 | bool acceptAbsPath = TRUE ) const;
|
|---|
| 148 | virtual bool rmdir( const QString &dirName,
|
|---|
| 149 | bool acceptAbsPath = TRUE ) const;
|
|---|
| 150 |
|
|---|
| 151 | virtual bool isReadable() const;
|
|---|
| 152 | virtual bool exists() const;
|
|---|
| 153 | virtual bool isRoot() const;
|
|---|
| 154 |
|
|---|
| 155 | virtual bool isRelative() const;
|
|---|
| 156 | virtual void convertToAbs();
|
|---|
| 157 |
|
|---|
| 158 | virtual bool operator==( const QDir & ) const;
|
|---|
| 159 | virtual bool operator!=( const QDir & ) const;
|
|---|
| 160 |
|
|---|
| 161 | virtual bool remove( const QString &fileName,
|
|---|
| 162 | bool acceptAbsPath = TRUE );
|
|---|
| 163 | virtual bool rename( const QString &name, const QString &newName,
|
|---|
| 164 | bool acceptAbsPaths = TRUE );
|
|---|
| 165 | virtual bool exists( const QString &name,
|
|---|
| 166 | bool acceptAbsPath = TRUE );
|
|---|
| 167 |
|
|---|
| 168 | static char separator();
|
|---|
| 169 |
|
|---|
| 170 | static bool setCurrent( const QString &path );
|
|---|
| 171 | static QDir current();
|
|---|
| 172 | static QDir home();
|
|---|
| 173 | static QDir root();
|
|---|
| 174 | static QString currentDirPath();
|
|---|
| 175 | static QString homeDirPath();
|
|---|
| 176 | static QString rootDirPath();
|
|---|
| 177 |
|
|---|
| 178 | static bool match( const QStringList &filters, const QString &fileName );
|
|---|
| 179 | static bool match( const QString &filter, const QString &fileName );
|
|---|
| 180 | static QString cleanDirPath( const QString &dirPath );
|
|---|
| 181 | static bool isRelativePath( const QString &path );
|
|---|
| 182 | void refresh() const;
|
|---|
| 183 |
|
|---|
| 184 | private:
|
|---|
| 185 | #ifdef Q_OS_MAC
|
|---|
| 186 | typedef struct FSSpec FSSpec;
|
|---|
| 187 | static FSSpec *make_spec(const QString &);
|
|---|
| 188 | #endif
|
|---|
| 189 | void init();
|
|---|
| 190 | virtual bool readDirEntries( const QString &nameFilter,
|
|---|
| 191 | int FilterSpec, int SortSpec );
|
|---|
| 192 |
|
|---|
| 193 | static void slashify( QString & );
|
|---|
| 194 |
|
|---|
| 195 | QString dPath;
|
|---|
| 196 | QStringList *fList;
|
|---|
| 197 | QFileInfoList *fiList;
|
|---|
| 198 | QString nameFilt;
|
|---|
| 199 | FilterSpec filtS;
|
|---|
| 200 | SortSpec sortS;
|
|---|
| 201 | uint dirty : 1;
|
|---|
| 202 | uint allDirs : 1;
|
|---|
| 203 |
|
|---|
| 204 | void detach();
|
|---|
| 205 | friend class QDeepCopy< QDir >;
|
|---|
| 206 | };
|
|---|
| 207 |
|
|---|
| 208 |
|
|---|
| 209 | inline QString QDir::path() const
|
|---|
| 210 | {
|
|---|
| 211 | return dPath;
|
|---|
| 212 | }
|
|---|
| 213 |
|
|---|
| 214 | inline QString QDir::nameFilter() const
|
|---|
| 215 | {
|
|---|
| 216 | return nameFilt;
|
|---|
| 217 | }
|
|---|
| 218 |
|
|---|
| 219 | inline QDir::FilterSpec QDir::filter() const
|
|---|
| 220 | {
|
|---|
| 221 | return filtS;
|
|---|
| 222 | }
|
|---|
| 223 |
|
|---|
| 224 | inline QDir::SortSpec QDir::sorting() const
|
|---|
| 225 | {
|
|---|
| 226 | return sortS;
|
|---|
| 227 | }
|
|---|
| 228 |
|
|---|
| 229 | inline bool QDir::matchAllDirs() const
|
|---|
| 230 | {
|
|---|
| 231 | return allDirs;
|
|---|
| 232 | }
|
|---|
| 233 |
|
|---|
| 234 | inline bool QDir::operator!=( const QDir &d ) const
|
|---|
| 235 | {
|
|---|
| 236 | return !(*this == d);
|
|---|
| 237 | }
|
|---|
| 238 |
|
|---|
| 239 |
|
|---|
| 240 | struct QDirSortItem {
|
|---|
| 241 | QString filename_cache;
|
|---|
| 242 | QFileInfo* item;
|
|---|
| 243 | };
|
|---|
| 244 |
|
|---|
| 245 | #endif // QT_NO_DIR
|
|---|
| 246 | #endif // QDIR_H
|
|---|