1/****************************************************************************
2**
3** Copyright (C) 2016 The Qt Company Ltd.
4** Contact: https://www.qt.io/licensing/
5**
6** This file is part of the examples of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:LGPL$
9** Commercial License Usage
10** Licensees holding valid commercial Qt licenses may use this file in
11** accordance with the commercial license agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and The Qt Company. For licensing terms
14** and conditions see https://www.qt.io/terms-conditions. For further
15** information use the contact form at https://www.qt.io/contact-us.
16**
17** GNU Lesser General Public License Usage
18** Alternatively, this file may be used under the terms of the GNU Lesser
19** General Public License version 3 as published by the Free Software
20** Foundation and appearing in the file LICENSE.LGPL3 included in the
21** packaging of this file. Please review the following information to
22** ensure the GNU Lesser General Public License version 3 requirements
23** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
24**
25** GNU General Public License Usage
26** Alternatively, this file may be used under the terms of the GNU
27** General Public License version 2.0 or (at your option) the GNU General
28** Public license version 3 or any later version approved by the KDE Free
29** Qt Foundation. The licenses are as published by the Free Software
30** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
31** included in the packaging of this file. Please review the following
32** information to ensure the GNU General Public License requirements will
33** be met: https://www.gnu.org/licenses/gpl-2.0.html and
34** https://www.gnu.org/licenses/gpl-3.0.html.
35**
36** $QT_END_LICENSE$
37**
38****************************************************************************/
39
40#ifndef FILEINFOTHREAD_P_H
41#define FILEINFOTHREAD_P_H
42
43//
44// W A R N I N G
45// -------------
46//
47// This file is not part of the Qt API. It exists purely as an
48// implementation detail. This header file may change from version to
49// version without notice, or even be removed.
50//
51// We mean it.
52//
53
54#include <QThread>
55#include <QMutex>
56#include <QWaitCondition>
57#if QT_CONFIG(filesystemwatcher)
58#include <QFileSystemWatcher>
59#endif
60#include <QFileInfo>
61#include <QDir>
62
63#include "fileproperty_p.h"
64#include "qquickfolderlistmodel.h"
65
66class FileInfoThread : public QThread
67{
68 Q_OBJECT
69
70Q_SIGNALS:
71 void directoryChanged(const QString &directory, const QList<FileProperty> &list) const;
72 void directoryUpdated(const QString &directory, const QList<FileProperty> &list, int fromIndex, int toIndex) const;
73 void sortFinished(const QList<FileProperty> &list) const;
74 void statusChanged(QQuickFolderListModel::Status status) const;
75
76public:
77 FileInfoThread(QObject *parent = 0);
78 ~FileInfoThread();
79
80 void clear();
81 void removePath(const QString &path);
82 void setPath(const QString &path);
83 void setRootPath(const QString &path);
84 void setSortFlags(QDir::SortFlags flags);
85 void setNameFilters(const QStringList & nameFilters);
86 void setShowFiles(bool show);
87 void setShowDirs(bool showFolders);
88 void setShowDirsFirst(bool show);
89 void setShowDotAndDotDot(bool on);
90 void setShowHidden(bool on);
91 void setShowOnlyReadable(bool on);
92 void setCaseSensitive(bool on);
93
94public Q_SLOTS:
95#if QT_CONFIG(filesystemwatcher)
96 void dirChanged(const QString &directoryPath);
97 void updateFile(const QString &path);
98#endif
99
100protected:
101 void run() override;
102 void runOnce();
103 void initiateScan();
104 void getFileInfos(const QString &path);
105 void findChangeRange(const QList<FileProperty> &list, int &fromIndex, int &toIndex);
106
107private:
108 QMutex mutex;
109 QWaitCondition condition;
110 volatile bool abort;
111 bool scanPending;
112
113#if QT_CONFIG(filesystemwatcher)
114 QFileSystemWatcher *watcher;
115#endif
116 QList<FileProperty> currentFileList;
117 QDir::SortFlags sortFlags;
118 QString currentPath;
119 QString rootPath;
120 QStringList nameFilters;
121 bool needUpdate;
122 bool folderUpdate;
123 bool sortUpdate;
124 bool showFiles;
125 bool showDirs;
126 bool showDirsFirst;
127 bool showDotAndDotDot;
128 bool showHidden;
129 bool showOnlyReadable;
130 bool caseSensitive;
131};
132
133#endif // FILEINFOTHREAD_P_H
134

source code of qtdeclarative/src/imports/folderlistmodel/fileinfothread_p.h