X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Fsupport%2FFileMonitor.h;h=07a8dc532c93335007ab4f9b79e5b24afa445dd6;hb=c6b17b7094c42ff6bf96e3452f69023c724d15b7;hp=49f12cba7271a0084d41fa9f1a0cfc63918752cd;hpb=db58111360d68f76c5797069a7b80967447d1379;p=lyx.git diff --git a/src/support/FileMonitor.h b/src/support/FileMonitor.h index 49f12cba72..07a8dc532c 100644 --- a/src/support/FileMonitor.h +++ b/src/support/FileMonitor.h @@ -60,16 +60,6 @@ typedef std::unique_ptr ActiveFileMonitorPtr; /// monitor.connect(...); /// (stops watching the first) /// -/// Block notifications for the duration of a scope: -/// { -/// FileMonitorBlocker block = monitor.block(); -/// ... -/// } -/// -/// Reset connections: -/// monitor.disconnect(); -/// or the disconnect method of the connection object for the boost signal. -/// class FileSystemWatcher { public: @@ -108,18 +98,16 @@ public: ~FileMonitorGuard(); /// absolute path being tracked std::string const & filename() { return filename_; } - /// if false, emit fileChanged() when we notice the existence of the file - void setExists(bool exists) { exists_ = exists; } public Q_SLOTS: /// Make sure it is being monitored, after e.g. a deletion. See /// . This is called /// automatically. - void refresh(); + void refresh(bool emit = true); Q_SIGNALS: /// Connect to this to be notified when the file changes - void fileChanged() const; + void fileChanged(bool exists) const; private Q_SLOTS: /// Receive notifications from the QFileSystemWatcher @@ -128,51 +116,25 @@ private Q_SLOTS: private: std::string const filename_; QFileSystemWatcher * qwatcher_; + /// for emitting fileChanged() when the file is created or deleted bool exists_; }; -class FileMonitorBlockerGuard : public QObject -{ - Q_OBJECT - QPointer monitor_; - int delay_; - -public: - FileMonitorBlockerGuard(FileMonitor * monitor); - ~FileMonitorBlockerGuard(); - void setDelay(int delay); -}; - - -typedef std::shared_ptr FileMonitorBlocker; - - /// Main class class FileMonitor : public QObject { Q_OBJECT - friend class FileMonitorBlockerGuard; public: FileMonitor(std::shared_ptr monitor); - typedef signals2::signal sig; + typedef signals2::signal sig; typedef sig::slot_type slot; /// Connect and you'll be informed when the file has changed. signals2::connection connect(slot const &); - /// disconnect all slots connected to the boost signal fileChanged_ or to - /// the qt signal fileChanged() - void disconnect(); /// absolute path being tracked std::string const & filename() { return monitor_->filename(); } - /// Creates a guard that blocks notifications. Copyable. Notifications from - /// this monitor are blocked as long as there are copies around. - /// \param delay is the amount waited in ms after expiration of the guard - /// before reconnecting. This delay thing is to deal with asynchronous - /// notifications in a not so elegant fashion. But it can also be used to - /// slow down incoming events. - FileMonitorBlocker block(int delay = 0); /// Make sure the good file is being monitored, after e.g. a move or a /// deletion. See . This is /// called automatically. @@ -180,21 +142,19 @@ public: Q_SIGNALS: /// Connect to this to be notified when the file changes - void fileChanged() const; + void fileChanged(bool exists) const; protected Q_SLOTS: /// Receive notifications from the FileMonitorGuard - void changed(); + void changed(bool exists); /// - void reconnectToFileMonitorGuard(); + void connectToFileMonitorGuard(); private: /// boost signal sig fileChanged_; /// the unique watch for our file std::shared_ptr const monitor_; - /// - std::weak_ptr blocker_; };