Phosphor
Qt6 / Wayland library suite for window-management tools
Loading...
Searching...
No Matches
WatchedFileSet.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: 2026 fuddlesworth
2// SPDX-License-Identifier: LGPL-2.1-or-later
3
4#pragma once
5
6#include <PhosphorFsLoader/phosphorfsloader_export.h>
7
8#include <QtCore/QHash>
9#include <QtCore/QObject>
10#include <QtCore/QString>
11#include <QtCore/QStringList>
12#include <QtCore/QTimer>
13
14#include <memory>
15
16QT_BEGIN_NAMESPACE
17class QFileSystemWatcher;
18QT_END_NAMESPACE
19
20namespace PhosphorFsLoader {
21
22namespace detail {
23class IdentityWatches;
24}
25
80class PHOSPHORFSLOADER_EXPORT WatchedFileSet : public QObject
81{
82 Q_OBJECT
83
84public:
87 static constexpr int DefaultDebounceMs = 100;
88
89 explicit WatchedFileSet(QObject* parent = nullptr);
90 ~WatchedFileSet() override;
91
94
108 void setPaths(const QStringList& paths);
109
111 QStringList paths() const;
112
117 int debounceInterval() const;
118
123 QStringList watchedPathsForTest() const;
124
125Q_SIGNALS:
133 void filesChanged(const QStringList& paths);
134
135private:
139 struct Fingerprint
140 {
141 bool exists = false;
142 quint64 device = 0;
143 quint64 inode = 0;
144 qint64 size = 0;
145 qint64 mtimeSec = 0;
146 qint64 mtimeNsec = 0;
147
148 bool operator==(const Fingerprint&) const = default;
149 };
150
151 static Fingerprint fingerprintOf(const QString& path);
152 void onDebounceElapsed();
153 void onIdentityWindowElapsed();
154
155 QFileSystemWatcher* m_watcher = nullptr;
158 std::unique_ptr<detail::IdentityWatches> m_watches;
159 QStringList m_paths;
160 QHash<QString, Fingerprint> m_fingerprints;
163 QTimer m_debounceTimer;
168 QTimer m_identityTimer;
169};
170
171} // namespace PhosphorFsLoader
void setDebounceInterval(int ms)
Change the debounce window, for reports and for identity checks alike.
WatchedFileSet(const WatchedFileSet &)=delete
QStringList paths() const
The watched paths in normalised form, in the order given to setPaths.
static constexpr int DefaultDebounceMs
Default debounce, long enough to coalesce an editor's write-temp-then-rename save into one report.
Definition WatchedFileSet.h:87
void filesChanged(const QStringList &paths)
Emitted once per debounce window that changed something.
WatchedFileSet & operator=(const WatchedFileSet &)=delete
QStringList watchedPathsForTest() const
Test-only: every path the underlying watcher currently holds (files and directories together,...
void setPaths(const QStringList &paths)
Replace the watched set with paths.
WatchedFileSet(QObject *parent=nullptr)
Definition MetadataPackScanStrategy.h:506
Definition ContainedFileReader.h:15