From: Baruch Even Date: Tue, 17 Jul 2001 00:38:04 +0000 (+0000) Subject: Minor code shuffle. X-Git-Tag: 1.6.10~21067 X-Git-Url: https://git.lyx.org/gitweb/?a=commitdiff_plain;ds=sidebyside;h=099779019f066ad014e2dd63ad1b9ec3b180f8de;p=lyx.git Minor code shuffle. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@2258 a592a061-630c-0410-9148-cb99ea01b6c8 --- diff --git a/src/graphics/ChangeLog b/src/graphics/ChangeLog index 96489a9ddd..67edad92ce 100644 --- a/src/graphics/ChangeLog +++ b/src/graphics/ChangeLog @@ -1,3 +1,9 @@ +2001-07-17 Baruch Even + + * 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 * ImageLoaderXPM.C (runImageLoader): get display information from diff --git a/src/graphics/GraphicsCacheItem.C b/src/graphics/GraphicsCacheItem.C index 8a066ff5ff..c145e8cb34 100644 --- a/src/graphics/GraphicsCacheItem.C +++ b/src/graphics/GraphicsCacheItem.C @@ -28,17 +28,30 @@ using std::endl; +/* + * 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); - // For now we do it synchronously - if (success) - imageConverted(0); - else - imageStatus_ = ErrorConverting; + if (! success) // Conversion failed miserably (couldn't even start). + setStatus(ErrorConverting); } @@ -50,19 +63,25 @@ GraphicsCacheItem::ImageStatus GraphicsCacheItem::getImageStatus() const { return imageStatus_; } +void GraphicsCacheItem::setStatus(ImageStatus new_status) +{ + imageStatus_ = new_status; +} + + 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; - if (retval) { + if (! success) { lyxerr << "(GraphicsCacheItem::imageConverter) " "Error converting image." << endl; - imageStatus_ = GraphicsCacheItem::ErrorConverting; + setStatus(GraphicsCacheItem::ErrorConverting); return; } @@ -126,6 +145,13 @@ GraphicsCacheItem::convertImage(string const & filename) converters.Convert(0, filename, tempfile, from, to); + // For now we are synchronous + imageConverted(true); + + // Cleanup after the conversion. + lyx::unlink(tempfile); + tempfile = string(); + return true; } @@ -141,14 +167,9 @@ GraphicsCacheItem::loadImage() 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; - imageStatus_ = GraphicsCacheItem::ErrorReading; + setStatus(GraphicsCacheItem::ErrorReading); } - - // remove the xpm file now. - lyx::unlink(tempfile); - // and remove the reference to the filename. - tempfile = string(); } diff --git a/src/graphics/GraphicsCacheItem.h b/src/graphics/GraphicsCacheItem.h index 6fc9ee4f1c..5074a320e0 100644 --- a/src/graphics/GraphicsCacheItem.h +++ b/src/graphics/GraphicsCacheItem.h @@ -58,12 +58,26 @@ public: /** Get a notification when the image conversion is done. used by an internal callback mechanism. */ - void imageConverted(int retval); + void imageConverted(bool success); 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. + */ 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. */