1 /****************************************************************************
2 ** $Id: qt/qdir.h 3.3.8 edited Jan 11 14:38 $
3 **
4 ** Definition of QDir class
5 **
6 ** Created : 950427
7 **
8 ** Copyright (C) 1992-2007 Trolltech ASA. 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 ASA 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 LocaleAware = 0x20,
87 DefaultSort = -1 };
88
89 QDir();
90 QDir( const QString &path, const QString &nameFilter = QString::null,
91 int sortSpec = Name | IgnoreCase, int filterSpec = All );
92 QDir( const QDir & );
93
94 virtual ~QDir();
95
96 QDir &operator=( const QDir & );
97 QDir &operator=( const QString &path );
98
99 virtual void setPath( const QString &path );
100 virtual QString path() const;
101 virtual QString absPath() const;
102 virtual QString canonicalPath() const;
103
104 virtual QString dirName() const;
105 virtual QString filePath( const QString &fileName,
106 bool acceptAbsPath = TRUE ) const;
107 virtual QString absFilePath( const QString &fileName,
108 bool acceptAbsPath = TRUE ) const;
109
110 static QString convertSeparators( const QString &pathName );
111
112 virtual bool cd( const QString &dirName, bool acceptAbsPath = TRUE );
113 virtual bool cdUp();
114
115 QString nameFilter() const;
116 virtual void setNameFilter( const QString &nameFilter );
117 FilterSpec filter() const;
118 virtual void setFilter( int filterSpec );
119 SortSpec sorting() const;
120 virtual void setSorting( int sortSpec );
121
122 bool matchAllDirs() const;
123 virtual void setMatchAllDirs( bool );
124
125 uint count() const;
126 QString operator[]( int ) const;
127
128 virtual QStrList encodedEntryList( int filterSpec = DefaultFilter,
129 int sortSpec = DefaultSort ) const;
130 virtual QStrList encodedEntryList( const QString &nameFilter,
131 int filterSpec = DefaultFilter,
132 int sortSpec = DefaultSort ) const;
133 virtual QStringList entryList( int filterSpec = DefaultFilter,
134 int sortSpec = DefaultSort ) const;
135 virtual QStringList entryList( const QString &nameFilter,
136 int filterSpec = DefaultFilter,
137 int sortSpec = DefaultSort ) const;
138
139 virtual const QFileInfoList *entryInfoList( int filterSpec = DefaultFilter,
140 int sortSpec = DefaultSort ) const;
141 virtual const QFileInfoList *entryInfoList( const QString &nameFilter,
142 int filterSpec = DefaultFilter,
143 int sortSpec = DefaultSort ) const;
144
145 static const QFileInfoList *drives();
146
147 virtual bool mkdir( const QString &dirName,
148 bool acceptAbsPath = TRUE ) const;
149 virtual bool rmdir( const QString &dirName,
150 bool acceptAbsPath = TRUE ) const;
151
152 virtual bool isReadable() const;
153 virtual bool exists() const;
154 virtual bool isRoot() const;
155
156 virtual bool isRelative() const;
157 virtual void convertToAbs();
158
159 virtual bool operator==( const QDir & ) const;
160 virtual bool operator!=( const QDir & ) const;
161
162 virtual bool remove( const QString &fileName,
163 bool acceptAbsPath = TRUE );
164 virtual bool rename( const QString &name, const QString &newName,
165 bool acceptAbsPaths = TRUE );
166 virtual bool exists( const QString &name,
167 bool acceptAbsPath = TRUE );
168
169 static char separator();
170
171 static bool setCurrent( const QString &path );
172 static QDir current();
173 static QDir home();
174 static QDir root();
175 static QString currentDirPath();
176 static QString homeDirPath();
177 static QString rootDirPath();
178
179 static bool match( const QStringList &filters, const QString &fileName );
180 static bool match( const QString &filter, const QString &fileName );
181 static QString cleanDirPath( const QString &dirPath );
182 static bool isRelativePath( const QString &path );
183 void refresh() const;
184
185 private:
186 #ifdef Q_OS_MAC
187 typedef struct FSSpec FSSpec;
188 static FSSpec *make_spec(const QString &);
189 #endif
190 void init();
191 virtual bool readDirEntries( const QString &nameFilter,
192 int FilterSpec, int SortSpec );
193
194 static void slashify( QString & );
195
196 QString dPath;
197 QStringList *fList;
198 QFileInfoList *fiList;
199 QString nameFilt;
200 FilterSpec filtS;
201 SortSpec sortS;
202 uint dirty : 1;
203 uint allDirs : 1;
204
205 void detach();
206 friend class QDeepCopy< QDir >;
207 };
208
209
path()210 inline QString QDir::path() const
211 {
212 return dPath;
213 }
214
nameFilter()215 inline QString QDir::nameFilter() const
216 {
217 return nameFilt;
218 }
219
filter()220 inline QDir::FilterSpec QDir::filter() const
221 {
222 return filtS;
223 }
224
sorting()225 inline QDir::SortSpec QDir::sorting() const
226 {
227 return sortS;
228 }
229
matchAllDirs()230 inline bool QDir::matchAllDirs() const
231 {
232 return allDirs;
233 }
234
235 inline bool QDir::operator!=( const QDir &d ) const
236 {
237 return !(*this == d);
238 }
239
240
241 struct QDirSortItem {
242 QString filename_cache;
243 QFileInfo* item;
244 };
245
246 #endif // QT_NO_DIR
247 #endif // QDIR_H
248