| 1 | /**************************************************************************** | 
|---|
| 2 | ** | 
|---|
| 3 | ** Copyright (C) 2020 The Qt Company Ltd. | 
|---|
| 4 | ** Contact: https://www.qt.io/licensing/ | 
|---|
| 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 The Qt Company. For licensing terms | 
|---|
| 14 | ** and conditions see https://www.qt.io/terms-conditions. For further | 
|---|
| 15 | ** information use the contact form at https://www.qt.io/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 3 as published by the Free Software | 
|---|
| 20 | ** Foundation and appearing in the file LICENSE.LGPL3 included in the | 
|---|
| 21 | ** packaging of this file. Please review the following information to | 
|---|
| 22 | ** ensure the GNU Lesser General Public License version 3 requirements | 
|---|
| 23 | ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. | 
|---|
| 24 | ** | 
|---|
| 25 | ** GNU General Public License Usage | 
|---|
| 26 | ** Alternatively, this file may be used under the terms of the GNU | 
|---|
| 27 | ** General Public License version 2.0 or (at your option) the GNU General | 
|---|
| 28 | ** Public license version 3 or any later version approved by the KDE Free | 
|---|
| 29 | ** Qt Foundation. The licenses are as published by the Free Software | 
|---|
| 30 | ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 | 
|---|
| 31 | ** included in the packaging of this file. Please review the following | 
|---|
| 32 | ** information to ensure the GNU General Public License requirements will | 
|---|
| 33 | ** be met: https://www.gnu.org/licenses/gpl-2.0.html and | 
|---|
| 34 | ** https://www.gnu.org/licenses/gpl-3.0.html. | 
|---|
| 35 | ** | 
|---|
| 36 | ** $QT_END_LICENSE$ | 
|---|
| 37 | ** | 
|---|
| 38 | ****************************************************************************/ | 
|---|
| 39 |  | 
|---|
| 40 | #ifndef QFILEINFO_H | 
|---|
| 41 | #define QFILEINFO_H | 
|---|
| 42 |  | 
|---|
| 43 | #include <QtCore/qfile.h> | 
|---|
| 44 | #include <QtCore/qlist.h> | 
|---|
| 45 | #include <QtCore/qshareddata.h> | 
|---|
| 46 | #include <QtCore/qmetatype.h> | 
|---|
| 47 | #include <QtCore/qdatetime.h> | 
|---|
| 48 |  | 
|---|
| 49 | QT_BEGIN_NAMESPACE | 
|---|
| 50 |  | 
|---|
| 51 |  | 
|---|
| 52 | class QDir; | 
|---|
| 53 | class QDirIteratorPrivate; | 
|---|
| 54 | class QFileInfoPrivate; | 
|---|
| 55 |  | 
|---|
| 56 | class Q_CORE_EXPORT QFileInfo | 
|---|
| 57 | { | 
|---|
| 58 | friend class QDirIteratorPrivate; | 
|---|
| 59 | public: | 
|---|
| 60 | explicit QFileInfo(QFileInfoPrivate *d); | 
|---|
| 61 |  | 
|---|
| 62 | QFileInfo(); | 
|---|
| 63 | QFileInfo(const QString &file); | 
|---|
| 64 | QFileInfo(const QFileDevice &file); | 
|---|
| 65 | QFileInfo(const QDir &dir, const QString &file); | 
|---|
| 66 | QFileInfo(const QFileInfo &fileinfo); | 
|---|
| 67 | #ifdef Q_CLANG_QDOC | 
|---|
| 68 | QFileInfo(const std::filesystem::path &file); | 
|---|
| 69 | QFileInfo(const QDir &dir, const std::filesystem::path &file); | 
|---|
| 70 | #elif QT_CONFIG(cxx17_filesystem) | 
|---|
| 71 | template<typename T, QtPrivate::ForceFilesystemPath<T> = 0> | 
|---|
| 72 | QFileInfo(const T &file) : QFileInfo(QtPrivate::fromFilesystemPath(file)) { } | 
|---|
| 73 |  | 
|---|
| 74 | template<typename T, QtPrivate::ForceFilesystemPath<T> = 0> | 
|---|
| 75 | QFileInfo(const QDir &dir, const T &file) : QFileInfo(dir, QtPrivate::fromFilesystemPath(file)) | 
|---|
| 76 | { | 
|---|
| 77 | } | 
|---|
| 78 | #endif // QT_CONFIG(cxx17_filesystem) | 
|---|
| 79 | ~QFileInfo(); | 
|---|
| 80 |  | 
|---|
| 81 | QFileInfo &operator=(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==(const QFileInfo &fileinfo) const; | 
|---|
| 88 | inline bool operator!=(const QFileInfo &fileinfo) const { return !(operator==(fileinfo)); } | 
|---|
| 89 |  | 
|---|
| 90 | void setFile(const QString &file); | 
|---|
| 91 | void setFile(const QFileDevice &file); | 
|---|
| 92 | void setFile(const QDir &dir, 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(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 | inline 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 | #if QT_CONFIG(cxx17_filesystem) || defined(Q_CLANG_QDOC) | 
|---|
| 156 | std::filesystem::path filesystemSymLinkTarget() const | 
|---|
| 157 | { return QtPrivate::toFilesystemPath(symLinkTarget()); } | 
|---|
| 158 | #endif // QT_CONFIG(cxx17_filesystem) | 
|---|
| 159 |  | 
|---|
| 160 | QString owner() const; | 
|---|
| 161 | uint ownerId() const; | 
|---|
| 162 | QString group() const; | 
|---|
| 163 | uint groupId() const; | 
|---|
| 164 |  | 
|---|
| 165 | bool permission(QFile::Permissions permissions) const; | 
|---|
| 166 | QFile::Permissions permissions() const; | 
|---|
| 167 |  | 
|---|
| 168 | qint64 size() const; | 
|---|
| 169 |  | 
|---|
| 170 | QDateTime birthTime() const { return fileTime(QFile::FileBirthTime); } | 
|---|
| 171 | QDateTime metadataChangeTime() const { return fileTime(QFile::FileMetadataChangeTime); } | 
|---|
| 172 | QDateTime lastModified() const { return fileTime(QFile::FileModificationTime); } | 
|---|
| 173 | QDateTime lastRead() const { return fileTime(QFile::FileAccessTime); } | 
|---|
| 174 | QDateTime fileTime(QFile::FileTime time) const; | 
|---|
| 175 |  | 
|---|
| 176 | bool caching() const; | 
|---|
| 177 | void setCaching(bool on); | 
|---|
| 178 | void stat(); | 
|---|
| 179 |  | 
|---|
| 180 | protected: | 
|---|
| 181 | QSharedDataPointer<QFileInfoPrivate> d_ptr; | 
|---|
| 182 |  | 
|---|
| 183 | private: | 
|---|
| 184 | QFileInfoPrivate* d_func(); | 
|---|
| 185 | inline const QFileInfoPrivate* d_func() const | 
|---|
| 186 | { | 
|---|
| 187 | return d_ptr.constData(); | 
|---|
| 188 | } | 
|---|
| 189 | }; | 
|---|
| 190 |  | 
|---|
| 191 | Q_DECLARE_SHARED(QFileInfo) | 
|---|
| 192 |  | 
|---|
| 193 | typedef QList<QFileInfo> QFileInfoList; | 
|---|
| 194 |  | 
|---|
| 195 | #ifndef QT_NO_DEBUG_STREAM | 
|---|
| 196 | Q_CORE_EXPORT QDebug operator<<(QDebug, const QFileInfo &); | 
|---|
| 197 | #endif | 
|---|
| 198 |  | 
|---|
| 199 | QT_END_NAMESPACE | 
|---|
| 200 |  | 
|---|
| 201 | Q_DECLARE_METATYPE(QFileInfo) | 
|---|
| 202 |  | 
|---|
| 203 | #endif // QFILEINFO_H | 
|---|
| 204 |  | 
|---|