]> git.lyx.org Git - lyx.git/blobdiff - src/graphics/GraphicsCache.cpp
Remove obsolete (and false) comment.
[lyx.git] / src / graphics / GraphicsCache.cpp
index 43743535f2504ed8b01e19db2043d01b2245eaf1..dbf9cafa5e93d0e14ccbefce7ab646280947cbfa 100644 (file)
 #include "GraphicsCacheItem.h"
 #include "GraphicsImage.h"
 
-#include "debug.h"
+#include "Format.h"
 
+#include "frontends/Application.h"
+
+#include "support/debug.h"
+#include "support/FileName.h"
 #include "support/filetools.h"
 
 #include <map>
 
-using std::string;
-
+using namespace std;
+using namespace lyx::support;
 
 namespace lyx {
 
-using support::FileName;
-
 namespace graphics {
 
 /** The cache contains one item per file, so use a map to find the
  *  cache item quickly by filename.
  */
-typedef std::map<FileName, Cache::ItemPtr> CacheType;
+typedef map<FileName, Cache::ItemPtr> CacheType;
 
 class Cache::Impl {
 public:
@@ -56,16 +58,50 @@ Cache::Cache()
 
 
 Cache::~Cache()
-{}
+{
+       delete pimpl_;
+}
 
 
-std::vector<string> Cache::loadableFormats() const
+vector<string> const & Cache::loadableFormats() const
 {
-       return Image::loadableFormats();
+       static vector<string> fmts;
+
+       if (!fmts.empty())
+               return fmts;
+
+       // The formats recognised by LyX
+       Formats::const_iterator begin = theFormats().begin();
+       Formats::const_iterator end   = theFormats().end();
+
+       // The formats natively loadable.
+       vector<string> nformat = frontend::loadableImageFormats();
+
+       vector<string>::const_iterator it = nformat.begin();
+       for (; it != nformat.end(); ++it) {
+               for (Formats::const_iterator fit = begin; fit != end; ++fit) {
+                       if (fit->extension() == *it) {
+                               fmts.push_back(fit->name());
+                               break;
+                       }
+               }
+       }
+
+       if (lyxerr.debugging()) {
+               LYXERR(Debug::GRAPHICS, "LyX recognises the following image formats:");
+
+               vector<string>::const_iterator fbegin = fmts.begin();
+               vector<string>::const_iterator fend = fmts.end();
+               for (vector<string>::const_iterator fit = fbegin; fit != fend; ++fit) {
+                       LYXERR(Debug::GRAPHICS, *fit << ',');
+               }
+       }
+
+       return fmts;
 }
 
 
-void Cache::add(FileName const & file) const
+void Cache::add(FileName const & file, FileName const & doc_file) const
 {
        // Is the file in the cache already?
        if (inCache(file)) {
@@ -74,7 +110,7 @@ void Cache::add(FileName const & file) const
                return;
        }
 
-       pimpl_->cache[file] = ItemPtr(new CacheItem(file));
+       pimpl_->cache[file] = ItemPtr(new CacheItem(file, doc_file));
 }