]> git.lyx.org Git - lyx.git/blobdiff - src/graphics/GraphicsCacheItem.cpp
merge recent changes from master
[lyx.git] / src / graphics / GraphicsCacheItem.cpp
index 0b262ad24126d966a195e96f4263051b66d35a10..c698168dee0c22a67e47eb7528e07b0f02d9a12f 100644 (file)
@@ -14,6 +14,7 @@
 
 #include "GraphicsCacheItem.h"
 
+#include "Buffer.h"
 #include "GraphicsCache.h"
 #include "GraphicsConverter.h"
 #include "GraphicsImage.h"
@@ -26,6 +27,7 @@
 #include "support/filetools.h"
 #include "support/FileMonitor.h"
 #include "support/lassert.h"
+#include "support/unique_ptr.h"
 
 #include "support/bind.h"
 #include "support/TempFile.h"
@@ -37,11 +39,11 @@ namespace lyx {
 
 namespace graphics {
 
-class CacheItem::Impl : public boost::signals::trackable {
+class CacheItem::Impl : public boost::signals2::trackable {
 public:
 
        ///
-       Impl(FileName const & file);
+       Impl(FileName const & file, FileName const & doc_file);
 
        /**
         *  If no file conversion is needed, then tryDisplayFormat() calls
@@ -92,6 +94,8 @@ public:
 
        /// The filename we refer too.
        FileName const filename_;
+       /// The document filename this graphic item belongs to
+       FileName const & doc_file_;
        ///
        FileMonitor const monitor_;
 
@@ -114,18 +118,18 @@ public:
        ImageStatus status_;
 
        /// This signal is emitted when the image loading status changes.
-       boost::signal<void()> statusChanged;
+       boost::signals2::signal<void()> statusChanged;
 
        /// The connection of the signal ConvProcess::finishedConversion,
-       boost::signals::connection cc_;
+       boost::signals2::connection cc_;
 
        ///
        unique_ptr<Converter> converter_;
 };
 
 
-CacheItem::CacheItem(FileName const & file)
-       : pimpl_(new Impl(file))
+CacheItem::CacheItem(FileName const & file, FileName const & doc_file)
+  : pimpl_(new Impl(file,doc_file))
 {}
 
 
@@ -192,7 +196,7 @@ ImageStatus CacheItem::status() const
 }
 
 
-boost::signals::connection CacheItem::connect(slot_type const & slot) const
+boost::signals2::connection CacheItem::connect(slot_type const & slot) const
 {
        return pimpl_->statusChanged.connect(slot);
 }
@@ -203,8 +207,8 @@ boost::signals::connection CacheItem::connect(slot_type const & slot) const
 //------------------------------
 
 
-CacheItem::Impl::Impl(FileName const & file)
-       : filename_(file),
+CacheItem::Impl::Impl(FileName const & file, FileName const & doc_file)
+       : filename_(file), doc_file_(doc_file),
          monitor_(file, 2000),
          zipped_(false),
          remove_loaded_file_(false),
@@ -311,11 +315,10 @@ bool CacheItem::Impl::loadImage()
 }
 
 
-static string const findTargetFormat(string const & from)
-{
-       typedef vector<string> FormatList;
-       FormatList const & formats = Cache::get().loadableFormats();
+typedef vector<string> FormatList;
 
+static string const findTargetFormat(FormatList const & formats, string const & from)
+{
         // There must be a format to load from.
        LASSERT(!formats.empty(), return string());
 
@@ -391,7 +394,7 @@ bool CacheItem::Impl::tryDisplayFormat(FileName & filename, string & from)
                LYXERR(Debug::GRAPHICS, "\tCould not determine file format.");
        }
        LYXERR(Debug::GRAPHICS, "\n\tThe file contains " << from << " format data.");
-       to_ = findTargetFormat(from);
+       to_ = findTargetFormat(Cache::get().loadableFormats(), from);
 
        if (from == to_) {
                // No conversion needed!
@@ -437,7 +440,8 @@ void CacheItem::Impl::convertToDisplayFormat()
        // Connect a signal to this->imageConverted and pass this signal to
        // the graphics converter so that we can load the modified file
        // on completion of the conversion process.
-       converter_.reset(new Converter(filename, to_file_base.absFileName(), from, to_));
+       converter_ = make_unique<Converter>(doc_file_, filename, to_file_base.absFileName(),
+                                           from, to_);
        converter_->connect(bind(&Impl::imageConverted, this, _1));
        converter_->startConversion();
 }