qfileinfogatherer.cpp

Absolute File Name:/home/qt/qt5_coco/qt5/qtbase/src/widgets/dialogs/qfileinfogatherer.cpp
Switch to Source codePreprocessed file
LineSourceCount
1-
2-
3-
4-
5-
6static QBasicAtomicInt fetchedRoot = { false };-
7__attribute__((visibility("default"))) void qt_test_resetFetchedRoot()-
8{-
9 fetchedRoot.store(false);-
10}
never executed: end of block
0
11-
12__attribute__((visibility("default"))) bool qt_test_isFetchedRoot()-
13{-
14 return
never executed: return fetchedRoot.load();
fetchedRoot.load();
never executed: return fetchedRoot.load();
0
15}-
16-
17-
18-
19-
20-
21QFileInfoGatherer::QFileInfoGatherer(QObject *parent)-
22 : QThread(parent), abort(false),-
23-
24 watcher(0),-
25-
26-
27-
28-
29 m_iconProvider(&defaultProvider)-
30{-
31-
32 watcher = new QFileSystemWatcher(this);-
33 connect(watcher, qFlagLocation("2""directoryChanged(QString)" "\0" __FILE__ ":" "83"), this, qFlagLocation("1""list(QString)" "\0" __FILE__ ":" "83"));-
34 connect(watcher, qFlagLocation("2""fileChanged(QString)" "\0" __FILE__ ":" "84"), this, qFlagLocation("1""updateFile(QString)" "\0" __FILE__ ":" "84"));-
35-
36 start(LowPriority);-
37}
never executed: end of block
0
38-
39-
40-
41-
42QFileInfoGatherer::~QFileInfoGatherer()-
43{-
44 abort.store(true);-
45 QMutexLocker locker(&mutex);-
46 condition.wakeAll();-
47 locker.unlock();-
48 wait();-
49}
never executed: end of block
0
50-
51void QFileInfoGatherer::setResolveSymlinks(bool enable)-
52{-
53 (void)enable;;-
54-
55-
56-
57}
never executed: end of block
0
58-
59bool QFileInfoGatherer::resolveSymlinks() const-
60{-
61-
62-
63-
64 return
never executed: return false;
false;
never executed: return false;
0
65-
66}-
67-
68void QFileInfoGatherer::setIconProvider(QFileIconProvider *provider)-
69{-
70 m_iconProvider = provider;-
71}
never executed: end of block
0
72-
73QFileIconProvider *QFileInfoGatherer::iconProvider() const-
74{-
75 return
never executed: return m_iconProvider;
m_iconProvider;
never executed: return m_iconProvider;
0
76}-
77-
78-
79-
80-
81-
82-
83void QFileInfoGatherer::fetchExtendedInformation(const QString &path, const QStringList &files)-
84{-
85 QMutexLocker locker(&mutex);-
86-
87 int loc = this->path.lastIndexOf(path);-
88 while (loc > 0
loc > 0Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
89 if (this->files.at(loc) == files
this->files.at(loc) == filesDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
90 return;
never executed: return;
0
91 }-
92 loc = this->path.lastIndexOf(path, loc - 1);-
93 }
never executed: end of block
0
94 this->path.push(path);-
95 this->files.push(files);-
96 condition.wakeAll();-
97-
98-
99 if (files.isEmpty()
files.isEmpty()Description
TRUEnever evaluated
FALSEnever evaluated
0
100 && !path.isEmpty()
!path.isEmpty()Description
TRUEnever evaluated
FALSEnever evaluated
0
101 && !path.startsWith(QLatin1String("//"))
!path.startsWi...1String("//"))Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
102 if (!watcher->directories().contains(path)
!watcher->dire...contains(path)Description
TRUEnever evaluated
FALSEnever evaluated
)
0
103 watcher->addPath(path);
never executed: watcher->addPath(path);
0
104 }
never executed: end of block
0
105-
106}
never executed: end of block
0
107-
108-
109-
110-
111-
112-
113void QFileInfoGatherer::updateFile(const QString &filePath)-
114{-
115 QString dir = filePath.mid(0, filePath.lastIndexOf(QDir::separator()));-
116 QString fileName = filePath.mid(dir.length() + 1);-
117 fetchExtendedInformation(dir, QStringList(fileName));-
118}
never executed: end of block
0
119-
120-
121-
122-
123-
124-
125void QFileInfoGatherer::clear()-
126{-
127-
128 QMutexLocker locker(&mutex);-
129 watcher->removePaths(watcher->files());-
130 watcher->removePaths(watcher->directories());-
131-
132}
never executed: end of block
0
133-
134-
135-
136-
137-
138-
139void QFileInfoGatherer::removePath(const QString &path)-
140{-
141-
142 QMutexLocker locker(&mutex);-
143 watcher->removePath(path);-
144-
145-
146-
147}
never executed: end of block
0
148-
149-
150-
151-
152-
153-
154void QFileInfoGatherer::list(const QString &directoryPath)-
155{-
156 fetchExtendedInformation(directoryPath, QStringList());-
157}
never executed: end of block
0
158-
159-
160-
161-
162void QFileInfoGatherer::run()-
163{-
164 for(;;) {-
165 QMutexLocker locker(&mutex);-
166 while (!abort.load()
!abort.load()Description
TRUEnever evaluated
FALSEnever evaluated
&& path.isEmpty()
path.isEmpty()Description
TRUEnever evaluated
FALSEnever evaluated
)
0
167 condition.wait(&mutex);
never executed: condition.wait(&mutex);
0
168 if (abort.load()
abort.load()Description
TRUEnever evaluated
FALSEnever evaluated
)
0
169 return;
never executed: return;
0
170 const QString thisPath = qAsConst(path).front();-
171 path.pop_front();-
172 const QStringList thisList = qAsConst(files).front();-
173 files.pop_front();-
174 locker.unlock();-
175-
176 getFileInfos(thisPath, thisList);-
177 }
never executed: end of block
0
178}
never executed: end of block
0
179-
180QExtendedInformation QFileInfoGatherer::getInfo(const QFileInfo &fileInfo) const-
181{-
182 QExtendedInformation info(fileInfo);-
183 info.icon = m_iconProvider->icon(fileInfo);-
184 info.displayType = m_iconProvider->type(fileInfo);-
185 return
never executed: return info;
info;
never executed: return info;
0
186}-
187-
188static QString translateDriveName(const QFileInfo &drive)-
189{-
190 QString driveName = drive.absoluteFilePath();-
191-
192-
193-
194-
195-
196-
197 return
never executed: return driveName;
driveName;
never executed: return driveName;
0
198}-
199-
200-
201-
202-
203-
204void QFileInfoGatherer::getFileInfos(const QString &path, const QStringList &files)-
205{-
206-
207 if (path.isEmpty()
path.isEmpty()Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
208-
209 fetchedRoot.store(true);-
210-
211 QFileInfoList infoList;-
212 if (files.isEmpty()
files.isEmpty()Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
213 infoList = QDir::drives();-
214 }
never executed: end of block
else {
0
215 infoList.reserve(files.count());-
216 for (const auto &file : files)-
217 infoList << QFileInfo(file);
never executed: infoList << QFileInfo(file);
0
218 }
never executed: end of block
0
219 for (int i = infoList.count() - 1; i >= 0
i >= 0Description
TRUEnever evaluated
FALSEnever evaluated
; --i) {
0
220 QString driveName = translateDriveName(infoList.at(i));-
221 QVector<QPair<QString,QFileInfo> > updatedFiles;-
222 updatedFiles.append(QPair<QString,QFileInfo>(driveName, infoList.at(i)));-
223 updates(path, updatedFiles);-
224 }
never executed: end of block
0
225 return;
never executed: return;
0
226 }-
227-
228 QElapsedTimer base;-
229 base.start();-
230 QFileInfo fileInfo;-
231 bool firstTime = true;-
232 QVector<QPair<QString, QFileInfo> > updatedFiles;-
233 QStringList filesToCheck = files;-
234-
235 QString itPath = QDir::fromNativeSeparators(files.isEmpty() ? path : QLatin1String(""));-
236 QDirIterator dirIt(itPath, QDir::AllEntries | QDir::System | QDir::Hidden);-
237 QStringList allFiles;-
238 while (!abort.load()
!abort.load()Description
TRUEnever evaluated
FALSEnever evaluated
&& dirIt.hasNext()
dirIt.hasNext()Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
239 dirIt.next();-
240 fileInfo = dirIt.fileInfo();-
241 allFiles.append(fileInfo.fileName());-
242 fetch(fileInfo, base, firstTime, updatedFiles, path);-
243 }
never executed: end of block
0
244 if (!allFiles.isEmpty()
!allFiles.isEmpty()Description
TRUEnever evaluated
FALSEnever evaluated
)
0
245 newListOfFiles(path, allFiles);
never executed: newListOfFiles(path, allFiles);
0
246-
247 QStringList::const_iterator filesIt = filesToCheck.constBegin();-
248 while (!abort.load()
!abort.load()Description
TRUEnever evaluated
FALSEnever evaluated
&& filesIt != filesToCheck.constEnd()
filesIt != fil...eck.constEnd()Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
249 fileInfo.setFile(path + QDir::separator() + *filesIt);-
250 ++filesIt;-
251 fetch(fileInfo, base, firstTime, updatedFiles, path);-
252 }
never executed: end of block
0
253 if (!updatedFiles.isEmpty()
!updatedFiles.isEmpty()Description
TRUEnever evaluated
FALSEnever evaluated
)
0
254 updates(path, updatedFiles);
never executed: updates(path, updatedFiles);
0
255 directoryLoaded(path);-
256}
never executed: end of block
0
257-
258void QFileInfoGatherer::fetch(const QFileInfo &fileInfo, QElapsedTimer &base, bool &firstTime, QVector<QPair<QString, QFileInfo> > &updatedFiles, const QString &path) {-
259 updatedFiles.append(QPair<QString, QFileInfo>(fileInfo.fileName(), fileInfo));-
260 QElapsedTimer current;-
261 current.start();-
262 if ((firstTime
firstTimeDescription
TRUEnever evaluated
FALSEnever evaluated
&& updatedFiles.count() > 100
updatedFiles.count() > 100Description
TRUEnever evaluated
FALSEnever evaluated
) || base.msecsTo(current) > 1000
base.msecsTo(current) > 1000Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
263 updates(path, updatedFiles);-
264 updatedFiles.clear();-
265 base = current;-
266 firstTime = false;-
267 }
never executed: end of block
0
268}
never executed: end of block
0
269-
270-
271-
272-
273-
Switch to Source codePreprocessed file

Generated by Squish Coco Non-Commercial 4.3.0-BETA-master-30-08-2018-4cb69e9