1 /*
2  * DQt - D bindings for the Qt Toolkit
3  *
4  * GNU Lesser General Public License Usage
5  * This file may be used under the terms of the GNU Lesser
6  * General Public License version 3 as published by the Free Software
7  * Foundation and appearing in the file LICENSE.LGPL3 included in the
8  * packaging of this file. Please review the following information to
9  * ensure the GNU Lesser General Public License version 3 requirements
10  * will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
11  */
12 module qt.core.fileinfo;
13 extern(C++):
14 
15 import qt.config;
16 import qt.core.datetime;
17 import qt.core.dir;
18 import qt.core.file;
19 import qt.core.filedevice;
20 import qt.core.global;
21 import qt.core.list;
22 import qt.core.shareddata;
23 import qt.core.string;
24 import qt.core.typeinfo;
25 import qt.helpers;
26 
27 extern(C++, class) struct QDirIteratorPrivate;
28 extern(C++, class) struct QFileInfoPrivate;
29 static if(false)
30 {
31 /+ #define QFILEINFO_MAYBE_EXPLICIT Q_IMPLICIT +/
32 }
33 /+ #define QFILEINFO_MAYBE_EXPLICIT explicit +/
34 
35 /// Binding for C++ class [QFileInfo](https://doc.qt.io/qt-6/qfileinfo.html).
36 @Q_RELOCATABLE_TYPE extern(C++, class) struct /+ Q_CORE_EXPORT +/ QFileInfo
37 {
38 private:
39     /+ friend class QDirIteratorPrivate; +/
40 public:
41     /+ explicit +/this(QFileInfoPrivate* d);
42 
43 /+ #ifdef QT_IMPLICIT_QFILEINFO_CONSTRUCTION
44 #define QFILEINFO_MAYBE_EXPLICIT Q_IMPLICIT
45 #else
46 #define QFILEINFO_MAYBE_EXPLICIT explicit
47 #endif +/
48 
49     @disable this();
50     pragma(mangle, defaultConstructorMangling(__traits(identifier, typeof(this))))
51     ref typeof(this) rawConstructor();
52     static typeof(this) create()
53     {
54         typeof(this) r = typeof(this).init;
55         r.rawConstructor();
56         return r;
57     }
58 
59     /+ QFILEINFO_MAYBE_EXPLICIT +/this(ref const(QString) file);
60     // /+ QFILEINFO_MAYBE_EXPLICIT +/this(const QFileDevice &file);
61     /+ QFILEINFO_MAYBE_EXPLICIT +/this(ref const(QDir) dir, ref const(QString) file);
62     @disable this(this);
63     this(ref const(QFileInfo) fileinfo);
64 /+ #ifdef Q_CLANG_QDOC
65     QFileInfo(const std::filesystem::path &file);
66     QFileInfo(const QDir &dir, const std::filesystem::path &file);
67 #elif QT_CONFIG(cxx17_filesystem)
68     template<typename T, QtPrivate::ForceFilesystemPath<T> = 0>
69     QFILEINFO_MAYBE_EXPLICIT QFileInfo(const T &file) : QFileInfo(QtPrivate::fromFilesystemPath(file)) { }
70 
71     template<typename T, QtPrivate::ForceFilesystemPath<T> = 0>
72     QFILEINFO_MAYBE_EXPLICIT QFileInfo(const QDir &dir, const T &file) : QFileInfo(dir, QtPrivate::fromFilesystemPath(file))
73     {
74     }
75 #endif // QT_CONFIG(cxx17_filesystem)
76 
77 #undef QFILEINFO_MAYBE_EXPLICIT +/
78 
79     ~this();
80 
81     /+ref QFileInfo operator =(ref const(QFileInfo) fileinfo);+/
82     /+ QT_MOVE_ASSIGNMENT_OPERATOR_IMPL_VIA_PURE_SWAP(QFileInfo) +/
83 
84     /+ void swap(QFileInfo &other) noexcept
85     { qSwap(d_ptr, other.d_ptr); } +/
86 
87     /+bool operator ==(ref const(QFileInfo) fileinfo) const;+/
88     /+pragma(inline, true) bool operator !=(ref const(QFileInfo) fileinfo) const { return !(operator==(fileinfo)); }+/
89 
90     void setFile(ref const(QString) file);
91     //void setFile(const QFileDevice &file);
92     void setFile(ref const(QDir) dir, ref const(QString) file);
93 /+ #ifdef Q_CLANG_QDOC
94     void setFile(const std::filesystem::path &file);
95 #elif QT_CONFIG(cxx17_filesystem)
96     template<typename T, QtPrivate::ForceFilesystemPath<T> = 0>
97     void setFile(const T &file) { setFile(QtPrivate::fromFilesystemPath(file)); }
98 #endif +/ // QT_CONFIG(cxx17_filesystem)
99 
100     bool exists() const;
101     static bool exists(ref const(QString) file);
102     void refresh();
103 
104     QString filePath() const;
105     QString absoluteFilePath() const;
106     QString canonicalFilePath() const;
107 /+ #if QT_CONFIG(cxx17_filesystem) || defined(Q_CLANG_QDOC)
108     std::filesystem::path filesystemFilePath() const
109     { return QtPrivate::toFilesystemPath(filePath()); }
110     std::filesystem::path filesystemAbsoluteFilePath() const
111     { return QtPrivate::toFilesystemPath(absoluteFilePath()); }
112     std::filesystem::path filesystemCanonicalFilePath() const
113     { return QtPrivate::toFilesystemPath(canonicalFilePath()); }
114 #endif +/ // QT_CONFIG(cxx17_filesystem)
115     QString fileName() const;
116     QString baseName() const;
117     QString completeBaseName() const;
118     QString suffix() const;
119     QString bundleName() const;
120     QString completeSuffix() const;
121 
122     QString path() const;
123     QString absolutePath() const;
124     QString canonicalPath() const;
125 /+ #if QT_CONFIG(cxx17_filesystem) || defined(Q_CLANG_QDOC)
126     std::filesystem::path filesystemPath() const { return QtPrivate::toFilesystemPath(path()); }
127     std::filesystem::path filesystemAbsolutePath() const
128     { return QtPrivate::toFilesystemPath(absolutePath()); }
129     std::filesystem::path filesystemCanonicalPath() const
130     { return QtPrivate::toFilesystemPath(canonicalPath()); }
131 #endif +/ // QT_CONFIG(cxx17_filesystem)
132     QDir dir() const;
133     QDir absoluteDir() const;
134 
135     bool isReadable() const;
136     bool isWritable() const;
137     bool isExecutable() const;
138     bool isHidden() const;
139     bool isNativePath() const;
140 
141     bool isRelative() const;
142     pragma(inline, true) bool isAbsolute() const { return !isRelative(); }
143     bool makeAbsolute();
144 
145     bool isFile() const;
146     bool isDir() const;
147     bool isSymLink() const;
148     bool isSymbolicLink() const;
149     bool isShortcut() const;
150     bool isJunction() const;
151     bool isRoot() const;
152     bool isBundle() const;
153 
154     QString symLinkTarget() const;
155     QString junctionTarget() const;
156 
157 /+ #if QT_CONFIG(cxx17_filesystem) || defined(Q_CLANG_QDOC)
158     std::filesystem::path filesystemSymLinkTarget() const
159     { return QtPrivate::toFilesystemPath(symLinkTarget()); }
160 
161     std::filesystem::path filesystemJunctionTarget() const
162     { return QtPrivate::toFilesystemPath(junctionTarget()); }
163 #endif +/ // QT_CONFIG(cxx17_filesystem)
164 
165     QString owner() const;
166     uint ownerId() const;
167     QString group() const;
168     uint groupId() const;
169 
170     bool permission(QFile.Permissions permissions) const;
171     QFile.Permissions permissions() const;
172 
173     qint64 size() const;
174 
175     QDateTime birthTime() const { return fileTime(QFile.FileTime.FileBirthTime); }
176     QDateTime metadataChangeTime() const { return fileTime(QFile.FileTime.FileMetadataChangeTime); }
177     QDateTime lastModified() const { return fileTime(QFile.FileTime.FileModificationTime); }
178     QDateTime lastRead() const { return fileTime(QFile.FileTime.FileAccessTime); }
179     QDateTime fileTime(QFile.FileTime time) const;
180 
181     bool caching() const;
182     void setCaching(bool on);
183     void stat();
184 
185 protected:
186     QSharedDataPointer!(QFileInfoPrivate) d_ptr;
187 
188 private:
189     /+ QFileInfoPrivate* d_func(); +/
190     /+ inline const QFileInfoPrivate* d_func() const
191     {
192         return d_ptr.constData();
193     } +/
194     mixin(CREATE_CONVENIENCE_WRAPPERS);
195 }
196 
197 /+ Q_DECLARE_SHARED(QFileInfo) +/
198 
199 //alias QFileInfoList = QList!(QFileInfo);
200 
201 /+ #ifndef QT_NO_DEBUG_STREAM
202 Q_CORE_EXPORT QDebug operator<<(QDebug, const QFileInfo &);
203 #endif
204 
205 
206 Q_DECLARE_METATYPE(QFileInfo) +/
207