]> git.lyx.org Git - lyx.git/blob - src/graphics/GraphicsCacheItem.h
Changed the singleton implementation in GraphicsCache, the former version
[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-2000 The LyX Team.
8  *
9  *          This file Copyright 2000 Baruch Even
10  * ================================================= */
11
12 #ifndef GRAPHICSCACHEITEM_H
13 #define GRAPHICSCACHEITEM_H
14
15 #include <config.h>
16
17 #ifdef __GNUG__
18 #pragma interface
19 #endif
20
21 #include XPM_H_LOCATION
22 #include "LString.h"
23
24 #include <boost/utility.hpp>
25 #include <boost/smart_ptr.hpp>
26
27 #include "sigc++/signal_system.h"
28 #ifdef SIGC_CXX_NAMESPACES
29 using SigC::Signal0;
30 #endif
31
32
33 class LyXImage;
34
35 /// A GraphicsCache item holder.
36 class GraphicsCacheItem : public noncopyable {
37 public:
38         /// c-tor
39         GraphicsCacheItem(string const & filename);
40         /// d-tor, frees the image structures.
41         ~GraphicsCacheItem();
42         
43         /// Return a pixmap that can be displayed on X server.
44         LyXImage * getImage() const; 
45         ///
46         enum ImageStatus {
47                 ///
48                 Loading = 1,
49                 ///
50                 ErrorConverting,
51                 ///
52                 ErrorReading,
53                 ///
54                 UnknownError,
55                 ///
56                 Loaded
57         };
58         
59         /// Is the pixmap ready for display?
60         ImageStatus getImageStatus() const; 
61
62         /** Get a notification when the image conversion is done.
63             used by an internal callback mechanism.
64         */
65         void imageConverted(int retval);
66
67 private:
68         bool renderXPM(string const & filename);
69         void loadXPMImage();
70
71         /** The filename we refer too.
72             This is used when removing ourselves from the cache.
73         */
74         string filename_;
75         /// The temporary file that we use
76         string tempfile;
77         /// The image status
78         ImageStatus imageStatus_;
79         /// The image (if it got loaded)
80         boost::scoped_ptr<LyXImage> image_;
81 };
82
83 #endif