#include "support/unique_ptr.h"
#include <QFile>
+#include <QStringList>
#include <QTimer>
#include <algorithm>
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,
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();
}
// 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
class FileMonitor;
class FileMonitorGuard;
-using FileMonitorPtr = std::unique_ptr<FileMonitor>;
+typedef std::unique_ptr<FileMonitor> FileMonitorPtr;
///
/// Watch a file:
/// 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_;
};
-using FileMonitorBlocker = std::shared_ptr<FileMonitorBlockerGuard>;
+typedef std::shared_ptr<FileMonitorBlockerGuard> FileMonitorBlocker;
/// Main class
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
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