]> git.lyx.org Git - lyx.git/blobdiff - src/graphics/PreviewImage.C
Remove cached var from RenderPreview. Changes elsewhere to suit.
[lyx.git] / src / graphics / PreviewImage.C
index 9bc6ba88c2d587a35bd224438224383db3ba24f5..75d41634ced7a43394d54dc6f2bf9d2fccf2633e 100644 (file)
@@ -1,31 +1,31 @@
 /**
- *  \file PreviewImage.C
- *  Copyright 2002 the LyX Team
- *  Read the file COPYING
+ * \file PreviewImage.C
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
  *
- * \author Angus Leeming <a.leeming@ic.ac.uk>
+ * \author Angus Leeming
+ *
+ * Full author contact details are available in file CREDITS.
  */
 
 #include <config.h>
 
-#ifdef __GNUG__
-#pragma implementation
-#endif
-
 #include "PreviewImage.h"
-#include "PreviewLoader.h"
 #include "GraphicsImage.h"
 #include "GraphicsLoader.h"
-
-#include "debug.h"
+#include "PreviewLoader.h"
 
 #include "support/lyxlib.h"
 
 #include <boost/bind.hpp>
-#include <boost/signals/trackable.hpp>
 
+namespace support = lyx::support;
+
+using std::string;
 
-namespace grfx {
+
+namespace lyx {
+namespace graphics {
 
 struct PreviewImage::Impl : public boost::signals::trackable {
        ///
@@ -34,8 +34,6 @@ struct PreviewImage::Impl : public boost::signals::trackable {
        ///
        ~Impl();
        ///
-       void startLoading();    
-       ///
        Image const * image();
        ///
        void statusChanged();
@@ -45,7 +43,7 @@ struct PreviewImage::Impl : public boost::signals::trackable {
        ///
        PreviewLoader & ploader_;
        ///
-       boost::scoped_ptr<Loader> const iloader_;
+       Loader iloader_;
        ///
        string const snippet_;
        ///
@@ -65,20 +63,15 @@ PreviewImage::~PreviewImage()
 {}
 
 
-void PreviewImage::startLoading()
-{
-       return pimpl_->startLoading();
-}
-
-
 string const & PreviewImage::snippet() const
 {
        return pimpl_->snippet_;
 }
 
+
 int PreviewImage::ascent() const
 {
-       Image const * const image = pimpl_->image();
+       Image const * const image = pimpl_->iloader_.image();
        if (!image)
                return 0;
 
@@ -88,7 +81,7 @@ int PreviewImage::ascent() const
 
 int PreviewImage::descent() const
 {
-       Image const * const image = pimpl_->image();
+       Image const * const image = pimpl_->iloader_.image();
        if (!image)
                return 0;
 
@@ -99,7 +92,7 @@ int PreviewImage::descent() const
 
 int PreviewImage::width() const
 {
-       Image const * const image = pimpl_->image();
+       Image const * const image = pimpl_->iloader_.image();
        return image ? image->getWidth() : 0;
 }
 
@@ -114,37 +107,31 @@ PreviewImage::Impl::Impl(PreviewImage & p, PreviewLoader & l,
                         string const & s,
                         string const & bf,
                         double af)
-       : parent_(p), ploader_(l), iloader_(new Loader(bf)),
+       : parent_(p), ploader_(l), iloader_(bf),
          snippet_(s), ascent_frac_(af)
-{}
-
-
-PreviewImage::Impl::~Impl()
 {
-       lyx::unlink(iloader_->filename());
+       iloader_.connect(boost::bind(&Impl::statusChanged, this));
 }
 
 
-void PreviewImage::Impl::startLoading()
+PreviewImage::Impl::~Impl()
 {
-       if (iloader_->status() != WaitingToLoad)
-               return;
-
-       iloader_->statusChanged.connect(
-               boost::bind(&Impl::statusChanged, this));
-       iloader_->startLoading();
+       support::unlink(iloader_.filename());
 }
 
 
 Image const * PreviewImage::Impl::image()
 {
-//     startLoading();
-       return iloader_->image();
+       if (iloader_.status() == WaitingToLoad)
+               iloader_.startLoading();
+
+       return iloader_.image();
 }
 
+
 void PreviewImage::Impl::statusChanged()
 {
-       switch (iloader_->status()) {
+       switch (iloader_.status()) {
        case WaitingToLoad:
        case Loading:
        case Converting:
@@ -157,15 +144,16 @@ void PreviewImage::Impl::statusChanged()
        case ErrorLoading:
        case ErrorGeneratingPixmap:
        case ErrorUnknown:
-               //lyx::unlink(iloader_->filename());
+               //lyx::unlink(iloader_.filename());
                ploader_.remove(snippet_);
                break;
 
        case Ready:
-               lyx::unlink(iloader_->filename());
-               ploader_.imageReady(parent_);
+               support::unlink(iloader_.filename());
                break;
        }
+       ploader_.emitSignal(parent_);
 }
 
-} // namespace grfx
+} // namespace graphics
+} // namespace lyx