Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Toggle main menu visibility
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
// Qt-Security score:significant reason:default
4
5
#
ifndef
QFILEINFOGATHERER_H
6
#
define
QFILEINFOGATHERER_H
7
8
//
9
// W A R N I N G
10
// -------------
11
//
12
// This file is not part of the Qt API. It exists purely as an
13
// implementation detail. This header file may change from version to
14
// version without notice, or even be removed.
15
//
16
// We mean it.
17
//
18
19
#
include
<
QtGui
/
private
/
qtguiglobal_p
.
h
>
20
21
#
include
<
qthread
.
h
>
22
#
include
<
qmutex
.
h
>
23
#
include
<
qwaitcondition
.
h
>
24
#
if
QT_CONFIG
(
filesystemwatcher
)
25
#
include
<
qfilesystemwatcher
.
h
>
26
#
endif
27
#
include
<
qabstractfileiconprovider
.
h
>
28
#
include
<
qstack
.
h
>
29
#
include
<
qdatetime
.
h
>
30
#
include
<
qdir
.
h
>
31
#
include
<
qelapsedtimer
.
h
>
32
33
#
include
<
private
/
qfileinfo_p
.
h
>
34
#
include
<
private
/
qfilesystemengine_p
.
h
>
35
36
#
include
<
utility
>
37
38
QT_REQUIRE_CONFIG
(
filesystemmodel
);
39
40
QT_BEGIN_NAMESPACE
41
42
class
QExtendedInformation {
43
public
:
44
enum
Type { Dir, File, System };
45
46
QExtendedInformation() {}
47
QExtendedInformation(
const
QFileInfo &info) : mFileInfo(info) {}
48
49
inline
bool
isDir() {
return
type() == Dir; }
50
inline
bool
isFile() {
return
type() == File; }
51
inline
bool
isSystem() {
return
type() == System; }
52
53
bool
operator ==(
const
QExtendedInformation &fileInfo)
const
{
54
return
mFileInfo == fileInfo.mFileInfo
55
&& displayType == fileInfo.displayType
56
&& permissions() == fileInfo.permissions()
57
&& lastModified(QTimeZone::UTC) == fileInfo.lastModified(QTimeZone::UTC);
58
}
59
60
#
ifndef
QT_NO_FSFILEENGINE
61
bool
isCaseSensitive()
const
{
62
auto
*fiPriv = QFileInfoPrivate::get(
const_cast
<QFileInfo*>(&mFileInfo));
63
return
qt_isCaseSensitive(fiPriv->fileEntry, fiPriv->metaData);
64
}
65
#
endif
66
67
QFile::Permissions permissions()
const
{
68
return
mFileInfo.permissions();
69
}
70
71
Type type()
const
{
72
if
(mFileInfo.isDir()) {
73
return
QExtendedInformation::Dir;
74
}
75
if
(mFileInfo.isFile()) {
76
return
QExtendedInformation::File;
77
}
78
if
(!mFileInfo.exists() && mFileInfo.isSymLink()) {
79
return
QExtendedInformation::System;
80
}
81
return
QExtendedInformation::System;
82
}
83
84
bool
isSymLink(
bool
ignoreNtfsSymLinks =
false
)
const
85
{
86
if
(ignoreNtfsSymLinks) {
87
#
ifdef
Q_OS_WIN
88
return
!mFileInfo.suffix().compare(QLatin1StringView(
"lnk"
), Qt::CaseInsensitive);
89
#
endif
90
}
91
return
mFileInfo.isSymLink();
92
}
93
94
bool
isHidden()
const
{
95
return
mFileInfo.isHidden();
96
}
97
98
QFileInfo fileInfo()
const
{
99
return
mFileInfo;
100
}
101
102
QDateTime lastModified(
const
QTimeZone &tz)
const
{
103
return
mFileInfo.lastModified(tz);
104
}
105
106
qint64 size()
const
{
107
qint64 size = -1;
108
if
(type() == QExtendedInformation::Dir)
109
size = 0;
110
if
(type() == QExtendedInformation::File)
111
size = mFileInfo.size();
112
if
(!mFileInfo.exists() && !mFileInfo.isSymLink())
113
size = -1;
114
return
size;
115
}
116
117
QString displayType;
118
QIcon icon;
119
120
private
:
121
QFileInfo mFileInfo;
122
};
123
124
class
QFileIconProvider;
125
126
class
Q_GUI_EXPORT
QFileInfoGatherer
:
public
QThread
127
{
128
Q_OBJECT
129
130
Q_SIGNALS:
131
void
updates(
const
QString &directory,
const
QList<std::pair<QString, QFileInfo>> &updates);
132
void
newListOfFiles(
const
QString &directory,
const
QStringList &listOfFiles)
const
;
133
void
nameResolved(
const
QString &fileName,
const
QString &resolvedName)
const
;
134
void
directoryLoaded(
const
QString &path);
135
136
public
:
137
explicit
QFileInfoGatherer(QObject *parent =
nullptr
);
138
~QFileInfoGatherer();
139
140
QStringList watchedFiles()
const
;
141
QStringList watchedDirectories()
const
;
142
void
watchPaths(
const
QStringList &paths);
143
void
unwatchPaths(
const
QStringList &paths);
144
145
bool
isWatching()
const
;
146
void
setWatching(
bool
v);
147
148
// only callable from this->thread():
149
void
clear();
150
void
removePath(
const
QString &path);
151
QExtendedInformation getInfo(
const
QFileInfo &info)
const
;
152
QAbstractFileIconProvider *iconProvider()
const
;
153
bool
resolveSymlinks()
const
;
154
155
void
requestAbort();
156
157
public
Q_SLOTS:
158
void
list(
const
QString &directoryPath);
159
void
fetchExtendedInformation(
const
QString &path,
const
QStringList &files);
160
void
updateFile(
const
QString &path);
161
void
setResolveSymlinks(
bool
enable);
162
void
setIconProvider(QAbstractFileIconProvider *provider);
163
164
private
Q_SLOTS:
165
void
driveAdded();
166
void
driveRemoved();
167
168
protected
:
169
bool
event(QEvent *event) override;
170
171
private
:
172
void
run() override;
173
// called by run():
174
void
getFileInfos(
const
QString &path,
const
QStringList &files);
175
void
fetch(
const
QFileInfo &info, QElapsedTimer &base,
bool
&firstTime,
176
QList<std::pair<QString, QFileInfo>> &updatedFiles,
const
QString &path);
177
178
private
:
179
void
createWatcher();
180
181
mutable
QMutex mutex;
182
// begin protected by mutex
183
QWaitCondition condition;
184
QStack<QString> path;
185
QStack<QStringList> files;
186
// end protected by mutex
187
188
#
if
QT_CONFIG
(
filesystemwatcher
)
189
QFileSystemWatcher *m_watcher =
nullptr
;
190
#
endif
191
QAbstractFileIconProvider *m_iconProvider;
// not accessed by run()
192
QAbstractFileIconProvider defaultProvider;
193
#
ifdef
Q_OS_WIN
194
bool
m_resolveSymlinks =
true
;
// not accessed by run()
195
#
endif
196
#
if
QT_CONFIG
(
filesystemwatcher
)
197
bool
m_watching =
true
;
198
#
endif
199
};
200
201
QT_END_NAMESPACE
202
#
endif
// QFILEINFOGATHERER_H
QFileInfoGatherer
\inmodule QtGui
Definition
qfileinfogatherer_p.h:127
QString
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition
qstring.h:177
translateDriveName
static QString translateDriveName(const QFileInfo &drive)
Definition
qfileinfogatherer.cpp:36
QT_REQUIRE_CONFIG
QT_REQUIRE_CONFIG(filesystemmodel)
qtbase
src
gui
itemmodels
qfileinfogatherer_p.h
Generated on
for Qt by
1.18.0