Phosphor
Qt6 / Wayland library suite for window-management tools
Loading...
Searching...
No Matches
WatchedDirectorySet.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/QSet>
11#include <QtCore/QString>
12#include <QtCore/QStringList>
13#include <QtCore/QTimer>
14
15#include <memory>
16
17QT_BEGIN_NAMESPACE
18class QFileSystemWatcher;
19QT_END_NAMESPACE
20
21namespace PhosphorFsLoader {
22
23class IScanStrategy;
24
25namespace detail {
26class IdentityWatches;
27}
28
40enum class LiveReload : quint8 {
43};
44
76
130class PHOSPHORFSLOADER_EXPORT WatchedDirectorySet : public QObject
131{
132 Q_OBJECT
133
134public:
142 explicit WatchedDirectorySet(IScanStrategy& strategy, QObject* parent = nullptr);
144
147
182 int registerDirectory(const QString& directory, LiveReload liveReload = LiveReload::Off);
183
196 int registerDirectories(const QStringList& directories, LiveReload liveReload = LiveReload::Off,
198
232 int setDirectories(const QStringList& directories, LiveReload liveReload = LiveReload::Off,
234
254
263 void rescanNow();
264
275 QStringList directories() const;
276
288 static QStringList filterNewSearchPaths(const QStringList& candidates, const QStringList& alreadyRegistered);
289
297
302 QString watchedAncestorForTest(const QString& target) const;
303
306 bool hasParentWatchForTest(const QString& path) const;
307
308Q_SIGNALS:
317
318private Q_SLOTS:
319 void rescanAll();
320
321private:
322 void installWatcherIfNeeded();
323 void attachWatcherForDir(const QString& directory);
324 void releaseAncestorWatchFor(const QString& targetKey);
325 void onWatchedPathChanged();
326 void syncFileWatches(const QStringList& desiredPaths);
331 bool refreshIdentityChains();
332 void dropWatchesOfMovedDirectories(const QStringList& moved);
336 bool isContentWatch(const QString& path) const;
337 void onIdentityCheckElapsed();
338
339 IScanStrategy* m_strategy = nullptr;
340 QStringList m_directories;
345 QFileSystemWatcher* m_watcher = nullptr;
349 std::unique_ptr<detail::IdentityWatches> m_identity;
350 QSet<QString> m_watchedParents;
361 QHash<QString, QString> m_parentWatchFor;
364 QSet<QString> m_watchedFiles;
368 QStringList m_linkedEntries;
375 QSet<QString> m_warnedFailedWatchPaths;
376 QTimer m_debounceTimer;
380 QTimer m_identityTimer;
387 int m_rescanDepth = 0;
388 bool m_rescanRequestedWhileRunning = false;
389};
390
391} // namespace PhosphorFsLoader
Pluggable enumeration / parse / commit policy for WatchedDirectorySet.
Definition IScanStrategy.h:63
WatchedDirectorySet(const WatchedDirectorySet &)=delete
int setDirectories(const QStringList &directories, LiveReload liveReload=LiveReload::Off, RegistrationOrder order=RegistrationOrder::LowestPriorityFirst)
Replace the registered directory set with directories.
void requestRescan()
Trigger a debounced rescan of every registered directory.
int registerDirectory(const QString &directory, LiveReload liveReload=LiveReload::Off)
Register a directory for scanning + (optionally) watching.
void rescanCompleted()
Fired after every rescan, coalesced by the 50 ms debounce.
static QStringList filterNewSearchPaths(const QStringList &candidates, const QStringList &alreadyRegistered)
Helper for consumers building search-path APIs on top of the set: canonicalises (QDir::cleanPath) eve...
void rescanNow()
Run a rescan synchronously on the calling stack.
bool hasParentWatchForTest(const QString &path) const
Test-only: returns true if path is currently in the internal parent-watch set.
WatchedDirectorySet & operator=(const WatchedDirectorySet &)=delete
QStringList directories() const
Currently-registered directories in registration order.
WatchedDirectorySet(IScanStrategy &strategy, QObject *parent=nullptr)
Construct with a borrowed strategy.
QString watchedAncestorForTest(const QString &target) const
Test-only: introspection of the ancestor-watch bookkeeping used by attachWatcherForDir when a target ...
int registerDirectories(const QStringList &directories, LiveReload liveReload=LiveReload::Off, RegistrationOrder order=RegistrationOrder::LowestPriorityFirst)
Register multiple directories in caller-declared priority order.
void setDebounceIntervalForTest(int ms)
Test-only: override the debounce interval (default 50 ms), for rescans and for identity checks alike.
Definition MetadataPackScanStrategy.h:506
Definition ContainedFileReader.h:15
RegistrationOrder
Caller's declared priority direction for registerDirectories / setDirectories input.
Definition WatchedDirectorySet.h:64
@ HighestPriorityFirst
[user, sys-highest, ..., sys-lowest] — the natural output of QStandardPaths::locateAll(GenericDataLoc...
Definition WatchedDirectorySet.h:74
@ LowestPriorityFirst
[sys-lowest, ..., sys-highest, user] — the canonical strategy view.
Definition WatchedDirectorySet.h:69
LiveReload
Opt-in policy for directory watching.
Definition WatchedDirectorySet.h:40
@ On
Definition WatchedDirectorySet.h:42
@ Off
Definition WatchedDirectorySet.h:41