From ad16347b087943741eaca30cc048e1aa32ad57c0 Mon Sep 17 00:00:00 2001 From: Guillaume Munch Date: Sun, 19 Mar 2017 14:41:54 +0100 Subject: [PATCH] Regularly check if graphics is modified when visible on screen (#10596) In case one cannot rely on QFileSystemWatcher. see https://www.mail-archive.com/lyx-devel@lists.lyx.org/msg199112.html --- src/graphics/GraphicsCacheItem.cpp | 12 ++++++++++-- src/graphics/GraphicsCacheItem.h | 2 ++ src/graphics/GraphicsLoader.cpp | 9 +++++++++ src/graphics/GraphicsLoader.h | 2 ++ src/insets/RenderGraphic.cpp | 1 + 5 files changed, 24 insertions(+), 2 deletions(-) diff --git a/src/graphics/GraphicsCacheItem.cpp b/src/graphics/GraphicsCacheItem.cpp index 0bd3779a4f..4ed496a533 100644 --- a/src/graphics/GraphicsCacheItem.cpp +++ b/src/graphics/GraphicsCacheItem.cpp @@ -99,7 +99,7 @@ public: /// The document filename this graphic item belongs to FileName const & doc_file_; /// - FileMonitorPtr monitor_; + ActiveFileMonitorPtr monitor_; /// Is the file compressed? bool zipped_; @@ -179,6 +179,14 @@ bool CacheItem::monitoring() const } +void CacheItem::checkModifiedAsync() const +{ + if (!pimpl_->monitor_) + return; + pimpl_->monitor_->checkModifiedAsync(); +} + + Image const * CacheItem::image() const { return pimpl_->image_.get(); @@ -214,7 +222,7 @@ void CacheItem::Impl::startMonitor() { if (monitor_) return; - monitor_ = FileSystemWatcher::monitor(filename_); + monitor_ = FileSystemWatcher::activeMonitor(filename_); monitor_->connect([=](){ startLoading(); }); } diff --git a/src/graphics/GraphicsCacheItem.h b/src/graphics/GraphicsCacheItem.h index b6d7d4164c..9cee2b872e 100644 --- a/src/graphics/GraphicsCacheItem.h +++ b/src/graphics/GraphicsCacheItem.h @@ -66,6 +66,8 @@ public: void startMonitoring() const; /// bool monitoring() const; + /// perform a modification check asynchronously + void checkModifiedAsync() const; /** Get the image associated with filename(). * If the image is not yet loaded, returns 0. diff --git a/src/graphics/GraphicsLoader.cpp b/src/graphics/GraphicsLoader.cpp index 617ce24fd0..26b4e5717e 100644 --- a/src/graphics/GraphicsLoader.cpp +++ b/src/graphics/GraphicsLoader.cpp @@ -328,6 +328,15 @@ bool Loader::monitoring() const } +void Loader::checkModifiedAsync() const +{ + if (!pimpl_->cached_item_) + return; + + pimpl_->cached_item_->checkModifiedAsync(); +} + + FileName const & Loader::filename() const { static FileName const empty; diff --git a/src/graphics/GraphicsLoader.h b/src/graphics/GraphicsLoader.h index 0b5885772e..62ea303b34 100644 --- a/src/graphics/GraphicsLoader.h +++ b/src/graphics/GraphicsLoader.h @@ -81,6 +81,8 @@ public: void startMonitoring() const; /// bool monitoring() const; + /// + void checkModifiedAsync() const; /// How far have we got in loading the image? ImageStatus status() const; diff --git a/src/insets/RenderGraphic.cpp b/src/insets/RenderGraphic.cpp index 7ab14cb63f..d48e4771e9 100644 --- a/src/insets/RenderGraphic.cpp +++ b/src/insets/RenderGraphic.cpp @@ -142,6 +142,7 @@ void RenderGraphic::metrics(MetricsInfo & mi, Dimension & dim) const loader_.startLoading(); if (!loader_.monitoring()) loader_.startMonitoring(); + loader_.checkModifiedAsync(); } bool const image_ready = displayGraphic(params_) && readyToDisplay(loader_); -- 2.39.2