1 /****************************************************************************
2 **
3 ** DQt - D bindings for the Qt Toolkit
4 **
5 ** GNU Lesser General Public License Usage
6 ** This file may be used under the terms of the GNU Lesser
7 ** General Public License version 3 as published by the Free Software
8 ** Foundation and appearing in the file LICENSE.LGPL3 included in the
9 ** packaging of this file. Please review the following information to
10 ** ensure the GNU Lesser General Public License version 3 requirements
11 ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
12 **
13 ****************************************************************************/
14 module qt.core.dir;
15 extern(C++):
16 
17 import qt.config;
18 import qt.core.fileinfo;
19 import qt.core.flags;
20 import qt.core.qchar;
21 import qt.core.shareddata;
22 import qt.core.string;
23 import qt.core.stringlist;
24 import qt.core.typeinfo;
25 import qt.helpers;
26 
27 /+ class QDirIterator; +/
28 extern(C++, class) struct QDirPrivate;
29 
30 @Q_MOVABLE_TYPE extern(C++, class) struct /+ Q_CORE_EXPORT +/ QDir
31 {
32 public:
33     enum Filter { Dirs        = 0x001,
34                   Files       = 0x002,
35                   Drives      = 0x004,
36                   NoSymLinks  = 0x008,
37                   AllEntries  = Filter.Dirs | Filter.Files | Filter.Drives,
38                   TypeMask    = 0x00f,
39 
40                   Readable    = 0x010,
41                   Writable    = 0x020,
42                   Executable  = 0x040,
43                   PermissionMask    = 0x070,
44 
45                   Modified    = 0x080,
46                   Hidden      = 0x100,
47                   System      = 0x200,
48 
49                   AccessMask  = 0x3F0,
50 
51                   AllDirs       = 0x400,
52                   CaseSensitive = 0x800,
53                   NoDot         = 0x2000,
54                   NoDotDot      = 0x4000,
55                   NoDotAndDotDot = Filter.NoDot | Filter.NoDotDot,
56 
57                   NoFilter = -1
58     }
59     /+ Q_DECLARE_FLAGS(Filters, Filter) +/
60 alias Filters = QFlags!(Filter);
61     enum SortFlag { Name        = 0x00,
62                     Time        = 0x01,
63                     Size        = 0x02,
64                     Unsorted    = 0x03,
65                     SortByMask  = 0x03,
66 
67                     DirsFirst   = 0x04,
68                     Reversed    = 0x08,
69                     IgnoreCase  = 0x10,
70                     DirsLast    = 0x20,
71                     LocaleAware = 0x40,
72                     Type        = 0x80,
73                     NoSort = -1
74     }
75     /+ Q_DECLARE_FLAGS(SortFlags, SortFlag) +/
76 alias SortFlags = QFlags!(SortFlag);
77     @disable this(this);
78     this(ref const(QDir) );
79     @disable this();
80     this(ref const(QString) path/* = globalInitVar!QString*/);
81     this(ref const(QString) path, ref const(QString) nameFilter,
82              SortFlags sort = SortFlags(SortFlag.Name | SortFlag.IgnoreCase), Filters filter = Filter.AllEntries);
83     ~this();
84 
85     /+ref QDir operator =(ref const(QDir) );+/
86 /+ #if QT_DEPRECATED_SINCE(5, 13) +/
87     /+/+ QT_DEPRECATED_X("Use QDir::setPath() instead") +/
88         ref QDir operator =(ref const(QString) path);+/
89 /+ #endif +/
90     /+ QDir &operator=(QDir &&other) noexcept { swap(other); return *this; } +/
91 
92     /+ void swap(QDir &other) noexcept
93     { qSwap(d_ptr, other.d_ptr); } +/
94 
95     void setPath(ref const(QString) path);
96     QString path() const;
97     QString absolutePath() const;
98     QString canonicalPath() const;
99 
100 /+ #if QT_DEPRECATED_SINCE(5, 13) +/
101     /+ QT_DEPRECATED_X("Use QDir::addSearchPath() instead") +/
102         static void addResourceSearchPath(ref const(QString) path);
103 /+ #endif +/
104 
105     static void setSearchPaths(ref const(QString) prefix, ref const(QStringList) searchPaths);
106     static void addSearchPath(ref const(QString) prefix, ref const(QString) path);
107     static QStringList searchPaths(ref const(QString) prefix);
108 
109     QString dirName() const;
110     QString filePath(ref const(QString) fileName) const;
111     QString absoluteFilePath(ref const(QString) fileName) const;
112     QString relativeFilePath(ref const(QString) fileName) const;
113 
114     static QString toNativeSeparators(ref const(QString) pathName);
115     static QString fromNativeSeparators(ref const(QString) pathName);
116 
117     bool cd(ref const(QString) dirName);
118     bool cdUp();
119 
120     QStringList nameFilters() const;
121     void setNameFilters(ref const(QStringList) nameFilters);
122 
123     Filters filter() const;
124     void setFilter(Filters filter);
125     SortFlags sorting() const;
126     void setSorting(SortFlags sort);
127 
128     uint count() const;
129     bool isEmpty(Filters filters = Filters(Filter.AllEntries | Filter.NoDotAndDotDot)) const;
130 
131     QString opIndex(int) const;
132 
133     static QStringList nameFiltersFromString(ref const(QString) nameFilter);
134 
135     QStringList entryList(Filters filters = Filter.NoFilter, SortFlags sort = SortFlag.NoSort) const;
136     QStringList entryList(ref const(QStringList) nameFilters, Filters filters = Filter.NoFilter,
137                               SortFlags sort = SortFlag.NoSort) const;
138 
139     QFileInfoList entryInfoList(Filters filters = Filter.NoFilter, SortFlags sort = SortFlag.NoSort) const;
140     QFileInfoList entryInfoList(ref const(QStringList) nameFilters, Filters filters = Filter.NoFilter,
141                                     SortFlags sort = SortFlag.NoSort) const;
142 
143     bool mkdir(ref const(QString) dirName) const;
144     bool rmdir(ref const(QString) dirName) const;
145     bool mkpath(ref const(QString) dirPath) const;
146     bool rmpath(ref const(QString) dirPath) const;
147 
148     bool removeRecursively();
149 
150     bool isReadable() const;
151     bool exists() const;
152     bool isRoot() const;
153 
154     static bool isRelativePath(ref const(QString) path);
155     pragma(inline, true) static bool isAbsolutePath(ref const(QString) path) { return !isRelativePath(path); }
156     bool isRelative() const;
157     pragma(inline, true) bool isAbsolute() const { return !isRelative(); }
158     bool makeAbsolute();
159 
160     /+bool operator ==(ref const(QDir) dir) const;+/
161     /+pragma(inline, true) bool operator !=(ref const(QDir) dir) const {  return !operator==(dir); }+/
162 
163     bool remove(ref const(QString) fileName);
164     bool rename(ref const(QString) oldName, ref const(QString) newName);
165     bool exists(ref const(QString) name) const;
166 
167     static QFileInfoList drives();
168 
169     pragma(inline, true) static QChar listSeparator()/+ noexcept+/
170     {
171         static if((versionIsSet!("Windows") && !versionIsSet!("Cygwin")))
172         {
173             return QChar(QLatin1Char(';'));
174         }
175         else
176         {
177             return QChar(QLatin1Char(':'));
178         }
179     }
180 
181     static QChar separator(); // ### Qt6: Make it inline
182 
183     static bool setCurrent(ref const(QString) path);
184     pragma(inline, true) static QDir current() { auto tmp = currentPath(); return QDir(tmp); }
185     static QString currentPath();
186 
187     pragma(inline, true) static QDir home() { auto tmp = homePath(); return QDir(tmp); }
188     static QString homePath();
189     pragma(inline, true) static QDir root() { auto tmp = rootPath(); return QDir(tmp); }
190     static QString rootPath();
191     pragma(inline, true) static QDir temp() { auto tmp = tempPath(); return QDir(tmp); }
192     static QString tempPath();
193 
194 /+ #if QT_CONFIG(regularexpression) +/
195     static bool match(ref const(QStringList) filters, ref const(QString) fileName);
196     static bool match(ref const(QString) filter, ref const(QString) fileName);
197 /+ #endif +/
198 
199     static QString cleanPath(ref const(QString) path);
200     void refresh() const;
201 
202 protected:
203     /+ explicit +/this(ref QDirPrivate d);
204 
205     QSharedDataPointer!(QDirPrivate) d_ptr;
206 
207 private:
208     /+ friend class QDirIterator; +/
209     // Q_DECLARE_PRIVATE equivalent for shared data pointers
210     /+ QDirPrivate* d_func(); +/
211     /+ inline const QDirPrivate* d_func() const
212     {
213         return d_ptr.constData();
214     } +/
215 
216 }
217 /+pragma(inline, true) QFlags!(QDir.Filters.enum_type) operator |(QDir.Filters.enum_type f1, QDir.Filters.enum_type f2)/+noexcept+/{return QFlags!(QDir.Filters.enum_type)(f1)|f2;}+/
218 /+pragma(inline, true) QFlags!(QDir.Filters.enum_type) operator |(QDir.Filters.enum_type f1, QFlags!(QDir.Filters.enum_type) f2)/+noexcept+/{return f2|f1;}+/
219 /+pragma(inline, true) QIncompatibleFlag operator |(QDir.Filters.enum_type f1, int f2)/+noexcept+/{return QIncompatibleFlag(int(f1)|f2);}+/
220 
221 /+ Q_DECLARE_SHARED(QDir)
222 Q_DECLARE_OPERATORS_FOR_FLAGS(QDir::Filters) +/
223 /+pragma(inline, true) QFlags!(QDir.SortFlags.enum_type) operator |(QDir.SortFlags.enum_type f1, QDir.SortFlags.enum_type f2)/+noexcept+/{return QFlags!(QDir.SortFlags.enum_type)(f1)|f2;}+/
224 /+pragma(inline, true) QFlags!(QDir.SortFlags.enum_type) operator |(QDir.SortFlags.enum_type f1, QFlags!(QDir.SortFlags.enum_type) f2)/+noexcept+/{return f2|f1;}+/
225 /+pragma(inline, true) QIncompatibleFlag operator |(QDir.SortFlags.enum_type f1, int f2)/+noexcept+/{return QIncompatibleFlag(int(f1)|f2);}+/
226 /+ Q_DECLARE_OPERATORS_FOR_FLAGS(QDir::SortFlags)
227 #ifndef QT_NO_DEBUG_STREAM
228 class QDebug;
229 Q_CORE_EXPORT QDebug operator<<(QDebug debug, QDir::Filters filters);
230 Q_CORE_EXPORT QDebug operator<<(QDebug debug, const QDir &dir);
231 #endif +/
232