From b5ff9955a87009ebb6dc48c90657876a7fe69bad Mon Sep 17 00:00:00 2001 From: John Maguire Date: Thu, 5 Jan 2012 15:01:43 +0000 Subject: [PATCH] Disable watching for FS updates when requested. (cherry picked from commit 55e9fd8dc39df3a8884656aec6fc1cebf1268ccc) --- src/core/filesystemwatcherinterface.h | 1 + src/core/macfslistener.h | 2 +- src/core/macfslistener.mm | 5 +++++ src/core/qtfslistener.cpp | 7 +++++++ src/core/qtfslistener.h | 1 + src/library/librarywatcher.cpp | 2 +- 6 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/core/filesystemwatcherinterface.h b/src/core/filesystemwatcherinterface.h index 582391c02..4663b46c8 100644 --- a/src/core/filesystemwatcherinterface.h +++ b/src/core/filesystemwatcherinterface.h @@ -9,6 +9,7 @@ class FileSystemWatcherInterface : public QObject { FileSystemWatcherInterface(QObject* parent = 0); virtual void Init() {} virtual void AddPath(const QString& path) = 0; + virtual void Clear() = 0; static FileSystemWatcherInterface* Create(QObject* parent = 0); diff --git a/src/core/macfslistener.h b/src/core/macfslistener.h index 9e214232e..de3602ad0 100644 --- a/src/core/macfslistener.h +++ b/src/core/macfslistener.h @@ -14,8 +14,8 @@ class MacFSListener : public FileSystemWatcherInterface { public: explicit MacFSListener(QObject* parent = 0); void Init(); - void AddPath(const QString& path); + void Clear(); signals: void PathChanged(const QString& path); diff --git a/src/core/macfslistener.mm b/src/core/macfslistener.mm index 3e245ac0c..88d6d1161 100644 --- a/src/core/macfslistener.mm +++ b/src/core/macfslistener.mm @@ -39,6 +39,11 @@ void MacFSListener::AddPath(const QString& path) { UpdateStream(); } +void MacFSListener::Clear() { + paths_.clear(); + UpdateStream(); +} + void MacFSListener::UpdateStream() { if (stream_) { FSEventStreamStop(stream_); diff --git a/src/core/qtfslistener.cpp b/src/core/qtfslistener.cpp index 0a136f779..5b8560a55 100644 --- a/src/core/qtfslistener.cpp +++ b/src/core/qtfslistener.cpp @@ -1,5 +1,7 @@ #include "qtfslistener.h" +#include + QtFSListener::QtFSListener(QObject* parent) : FileSystemWatcherInterface(parent), watcher_(this) { @@ -10,3 +12,8 @@ QtFSListener::QtFSListener(QObject* parent) void QtFSListener::AddPath(const QString& path) { watcher_.addPath(path); } + +void QtFSListener::Clear() { + watcher_.removePaths(watcher_.directories()); + watcher_.removePaths(watcher_.files()); +} diff --git a/src/core/qtfslistener.h b/src/core/qtfslistener.h index 8b2dec126..cb3b737cb 100644 --- a/src/core/qtfslistener.h +++ b/src/core/qtfslistener.h @@ -10,6 +10,7 @@ class QtFSListener : public FileSystemWatcherInterface { public: QtFSListener(QObject* parent); virtual void AddPath(const QString& path); + virtual void Clear(); private: QFileSystemWatcher watcher_; diff --git a/src/library/librarywatcher.cpp b/src/library/librarywatcher.cpp index 4396c4f32..74457d239 100644 --- a/src/library/librarywatcher.cpp +++ b/src/library/librarywatcher.cpp @@ -694,7 +694,7 @@ void LibraryWatcher::ReloadSettings() { } if (!monitor_ && was_monitoring_before) { - // TODO: Remove all directories from watcher. + fs_watcher_->Clear(); } else if (monitor_ && !was_monitoring_before) { // Add all directories to all QFileSystemWatchers again foreach (const DirData& data, watched_dirs_.values()) {