]> git.lyx.org Git - lyx.git/blobdiff - src/graphics/GraphicsCacheItem.h
Fix bug in replacement of "$$s/" in converter commands, introduced in 8b66f9ce.
[lyx.git] / src / graphics / GraphicsCacheItem.h
index 3895f3dafd535d8d9adab1b250cf63e471de9e03..289b827a4fff15f5049d232e6b278a2d2bbbaa32 100644 (file)
 // -*- C++ -*-
-/* This file is part of
- * =================================================
- * 
- *          LyX, The Document Processor
- *          Copyright 1995 Matthias Ettrich.
- *          Copyright 1995-2001 The LyX Team.
+/**
+ * \file GraphicsCacheItem.h
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
  *
- *          This file Copyright 2000 Baruch Even
- * ================================================= */
+ * \author Baruch Even
+ * \author Angus Leeming
+ *
+ * Full author contact details are available in file CREDITS.
+ *
+ * The graphics cache is a container of graphics::CacheItems.
+ * Each graphics::CacheItem, defined here represents a separate image file.
+ *
+ * The routines here can be used to load the graphics file into memory at
+ * which point (status() == graphics::Loaded).
+ * The user is then free to access image() in order to copy it and to then
+ * transform the copy (rotate, scale, clip) and to generate the pixmap.
+ *
+ * The graphics cache supports fully asynchronous:
+ * file conversion to a loadable format;
+ * file loading.
+ *
+ * Whether you get that, of course, depends on graphics::Converter and
+ * on the graphics::Image-derived image class.
+ */
 
 #ifndef GRAPHICSCACHEITEM_H
 #define GRAPHICSCACHEITEM_H
 
-#ifdef __GNUG__
-#pragma interface
-#endif
+#include "GraphicsTypes.h"
+
+#include <boost/signals2.hpp>
 
-#include XPM_H_LOCATION
-#include "LString.h"
 
-#include <boost/utility.hpp>
-#include <boost/smart_ptr.hpp>
+namespace lyx {
 
-#include <sigc++/signal_system.h>
+namespace support { class FileName; }
 
-class LyXImage;
+namespace graphics {
 
-/// A GraphicsCache item holder.
-class GraphicsCacheItem : boost::noncopyable {
+class Image;
+class Converter;
+
+/// A graphics::Cache item holder.
+class CacheItem {
 public:
-       /// c-tor
-       GraphicsCacheItem(string const & filename);
-       /// d-tor, frees the image structures.
-       ~GraphicsCacheItem();
-       
-       /// Return a pixmap that can be displayed on X server.
-       LyXImage * getImage() const; 
        ///
-       enum ImageStatus {
-               ///
-               Loading = 1,
-               ///
-               ErrorConverting,
-               ///
-               ErrorReading,
-               ///
-               UnknownError,
-               ///
-               Loaded
-       };
-       
-       /// Is the pixmap ready for display?
-       ImageStatus getImageStatus() const; 
-
-       /** Get a notification when the image conversion is done.
-           used by an internal callback mechanism.
-       */
-       void imageConverted(bool success);
+       CacheItem(support::FileName const & file);
+       /// Needed for the pimpl
+       ~CacheItem();
 
-private:
-       /** Start image conversion process, checks first that it is necessary
-        *  if necessary will start an (a)synchronous task and notify upon
-        *  completion by calling imageConverted(bool) where true is for success
-        *  and false is for a failure.
-        *
-        *  Returns a bool to denote success or failure of starting the conversion
-        *  task.
+       ///
+       support::FileName const & filename() const;
+
+       /// Try to load a display format.
+       bool tryDisplayFormat() const;
+
+       /// It's in the cache. Now start the loading process.
+       void startLoading() const;
+
+       /** Monitor any changes to the file.
+        *  There is no point monitoring the file before startLoading() is
+        *  invoked.
         */
-       bool convertImage(string const & filename);
-
-       /// Load the image into memory, this gets called from imageConverted(bool).
-       void loadImage();
-
-       /// Sets the status of the image, in the future will also notify listeners
-       /// that the status is updated.
-       void setStatus(ImageStatus new_status);
-
-       /** The filename we refer too.
-           This is used when removing ourselves from the cache.
-       */
-       string filename_;
-       /// The temporary file that we use
-       string tempfile;
-       /// The image status
-       ImageStatus imageStatus_;
-       /// The image (if it got loaded)
-       boost::scoped_ptr<LyXImage> image_;
+       void startMonitoring() const;
+       ///
+       bool monitoring() const;
+       /** Returns the check checksum of filename() so that, for example, you can
+        *  ascertain whether to output a new PostScript version of the file
+        *  for a LaTeX run.
+        */
+       unsigned long checksum() const;
+
+       /** Get the image associated with filename().
+        *  If the image is not yet loaded, returns 0.
+        *  This routine returns a pointer to const; if you want to modify it,
+        *  create a copy and modify that.
+        */
+       Image const * image() const;
+
+       /// How far have we got in loading the image?
+       ImageStatus status() const;
+
+       /** Connect and you'll be informed when the loading status of the image
+        *  changes.
+        */
+       typedef boost::signals2::signal<void()> sig_type;
+       typedef sig_type::slot_type slot_type;
+       ///
+       boost::signals2::connection connect(slot_type const &) const;
+
+private:
+       /// noncopyable
+       CacheItem(CacheItem const &);
+       void operator=(CacheItem const &);
+
+       /// Use the Pimpl idiom to hide the internals.
+       class Impl;
+       /// The pointer never changes although *pimpl_'s contents may.
+       Impl * const pimpl_;
 };
 
-#endif
+} // namespace graphics
+} // namespace lyx
+
+#endif // GRAPHICSCACHEITEM_H