From: Guillaume Munch Date: Fri, 10 Mar 2017 23:11:02 +0000 (+0100) Subject: Nonsense for whoever insists on using gcc4.6 & qt4.8 in 2017 X-Git-Tag: 2.3.0alpha1~231 X-Git-Url: https://git.lyx.org/gitweb/?a=commitdiff_plain;h=24f68aff8d2ba9139017ca3927eda1f1aaf039af;p=features.git Nonsense for whoever insists on using gcc4.6 & qt4.8 in 2017 --- diff --git a/src/support/FileMonitor.cpp b/src/support/FileMonitor.cpp index a55fd2396b..051bbbbe0f 100644 --- a/src/support/FileMonitor.cpp +++ b/src/support/FileMonitor.cpp @@ -18,6 +18,7 @@ #include "support/unique_ptr.h" #include +#include #include #include @@ -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 09d85e81a1..deca740657 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; +typedef std::unique_ptr 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; +typedef std::shared_ptr FileMonitorBlocker; /// Main class @@ -146,7 +154,7 @@ class FileMonitor : public QObject public: FileMonitor(std::shared_ptr monitor); - using sig = boost::signals2::signal; + typedef boost::signals2::signal 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