]> git.lyx.org Git - lyx.git/commitdiff
Minor code shuffle.
authorBaruch Even <baruch@lyx.org>
Tue, 17 Jul 2001 00:38:04 +0000 (00:38 +0000)
committerBaruch Even <baruch@lyx.org>
Tue, 17 Jul 2001 00:38:04 +0000 (00:38 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@2258 a592a061-630c-0410-9148-cb99ea01b6c8

src/graphics/ChangeLog
src/graphics/GraphicsCacheItem.C
src/graphics/GraphicsCacheItem.h

index 96489a9ddd13d229398735eb69676cd27d42d850..67edad92ce874f7f70195d82e6ecb00ce9fd22f2 100644 (file)
@@ -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
 2001-07-03  Jean-Marc Lasgouttes  <Jean-Marc.Lasgouttes@inria.fr>
 
        * ImageLoaderXPM.C (runImageLoader): get display information from
index 8a066ff5ff58ebda8c8163b5deb5393747b2e97a..c145e8cb34477979d0457d7824ba11ffe55dc91e 100644 (file)
 
 using std::endl;
 
 
 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);
 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_; }
 
 
 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;
 
 
-       if (retval) {
+       if (! success) {
                lyxerr << "(GraphicsCacheItem::imageConverter) "
                        "Error converting image." << endl;
                lyxerr << "(GraphicsCacheItem::imageConverter) "
                        "Error converting image." << endl;
-               imageStatus_ = GraphicsCacheItem::ErrorConverting;
+               setStatus(GraphicsCacheItem::ErrorConverting);
                return;
        }
 
                return;
        }
 
@@ -126,6 +145,13 @@ GraphicsCacheItem::convertImage(string const & filename)
 
        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();
+
        return true;
 }
 
        return true;
 }
 
@@ -141,14 +167,9 @@ GraphicsCacheItem::loadImage()
        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();
 }
 }
index 6fc9ee4f1c6f1b56ad82090ac2f5e5d18bb8717b..5074a320e050c8fae799595338d8a851f5b41eb9 100644 (file)
@@ -58,12 +58,26 @@ public:
        /** 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);
 
 private:
 
 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);
        bool convertImage(string const & filename);
+
+       /// Load the image into memory, this gets called from imageConverted(bool).
        void loadImage();
 
        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.
        */
        /** The filename we refer too.
            This is used when removing ourselves from the cache.
        */