17FileInfoThread::FileInfoThread(QObject *parent)
21#if QT_CONFIG(filesystemwatcher)
24 sortFlags(QDir::Name),
26 updateTypes(UpdateType::None),
30 showDotAndDotDot(
false),
32 showOnlyReadable(
false),
35#if QT_CONFIG(filesystemwatcher)
36 watcher =
new QFileSystemWatcher(
this);
37 connect(watcher, SIGNAL(directoryChanged(QString)),
this, SLOT(dirChanged(QString)));
38 connect(watcher, SIGNAL(fileChanged(QString)),
this, SLOT(updateFile(QString)));
206 bool updateFiles =
false;
207 QMutexLocker locker(&mutex);
211 if (currentPath.isEmpty() || !needUpdate) {
212 emit statusChanged(currentPath.isEmpty() ? QQuickFolderListModel::Null : QQuickFolderListModel::Ready);
213 condition.wait(&mutex);
220 if (!currentPath.isEmpty()) {
222 emit statusChanged(QQuickFolderListModel::Loading);
225 getFileInfos(currentPath);
237 auto getFileInfosAsync = [guardedThis](){
240 guardedThis->scanPending =
false;
241 if (guardedThis->currentPath.isEmpty()) {
242 emit guardedThis->statusChanged(QQuickFolderListModel::Null);
245 emit guardedThis->statusChanged(QQuickFolderListModel::Loading);
246 guardedThis->getFileInfos(guardedThis->currentPath);
247 emit guardedThis->statusChanged(QQuickFolderListModel::Ready);
250 QTimer::singleShot(0, getFileInfosAsync);
273 qCDebug(lcFileInfoThread) <<
"getFileInfos called with path" << path <<
"- updateType" << updateTypes;
275 QDir::Filters filter;
277 filter = QDir::CaseSensitive;
279 filter = filter | QDir::Files;
281 filter = filter | QDir::AllDirs | QDir::Drives;
282 if (!showDotAndDotDot)
283 filter = filter | QDir::NoDot | QDir::NoDotDot;
284 else if (path == rootPath)
285 filter = filter | QDir::NoDotDot;
287 filter = filter | QDir::Hidden;
288 if (showOnlyReadable)
289 filter = filter | QDir::Readable;
291 sortFlags = sortFlags | QDir::DirsFirst;
293 QDir currentDir(path, QString(), sortFlags);
294 QList<FileProperty> filePropertyList;
296 const QFileInfoList fileInfoList = currentDir.entryInfoList(nameFilters, filter, sortFlags);
298 if (!fileInfoList.isEmpty()) {
299 filePropertyList.reserve(fileInfoList.size());
300 for (
const QFileInfo &info : fileInfoList)
301 filePropertyList << FileProperty(info);
303 if (updateTypes & UpdateType::Contents) {
305 int toIndex = currentFileList.size()-1;
306 findChangeRange(filePropertyList, fromIndex, toIndex);
307 currentFileList = filePropertyList;
308 qCDebug(lcFileInfoThread) <<
"- about to emit directoryUpdated with fromIndex" << fromIndex
309 <<
"toIndex" << toIndex <<
"fileInfoList" << fileInfoListToString(fileInfoList);
310 emit directoryUpdated(path, filePropertyList, fromIndex, toIndex);
312 currentFileList = filePropertyList;
313 if (updateTypes & UpdateType::Sort) {
314 qCDebug(lcFileInfoThread) <<
"- about to emit sortFinished - fileInfoList:"
315 << fileInfoListToString(fileInfoList);
316 emit sortFinished(filePropertyList);
318 qCDebug(lcFileInfoThread) <<
"- about to emit directoryChanged - fileInfoList:"
319 << fileInfoListToString(fileInfoList);
320 emit directoryChanged(path, filePropertyList);
325 if (updateTypes & UpdateType::Contents) {
327 int toIndex = currentFileList.size()-1;
328 currentFileList.clear();
329 qCDebug(lcFileInfoThread) <<
"- directory is empty, about to emit directoryUpdated with fromIndex"
330 << fromIndex <<
"toIndex" << toIndex;
331 emit directoryUpdated(path, filePropertyList, fromIndex, toIndex);
333 currentFileList.clear();
334 qCDebug(lcFileInfoThread) <<
"- directory is empty, about to emit directoryChanged";
335 emit directoryChanged(path, filePropertyList);
338 updateTypes = UpdateType::None;
344 if (currentFileList.size() == 0) {
346 toIndex = list.size();
351 int listSize = list.size() < currentFileList.size() ? list.size() : currentFileList.size();
352 bool changeFound =
false;
354 for (i=0; i < listSize; i++) {
355 if (list.at(i) != currentFileList.at(i)) {
367 toIndex = list.size() > currentFileList.size() ? list.size() - 1 : currentFileList.size() - 1;