mirror of
https://git.lyx.org/repos/lyx.git
synced 2025-01-18 13:40:19 +00:00
Nonsense for whoever insists on using gcc4.6 & qt4.8 in 2017
This commit is contained in:
parent
f96d7a8b2c
commit
24f68aff8d
@ -18,6 +18,7 @@
|
|||||||
#include "support/unique_ptr.h"
|
#include "support/unique_ptr.h"
|
||||||
|
|
||||||
#include <QFile>
|
#include <QFile>
|
||||||
|
#include <QStringList>
|
||||||
#include <QTimer>
|
#include <QTimer>
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
@ -103,6 +104,7 @@ void FileMonitorGuard::refresh(bool new_file)
|
|||||||
QString const qfilename = toqstr(filename_);
|
QString const qfilename = toqstr(filename_);
|
||||||
if(!qwatcher_->files().contains(qfilename)) {
|
if(!qwatcher_->files().contains(qfilename)) {
|
||||||
bool exists = QFile(qfilename).exists();
|
bool exists = QFile(qfilename).exists();
|
||||||
|
#if (QT_VERSION >= 0x050000)
|
||||||
if (!exists || !qwatcher_->addPath(qfilename)) {
|
if (!exists || !qwatcher_->addPath(qfilename)) {
|
||||||
if (exists)
|
if (exists)
|
||||||
LYXERR(Debug::FILES,
|
LYXERR(Debug::FILES,
|
||||||
@ -111,6 +113,21 @@ void FileMonitorGuard::refresh(bool new_file)
|
|||||||
QTimer::singleShot(1000, this, [=](){
|
QTimer::singleShot(1000, this, [=](){
|
||||||
refresh(new_file || !exists);
|
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)
|
} else if (exists && new_file)
|
||||||
Q_EMIT fileChanged();
|
Q_EMIT fileChanged();
|
||||||
}
|
}
|
||||||
@ -199,9 +216,7 @@ FileMonitorBlockerGuard::~FileMonitorBlockerGuard()
|
|||||||
// from QFileSystemWatcher that we meant to ignore are not going to be
|
// from QFileSystemWatcher that we meant to ignore are not going to be
|
||||||
// treated immediately, so we must yield to give us the opportunity to
|
// treated immediately, so we must yield to give us the opportunity to
|
||||||
// ignore them.
|
// ignore them.
|
||||||
QTimer::singleShot(delay_, parent, [parent]() {
|
QTimer::singleShot(delay_, parent, SLOT(connectToFileMonitorGuard()));
|
||||||
parent->connectToFileMonitorGuard();
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace support
|
} // namespace support
|
||||||
|
@ -34,7 +34,7 @@ class FileName;
|
|||||||
|
|
||||||
class FileMonitor;
|
class FileMonitor;
|
||||||
class FileMonitorGuard;
|
class FileMonitorGuard;
|
||||||
using FileMonitorPtr = std::unique_ptr<FileMonitor>;
|
typedef std::unique_ptr<FileMonitor> FileMonitorPtr;
|
||||||
|
|
||||||
///
|
///
|
||||||
/// Watch a file:
|
/// Watch a file:
|
||||||
@ -115,6 +115,14 @@ private Q_SLOTS:
|
|||||||
/// Receive notifications from the QFileSystemWatcher
|
/// Receive notifications from the QFileSystemWatcher
|
||||||
void notifyChange(QString const & path);
|
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:
|
private:
|
||||||
std::string const filename_;
|
std::string const filename_;
|
||||||
QFileSystemWatcher * qwatcher_;
|
QFileSystemWatcher * qwatcher_;
|
||||||
@ -134,7 +142,7 @@ public:
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
using FileMonitorBlocker = std::shared_ptr<FileMonitorBlockerGuard>;
|
typedef std::shared_ptr<FileMonitorBlockerGuard> FileMonitorBlocker;
|
||||||
|
|
||||||
|
|
||||||
/// Main class
|
/// Main class
|
||||||
@ -146,7 +154,7 @@ class FileMonitor : public QObject
|
|||||||
public:
|
public:
|
||||||
FileMonitor(std::shared_ptr<FileMonitorGuard> monitor);
|
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.
|
/// Connect and you'll be informed when the file has changed.
|
||||||
boost::signals2::connection connect(sig::slot_type const &);
|
boost::signals2::connection connect(sig::slot_type const &);
|
||||||
/// disconnect all slots connected to the boost signal fileChanged_ or to
|
/// disconnect all slots connected to the boost signal fileChanged_ or to
|
||||||
@ -173,9 +181,10 @@ Q_SIGNALS:
|
|||||||
private Q_SLOTS:
|
private Q_SLOTS:
|
||||||
/// Receive notifications from the FileMonitorGuard
|
/// Receive notifications from the FileMonitorGuard
|
||||||
void changed();
|
void changed();
|
||||||
|
///
|
||||||
|
void connectToFileMonitorGuard();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void connectToFileMonitorGuard();
|
|
||||||
// boost signal
|
// boost signal
|
||||||
sig fileChanged_;
|
sig fileChanged_;
|
||||||
// the unique watch for our file
|
// the unique watch for our file
|
||||||
|
Loading…
x
Reference in New Issue
Block a user