Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
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 <qstack.h>
28#include <qdatetime.h>
29#include <qdir.h>
30#include <qelapsedtimer.h>
31
32#include <private/qfilesystemengine_p.h>
33
34#include <utility>
35
36QT_REQUIRE_CONFIG(filesystemmodel);
37
39
41public:
42 enum Type { Dir, File, System };
43
45 QExtendedInformation(const QFileInfo &info) : mFileInfo(info) {}
46
47 inline bool isDir() { return type() == Dir; }
48 inline bool isFile() { return type() == File; }
49 inline bool isSystem() { return type() == System; }
50
52 return mFileInfo == fileInfo.mFileInfo
53 && displayType == fileInfo.displayType
56 }
57
58#ifndef QT_NO_FSFILEENGINE
59 bool isCaseSensitive() const {
61 }
62#endif
63
64 QFile::Permissions permissions() const {
65 return mFileInfo.permissions();
66 }
67
68 Type type() const {
69 if (mFileInfo.isDir()) {
71 }
72 if (mFileInfo.isFile()) {
74 }
75 if (!mFileInfo.exists() && mFileInfo.isSymLink()) {
77 }
79 }
80
81 bool isSymLink(bool ignoreNtfsSymLinks = false) const
82 {
83 if (ignoreNtfsSymLinks) {
84#ifdef Q_OS_WIN
85 return !mFileInfo.suffix().compare(QLatin1StringView("lnk"), Qt::CaseInsensitive);
86#endif
87 }
88 return mFileInfo.isSymLink();
89 }
90
91 bool isHidden() const {
92 return mFileInfo.isHidden();
93 }
94
96 return mFileInfo;
97 }
98
100 return mFileInfo.lastModified(tz);
101 }
102
103 qint64 size() const {
104 qint64 size = -1;
106 size = 0;
108 size = mFileInfo.size();
109 if (!mFileInfo.exists() && !mFileInfo.isSymLink())
110 size = -1;
111 return size;
112 }
113
116
117private :
118 QFileInfo mFileInfo;
119};
120
122
123class Q_GUI_EXPORT QFileInfoGatherer : public QThread
124{
126
128 void updates(const QString &directory, const QList<std::pair<QString, QFileInfo>> &updates);
129 void newListOfFiles(const QString &directory, const QStringList &listOfFiles) const;
130 void nameResolved(const QString &fileName, const QString &resolvedName) const;
132
133public:
134 explicit QFileInfoGatherer(QObject *parent = nullptr);
136
137 QStringList watchedFiles() const;
138 QStringList watchedDirectories() const;
139 void watchPaths(const QStringList &paths);
140 void unwatchPaths(const QStringList &paths);
141
142 bool isWatching() const;
143 void setWatching(bool v);
144
145 // only callable from this->thread():
146 void clear();
147 void removePath(const QString &path);
148 QExtendedInformation getInfo(const QFileInfo &info) const;
149 QAbstractFileIconProvider *iconProvider() const;
150 bool resolveSymlinks() const;
151
152 void requestAbort();
153
154public Q_SLOTS:
155 void list(const QString &directoryPath);
156 void fetchExtendedInformation(const QString &path, const QStringList &files);
157 void updateFile(const QString &path);
158 void setResolveSymlinks(bool enable);
159 void setIconProvider(QAbstractFileIconProvider *provider);
160
161private Q_SLOTS:
162 void driveAdded();
163 void driveRemoved();
164
165protected:
166 bool event(QEvent *event) override;
167
168private:
169 void run() override;
170 // called by run():
171 void getFileInfos(const QString &path, const QStringList &files);
172 void fetch(const QFileInfo &info, QElapsedTimer &base, bool &firstTime,
173 QList<std::pair<QString, QFileInfo>> &updatedFiles, const QString &path);
174
175private:
176 void createWatcher();
177
178 mutable QMutex mutex;
179 // begin protected by mutex
181 QStack<QString> path;
182 QStack<QStringList> files;
183 // end protected by mutex
184
185#if QT_CONFIG(filesystemwatcher)
186 QFileSystemWatcher *m_watcher = nullptr;
187#endif
188 QAbstractFileIconProvider *m_iconProvider; // not accessed by run()
189 QAbstractFileIconProvider defaultProvider;
190#ifdef Q_OS_WIN
191 bool m_resolveSymlinks = true; // not accessed by run()
192#endif
193#if QT_CONFIG(filesystemwatcher)
194 bool m_watching = true;
195#endif
196};
197
199#endif // QFILEINFOGATHERER_H
\inmodule QtCore\reentrant
Definition qdatetime.h:283
\inmodule QtCore
\inmodule QtCore
Definition qcoreevent.h:45
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 newListOfFiles(const QString &directory, const QStringList &listOfFiles) const
void updates(const QString &directory, const QList< std::pair< QString, QFileInfo > > &updates)
void nameResolved(const QString &fileName, const QString &resolvedName) const
void directoryLoaded(const QString &path)
QDateTime lastModified() const
Returns the date and time when the file was last modified.
Definition qfileinfo.h:160
bool isSymLink() const
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 the file system entry this QFileInfo refers to is ‘hidden’; otherwise returns false.
bool exists() const
Returns true if the file system entry this QFileInfo refers to 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:75
\inmodule QtCore
Definition qmutex.h:281
\inmodule QtCore
Definition qobject.h:103
\inmodule QtCore
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:129
int compare(const QString &s, Qt::CaseSensitivity cs=Qt::CaseSensitive) const noexcept
Definition qstring.cpp:6664
\inmodule QtCore
Definition qtimezone.h:26
b clear()
Combined button and popup list for selecting options.
@ CaseInsensitive
GLsizei const GLfloat * v
[13]
GLenum GLuint GLintptr GLsizeiptr size
[1]
GLenum condition
GLsizei const GLuint * paths
GLboolean enable
GLbyte GLbyte tz
struct _cl_event * event
GLsizei const GLchar *const * path
bool updateFile(const QString &fileName, const QHash< QString, QString > &replacements)
Definition main.cpp:1620
#define QT_REQUIRE_CONFIG(feature)
#define Q_OBJECT
#define Q_SLOTS
#define Q_SIGNALS
long long qint64
Definition qtypes.h:60
static const uint base
Definition qurlidna.cpp:20
QList< int > list
[14]
QMutex mutex
[2]
QStringList files
[8]
QHostInfo info
[0]
Definition moc.h:23