// -*- C++ -*-
-/*
+/**
* \file GraphicsCacheItem.h
- * Copyright 2002 the LyX Team
- * Read the file COPYING
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
*
- * \author Baruch Even <baruch.even@writeme.com>
- * \author Angus Leeming <a.leeming@ic.ac.uk>
+ * \author Baruch Even
+ * \author Angus Leeming
*
- * The graphics cache is a container of GCacheItems. Each GCacheItem, defined
- * here represents a separate image file. The routines here can be used to
- * load the graphics file into memory at which point (status() == grfx::Loaded).
- * The user is then free to access image() in order to transform the image
- * (rotate, scale, clip) and to generate the pixmap.
+ * Full author contact details are available in file CREDITS.
+ *
+ * The graphics cache is a container of lyx::graphics::CacheItems.
+ * Each lyx::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() == lyx::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 grfx::GConverter and on the
- * grfx::GImage-derived image class.
+ * Whether you get that, of course, depends on lyx::graphics::Converter and
+ * on the lyx::graphics::Image-derived image class.
*/
#ifndef GRAPHICSCACHEITEM_H
#define GRAPHICSCACHEITEM_H
-#ifdef __GNUG__
-#pragma interface
-#endif
-
#include "GraphicsTypes.h"
-#include "LString.h"
#include <boost/utility.hpp>
-#include <boost/shared_ptr.hpp>
+#include <boost/scoped_ptr.hpp>
+#include <boost/signal.hpp>
-#include <boost/signals/signal0.hpp>
-#include <boost/signals/signal1.hpp>
-#include <boost/signals/connection.hpp>
-#include <boost/signals/trackable.hpp>
-class InsetGraphics;
+namespace lyx {
-namespace grfx {
-
-/// A grfx::GCache item holder.
-class GCacheItem : boost::noncopyable, public boost::signals::trackable {
-public:
- ///
- GCacheItem(string const & file);
+namespace support { class FileName; }
- /// It's in the cache. Now start the loading process.
- void startLoading();
+namespace graphics {
- /** Get the image associated with filename_.
- If the image is not yet loaded, return a null pointer.
- */
- ImagePtr const image() const { return image_; }
+class Image;
+class Converter;
- /// How far have we got in loading the image?
- ImageStatus status() const { return status_; }
+/// A lyx::graphics::Cache item holder.
+class CacheItem : boost::noncopyable {
+public:
+ ///
+ CacheItem(support::FileName const & file);
- /// This signal is emitted when the image loading status changes.
- boost::signal0<void> statusChanged;
+ /// Define an empty d-tor out-of-line to keep boost::scoped_ptr happy.
+ ~CacheItem();
///
- string const & filename() const { return filename_; }
+ support::FileName const & filename() const;
-private:
- /** Start the image conversion process, checking first that it is
- * necessary. If it is necessary, then a conversion task is started.
- * GCacheItem asumes that the conversion is asynchronous and so
- * passes a Signal to the converting routine. When the conversion
- * is finished, this Signal is emitted, returning the converted
- * file to this->imageConverted.
- *
- * If no file conversion is needed, then convertToDisplayFormat() calls
- * loadImage() directly.
- *
- * convertToDisplayFormat() will set the loading status flag as
- * approriate through calls to setStatus().
- */
- void convertToDisplayFormat();
+ /// It's in the cache. Now start the loading process.
+ void startLoading() const;
- /** Load the image into memory. This is called either from
- * convertToDisplayFormat() direct or from imageConverted().
+ /** Monitor any changes to the file.
+ * There is no point monitoring the file before startLoading() is
+ * invoked.
*/
- void loadImage();
-
- /** Get a notification when the image conversion is done.
- * Connected to a signal on_finish_ which is passed to
- * GConverter::convert.
+ void startMonitoring() const;
+ ///
+ bool monitoring() const;
+ /** Returns the check sum of filename() so that, for example, you can
+ * ascertain whether to output a new PostScript version of the file
+ * for a LaTeX run.
*/
- void imageConverted(string const & file_to_load);
+ unsigned long checksum() const;
- /** Get a notification when the image loading is done.
- * Connected to a signal on_finish_ which is passed to
- * GImage::loadImage.
+ /** 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.
*/
- void imageLoaded(bool);
+ Image const * image() const;
- /** Sets the status of the loading process. Also notifies
- * listeners that the status has chacnged.
- */
- void setStatus(ImageStatus new_status);
-
- /// The filename we refer too.
- string filename_;
- /// Is the file compressed?
- bool zipped_;
- /// If so, store the uncompressed file in this temporary file.
- string unzipped_filename_;
- /// What file are we trying to load?
- string file_to_load_;
- /** Should we delete the file after loading? True if the file is
- * the result of a conversion process.
- */
- bool remove_loaded_file_;
+ /// How far have we got in loading the image?
+ ImageStatus status() const;
- /// The image and its loading status.
- ImagePtr image_;
- ///
- ImageStatus status_;
-
- /** A SignalLoadTypePtr is connected to this->imageLoaded and
- * then passed to ImagePtr::load.
- * When the image has been loaded, the signal is emitted.
- *
- * We pass a shared_ptr because it is eminently possible for the
- * GCacheItem to be destructed before the loading is complete and
- * the signal must remain in scope. It doesn't matter if the slot
- * disappears, SigC takes care of that.
+ /** Connect and you'll be informed when the loading status of the image
+ * changes.
*/
- typedef boost::signal1<void, bool> SignalLoadType;
+ typedef boost::signal<void()> sig_type;
+ typedef sig_type::slot_type slot_type;
///
- typedef boost::shared_ptr<SignalLoadType> SignalLoadTypePtr;
-
- /// The connection of the signal passed to ImagePtr::loadImage.
- boost::signals::connection cl_;
+ boost::signals::connection connect(slot_type const &) const;
- /** A SignalConvertTypePtr is connected to this->imageConverted and
- * then passed to GConverter::convert.
- * When the image has been converted to a loadable format, the signal
- * is emitted, returning the name of the loadable file to
- * imageConverted.
- */
- typedef boost::signal1<void, string const &> SignalConvertType;
- ///
- typedef boost::shared_ptr<SignalConvertType> SignalConvertTypePtr;
+private:
+ /// Use the Pimpl idiom to hide the internals.
+ class Impl;
- /// The connection of the signal passed to GConverter::convert.
- boost::signals::connection cc_;
+ /// The pointer never changes although *pimpl_'s contents may.
+ boost::scoped_ptr<Impl> const pimpl_;
};
-} // namespace grfx
+} // namespace graphics
+} // namespace lyx
#endif // GRAPHICSCACHEITEM_H