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:202
202
19 -
20 -
21 -
22 -
23QFileInfoGatherer::~QFileInfoGatherer() -
24{ -
25 abort.store(true); -
26 condition.wakeAll(); -
27 wait(); -
28}
executed: }
Execution Count:202
202
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:576
576
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:185
185
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) {
partially evaluated: loc > 0
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:341
0-341
68 if (this->files.at(loc) == files) {
never evaluated: this->files.at(loc) == files
0
69 return;
never executed: return;
0
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:341
341
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:37
37
116 -
117 -
118 -
119 -
120 -
121 -
122void QFileInfoGatherer::list(const QString &directoryPath) -
123{ -
124 fetchExtendedInformation(directoryPath, QStringList()); -
125}
executed: }
Execution Count:341
341
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:797
yes
Evaluation Count:202
evaluated: path.isEmpty()
TRUEFALSE
yes
Evaluation Count:458
yes
Evaluation Count:339
202-797
135 condition.wait(&mutex);
executed: condition.wait(&mutex);
Execution Count:458
458
136 if (abort.load())
evaluated: abort.load()
TRUEFALSE
yes
Evaluation Count:202
yes
Evaluation Count:339
202-339
137 return;
executed: return;
Execution Count:202
202
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:339
339
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:3890
3890
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:78
78
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:339
no
Evaluation Count:0
0-339
176 && !path.isEmpty()
evaluated: !path.isEmpty()
TRUEFALSE
yes
Evaluation Count:261
yes
Evaluation Count:78
78-261
177 && !path.startsWith(QLatin1String("//")) ) {
partially evaluated: !path.startsWith(QLatin1String("//"))
TRUEFALSE
yes
Evaluation Count:261
no
Evaluation Count:0
0-261
178 QMutexLocker locker(&mutex); -
179 if (!watcher->directories().contains(path))
evaluated: !watcher->directories().contains(path)
TRUEFALSE
yes
Evaluation Count:221
yes
Evaluation Count:40
40-221
180 watcher->addPath(path);
executed: watcher->addPath(path);
Execution Count:221
221
181 }
executed: }
Execution Count:261
261
182 -
183 -
184 -
185 if (path.isEmpty()) {
evaluated: path.isEmpty()
TRUEFALSE
yes
Evaluation Count:78
yes
Evaluation Count:261
78-261
186 -
187 -
188 -
189 QFileInfoList infoList; -
190 if (files.isEmpty()) {
partially evaluated: files.isEmpty()
TRUEFALSE
yes
Evaluation Count:78
no
Evaluation Count:0
0-78
191 infoList = QDir::drives(); -
192 } else {
executed: }
Execution Count:78
78
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:78
yes
Evaluation Count:78
78
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:78
78
203 return;
executed: return;
Execution Count:78
78
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:7682
yes
Evaluation Count:1
evaluated: dirIt.hasNext()
TRUEFALSE
yes
Evaluation Count:7422
yes
Evaluation Count:260
1-7682
217 dirIt.next(); -
218 fileInfo = dirIt.fileInfo(); -
219 allFiles.append(fileInfo.fileName()); -
220 fetch(fileInfo, base, firstTime, updatedFiles, path); -
221 }
executed: }
Execution Count:7422
7422
222 if (!allFiles.isEmpty())
evaluated: !allFiles.isEmpty()
TRUEFALSE
yes
Evaluation Count:260
yes
Evaluation Count:1
1-260
223 newListOfFiles(path, allFiles);
executed: newListOfFiles(path, allFiles);
Execution Count:260
260
224 -
225 QStringList::const_iterator filesIt = filesToCheck.constBegin(); -
226 while (!abort.load() && filesIt != filesToCheck.constEnd()) {
evaluated: !abort.load()
TRUEFALSE
yes
Evaluation Count:260
yes
Evaluation Count:1
partially evaluated: filesIt != filesToCheck.constEnd()
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:260
0-260
227 fileInfo.setFile(path + QDir::separator() + *filesIt); -
228 ++filesIt; -
229 fetch(fileInfo, base, firstTime, updatedFiles, path); -
230 }
never executed: }
0
231 if (!updatedFiles.isEmpty())
evaluated: !updatedFiles.isEmpty()
TRUEFALSE
yes
Evaluation Count:260
yes
Evaluation Count:1
1-260
232 updates(path, updatedFiles);
executed: updates(path, updatedFiles);
Execution Count:260
260
233 directoryLoaded(path); -
234}
executed: }
Execution Count:261
261
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:7052
yes
Evaluation Count:370
evaluated: updatedFiles.count() > 100
TRUEFALSE
yes
Evaluation Count:19
yes
Evaluation Count:7033
partially evaluated: base.msecsTo(current) > 1000
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:7403
0-7403
241 updates(path, updatedFiles); -
242 updatedFiles.clear(); -
243 base = current; -
244 firstTime = false; -
245 }
executed: }
Execution Count:19
19
246}
executed: }
Execution Count:7422
7422
247 -
248 -
249 -
250 -
251 -
Switch to Source codePreprocessed file

Generated by Squish Coco Non-Commercial