17FileInfoThread::FileInfoThread(QObject *parent)
21#if QT_CONFIG(filesystemwatcher)
24 sortFlags(QDir::Name),
26 updateTypes(UpdateType::None),
30 showDotAndDotDot(
false),
34 showOnlyReadable(
false),
37#if QT_CONFIG(filesystemwatcher)
38 watcher =
new QFileSystemWatcher(
this);
39 connect(watcher, SIGNAL(directoryChanged(QString)),
this, SLOT(dirChanged(QString)));
40 connect(watcher, SIGNAL(fileChanged(QString)),
this, SLOT(updateFile(QString)));
228 bool updateFiles =
false;
229 QMutexLocker locker(&mutex);
233 if (currentPath.isEmpty() || !needUpdate) {
234 emit statusChanged(currentPath.isEmpty() ? QQuickFolderListModel::Null : QQuickFolderListModel::Ready);
235 condition.wait(&mutex);
242 if (!currentPath.isEmpty()) {
244 emit statusChanged(QQuickFolderListModel::Loading);
247 getFileInfos(currentPath);
259 auto getFileInfosAsync = [guardedThis](){
262 guardedThis->scanPending =
false;
263 if (guardedThis->currentPath.isEmpty()) {
264 emit guardedThis->statusChanged(QQuickFolderListModel::Null);
267 emit guardedThis->statusChanged(QQuickFolderListModel::Loading);
268 guardedThis->getFileInfos(guardedThis->currentPath);
269 emit guardedThis->statusChanged(QQuickFolderListModel::Ready);
272 QTimer::singleShot(0, getFileInfosAsync);
295 qCDebug(lcFileInfoThread) <<
"getFileInfos called with path" << path <<
"- updateType" << updateTypes;
297 QDir::Filters filter;
299 filter = QDir::CaseSensitive;
301 filter = filter | QDir::Files;
303 filter = filter | QDir::AllDirs | QDir::Drives;
304 if (!showDot && !showDotAndDotDot)
305 filter = filter | QDir::NoDot;
306 if (path == rootPath || (!showDotDot && !showDotAndDotDot))
307 filter = filter | QDir::NoDotDot;
309 filter = filter | QDir::Hidden;
310 if (showOnlyReadable)
311 filter = filter | QDir::Readable;
313 sortFlags = sortFlags | QDir::DirsFirst;
315 QDir currentDir(path, QString(), sortFlags);
316 QList<FileProperty> filePropertyList;
318 const QFileInfoList fileInfoList = currentDir.entryInfoList(nameFilters, filter, sortFlags);
320 if (!fileInfoList.isEmpty()) {
321 filePropertyList.reserve(fileInfoList.size());
322 for (
const QFileInfo &info : fileInfoList)
323 filePropertyList << FileProperty(info);
325 if (updateTypes & UpdateType::Contents) {
327 int toIndex = currentFileList.size()-1;
328 findChangeRange(filePropertyList, fromIndex, toIndex);
329 currentFileList = filePropertyList;
330 qCDebug(lcFileInfoThread) <<
"- about to emit directoryUpdated with fromIndex" << fromIndex
331 <<
"toIndex" << toIndex <<
"fileInfoList" << fileInfoListToString(fileInfoList);
332 emit directoryUpdated(path, filePropertyList, fromIndex, toIndex);
334 currentFileList = filePropertyList;
335 if (updateTypes & UpdateType::Sort) {
336 qCDebug(lcFileInfoThread) <<
"- about to emit sortFinished - fileInfoList:"
337 << fileInfoListToString(fileInfoList);
338 emit sortFinished(filePropertyList);
340 qCDebug(lcFileInfoThread) <<
"- about to emit directoryChanged - fileInfoList:"
341 << fileInfoListToString(fileInfoList);
342 emit directoryChanged(path, filePropertyList);
347 if (updateTypes & UpdateType::Contents) {
349 int toIndex = currentFileList.size()-1;
350 currentFileList.clear();
351 qCDebug(lcFileInfoThread) <<
"- directory is empty, about to emit directoryUpdated with fromIndex"
352 << fromIndex <<
"toIndex" << toIndex;
353 emit directoryUpdated(path, filePropertyList, fromIndex, toIndex);
355 currentFileList.clear();
356 qCDebug(lcFileInfoThread) <<
"- directory is empty, about to emit directoryChanged";
357 emit directoryChanged(path, filePropertyList);
360 updateTypes = UpdateType::None;
366 if (currentFileList.size() == 0) {
368 toIndex = list.size();
373 int listSize = list.size() < currentFileList.size() ? list.size() : currentFileList.size();
374 bool changeFound =
false;
376 for (i=0; i < listSize; i++) {
377 if (list.at(i) != currentFileList.at(i)) {
389 toIndex = list.size() > currentFileList.size() ? list.size() - 1 : currentFileList.size() - 1;