commit 24f68aff8d2ba9139017ca3927eda1f1aaf039af
Author: Guillaume Munch <[email protected]>
Date:   Sat Mar 11 00:11:02 2017 +0100

    Nonsense for whoever insists on using gcc4.6 & qt4.8 in 2017
---
 src/support/FileMonitor.cpp |   21 ++++++++++++++++++---
 src/support/FileMonitor.h   |   17 +++++++++++++----
 2 files changed, 31 insertions(+), 7 deletions(-)

diff --git a/src/support/FileMonitor.cpp b/src/support/FileMonitor.cpp
index a55fd23..051bbbb 100644
--- a/src/support/FileMonitor.cpp
+++ b/src/support/FileMonitor.cpp
@@ -18,6 +18,7 @@
 #include "support/unique_ptr.h"
 
 #include <QFile>
+#include <QStringList>
 #include <QTimer>
 
 #include <algorithm>
@@ -103,6 +104,7 @@ void FileMonitorGuard::refresh(bool new_file)
        QString const qfilename = toqstr(filename_);
        if(!qwatcher_->files().contains(qfilename)) {
                bool exists = QFile(qfilename).exists();
+#if (QT_VERSION >= 0x050000)
                if (!exists || !qwatcher_->addPath(qfilename)) {
                        if (exists)
                                LYXERR(Debug::FILES,
@@ -111,6 +113,21 @@ void FileMonitorGuard::refresh(bool new_file)
                        QTimer::singleShot(1000, this, [=](){
                                        refresh(new_file || !exists);
                                });
+#else
+               auto add_path = [&]() {
+                       qwatcher_->addPath(qfilename);
+                       return qwatcher_->files().contains(qfilename);
+               };
+               if (!exists || !add_path()) {
+                       if (exists)
+                               LYXERR(Debug::FILES,
+                                      "Could not add path to 
QFileSystemWatcher: "
+                                      << filename_);
+                       if (new_file || !exists)
+                               QTimer::singleShot(1000, this, 
SLOT(refreshTrue()));
+                       else
+                               QTimer::singleShot(1000, this, 
SLOT(refreshFalse()));
+#endif
                } else if (exists && new_file)
                        Q_EMIT fileChanged();
        }
@@ -199,9 +216,7 @@ FileMonitorBlockerGuard::~FileMonitorBlockerGuard()
        // from QFileSystemWatcher that we meant to ignore are not going to be
        // treated immediately, so we must yield to give us the opportunity to
        // ignore them.
-       QTimer::singleShot(delay_, parent, [parent]() {
-                       parent->connectToFileMonitorGuard();
-               });
+       QTimer::singleShot(delay_, parent, SLOT(connectToFileMonitorGuard()));
 }
 
 } // namespace support
diff --git a/src/support/FileMonitor.h b/src/support/FileMonitor.h
index 09d85e8..deca740 100644
--- a/src/support/FileMonitor.h
+++ b/src/support/FileMonitor.h
@@ -34,7 +34,7 @@ class FileName;
 
 class FileMonitor;
 class FileMonitorGuard;
-using FileMonitorPtr = std::unique_ptr<FileMonitor>;
+typedef std::unique_ptr<FileMonitor> FileMonitorPtr;
 
 ///
 /// Watch a file:
@@ -115,6 +115,14 @@ private Q_SLOTS:
        /// Receive notifications from the QFileSystemWatcher
        void notifyChange(QString const & path);
 
+       /// nonsense introduced for when QT_VERSION < 0x050000, cannot be placed
+       /// between #ifdef
+       void refreshTrue() { refresh(true); }
+       /// nonsense introduced for when QT_VERSION < 0x050000, cannot be placed
+       /// between #ifdef
+       void refreshFalse() { refresh(false); }
+
+
 private:
        std::string const filename_;
        QFileSystemWatcher * qwatcher_;
@@ -134,7 +142,7 @@ public:
 };
 
 
-using FileMonitorBlocker = std::shared_ptr<FileMonitorBlockerGuard>;
+typedef std::shared_ptr<FileMonitorBlockerGuard> FileMonitorBlocker;
 
 
 /// Main class
@@ -146,7 +154,7 @@ class FileMonitor : public QObject
 public:
        FileMonitor(std::shared_ptr<FileMonitorGuard> monitor);
 
-       using sig = boost::signals2::signal<void()>;
+       typedef boost::signals2::signal<void()> sig;
        /// Connect and you'll be informed when the file has changed.
        boost::signals2::connection connect(sig::slot_type const &);
        /// disconnect all slots connected to the boost signal fileChanged_ or 
to
@@ -173,9 +181,10 @@ Q_SIGNALS:
 private Q_SLOTS:
        /// Receive notifications from the FileMonitorGuard
        void changed();
+       ///
+       void connectToFileMonitorGuard();
 
 private:
-       void connectToFileMonitorGuard();
        // boost signal
        sig fileChanged_;
        // the unique watch for our file

Reply via email to