mirror of
https://git.lyx.org/repos/lyx.git
synced 2025-01-13 20:09:59 +00:00
Minor code shuffle.
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@2258 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
parent
b10dd6dc0b
commit
099779019f
@ -1,3 +1,9 @@
|
||||
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
|
||||
|
@ -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();
|
||||
}
|
||||
|
@ -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.
|
||||
*/
|
||||
|
Loading…
x
Reference in New Issue
Block a user