0
|
1 |
/****************************************************************************
|
|
2 |
**
|
|
3 |
** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
|
4 |
** All rights reserved.
|
|
5 |
** Contact: Nokia Corporation (qt-info@nokia.com)
|
|
6 |
**
|
|
7 |
** This file is part of the QtCore module of the Qt Toolkit.
|
|
8 |
**
|
|
9 |
** $QT_BEGIN_LICENSE:LGPL$
|
|
10 |
** No Commercial Usage
|
|
11 |
** This file contains pre-release code and may not be distributed.
|
|
12 |
** You may use this file in accordance with the terms and conditions
|
|
13 |
** contained in the Technology Preview License Agreement accompanying
|
|
14 |
** this package.
|
|
15 |
**
|
|
16 |
** GNU Lesser General Public License Usage
|
|
17 |
** Alternatively, this file may be used under the terms of the GNU Lesser
|
|
18 |
** General Public License version 2.1 as published by the Free Software
|
|
19 |
** Foundation and appearing in the file LICENSE.LGPL included in the
|
|
20 |
** packaging of this file. Please review the following information to
|
|
21 |
** ensure the GNU Lesser General Public License version 2.1 requirements
|
|
22 |
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
|
23 |
**
|
|
24 |
** In addition, as a special exception, Nokia gives you certain additional
|
|
25 |
** rights. These rights are described in the Nokia Qt LGPL Exception
|
|
26 |
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
27 |
**
|
|
28 |
** If you have questions regarding the use of this file, please contact
|
|
29 |
** Nokia at qt-info@nokia.com.
|
|
30 |
**
|
|
31 |
**
|
|
32 |
**
|
|
33 |
**
|
|
34 |
**
|
|
35 |
**
|
|
36 |
**
|
|
37 |
**
|
|
38 |
** $QT_END_LICENSE$
|
|
39 |
**
|
|
40 |
****************************************************************************/
|
|
41 |
|
|
42 |
#ifndef QDIR_H
|
|
43 |
#define QDIR_H
|
|
44 |
|
|
45 |
#include <QtCore/qstring.h>
|
|
46 |
#include <QtCore/qfileinfo.h>
|
|
47 |
#include <QtCore/qstringlist.h>
|
|
48 |
#include <QtCore/qscopedpointer.h>
|
|
49 |
|
|
50 |
QT_BEGIN_HEADER
|
|
51 |
|
|
52 |
QT_BEGIN_NAMESPACE
|
|
53 |
|
|
54 |
QT_MODULE(Core)
|
|
55 |
|
|
56 |
class QDirPrivate;
|
|
57 |
|
|
58 |
class Q_CORE_EXPORT QDir
|
|
59 |
{
|
|
60 |
protected:
|
|
61 |
QScopedPointer<QDirPrivate> d_ptr;
|
|
62 |
private:
|
|
63 |
Q_DECLARE_PRIVATE(QDir)
|
|
64 |
public:
|
|
65 |
enum Filter { Dirs = 0x001,
|
|
66 |
Files = 0x002,
|
|
67 |
Drives = 0x004,
|
|
68 |
NoSymLinks = 0x008,
|
|
69 |
AllEntries = Dirs | Files | Drives,
|
|
70 |
TypeMask = 0x00f,
|
|
71 |
#ifdef QT3_SUPPORT
|
|
72 |
All = AllEntries,
|
|
73 |
#endif
|
|
74 |
|
|
75 |
Readable = 0x010,
|
|
76 |
Writable = 0x020,
|
|
77 |
Executable = 0x040,
|
|
78 |
PermissionMask = 0x070,
|
|
79 |
#ifdef QT3_SUPPORT
|
|
80 |
RWEMask = 0x070,
|
|
81 |
#endif
|
|
82 |
|
|
83 |
Modified = 0x080,
|
|
84 |
Hidden = 0x100,
|
|
85 |
System = 0x200,
|
|
86 |
|
|
87 |
AccessMask = 0x3F0,
|
|
88 |
|
|
89 |
AllDirs = 0x400,
|
|
90 |
CaseSensitive = 0x800,
|
|
91 |
NoDotAndDotDot = 0x1000,
|
|
92 |
|
|
93 |
NoFilter = -1
|
|
94 |
#ifdef QT3_SUPPORT
|
|
95 |
,DefaultFilter = NoFilter
|
|
96 |
#endif
|
|
97 |
};
|
|
98 |
Q_DECLARE_FLAGS(Filters, Filter)
|
|
99 |
#ifdef QT3_SUPPORT
|
|
100 |
typedef Filters FilterSpec;
|
|
101 |
#endif
|
|
102 |
|
|
103 |
enum SortFlag { Name = 0x00,
|
|
104 |
Time = 0x01,
|
|
105 |
Size = 0x02,
|
|
106 |
Unsorted = 0x03,
|
|
107 |
SortByMask = 0x03,
|
|
108 |
|
|
109 |
DirsFirst = 0x04,
|
|
110 |
Reversed = 0x08,
|
|
111 |
IgnoreCase = 0x10,
|
|
112 |
DirsLast = 0x20,
|
|
113 |
LocaleAware = 0x40,
|
|
114 |
Type = 0x80,
|
|
115 |
NoSort = -1
|
|
116 |
#ifdef QT3_SUPPORT
|
|
117 |
,DefaultSort = NoSort
|
|
118 |
#endif
|
|
119 |
};
|
|
120 |
Q_DECLARE_FLAGS(SortFlags, SortFlag)
|
|
121 |
|
|
122 |
QDir(const QDir &);
|
|
123 |
QDir(const QString &path = QString());
|
|
124 |
QDir(const QString &path, const QString &nameFilter,
|
|
125 |
SortFlags sort = SortFlags(Name | IgnoreCase), Filters filter = AllEntries);
|
|
126 |
~QDir();
|
|
127 |
|
|
128 |
QDir &operator=(const QDir &);
|
|
129 |
QDir &operator=(const QString &path);
|
|
130 |
|
|
131 |
void setPath(const QString &path);
|
|
132 |
QString path() const;
|
|
133 |
QString absolutePath() const;
|
|
134 |
QString canonicalPath() const;
|
|
135 |
|
|
136 |
static void addResourceSearchPath(const QString &path);
|
|
137 |
|
|
138 |
static void setSearchPaths(const QString &prefix, const QStringList &searchPaths);
|
|
139 |
static void addSearchPath(const QString &prefix, const QString &path);
|
|
140 |
static QStringList searchPaths(const QString &prefix);
|
|
141 |
|
|
142 |
QString dirName() const;
|
|
143 |
QString filePath(const QString &fileName) const;
|
|
144 |
QString absoluteFilePath(const QString &fileName) const;
|
|
145 |
QString relativeFilePath(const QString &fileName) const;
|
|
146 |
|
|
147 |
#ifdef QT_DEPRECATED
|
|
148 |
QT_DEPRECATED static QString convertSeparators(const QString &pathName);
|
|
149 |
#endif
|
|
150 |
static QString toNativeSeparators(const QString &pathName);
|
|
151 |
static QString fromNativeSeparators(const QString &pathName);
|
|
152 |
|
|
153 |
bool cd(const QString &dirName);
|
|
154 |
bool cdUp();
|
|
155 |
|
|
156 |
QStringList nameFilters() const;
|
|
157 |
void setNameFilters(const QStringList &nameFilters);
|
|
158 |
|
|
159 |
Filters filter() const;
|
|
160 |
void setFilter(Filters filter);
|
|
161 |
SortFlags sorting() const;
|
|
162 |
void setSorting(SortFlags sort);
|
|
163 |
|
|
164 |
uint count() const;
|
|
165 |
QString operator[](int) const;
|
|
166 |
|
|
167 |
static QStringList nameFiltersFromString(const QString &nameFilter);
|
|
168 |
|
|
169 |
QStringList entryList(Filters filters = NoFilter, SortFlags sort = NoSort) const;
|
|
170 |
QStringList entryList(const QStringList &nameFilters, Filters filters = NoFilter,
|
|
171 |
SortFlags sort = NoSort) const;
|
|
172 |
|
|
173 |
QFileInfoList entryInfoList(Filters filters = NoFilter, SortFlags sort = NoSort) const;
|
|
174 |
QFileInfoList entryInfoList(const QStringList &nameFilters, Filters filters = NoFilter,
|
|
175 |
SortFlags sort = NoSort) const;
|
|
176 |
|
|
177 |
bool mkdir(const QString &dirName) const;
|
|
178 |
bool rmdir(const QString &dirName) const;
|
|
179 |
bool mkpath(const QString &dirPath) const;
|
|
180 |
bool rmpath(const QString &dirPath) const;
|
|
181 |
|
|
182 |
bool isReadable() const;
|
|
183 |
bool exists() const;
|
|
184 |
bool isRoot() const;
|
|
185 |
|
|
186 |
static bool isRelativePath(const QString &path);
|
|
187 |
inline static bool isAbsolutePath(const QString &path) { return !isRelativePath(path); }
|
|
188 |
bool isRelative() const;
|
|
189 |
inline bool isAbsolute() const { return !isRelative(); }
|
|
190 |
bool makeAbsolute();
|
|
191 |
|
|
192 |
bool operator==(const QDir &dir) const;
|
|
193 |
inline bool operator!=(const QDir &dir) const { return !operator==(dir); }
|
|
194 |
|
|
195 |
bool remove(const QString &fileName);
|
|
196 |
bool rename(const QString &oldName, const QString &newName);
|
|
197 |
bool exists(const QString &name) const;
|
|
198 |
|
|
199 |
static QFileInfoList drives();
|
|
200 |
|
|
201 |
static QChar separator();
|
|
202 |
|
|
203 |
static bool setCurrent(const QString &path);
|
|
204 |
static inline QDir current() { return QDir(currentPath()); }
|
|
205 |
static QString currentPath();
|
|
206 |
|
|
207 |
static inline QDir home() { return QDir(homePath()); }
|
|
208 |
static QString homePath();
|
|
209 |
static inline QDir root() { return QDir(rootPath()); }
|
|
210 |
static QString rootPath();
|
|
211 |
static inline QDir temp() { return QDir(tempPath()); }
|
|
212 |
static QString tempPath();
|
|
213 |
|
|
214 |
#ifndef QT_NO_REGEXP
|
|
215 |
static bool match(const QStringList &filters, const QString &fileName);
|
|
216 |
static bool match(const QString &filter, const QString &fileName);
|
|
217 |
#endif
|
|
218 |
static QString cleanPath(const QString &path);
|
|
219 |
void refresh() const;
|
|
220 |
|
|
221 |
#ifdef QT3_SUPPORT
|
|
222 |
typedef SortFlags SortSpec;
|
|
223 |
inline QT3_SUPPORT QString absPath() const { return absolutePath(); }
|
|
224 |
inline QT3_SUPPORT QString absFilePath(const QString &fileName, bool acceptAbsPath = true) const
|
|
225 |
{ Q_UNUSED(acceptAbsPath); return absoluteFilePath(fileName); }
|
|
226 |
QT3_SUPPORT bool matchAllDirs() const;
|
|
227 |
QT3_SUPPORT void setMatchAllDirs(bool on);
|
|
228 |
inline QT3_SUPPORT QStringList entryList(const QString &nameFilter, Filters filters = NoFilter,
|
|
229 |
SortFlags sort = NoSort) const
|
|
230 |
{ return entryList(nameFiltersFromString(nameFilter), filters, sort); }
|
|
231 |
inline QT3_SUPPORT QFileInfoList entryInfoList(const QString &nameFilter,
|
|
232 |
Filters filters = NoFilter,
|
|
233 |
SortFlags sort = NoSort) const
|
|
234 |
{ return entryInfoList(nameFiltersFromString(nameFilter), filters, sort); }
|
|
235 |
|
|
236 |
QT3_SUPPORT QString nameFilter() const;
|
|
237 |
QT3_SUPPORT void setNameFilter(const QString &nameFilter);
|
|
238 |
|
|
239 |
inline QT3_SUPPORT bool mkdir(const QString &dirName, bool acceptAbsPath) const
|
|
240 |
{ Q_UNUSED(acceptAbsPath); return mkdir(dirName); }
|
|
241 |
inline QT3_SUPPORT bool rmdir(const QString &dirName, bool acceptAbsPath) const
|
|
242 |
{ Q_UNUSED(acceptAbsPath); return rmdir(dirName); }
|
|
243 |
|
|
244 |
inline QT3_SUPPORT void convertToAbs() { makeAbsolute(); }
|
|
245 |
inline QT3_SUPPORT static QString currentDirPath() { return currentPath(); }
|
|
246 |
inline QT3_SUPPORT static QString homeDirPath() { return homePath(); }
|
|
247 |
inline QT3_SUPPORT static QString rootDirPath() { return rootPath(); }
|
|
248 |
inline QT3_SUPPORT static QString cleanDirPath(const QString &name) { return cleanPath(name); }
|
|
249 |
#endif
|
|
250 |
};
|
|
251 |
|
|
252 |
Q_DECLARE_OPERATORS_FOR_FLAGS(QDir::Filters)
|
|
253 |
Q_DECLARE_OPERATORS_FOR_FLAGS(QDir::SortFlags)
|
|
254 |
|
|
255 |
#ifndef QT_NO_DEBUG_STREAM
|
|
256 |
class QDebug;
|
|
257 |
Q_CORE_EXPORT QDebug operator<<(QDebug debug, QDir::Filters filters);
|
|
258 |
Q_CORE_EXPORT QDebug operator<<(QDebug debug, const QDir &dir);
|
|
259 |
#endif
|
|
260 |
|
|
261 |
QT_END_NAMESPACE
|
|
262 |
|
|
263 |
QT_END_HEADER
|
|
264 |
|
|
265 |
#endif // QDIR_H
|