Postpone FSEvent stream updates to avoid churn when adding large numbers of directories.
This commit is contained in:
parent
c0f905a478
commit
5ddf9bcf41
@ -22,6 +22,7 @@
|
||||
|
||||
#include <QObject>
|
||||
#include <QSet>
|
||||
#include <QTimer>
|
||||
|
||||
#include "filesystemwatcherinterface.h"
|
||||
|
||||
@ -38,9 +39,12 @@ class MacFSListener : public FileSystemWatcherInterface {
|
||||
signals:
|
||||
void PathChanged(const QString& path);
|
||||
|
||||
private:
|
||||
private slots:
|
||||
void UpdateStream();
|
||||
|
||||
private:
|
||||
void UpdateStreamAsync();
|
||||
|
||||
static void EventStreamCallback(
|
||||
ConstFSEventStreamRef stream,
|
||||
void* user_data,
|
||||
@ -53,6 +57,7 @@ class MacFSListener : public FileSystemWatcherInterface {
|
||||
FSEventStreamRef stream_;
|
||||
|
||||
QSet<QString> paths_;
|
||||
QTimer update_timer_;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@ -28,6 +28,9 @@ MacFSListener::MacFSListener(QObject* parent)
|
||||
: FileSystemWatcherInterface(parent),
|
||||
run_loop_(NULL),
|
||||
stream_(NULL) {
|
||||
update_timer_.setSingleShot(true);
|
||||
update_timer_.setInterval(2000);
|
||||
connect(&update_timer_, SIGNAL(timeout()), SLOT(UpdateStream()));
|
||||
}
|
||||
|
||||
void MacFSListener::Init() {
|
||||
@ -56,18 +59,22 @@ void MacFSListener::EventStreamCallback(
|
||||
void MacFSListener::AddPath(const QString& path) {
|
||||
Q_ASSERT(run_loop_);
|
||||
paths_.insert(path);
|
||||
UpdateStream();
|
||||
UpdateStreamAsync();
|
||||
}
|
||||
|
||||
void MacFSListener::RemovePath(const QString& path) {
|
||||
Q_ASSERT(run_loop_);
|
||||
paths_.remove(path);
|
||||
UpdateStream();
|
||||
UpdateStreamAsync();
|
||||
}
|
||||
|
||||
void MacFSListener::Clear() {
|
||||
paths_.clear();
|
||||
UpdateStream();
|
||||
UpdateStreamAsync();
|
||||
}
|
||||
|
||||
void MacFSListener::UpdateStreamAsync() {
|
||||
update_timer_.start();
|
||||
}
|
||||
|
||||
void MacFSListener::UpdateStream() {
|
||||
|
Loading…
x
Reference in New Issue
Block a user