3 * \file GraphicsCacheItem.h
4 * Copyright 2002 the LyX Team
5 * Read the file COPYING
7 * \author Baruch Even <baruch.even@writeme.com>
8 * \author Angus Leeming <a.leeming@ic.ac.uk>
10 * The graphics cache is a container of GCacheItems. Each GCacheItem, defined
11 * here represents a separate image file. However, each file can be viewed in
12 * different ways (different sizes, rotations etc), so each GCacheItem itself
13 * contains a list of ModifiedItems, also defined here. Each ModifiedItem
14 * has a GParams variable that defines the way it will be viewed. It also
15 * contains a list of the graphics insets that refer to it, so calls through
16 * the GCache to GCacheItem ultimately return the loading status and image
17 * for that particular graphics inset.
19 * The graphics cache supports fully asynchronous:
20 * file conversion to a loadable format;
23 * Whether you get that, of course, depends on grfx::GConverter and on the
24 * grfx::GImage-derived image class.
26 * Image modification (scaling, rotation etc) is blocking.
29 #ifndef GRAPHICSCACHEITEM_H
30 #define GRAPHICSCACHEITEM_H
36 #include "GraphicsTypes.h"
39 #include <boost/utility.hpp>
40 #include <boost/shared_ptr.hpp>
42 #include <boost/signals/signal0.hpp>
43 #include <boost/signals/signal1.hpp>
44 #include <boost/signals/connection.hpp>
45 #include <boost/signals/trackable.hpp>
51 /// A grfx::GCache item holder.
52 class GCacheItem : boost::noncopyable, public boost::signals::trackable {
55 GCacheItem(string const & file);
57 /// It's in the cache. Now start the loading process.
60 /** Get the image associated with filename_.
61 If the image is not yet loaded, return a null pointer.
63 ImagePtr const image() const { return image_; }
65 /// How far have we got in loading the image?
66 ImageStatus status() const { return status_; }
68 /// This signal is emitted when the image loading status changes.
69 boost::signal0<void> statusChanged;
72 string const & filename() const { return filename_; }
75 /** Start the image conversion process, checking first that it is
76 * necessary. If it is necessary, then a conversion task is started.
77 * GCacheItem asumes that the conversion is asynchronous and so
78 * passes a Signal to the converting routine. When the conversion
79 * is finished, this Signal is emitted, returning the converted
80 * file to this->imageConverted.
82 * If no file conversion is needed, then convertToDisplayFormat() calls
83 * loadImage() directly.
85 * convertToDisplayFormat() will set the loading status flag as
86 * approriate through calls to setStatus().
88 void convertToDisplayFormat();
90 /** Load the image into memory. This is called either from
91 * convertToDisplayFormat() direct or from imageConverted().
95 /** Get a notification when the image conversion is done.
96 * Connected to a signal on_finish_ which is passed to
97 * GConverter::convert.
99 void imageConverted(string const & file_to_load);
101 /** Get a notification when the image loading is done.
102 * Connected to a signal on_finish_ which is passed to
105 void imageLoaded(bool);
107 /** Sets the status of the loading process. Also notifies
108 * listeners that the status has chacnged.
110 void setStatus(ImageStatus new_status);
112 /// The filename we refer too.
114 /// Is the file compressed?
116 /// If so, store the uncompressed file in this temporary file.
117 string unzipped_filename_;
118 /// What file are we trying to load?
119 string file_to_load_;
120 /** Should we delete the file after loading? True if the file is
121 * the result of a conversion process.
123 bool remove_loaded_file_;
125 /// The image and its loading status.
130 /** A SignalLoadTypePtr is connected to this->imageLoaded and
131 * then passed to ImagePtr::load.
132 * When the image has been loaded, the signal is emitted.
134 * We pass a shared_ptr because it is eminently possible for the
135 * GCacheItem to be destructed before the loading is complete and
136 * the signal must remain in scope. It doesn't matter if the slot
137 * disappears, SigC takes care of that.
139 typedef boost::signal1<void, bool> SignalLoadType;
141 typedef boost::shared_ptr<SignalLoadType> SignalLoadTypePtr;
143 /// The connection of the signal passed to ImagePtr::loadImage.
144 boost::signals::connection cl_;
146 /** A SignalConvertTypePtr is connected to this->imageConverted and
147 * then passed to GConverter::convert.
148 * When the image has been converted to a loadable format, the signal
149 * is emitted, returning the name of the loadable file to
152 typedef boost::signal1<void, string const &> SignalConvertType;
154 typedef boost::shared_ptr<SignalConvertType> SignalConvertTypePtr;
156 /// The connection of the signal passed to GConverter::convert.
157 boost::signals::connection cc_;
162 #endif // GRAPHICSCACHEITEM_H