X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Fsupport%2FFileMonitor.cpp;h=a3b17ad012f3f9a86e6505790ee16a400532b446;hb=cf14e814124ccbc8155fa1dde98d03be319c0e87;hp=2a794f29318b0442726d01182c11c17fb69518ec;hpb=b30161b591264f06579dd30805573e456bb870d3;p=lyx.git diff --git a/src/support/FileMonitor.cpp b/src/support/FileMonitor.cpp index 2a794f2931..a3b17ad012 100644 --- a/src/support/FileMonitor.cpp +++ b/src/support/FileMonitor.cpp @@ -176,7 +176,14 @@ FileMonitor::FileMonitor(std::shared_ptr monitor) void FileMonitor::connectToFileMonitorGuard() { + // Connections need to be asynchronous because the receiver can own this + // object and therefore is allowed to delete it. + // Qt signal: QObject::connect(monitor_.get(), SIGNAL(fileChanged(bool)), + this, SIGNAL(fileChanged(bool)), + Qt::QueuedConnection); + // Boost signal: + QObject::connect(this, SIGNAL(fileChanged(bool)), this, SLOT(changed(bool))); } @@ -187,54 +194,10 @@ signals2::connection FileMonitor::connect(slot const & slot) } -void FileMonitor::disconnect() -{ - fileChanged_.disconnect_all_slots(); - QObject::disconnect(this, SIGNAL(fileChanged(bool))); -} - - void FileMonitor::changed(bool const exists) { // emit boost signal fileChanged_(exists); - Q_EMIT fileChanged(exists); -} - - -FileMonitorBlocker FileMonitor::block(int delay) -{ - FileMonitorBlocker blocker = blocker_.lock(); - if (!blocker) - blocker_ = blocker = make_shared(this); - blocker->setDelay(delay); - return blocker; -} - - -FileMonitorBlockerGuard::FileMonitorBlockerGuard(FileMonitor * monitor) - : monitor_(monitor), delay_(0) -{ - QObject::disconnect(monitor->monitor_.get(), SIGNAL(fileChanged(bool)), - monitor, SLOT(changed(bool))); -} - - -void FileMonitorBlockerGuard::setDelay(int delay) -{ - delay_ = max(delay_, delay); -} - - -FileMonitorBlockerGuard::~FileMonitorBlockerGuard() -{ - if (!monitor_) - return; - // Even if delay_ is 0, the QTimer is necessary. Indeed, the notifications - // 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_, monitor_, SLOT(connectToFileMonitorGuard())); } @@ -280,7 +243,7 @@ void ActiveFileMonitor::checkModified() } } if (changed) - FileMonitor::changed(exists); + Q_EMIT FileMonitor::fileChanged(exists); QTimer::singleShot(interval_, this, SLOT(clearCooldown())); }