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 QFILESYSTEMWATCHER_POLLING_P_H
5#define QFILESYSTEMWATCHER_POLLING_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 <QtCore/qbasictimer.h>
19#include <QtCore/qfileinfo.h>
20#include <QtCore/qmutex.h>
21#include <QtCore/qdatetime.h>
22#include <QtCore/qdir.h>
23#include <QtCore/qhash.h>
24
25#include "qfilesystemwatcher_p.h"
26
27QT_REQUIRE_CONFIG(filesystemwatcher);
28QT_BEGIN_NAMESPACE
29
30class QPollingFileSystemWatcherEngine : public QFileSystemWatcherEngine
31{
32 Q_OBJECT
33
34 class FileInfo
35 {
36 uint ownerId;
37 uint groupId;
38 QFile::Permissions permissions;
39 QDateTime lastModified;
40 QStringList entries;
41
42 public:
43 FileInfo(const QFileInfo &fileInfo)
44 : ownerId(fileInfo.ownerId()),
45 groupId(fileInfo.groupId()),
46 permissions(fileInfo.permissions()),
47 lastModified(fileInfo.lastModified(tz: QTimeZone::UTC))
48 {
49 if (fileInfo.isDir()) {
50 entries = fileInfo.absoluteDir().entryList(filters: QDir::AllEntries);
51 }
52 }
53 FileInfo &operator=(const QFileInfo &fileInfo)
54 {
55 *this = FileInfo(fileInfo);
56 return *this;
57 }
58
59 bool operator!=(const QFileInfo &fileInfo) const
60 {
61 if (fileInfo.isDir() && entries != fileInfo.absoluteDir().entryList(filters: QDir::AllEntries))
62 return true;
63 return (ownerId != fileInfo.ownerId()
64 || groupId != fileInfo.groupId()
65 || permissions != fileInfo.permissions()
66 || lastModified != fileInfo.lastModified(tz: QTimeZone::UTC));
67 }
68 };
69
70 QHash<QString, FileInfo> files, directories;
71
72public:
73 QPollingFileSystemWatcherEngine(QObject *parent);
74
75 QStringList addPaths(const QStringList &paths, QStringList *files, QStringList *directories) override;
76 QStringList removePaths(const QStringList &paths, QStringList *files, QStringList *directories) override;
77
78private:
79 void timerEvent(QTimerEvent *) final;
80
81private:
82 QBasicTimer timer;
83};
84
85QT_END_NAMESPACE
86#endif // QFILESYSTEMWATCHER_POLLING_P_H
87
88

source code of qtbase/src/corelib/io/qfilesystemwatcher_polling_p.h