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