]> git.lyx.org Git - lyx.git/blobdiff - src/support/FileMonitor.h
Account for old versions of Pygments
[lyx.git] / src / support / FileMonitor.h
index 5e516bb01283bfdb6f5d8869237c13ade3cd50cf..14aa834c80c6a556a09fb2a73ae96f92999f5154 100644 (file)
@@ -60,12 +60,6 @@ typedef std::unique_ptr<ActiveFileMonitor> 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.
@@ -108,18 +102,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
        /// <https://bugreports.qt.io/browse/QTBUG-46483>. 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,36 +120,20 @@ 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<FileMonitor> monitor_;
-       int delay_;
-
-public:
-       FileMonitorBlockerGuard(FileMonitor * monitor);
-       ~FileMonitorBlockerGuard();
-       void setDelay(int delay);
-};
-
-
-typedef std::shared_ptr<FileMonitorBlockerGuard> FileMonitorBlocker;
-
-
 /// Main class
 class FileMonitor : public QObject
 {
        Q_OBJECT
-       friend class FileMonitorBlockerGuard;
 
 public:
        FileMonitor(std::shared_ptr<FileMonitorGuard> monitor);
 
-       typedef signals2::signal<void()> sig;
+       typedef signals2::signal<void(bool)> sig;
        typedef sig::slot_type slot;
        /// Connect and you'll be informed when the file has changed.
        signals2::connection connect(slot const &);
@@ -166,20 +142,6 @@ public:
        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 of the
-       /// FileMonitorBlocker around.
-       /// \param delay is the amount waited in ms after expiration of the guard
-       /// before reconnecting. It can be used to slow down incoming events
-       /// accordingly. A value of 0 is still made asynchronous, because of the
-       /// fundamentally asynchronous nature of QFileSystemWatcher. To catch one's
-       /// own file operations, a value of 0 for delay is sufficient with the
-       /// inotify backend (e.g. Linux); for OSX (kqueue), a value of 100ms is
-       /// unsufficient and more tests need to be done in combination with
-       /// flushing/syncing to disk in order to understand how to catch one's own
-       /// operations reliably. No feedback from Windows yet. See
-       /// <https://www.mail-archive.com/lyx-devel@lists.lyx.org/msg200252.html>.
-       FileMonitorBlocker block(int delay = 0);
        /// Make sure the good file is being monitored, after e.g. a move or a
        /// deletion. See <https://bugreports.qt.io/browse/QTBUG-46483>. This is
        /// called automatically.
@@ -187,21 +149,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<FileMonitorGuard> const monitor_;
-       ///
-       std::weak_ptr<FileMonitorBlockerGuard> blocker_;
 };