Line | Source Code | Coverage |
---|
1 | | - |
2 | QFileInfoGatherer::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 | | - |
23 | QFileInfoGatherer::~QFileInfoGatherer() | - |
24 | { | - |
25 | abort.store(true); | - |
26 | condition.wakeAll(); | - |
27 | wait(); | - |
28 | } executed: } Execution Count:273 | 273 |
29 | | - |
30 | void QFileInfoGatherer::setResolveSymlinks(bool enable) | - |
31 | { | - |
32 | (void)enable;; | - |
33 | | - |
34 | | - |
35 | | - |
36 | } executed: } Execution Count:2 | 2 |
37 | | - |
38 | bool QFileInfoGatherer::resolveSymlinks() const | - |
39 | { | - |
40 | | - |
41 | | - |
42 | | - |
43 | return false; executed: return false; Execution Count:593 | 593 |
44 | | - |
45 | } | - |
46 | | - |
47 | void QFileInfoGatherer::setIconProvider(QFileIconProvider *provider) | - |
48 | { | - |
49 | m_iconProvider = provider; | - |
50 | } executed: } Execution Count:4 | 4 |
51 | | - |
52 | QFileIconProvider *QFileInfoGatherer::iconProvider() const | - |
53 | { | - |
54 | return m_iconProvider; executed: return m_iconProvider; Execution Count:302 | 302 |
55 | } | - |
56 | | - |
57 | | - |
58 | | - |
59 | | - |
60 | | - |
61 | | - |
62 | void 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 yes Evaluation Count:7 | yes Evaluation Count:448 |
| 7-448 |
68 | if (this->files.at(loc) == files) { partially evaluated: this->files.at(loc) == files 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 | } | 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 | | - |
83 | void 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 | } | 0 |
89 | | - |
90 | | - |
91 | | - |
92 | | - |
93 | | - |
94 | | - |
95 | void QFileInfoGatherer::clear() | - |
96 | { | - |
97 | | - |
98 | QMutexLocker locker(&mutex); | - |
99 | watcher->removePaths(watcher->files()); | - |
100 | watcher->removePaths(watcher->directories()); | - |
101 | | - |
102 | } | 0 |
103 | | - |
104 | | - |
105 | | - |
106 | | - |
107 | | - |
108 | | - |
109 | void 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 | | - |
122 | void QFileInfoGatherer::list(const QString &directoryPath) | - |
123 | { | - |
124 | fetchExtendedInformation(directoryPath, QStringList()); | - |
125 | } executed: } Execution Count:455 | 455 |
126 | | - |
127 | | - |
128 | | - |
129 | | - |
130 | void QFileInfoGatherer::run() | - |
131 | { | - |
132 | for(;;) { | - |
133 | QMutexLocker locker(&mutex); | - |
134 | while (!abort.load() && path.isEmpty()) evaluated: !abort.load() yes Evaluation Count:1020 | yes Evaluation Count:273 |
evaluated: path.isEmpty() 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() 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 | } | 0 |
147 | | - |
148 | QExtendedInformation 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 | | - |
156 | static 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 | | - |
172 | void QFileInfoGatherer::getFileInfos(const QString &path, const QStringList &files) | - |
173 | { | - |
174 | | - |
175 | if (files.isEmpty() partially evaluated: files.isEmpty() yes Evaluation Count:439 | no Evaluation Count:0 |
| 0-439 |
176 | && !path.isEmpty() evaluated: !path.isEmpty() yes Evaluation Count:342 | yes Evaluation Count:97 |
| 97-342 |
177 | && !path.startsWith(QLatin1String("//")) ) { partially evaluated: !path.startsWith(QLatin1String("//")) 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) 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() yes Evaluation Count:97 | yes Evaluation Count:342 |
| 97-342 |
186 | | - |
187 | | - |
188 | | - |
189 | QFileInfoList infoList; | - |
190 | if (files.isEmpty()) { partially evaluated: files.isEmpty() 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 | } | 0 |
197 | for (int i = infoList.count() - 1; i >= 0; --i) { evaluated: i >= 0 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() yes Evaluation Count:50672 | yes Evaluation Count:43 |
evaluated: dirIt.hasNext() 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() 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() yes Evaluation Count:299 | yes Evaluation Count:43 |
partially evaluated: filesIt != filesToCheck.constEnd() 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 | } | 0 |
231 | if (!updatedFiles.isEmpty()) partially evaluated: !updatedFiles.isEmpty() 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 | | - |
236 | void 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 yes Evaluation Count:11022 | yes Evaluation Count:39354 |
evaluated: updatedFiles.count() > 100 yes Evaluation Count:79 | yes Evaluation Count:10943 |
partially evaluated: base.msecsTo(current) > 1000 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 | | - |
| | |