+2001-07-17 Baruch Even <baruch@lyx.org>
+
+ * GraphicsCacheItem.h:
+ * GraphicsCacheItem.C: Shuffled things a bit to make it easier to switch
+ from synchronous to asynchronous and to ease the coming changes.
+
2001-07-03 Jean-Marc Lasgouttes <Jean-Marc.Lasgouttes@inria.fr>
* ImageLoaderXPM.C (runImageLoader): get display information from
2001-07-03 Jean-Marc Lasgouttes <Jean-Marc.Lasgouttes@inria.fr>
* ImageLoaderXPM.C (runImageLoader): get display information from
+/*
+ * The order of conversion:
+ *
+ * The c-tor calls convertImage()
+ *
+ * convertImage() verifies that we need to do conversion, if not it will just
+ * call the loadImage()
+ * if conversion is needed, it will initiate the conversion.
+ *
+ * When the conversion is completed imageConverted() is called, which in turn
+ * calls loadImage().
+ *
+ * Since we currently do everything synchronously, convertImage() calls
+ * imageConverted() right after it does the call to the conversion process.
+*/
+
GraphicsCacheItem::GraphicsCacheItem(string const & filename)
: imageStatus_(GraphicsCacheItem::Loading)
{
filename_ = filename;
bool success = convertImage(filename);
GraphicsCacheItem::GraphicsCacheItem(string const & filename)
: imageStatus_(GraphicsCacheItem::Loading)
{
filename_ = filename;
bool success = convertImage(filename);
- // For now we do it synchronously
- if (success)
- imageConverted(0);
- else
- imageStatus_ = ErrorConverting;
+ if (! success) // Conversion failed miserably (couldn't even start).
+ setStatus(ErrorConverting);
GraphicsCacheItem::getImageStatus() const { return imageStatus_; }
GraphicsCacheItem::getImageStatus() const { return imageStatus_; }
+void GraphicsCacheItem::setStatus(ImageStatus new_status)
+{
+ imageStatus_ = new_status;
+}
+
+
LyXImage *
GraphicsCacheItem::getImage() const { return image_.get(); }
void
LyXImage *
GraphicsCacheItem::getImage() const { return image_.get(); }
void
-GraphicsCacheItem::imageConverted(int retval)
+GraphicsCacheItem::imageConverted(bool success)
- lyxerr << "imageConverted, retval=" << retval << endl;
+ lyxerr << "imageConverted, status=" << success << endl;
lyxerr << "(GraphicsCacheItem::imageConverter) "
"Error converting image." << endl;
lyxerr << "(GraphicsCacheItem::imageConverter) "
"Error converting image." << endl;
- imageStatus_ = GraphicsCacheItem::ErrorConverting;
+ setStatus(GraphicsCacheItem::ErrorConverting);
converters.Convert(0, filename, tempfile, from, to);
converters.Convert(0, filename, tempfile, from, to);
+ // For now we are synchronous
+ imageConverted(true);
+
+ // Cleanup after the conversion.
+ lyx::unlink(tempfile);
+ tempfile = string();
+
if (imageLoader.loadImage(tempfile) == ImageLoader::OK) {
lyxerr << "Success." << endl;
image_.reset(imageLoader.getImage());
if (imageLoader.loadImage(tempfile) == ImageLoader::OK) {
lyxerr << "Success." << endl;
image_.reset(imageLoader.getImage());
- imageStatus_ = GraphicsCacheItem::Loaded;
+ setStatus(GraphicsCacheItem::Loaded);
} else {
lyxerr << "Loading " << tempfile << "Failed" << endl;
} else {
lyxerr << "Loading " << tempfile << "Failed" << endl;
- imageStatus_ = GraphicsCacheItem::ErrorReading;
+ setStatus(GraphicsCacheItem::ErrorReading);
-
- // remove the xpm file now.
- lyx::unlink(tempfile);
- // and remove the reference to the filename.
- tempfile = string();
/** Get a notification when the image conversion is done.
used by an internal callback mechanism.
*/
/** Get a notification when the image conversion is done.
used by an internal callback mechanism.
*/
- void imageConverted(int retval);
+ void imageConverted(bool success);
+ /** 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.
+ */
bool convertImage(string const & filename);
bool convertImage(string const & filename);
+
+ /// Load the image into memory, this gets called from imageConverted(bool).
+ /// 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.
*/
/** The filename we refer too.
This is used when removing ourselves from the cache.
*/