commit 6c4b9c97cb4ca7c279777e84e9d6686153334b76
Author: Guillaume Munch <[email protected]>
Date: Sat Mar 18 20:39:34 2017 +0100
Blocking signals also blocks the notification of file creation (#10595)
---
src/support/FileMonitor.cpp | 22 +++++++++-------------
src/support/FileMonitor.h | 19 +++++++------------
2 files changed, 16 insertions(+), 25 deletions(-)
diff --git a/src/support/FileMonitor.cpp b/src/support/FileMonitor.cpp
index c14d3d6..ced1188 100644
--- a/src/support/FileMonitor.cpp
+++ b/src/support/FileMonitor.cpp
@@ -82,7 +82,7 @@ void FileSystemWatcher::debug()
FileMonitorGuard::FileMonitorGuard(string const & filename,
QFileSystemWatcher * qwatcher)
- : filename_(filename), qwatcher_(qwatcher)
+ : filename_(filename), qwatcher_(qwatcher), exists_(true)
{
QObject::connect(qwatcher, SIGNAL(fileChanged(QString const &)),
this, SLOT(notifyChange(QString const &)));
@@ -99,7 +99,7 @@ FileMonitorGuard::~FileMonitorGuard()
}
-void FileMonitorGuard::refresh(bool new_file)
+void FileMonitorGuard::refresh()
{
QString const qfilename = toqstr(filename_);
if(!qwatcher_->files().contains(qfilename)) {
@@ -117,16 +117,10 @@ void FileMonitorGuard::refresh(bool new_file)
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()));
- // Better (qt>=5.4):
- /*QTimer::singleShot(1000, this, [=](){
- refresh(new_file || !exists);
- });*/
- } else if (exists && new_file)
+ QTimer::singleShot(2000, this, SLOT(refresh()));
+ } else if (exists && !exists_)
Q_EMIT fileChanged();
+ setExists(exists);
}
}
@@ -146,13 +140,15 @@ void FileMonitorGuard::notifyChange(QString const & path)
FileMonitor::FileMonitor(std::shared_ptr<FileMonitorGuard> monitor)
: monitor_(monitor)
{
- connectToFileMonitorGuard();
+ QObject::connect(monitor_.get(), SIGNAL(fileChanged()),
+ this, SLOT(changed()));
refresh();
}
-void FileMonitor::connectToFileMonitorGuard()
+void FileMonitor::reconnectToFileMonitorGuard()
{
+ monitor_->setExists(true);
QObject::connect(monitor_.get(), SIGNAL(fileChanged()),
this, SLOT(changed()));
}
diff --git a/src/support/FileMonitor.h b/src/support/FileMonitor.h
index 768e61f..51dbd7c 100644
--- a/src/support/FileMonitor.h
+++ b/src/support/FileMonitor.h
@@ -101,12 +101,14 @@ public:
~FileMonitorGuard();
/// absolute path being tracked
std::string const & filename() { return filename_; }
+ /// if false, emit fileChanged() when we notice the existence of the
file
+ void setExists(bool exists) { exists_ = exists; }
+
+public Q_SLOTS:
/// Make sure it is being monitored, after e.g. a deletion. See
/// <https://bugreports.qt.io/browse/QTBUG-46483>. This is called
/// automatically.
- /// \param new_file If true, emit fileChanged if the file exists and
was
- /// successfully added.
- void refresh(bool new_file = false);
+ void refresh();
Q_SIGNALS:
/// Connect to this to be notified when the file changes
@@ -116,17 +118,10 @@ 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_;
+ bool exists_;
};
@@ -183,7 +178,7 @@ private Q_SLOTS:
/// Receive notifications from the FileMonitorGuard
void changed();
///
- void connectToFileMonitorGuard();
+ void reconnectToFileMonitorGuard();
private:
// boost signal