dialogs/qfileinfogatherer.cpp

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

Generated by Squish Coco Non-Commercial