]> git.lyx.org Git - lyx.git/blob - src/graphics/GraphicsCacheItem.h
removed most uses of toupper and friends, removed <config.h> from headers and added...
[lyx.git] / src / graphics / GraphicsCacheItem.h
1 // -*- C++ -*-
2 /* This file is part of
3  * =================================================
4  * 
5  *          LyX, The Document Processor
6  *          Copyright 1995 Matthias Ettrich.
7  *          Copyright 1995-2001 The LyX Team.
8  *
9  *          This file Copyright 2000 Baruch Even
10  * ================================================= */
11
12 #ifndef GRAPHICSCACHEITEM_H
13 #define GRAPHICSCACHEITEM_H
14
15 #ifdef __GNUG__
16 #pragma interface
17 #endif
18
19 #include XPM_H_LOCATION
20 #include "LString.h"
21
22 #include <boost/utility.hpp>
23 #include <boost/smart_ptr.hpp>
24
25 #include <sigc++/signal_system.h>
26
27 class LyXImage;
28
29 /// A GraphicsCache item holder.
30 class GraphicsCacheItem : boost::noncopyable {
31 public:
32         /// c-tor
33         GraphicsCacheItem(string const & filename);
34         /// d-tor, frees the image structures.
35         ~GraphicsCacheItem();
36         
37         /// Return a pixmap that can be displayed on X server.
38         LyXImage * getImage() const; 
39         ///
40         enum ImageStatus {
41                 ///
42                 Loading = 1,
43                 ///
44                 ErrorConverting,
45                 ///
46                 ErrorReading,
47                 ///
48                 UnknownError,
49                 ///
50                 Loaded
51         };
52         
53         /// Is the pixmap ready for display?
54         ImageStatus getImageStatus() const; 
55
56         /** Get a notification when the image conversion is done.
57             used by an internal callback mechanism.
58         */
59         void imageConverted(bool success);
60
61 private:
62         /** Start image conversion process, checks first that it is necessary
63          *  if necessary will start an (a)synchronous task and notify upon
64          *  completion by calling imageConverted(bool) where true is for success
65          *  and false is for a failure.
66          *
67          *  Returns a bool to denote success or failure of starting the conversion
68          *  task.
69          */
70         bool convertImage(string const & filename);
71
72         /// Load the image into memory, this gets called from imageConverted(bool).
73         void loadImage();
74
75         /// Sets the status of the image, in the future will also notify listeners
76         /// that the status is updated.
77         void setStatus(ImageStatus new_status);
78
79         /** The filename we refer too.
80             This is used when removing ourselves from the cache.
81         */
82         string filename_;
83         /// The temporary file that we use
84         string tempfile;
85         /// The image status
86         ImageStatus imageStatus_;
87         /// The image (if it got loaded)
88         boost::scoped_ptr<LyXImage> image_;
89 };
90
91 #endif