Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-09-15 09:07:25

0001 // Copyright (C) 2020 The Qt Company Ltd.
0002 // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
0003 
0004 #ifndef QFILEINFO_H
0005 #define QFILEINFO_H
0006 
0007 #include <QtCore/qcompare.h>
0008 #include <QtCore/qfile.h>
0009 #include <QtCore/qlist.h>
0010 #include <QtCore/qshareddata.h>
0011 #include <QtCore/qmetatype.h>
0012 #include <QtCore/qdatetime.h>
0013 #include <QtCore/qtimezone.h>
0014 
0015 QT_BEGIN_NAMESPACE
0016 
0017 
0018 class QDir;
0019 class QDirIteratorPrivate;
0020 class QFileInfoPrivate;
0021 
0022 class Q_CORE_EXPORT QFileInfo
0023 {
0024     friend class QDirIteratorPrivate;
0025     friend class QDirListingPrivate;
0026     friend class QFileInfoPrivate;
0027 public:
0028     explicit QFileInfo(QFileInfoPrivate *d);
0029 
0030 #ifdef QT_IMPLICIT_QFILEINFO_CONSTRUCTION
0031 #define QFILEINFO_MAYBE_EXPLICIT Q_IMPLICIT
0032 #else
0033 #define QFILEINFO_MAYBE_EXPLICIT explicit
0034 #endif
0035 
0036     QFileInfo();
0037     QFILEINFO_MAYBE_EXPLICIT QFileInfo(const QString &file);
0038     QFILEINFO_MAYBE_EXPLICIT QFileInfo(const QFileDevice &file);
0039     QFILEINFO_MAYBE_EXPLICIT QFileInfo(const QDir &dir, const QString &file);
0040     QFileInfo(const QFileInfo &fileinfo);
0041 #ifdef Q_QDOC
0042     QFileInfo(const std::filesystem::path &file);
0043     QFileInfo(const QDir &dir, const std::filesystem::path &file);
0044 #elif QT_CONFIG(cxx17_filesystem)
0045     template<typename T, QtPrivate::ForceFilesystemPath<T> = 0>
0046     QFILEINFO_MAYBE_EXPLICIT QFileInfo(const T &file) : QFileInfo(QtPrivate::fromFilesystemPath(file)) { }
0047 
0048     template<typename T, QtPrivate::ForceFilesystemPath<T> = 0>
0049     QFILEINFO_MAYBE_EXPLICIT QFileInfo(const QDir &dir, const T &file) : QFileInfo(dir, QtPrivate::fromFilesystemPath(file))
0050     {
0051     }
0052 #endif // QT_CONFIG(cxx17_filesystem)
0053 
0054 #undef QFILEINFO_MAYBE_EXPLICIT
0055 
0056     ~QFileInfo();
0057 
0058     QFileInfo &operator=(const QFileInfo &fileinfo);
0059     QT_MOVE_ASSIGNMENT_OPERATOR_IMPL_VIA_PURE_SWAP(QFileInfo)
0060 
0061     void swap(QFileInfo &other) noexcept
0062     { d_ptr.swap(other.d_ptr); }
0063 
0064 #if QT_CORE_REMOVED_SINCE(6, 8)
0065     bool operator==(const QFileInfo &fileinfo) const;
0066     inline bool operator!=(const QFileInfo &fileinfo) const { return !(operator==(fileinfo)); }
0067 #endif
0068 
0069     void setFile(const QString &file);
0070     void setFile(const QFileDevice &file);
0071     void setFile(const QDir &dir, const QString &file);
0072 #ifdef Q_QDOC
0073     void setFile(const std::filesystem::path &file);
0074 #elif QT_CONFIG(cxx17_filesystem)
0075     template<typename T, QtPrivate::ForceFilesystemPath<T> = 0>
0076     void setFile(const T &file) { setFile(QtPrivate::fromFilesystemPath(file)); }
0077 #endif // QT_CONFIG(cxx17_filesystem)
0078 
0079     bool exists() const;
0080     static bool exists(const QString &file);
0081     void refresh();
0082 
0083     QString filePath() const;
0084     QString absoluteFilePath() const;
0085     QString canonicalFilePath() const;
0086 #if QT_CONFIG(cxx17_filesystem) || defined(Q_QDOC)
0087     std::filesystem::path filesystemFilePath() const
0088     { return QtPrivate::toFilesystemPath(filePath()); }
0089     std::filesystem::path filesystemAbsoluteFilePath() const
0090     { return QtPrivate::toFilesystemPath(absoluteFilePath()); }
0091     std::filesystem::path filesystemCanonicalFilePath() const
0092     { return QtPrivate::toFilesystemPath(canonicalFilePath()); }
0093 #endif // QT_CONFIG(cxx17_filesystem)
0094     QString fileName() const;
0095     QString baseName() const;
0096     QString completeBaseName() const;
0097     QString suffix() const;
0098     QString bundleName() const;
0099     QString completeSuffix() const;
0100 
0101     QString path() const;
0102     QString absolutePath() const;
0103     QString canonicalPath() const;
0104 #if QT_CONFIG(cxx17_filesystem) || defined(Q_QDOC)
0105     std::filesystem::path filesystemPath() const { return QtPrivate::toFilesystemPath(path()); }
0106     std::filesystem::path filesystemAbsolutePath() const
0107     { return QtPrivate::toFilesystemPath(absolutePath()); }
0108     std::filesystem::path filesystemCanonicalPath() const
0109     { return QtPrivate::toFilesystemPath(canonicalPath()); }
0110 #endif // QT_CONFIG(cxx17_filesystem)
0111     QDir dir() const;
0112     QDir absoluteDir() const;
0113 
0114     bool isReadable() const;
0115     bool isWritable() const;
0116     bool isExecutable() const;
0117     bool isHidden() const;
0118     bool isNativePath() const;
0119 
0120     bool isRelative() const;
0121     inline bool isAbsolute() const { return !isRelative(); }
0122     bool makeAbsolute();
0123 
0124     bool isFile() const;
0125     bool isDir() const;
0126     bool isSymLink() const;
0127     bool isSymbolicLink() const;
0128     bool isShortcut() const;
0129     bool isAlias() const;
0130     bool isJunction() const;
0131     bool isRoot() const;
0132     bool isBundle() const;
0133 
0134     QString symLinkTarget() const;
0135     QString readSymLink() const;
0136     QString junctionTarget() const;
0137 
0138 #if QT_CONFIG(cxx17_filesystem) || defined(Q_QDOC)
0139     std::filesystem::path filesystemSymLinkTarget() const
0140     { return QtPrivate::toFilesystemPath(symLinkTarget()); }
0141 
0142     std::filesystem::path filesystemReadSymLink() const
0143     { return QtPrivate::toFilesystemPath(readSymLink()); }
0144 
0145     std::filesystem::path filesystemJunctionTarget() const
0146     { return QtPrivate::toFilesystemPath(junctionTarget()); }
0147 #endif // QT_CONFIG(cxx17_filesystem)
0148 
0149     QString owner() const;
0150     uint ownerId() const;
0151     QString group() const;
0152     uint groupId() const;
0153 
0154     bool permission(QFile::Permissions permissions) const;
0155     QFile::Permissions permissions() const;
0156 
0157     qint64 size() const;
0158 
0159     QDateTime birthTime() const { return fileTime(QFile::FileBirthTime); }
0160     QDateTime metadataChangeTime() const { return fileTime(QFile::FileMetadataChangeTime); }
0161     QDateTime lastModified() const { return fileTime(QFile::FileModificationTime); }
0162     QDateTime lastRead() const { return fileTime(QFile::FileAccessTime); }
0163     QDateTime fileTime(QFile::FileTime time) const;
0164 
0165     QDateTime birthTime(const QTimeZone &tz) const { return fileTime(QFile::FileBirthTime, tz); }
0166     QDateTime metadataChangeTime(const QTimeZone &tz) const { return fileTime(QFile::FileMetadataChangeTime, tz); }
0167     QDateTime lastModified(const QTimeZone &tz) const { return fileTime(QFile::FileModificationTime, tz); }
0168     QDateTime lastRead(const QTimeZone &tz) const { return fileTime(QFile::FileAccessTime, tz); }
0169     QDateTime fileTime(QFile::FileTime time, const QTimeZone &tz) const;
0170 
0171     bool caching() const;
0172     void setCaching(bool on);
0173     void stat();
0174 
0175 protected:
0176     QSharedDataPointer<QFileInfoPrivate> d_ptr;
0177 
0178 private:
0179     friend Q_CORE_EXPORT bool comparesEqual(const QFileInfo &lhs, const QFileInfo &rhs);
0180     Q_DECLARE_EQUALITY_COMPARABLE_NON_NOEXCEPT(QFileInfo)
0181     QFileInfoPrivate* d_func();
0182     inline const QFileInfoPrivate* d_func() const
0183     {
0184         return d_ptr.constData();
0185     }
0186 };
0187 
0188 Q_DECLARE_SHARED(QFileInfo)
0189 
0190 typedef QList<QFileInfo> QFileInfoList;
0191 
0192 #ifndef QT_NO_DEBUG_STREAM
0193 Q_CORE_EXPORT QDebug operator<<(QDebug, const QFileInfo &);
0194 #endif
0195 
0196 QT_END_NAMESPACE
0197 
0198 QT_DECL_METATYPE_EXTERN(QFileInfo, Q_CORE_EXPORT)
0199 
0200 #endif // QFILEINFO_H