X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Fgraphics%2FGraphicsCacheItem.cpp;h=2960ae6002d84484c244acb718edeb3b733d7bc6;hb=06254d11dfdf670fab3548dc2a2674e7a261262c;hp=74e9eb41272747f8bee2187911a8471374a56e40;hpb=f497296c30e6da2f97b16da8ad1c9e96feffb16b;p=lyx.git diff --git a/src/graphics/GraphicsCacheItem.cpp b/src/graphics/GraphicsCacheItem.cpp index 74e9eb4127..2960ae6002 100644 --- a/src/graphics/GraphicsCacheItem.cpp +++ b/src/graphics/GraphicsCacheItem.cpp @@ -17,32 +17,20 @@ #include "GraphicsImage.h" #include "ConverterCache.h" -#include "debug.h" -#include "format.h" +#include "support/debug.h" +#include "Format.h" +#include "support/FileName.h" #include "support/filetools.h" #include "support/FileMonitor.h" -#include "support/lyxlib.h" #include +using namespace std; +using namespace lyx::support; namespace lyx { -using support::FileMonitor; -using support::FileName; -using support::isFileReadable; -using support::makeDisplayPath; -using support::onlyFilename; -using support::tempName; -using support::unlink; -using support::unzipFile; -using support::zippedFile; - -using std::endl; -using std::string; - - namespace graphics { class CacheItem::Impl : public boost::signals::trackable { @@ -143,7 +131,9 @@ CacheItem::CacheItem(FileName const & file) CacheItem::~CacheItem() -{} +{ + delete pimpl_; +} FileName const & CacheItem::filename() const @@ -224,11 +214,11 @@ void CacheItem::Impl::reset() { zipped_ = false; if (!unzipped_filename_.empty()) - unlink(unzipped_filename_); + unzipped_filename_.removeFile(); unzipped_filename_.erase(); if (remove_loaded_file_ && !file_to_load_.empty()) - unlink(file_to_load_); + file_to_load_.removeFile(); remove_loaded_file_ = false; file_to_load_.erase(); to_.erase(); @@ -262,22 +252,21 @@ void CacheItem::Impl::setStatus(ImageStatus new_status) void CacheItem::Impl::imageConverted(bool success) { string const text = success ? "succeeded" : "failed"; - LYXERR(Debug::GRAPHICS) << "Image conversion " << text << '.' << endl; + LYXERR(Debug::GRAPHICS, "Image conversion " << text << '.'); file_to_load_ = converter_.get() ? FileName(converter_->convertedFile()) : FileName(); converter_.reset(); cc_.disconnect(); - success = !file_to_load_.empty() && isFileReadable(file_to_load_); + success = !file_to_load_.empty() && file_to_load_.isReadableFile(); if (!success) { - LYXERR(Debug::GRAPHICS) << "Unable to find converted file!" - << endl; + LYXERR(Debug::GRAPHICS, "Unable to find converted file!"); setStatus(ErrorConverting); if (zipped_) - unlink(unzipped_filename_); + unzipped_filename_.removeFile(); return; } @@ -294,9 +283,9 @@ void CacheItem::Impl::imageConverted(bool success) void CacheItem::Impl::loadImage() { setStatus(Loading); - LYXERR(Debug::GRAPHICS) << "Loading image." << endl; + LYXERR(Debug::GRAPHICS, "Loading image."); - image_ = Image::newImage(); + image_.reset(Image::newImage()); cl_.disconnect(); cl_ = image_->finishedLoading.connect( @@ -308,14 +297,14 @@ void CacheItem::Impl::loadImage() void CacheItem::Impl::imageLoaded(bool success) { string const text = success ? "succeeded" : "failed"; - LYXERR(Debug::GRAPHICS) << "Image loading " << text << '.' << endl; + LYXERR(Debug::GRAPHICS, "Image loading " << text << '.'); // Clean up after loading. if (zipped_) - unlink(unzipped_filename_); + unzipped_filename_.removeFile(); if (remove_loaded_file_ && unzipped_filename_ != file_to_load_) - unlink(file_to_load_); + file_to_load_.removeFile(); cl_.disconnect(); @@ -356,9 +345,8 @@ static string const findTargetFormat(string const & from) if (lyx::graphics::Converter::isReachable(from, *it)) return *it; else - LYXERR(Debug::GRAPHICS) - << "Unable to convert from " << from - << " to " << *it << std::endl; + LYXERR(Debug::GRAPHICS, "Unable to convert from " << from + << " to " << *it); } // Failed! so we have to try to convert it to PPM format @@ -372,72 +360,68 @@ void CacheItem::Impl::convertToDisplayFormat() setStatus(Converting); // First, check that the file exists! - if (!isFileReadable(filename_)) { + if (!filename_.isReadableFile()) { if (status_ != ErrorNoFile) { setStatus(ErrorNoFile); - LYXERR(Debug::GRAPHICS) - << "\tThe file is not readable" << endl; + LYXERR(Debug::GRAPHICS, "\tThe file is not readable"); } return; } // Make a local copy in case we unzip it FileName filename; - zipped_ = zippedFile(filename_); + zipped_ = filename_.isZippedFile(); if (zipped_) { - unzipped_filename_ = tempName(FileName(), filename_.toFilesystemEncoding()); + unzipped_filename_ = FileName::tempName( + filename_.toFilesystemEncoding()); if (unzipped_filename_.empty()) { setStatus(ErrorConverting); - LYXERR(Debug::GRAPHICS) - << "\tCould not create temporary file." << endl; + LYXERR(Debug::GRAPHICS, "\tCould not create temporary file."); return; } filename = unzipFile(filename_, unzipped_filename_.toFilesystemEncoding()); - } else + } else { filename = filename_; + } docstring const displayed_filename = makeDisplayPath(filename_.absFilename()); - LYXERR(Debug::GRAPHICS) << "[graphics::CacheItem::Impl::convertToDisplayFormat]\n" + LYXERR(Debug::GRAPHICS, "[CacheItem::Impl::convertToDisplayFormat]\n" << "\tAttempting to convert image file: " << filename - << "\n\twith displayed filename: " << lyx::to_utf8(displayed_filename) - << endl; + << "\n\twith displayed filename: " << to_utf8(displayed_filename)); string const from = formats.getFormatFromFile(filename); if (from.empty()) { setStatus(ErrorConverting); - LYXERR(Debug::GRAPHICS) - << "\tCould not determine file format." << endl; + LYXERR(Debug::GRAPHICS, "\tCould not determine file format."); } - LYXERR(Debug::GRAPHICS) - << "\n\tThe file contains " << from << " format data." << endl; + LYXERR(Debug::GRAPHICS, "\n\tThe file contains " << from << " format data."); to_ = findTargetFormat(from); if (from == to_) { // No conversion needed! - LYXERR(Debug::GRAPHICS) << "\tNo conversion needed (from == to)!" << endl; + LYXERR(Debug::GRAPHICS, "\tNo conversion needed (from == to)!"); file_to_load_ = filename; loadImage(); return; } if (ConverterCache::get().inCache(filename, to_)) { - LYXERR(Debug::GRAPHICS) << "\tNo conversion needed (file in file cache)!" - << endl; + LYXERR(Debug::GRAPHICS, "\tNo conversion needed (file in file cache)!"); file_to_load_ = ConverterCache::get().cacheName(filename, to_); loadImage(); return; } - LYXERR(Debug::GRAPHICS) << "\tConverting it to " << to_ << " format." << endl; + LYXERR(Debug::GRAPHICS, "\tConverting it to " << to_ << " format."); // Add some stuff to create a uniquely named temporary file. // This file is deleted in loadImage after it is loaded into memory. - FileName const to_file_base(tempName(FileName(), "CacheItem")); + FileName const to_file_base = FileName::tempName("CacheItem"); remove_loaded_file_ = true; // Remove the temp file, we only want the name... // FIXME: This is unsafe! - unlink(to_file_base); + to_file_base.removeFile(); // Connect a signal to this->imageConverted and pass this signal to // the graphics converter so that we can load the modified file