Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
fileinfothread_p.h
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#ifndef FILEINFOTHREAD_P_H
5#define FILEINFOTHREAD_P_H
6
7//
8// W A R N I N G
9// -------------
10//
11// This file is not part of the Qt API. It exists purely as an
12// implementation detail. This header file may change from version to
13// version without notice, or even be removed.
14//
15// We mean it.
16//
17
18#include <QThread>
19#include <QMutex>
20#include <QWaitCondition>
21#if QT_CONFIG(filesystemwatcher)
22#include <QFileSystemWatcher>
23#endif
24#include <QFileInfo>
25#include <QDir>
26
27#include "fileproperty_p.h"
29
31
32class FileInfoThread : public QThread
33{
34 Q_OBJECT
35
36Q_SIGNALS:
38 void directoryUpdated(const QString &directory, const QList<FileProperty> &list, int fromIndex, int toIndex) const;
39 void sortFinished(const QList<FileProperty> &list) const;
40 void statusChanged(QQuickFolderListModel::Status status) const;
41
42public:
43 FileInfoThread(QObject *parent = nullptr);
45
46 void clear();
47 void removePath(const QString &path);
48 void setPath(const QString &path);
49 void setRootPath(const QString &path);
50 void setSortFlags(QDir::SortFlags flags);
51 void setNameFilters(const QStringList & nameFilters);
52 void setShowFiles(bool show);
53 void setShowDirs(bool showFolders);
54 void setShowDirsFirst(bool show);
55 void setShowDotAndDotDot(bool on);
56 void setShowDot(bool on);
57 void setShowDotDot(bool on);
58 void setShowHidden(bool on);
59 void setShowOnlyReadable(bool on);
60 void setCaseSensitive(bool on);
61
62public Q_SLOTS:
63#if QT_CONFIG(filesystemwatcher)
64 void dirChanged(const QString &directoryPath);
65 void updateFile(const QString &path);
66#endif
67
68protected:
69 void run() override;
70 void runOnce();
71 void initiateScan();
72 void getFileInfos(const QString &path);
73 void findChangeRange(const QList<FileProperty> &list, int &fromIndex, int &toIndex);
74
75private:
76 enum class UpdateType {
77 None = 1 << 0,
78 // The order of the files in the current folder changed.
79 Sort = 1 << 1,
80 // A subset of files in the current folder changed.
81 Contents = 1 << 2
82 };
83 Q_DECLARE_FLAGS(UpdateTypes, UpdateType)
84
85 // Declare these ourselves, as Q_DECLARE_OPERATORS_FOR_FLAGS needs the enum to be public.
86 friend constexpr UpdateTypes operator|(UpdateType f1, UpdateTypes f2) noexcept;
87 friend constexpr UpdateTypes operator&(UpdateType f1, UpdateTypes f2) noexcept;
88
89 QMutex mutex;
90 QWaitCondition condition;
91 volatile bool abort;
92 bool scanPending;
93
94#if QT_CONFIG(filesystemwatcher)
96#endif
97 QList<FileProperty> currentFileList;
98 QDir::SortFlags sortFlags;
99 QString currentPath;
100 QString rootPath;
101 QStringList nameFilters;
102 bool needUpdate;
103 UpdateTypes updateTypes;
104 bool showFiles;
105 bool showDirs;
106 bool showDirsFirst;
107 bool showDotAndDotDot;
108 bool showDot;
109 bool showDotDot;
110 bool showHidden;
111 bool showOnlyReadable;
112 bool caseSensitive;
113};
114
115QT_END_NAMESPACE
116
117#endif // FILEINFOTHREAD_P_H
void removePath(const QString &path)
void setRootPath(const QString &path)
void setShowFiles(bool show)
void directoryUpdated(const QString &directory, const QList< FileProperty > &list, int fromIndex, int toIndex) const
void setShowDotAndDotDot(bool on)
void setShowDotDot(bool on)
void statusChanged(QQuickFolderListModel::Status status) const
void setShowDot(bool on)
void setNameFilters(const QStringList &nameFilters)
FileInfoThread(QObject *parent=nullptr)
void setShowDirsFirst(bool show)
void setCaseSensitive(bool on)
void setShowDirs(bool showFolders)
void sortFinished(const QList< FileProperty > &list) const
void findChangeRange(const QList< FileProperty > &list, int &fromIndex, int &toIndex)
void setShowHidden(bool on)
void getFileInfos(const QString &path)
void setShowOnlyReadable(bool on)
void setPath(const QString &path)
void setSortFlags(QDir::SortFlags flags)
QString fileInfoListToString(const QFileInfoList &fileInfoList)
constexpr FileInfoThread::UpdateTypes operator|(FileInfoThread::UpdateType f1, FileInfoThread::UpdateTypes f2) noexcept
constexpr FileInfoThread::UpdateTypes operator&(FileInfoThread::UpdateType f1, FileInfoThread::UpdateTypes f2) noexcept
Combined button and popup list for selecting options.