//static
FileMonitorPtr FileSystemWatcher::monitor(FileName const & filename)
{
- return make_unique<FileMonitor>(instance().getGuard(filename));
+ return lyx::make_unique<FileMonitor>(instance().getGuard(filename));
}
ActiveFileMonitorPtr FileSystemWatcher::activeMonitor(FileName const & filename,
int interval)
{
- return make_unique<ActiveFileMonitor>(instance().getGuard(filename),
+ return lyx::make_unique<ActiveFileMonitor>(instance().getGuard(filename),
filename, interval);
}
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)));
}
-signals2::connection FileMonitor::connect(slot const & slot)
+connection FileMonitor::connect(slot const & slot)
{
return fileChanged_.connect(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<FileMonitorBlockerGuard>(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()));
}
}
}
if (changed)
- FileMonitor::changed(exists);
+ Q_EMIT FileMonitor::fileChanged(exists);
QTimer::singleShot(interval_, this, SLOT(clearCooldown()));
}