]> git.lyx.org Git - features.git/commitdiff
Nonsense for whoever insists on using gcc4.6 & qt4.8 in 2017
authorGuillaume Munch <gm@lyx.org>
Fri, 10 Mar 2017 23:11:02 +0000 (00:11 +0100)
committerGuillaume Munch <gm@lyx.org>
Fri, 10 Mar 2017 23:50:57 +0000 (00:50 +0100)
src/support/FileMonitor.cpp
src/support/FileMonitor.h

index a55fd2396baf240e750e71b1d00394d03136e3cd..051bbbbe0fac5f61e0ab7b236d7f7bbe3f9c62ca 100644 (file)
@@ -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
index 09d85e81a11eb2ac3b2ab279c8ec550f340f791f..deca740657b5867dcf599b48e21d68d93bb27630 100644 (file)
@@ -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