Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-04-03 08:31:19

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