Qt 6.x
The Qt SDK
Loading...
Searching...
No Matches
qfileinfogatherer_p.h
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#ifndef QFILEINFOGATHERER_H
5#define QFILEINFOGATHERER_H
6
7//
8// W A R N I N G
9// -------------
10//
11// This file is not part of the Qt API. It exists purely as an
12// implementation detail. This header file may change from version to
13// version without notice, or even be removed.
14//
15// We mean it.
16//
17
18#include <QtGui/private/qtguiglobal_p.h>
19
20#include <qthread.h>
21#include <qmutex.h>
22#include <qwaitcondition.h>
23#if QT_CONFIG(filesystemwatcher)
24#include <qfilesystemwatcher.h>
25#endif
27#include <qpair.h>
28#include <qstack.h>
29#include <qdatetime.h>
30#include <qdir.h>
31#include <qelapsedtimer.h>
32
33#include <private/qfilesystemengine_p.h>
34
35QT_REQUIRE_CONFIG(filesystemmodel);
36
38
40public:
41 enum Type { Dir, File, System };
42
44 QExtendedInformation(const QFileInfo &info) : mFileInfo(info) {}
45
46 inline bool isDir() { return type() == Dir; }
47 inline bool isFile() { return type() == File; }
48 inline bool isSystem() { return type() == System; }
49
51 return mFileInfo == fileInfo.mFileInfo
52 && displayType == fileInfo.displayType
55 }
56
57#ifndef QT_NO_FSFILEENGINE
58 bool isCaseSensitive() const {
60 }
61#endif
62
63 QFile::Permissions permissions() const {
64 return mFileInfo.permissions();
65 }
66
67 Type type() const {
68 if (mFileInfo.isDir()) {
70 }
71 if (mFileInfo.isFile()) {
73 }
74 if (!mFileInfo.exists() && mFileInfo.isSymLink()) {
76 }
78 }
79
80 bool isSymLink(bool ignoreNtfsSymLinks = false) const
81 {
82 if (ignoreNtfsSymLinks) {
83#ifdef Q_OS_WIN
84 return !mFileInfo.suffix().compare(QLatin1StringView("lnk"), Qt::CaseInsensitive);
85#endif
86 }
87 return mFileInfo.isSymLink();
88 }
89
90 bool isHidden() const {
91 return mFileInfo.isHidden();
92 }
93
95 return mFileInfo;
96 }
97
99 return mFileInfo.lastModified(tz);
100 }
101
102 qint64 size() const {
103 qint64 size = -1;
105 size = 0;
107 size = mFileInfo.size();
108 if (!mFileInfo.exists() && !mFileInfo.isSymLink())
109 size = -1;
110 return size;
111 }
112
115
116private :
117 QFileInfo mFileInfo;
118};
119
121
122class Q_GUI_EXPORT QFileInfoGatherer : public QThread
123{
125
128 void newListOfFiles(const QString &directory, const QStringList &listOfFiles) const;
129 void nameResolved(const QString &fileName, const QString &resolvedName) const;
131
132public:
133 explicit QFileInfoGatherer(QObject *parent = nullptr);
135
136 QStringList watchedFiles() const;
137 QStringList watchedDirectories() const;
138 void watchPaths(const QStringList &paths);
139 void unwatchPaths(const QStringList &paths);
140
141 bool isWatching() const;
142 void setWatching(bool v);
143
144 // only callable from this->thread():
145 void clear();
146 void removePath(const QString &path);
147 QExtendedInformation getInfo(const QFileInfo &info) const;
148 QAbstractFileIconProvider *iconProvider() const;
149 bool resolveSymlinks() const;
150
151public Q_SLOTS:
152 void list(const QString &directoryPath);
153 void fetchExtendedInformation(const QString &path, const QStringList &files);
154 void updateFile(const QString &path);
155 void setResolveSymlinks(bool enable);
156 void setIconProvider(QAbstractFileIconProvider *provider);
157
158private Q_SLOTS:
159 void driveAdded();
160 void driveRemoved();
161
162private:
163 void run() override;
164 // called by run():
165 void getFileInfos(const QString &path, const QStringList &files);
166 void fetch(const QFileInfo &info, QElapsedTimer &base, bool &firstTime,
167 QList<QPair<QString, QFileInfo>> &updatedFiles, const QString &path);
168
169private:
170 void createWatcher();
171
172 mutable QMutex mutex;
173 // begin protected by mutex
177 // end protected by mutex
178 QAtomicInt abort;
179
180#if QT_CONFIG(filesystemwatcher)
181 QFileSystemWatcher *m_watcher = nullptr;
182#endif
183 QAbstractFileIconProvider *m_iconProvider; // not accessed by run()
184 QAbstractFileIconProvider defaultProvider;
185#ifdef Q_OS_WIN
186 bool m_resolveSymlinks = true; // not accessed by run()
187#endif
188#if QT_CONFIG(filesystemwatcher)
189 bool m_watching = true;
190#endif
191};
192
194#endif // QFILEINFOGATHERER_H
\inmodule QtCore
Definition qatomic.h:112
\inmodule QtCore\reentrant
Definition qdatetime.h:257
\inmodule QtCore
QFileInfo fileInfo() const
QFile::Permissions permissions() const
QDateTime lastModified(const QTimeZone &tz) const
QExtendedInformation(const QFileInfo &info)
bool isSymLink(bool ignoreNtfsSymLinks=false) const
bool operator==(const QExtendedInformation &fileInfo) const
\inmodule QtWidgets
void updates(const QString &directory, const QList< QPair< QString, QFileInfo > > &updates)
void newListOfFiles(const QString &directory, const QStringList &listOfFiles) const
void nameResolved(const QString &fileName, const QString &resolvedName) const
void directoryLoaded(const QString &path)
\inmodule QtCore \reentrant
Definition qfileinfo.h:22
QDateTime lastModified() const
Returns the date and time when the file was last modified.
Definition qfileinfo.h:156
bool isSymLink() const
Returns true if this object points to a symbolic link, shortcut, or alias; otherwise returns false.
QString suffix() const
Returns the suffix (extension) of the file.
bool isFile() const
Returns true if this object points to a file or to a symbolic link to a file.
bool isDir() const
Returns true if this object points to a directory or to a symbolic link to a directory.
qint64 size() const
Returns the file size in bytes.
bool isHidden() const
Returns true if this is a ‘hidden’ file; otherwise returns false.
bool exists() const
Returns true if the file exists; otherwise returns false.
QFile::Permissions permissions() const
Returns the complete OR-ed together combination of QFile::Permissions for the file.
static bool isCaseSensitive()
The QIcon class provides scalable icons in different modes and states.
Definition qicon.h:20
Definition qlist.h:74
\inmodule QtCore
Definition qmutex.h:285
\inmodule QtCore
Definition qobject.h:90
\inmodule QtCore
Definition qstack.h:13
\inmodule QtCore
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:127
int compare(const QString &s, Qt::CaseSensitivity cs=Qt::CaseSensitive) const noexcept
Definition qstring.cpp:6498
virtual void run()
Definition qthread.cpp:913
\inmodule QtCore
Definition qtimezone.h:25
b clear()
Combined button and popup list for selecting options.
@ CaseInsensitive
std::pair< T1, T2 > QPair
GLsizei const GLfloat * v
[13]
GLenum GLuint GLintptr GLsizeiptr size
[1]
GLenum condition
GLsizei const GLuint * paths
GLboolean enable
GLbyte GLbyte tz
GLsizei const GLchar *const * path
bool updateFile(const QString &fileName, const QHash< QString, QString > &replacements)
Definition main.cpp:1503
#define QT_REQUIRE_CONFIG(feature)
#define Q_OBJECT
#define Q_SLOTS
#define Q_SIGNALS
long long qint64
Definition qtypes.h:55
QList< int > list
[14]
QFileInfo info(fileName)
[8]
QMutex mutex
[2]
QStringList files
[8]
Definition moc.h:24
IUIAutomationTreeWalker __RPC__deref_out_opt IUIAutomationElement ** parent