1 | /****************************************************************************
|
---|
2 | **
|
---|
3 | ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
|
---|
4 | ** All rights reserved.
|
---|
5 | ** Contact: Nokia Corporation ([email protected])
|
---|
6 | **
|
---|
7 | ** This file is part of the QtCore module of the Qt Toolkit.
|
---|
8 | **
|
---|
9 | ** $QT_BEGIN_LICENSE:LGPL$
|
---|
10 | ** Commercial Usage
|
---|
11 | ** Licensees holding valid Qt Commercial licenses may use this file in
|
---|
12 | ** accordance with the Qt Commercial License Agreement provided with the
|
---|
13 | ** Software or, alternatively, in accordance with the terms contained in
|
---|
14 | ** a written agreement between you and Nokia.
|
---|
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 | ** GNU General Public License Usage
|
---|
29 | ** Alternatively, this file may be used under the terms of the GNU
|
---|
30 | ** General Public License version 3.0 as published by the Free Software
|
---|
31 | ** Foundation and appearing in the file LICENSE.GPL included in the
|
---|
32 | ** packaging of this file. Please review the following information to
|
---|
33 | ** ensure the GNU General Public License version 3.0 requirements will be
|
---|
34 | ** met: http://www.gnu.org/copyleft/gpl.html.
|
---|
35 | **
|
---|
36 | ** If you have questions regarding the use of this file, please contact
|
---|
37 | ** Nokia at [email protected].
|
---|
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 |
|
---|
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 | QSharedDataPointer<QDirPrivate> d_ptr;
|
---|
62 |
|
---|
63 | public:
|
---|
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 |
|
---|
132 | void setPath(const QString &path);
|
---|
133 | QString path() const;
|
---|
134 | QString absolutePath() const;
|
---|
135 | QString canonicalPath() const;
|
---|
136 |
|
---|
137 | static void addResourceSearchPath(const QString &path);
|
---|
138 |
|
---|
139 | static void setSearchPaths(const QString &prefix, const QStringList &searchPaths);
|
---|
140 | static void addSearchPath(const QString &prefix, const QString &path);
|
---|
141 | static QStringList searchPaths(const QString &prefix);
|
---|
142 |
|
---|
143 | QString dirName() const;
|
---|
144 | QString filePath(const QString &fileName) const;
|
---|
145 | QString absoluteFilePath(const QString &fileName) const;
|
---|
146 | QString relativeFilePath(const QString &fileName) const;
|
---|
147 |
|
---|
148 | #ifdef QT_DEPRECATED
|
---|
149 | QT_DEPRECATED static QString convertSeparators(const QString &pathName);
|
---|
150 | #endif
|
---|
151 | static QString toNativeSeparators(const QString &pathName);
|
---|
152 | static QString fromNativeSeparators(const QString &pathName);
|
---|
153 |
|
---|
154 | bool cd(const QString &dirName);
|
---|
155 | bool cdUp();
|
---|
156 |
|
---|
157 | QStringList nameFilters() const;
|
---|
158 | void setNameFilters(const QStringList &nameFilters);
|
---|
159 |
|
---|
160 | Filters filter() const;
|
---|
161 | void setFilter(Filters filter);
|
---|
162 | SortFlags sorting() const;
|
---|
163 | void setSorting(SortFlags sort);
|
---|
164 |
|
---|
165 | uint count() const;
|
---|
166 | QString operator[](int) const;
|
---|
167 |
|
---|
168 | static QStringList nameFiltersFromString(const QString &nameFilter);
|
---|
169 |
|
---|
170 | QStringList entryList(Filters filters = NoFilter, SortFlags sort = NoSort) const;
|
---|
171 | QStringList entryList(const QStringList &nameFilters, Filters filters = NoFilter,
|
---|
172 | SortFlags sort = NoSort) const;
|
---|
173 |
|
---|
174 | QFileInfoList entryInfoList(Filters filters = NoFilter, SortFlags sort = NoSort) const;
|
---|
175 | QFileInfoList entryInfoList(const QStringList &nameFilters, Filters filters = NoFilter,
|
---|
176 | SortFlags sort = NoSort) const;
|
---|
177 |
|
---|
178 | bool mkdir(const QString &dirName) const;
|
---|
179 | bool rmdir(const QString &dirName) const;
|
---|
180 | bool mkpath(const QString &dirPath) const;
|
---|
181 | bool rmpath(const QString &dirPath) const;
|
---|
182 |
|
---|
183 | bool isReadable() const;
|
---|
184 | bool exists() const;
|
---|
185 | bool isRoot() const;
|
---|
186 |
|
---|
187 | static bool isRelativePath(const QString &path);
|
---|
188 | inline static bool isAbsolutePath(const QString &path) { return !isRelativePath(path); }
|
---|
189 | bool isRelative() const;
|
---|
190 | inline bool isAbsolute() const { return !isRelative(); }
|
---|
191 | bool makeAbsolute();
|
---|
192 |
|
---|
193 | bool operator==(const QDir &dir) const;
|
---|
194 | inline bool operator!=(const QDir &dir) const { return !operator==(dir); }
|
---|
195 |
|
---|
196 | bool remove(const QString &fileName);
|
---|
197 | bool rename(const QString &oldName, const QString &newName);
|
---|
198 | bool exists(const QString &name) const;
|
---|
199 |
|
---|
200 | static QFileInfoList drives();
|
---|
201 |
|
---|
202 | static QChar separator();
|
---|
203 |
|
---|
204 | static bool setCurrent(const QString &path);
|
---|
205 | static inline QDir current() { return QDir(currentPath()); }
|
---|
206 | static QString currentPath();
|
---|
207 |
|
---|
208 | static inline QDir home() { return QDir(homePath()); }
|
---|
|
---|