2002-09-05 11:31:30 +00:00
|
|
|
|
/**
|
2007-04-25 03:01:35 +00:00
|
|
|
|
* \file GraphicsCacheItem.cpp
|
2002-09-05 15:14:23 +00:00
|
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
|
* Licence details can be found in the file COPYING.
|
2000-07-31 12:30:10 +00:00
|
|
|
|
*
|
2002-11-27 10:30:28 +00:00
|
|
|
|
* \author Baruch Even
|
2003-09-07 01:45:40 +00:00
|
|
|
|
* \author Herbert Vo<EFBFBD>
|
2002-11-27 10:30:28 +00:00
|
|
|
|
* \author Angus Leeming
|
2002-09-05 11:31:30 +00:00
|
|
|
|
*
|
2003-08-23 00:17:00 +00:00
|
|
|
|
* Full author contact details are available in file CREDITS.
|
2002-02-27 09:59:52 +00:00
|
|
|
|
*/
|
2000-07-31 12:30:10 +00:00
|
|
|
|
|
2000-07-31 16:39:50 +00:00
|
|
|
|
#include <config.h>
|
|
|
|
|
|
2002-07-17 16:56:42 +00:00
|
|
|
|
#include "GraphicsCacheItem.h"
|
|
|
|
|
#include "GraphicsConverter.h"
|
2003-09-05 03:10:30 +00:00
|
|
|
|
#include "GraphicsImage.h"
|
2002-07-18 14:01:42 +00:00
|
|
|
|
|
2006-11-13 10:27:57 +00:00
|
|
|
|
#include "ConverterCache.h"
|
2001-02-22 16:53:59 +00:00
|
|
|
|
#include "debug.h"
|
2007-04-26 04:41:58 +00:00
|
|
|
|
#include "Format.h"
|
2002-05-29 16:21:03 +00:00
|
|
|
|
|
2002-02-16 15:59:55 +00:00
|
|
|
|
#include "support/filetools.h"
|
2003-09-05 03:10:30 +00:00
|
|
|
|
#include "support/FileMonitor.h"
|
2003-06-30 23:56:22 +00:00
|
|
|
|
#include "support/lyxlib.h"
|
2002-02-27 09:59:52 +00:00
|
|
|
|
|
2002-05-29 16:21:03 +00:00
|
|
|
|
#include <boost/bind.hpp>
|
|
|
|
|
|
2003-10-06 15:43:21 +00:00
|
|
|
|
|
2006-10-21 00:16:43 +00:00
|
|
|
|
namespace lyx {
|
2003-09-04 00:29:22 +00:00
|
|
|
|
|
|
|
|
|
using support::FileMonitor;
|
2006-11-26 21:30:39 +00:00
|
|
|
|
using support::FileName;
|
2006-04-08 22:31:11 +00:00
|
|
|
|
using support::makeDisplayPath;
|
|
|
|
|
using support::onlyFilename;
|
2003-09-04 00:29:22 +00:00
|
|
|
|
using support::tempName;
|
|
|
|
|
using support::unlink;
|
|
|
|
|
using support::unzipFile;
|
2003-06-30 23:56:22 +00:00
|
|
|
|
|
2001-02-22 16:53:59 +00:00
|
|
|
|
using std::endl;
|
2003-10-06 15:43:21 +00:00
|
|
|
|
using std::string;
|
|
|
|
|
|
2001-02-22 16:53:59 +00:00
|
|
|
|
|
2003-07-04 08:23:23 +00:00
|
|
|
|
namespace graphics {
|
2002-02-27 09:59:52 +00:00
|
|
|
|
|
2005-01-19 15:03:31 +00:00
|
|
|
|
class CacheItem::Impl : public boost::signals::trackable {
|
|
|
|
|
public:
|
2002-06-28 11:22:56 +00:00
|
|
|
|
|
|
|
|
|
///
|
2006-11-26 21:30:39 +00:00
|
|
|
|
Impl(FileName const & file);
|
2002-06-28 11:22:56 +00:00
|
|
|
|
|
|
|
|
|
/** Start the image conversion process, checking first that it is
|
|
|
|
|
* necessary. If it is necessary, then a conversion task is started.
|
|
|
|
|
* CacheItem asumes that the conversion is asynchronous and so
|
|
|
|
|
* passes a Signal to the converting routine. When the conversion
|
|
|
|
|
* is finished, this Signal is emitted, returning the converted
|
|
|
|
|
* file to this->imageConverted.
|
|
|
|
|
*
|
|
|
|
|
* If no file conversion is needed, then convertToDisplayFormat() calls
|
|
|
|
|
* loadImage() directly.
|
|
|
|
|
*
|
|
|
|
|
* convertToDisplayFormat() will set the loading status flag as
|
|
|
|
|
* approriate through calls to setStatus().
|
|
|
|
|
*/
|
|
|
|
|
void convertToDisplayFormat();
|
|
|
|
|
|
|
|
|
|
/** Load the image into memory. This is called either from
|
|
|
|
|
* convertToDisplayFormat() direct or from imageConverted().
|
|
|
|
|
*/
|
|
|
|
|
void loadImage();
|
|
|
|
|
|
|
|
|
|
/** Get a notification when the image conversion is done.
|
|
|
|
|
* Connected to a signal on_finish_ which is passed to
|
|
|
|
|
* Converter::convert.
|
|
|
|
|
*/
|
|
|
|
|
void imageConverted(bool);
|
|
|
|
|
|
|
|
|
|
/** Get a notification when the image loading is done.
|
|
|
|
|
* Connected to a signal on_finish_ which is passed to
|
2003-07-21 21:30:57 +00:00
|
|
|
|
* lyx::graphics::Image::loadImage.
|
2002-06-28 11:22:56 +00:00
|
|
|
|
*/
|
|
|
|
|
void imageLoaded(bool);
|
|
|
|
|
|
|
|
|
|
/** Sets the status of the loading process. Also notifies
|
2002-07-17 16:56:42 +00:00
|
|
|
|
* listeners that the status has changed.
|
2002-06-28 11:22:56 +00:00
|
|
|
|
*/
|
|
|
|
|
void setStatus(ImageStatus new_status);
|
|
|
|
|
|
2002-07-18 14:01:42 +00:00
|
|
|
|
/** Can be invoked directly by the user, but is also connected to the
|
|
|
|
|
* FileMonitor and so is invoked when the file is changed
|
|
|
|
|
* (if monitoring is taking place).
|
|
|
|
|
*/
|
|
|
|
|
void startLoading();
|
|
|
|
|
|
|
|
|
|
/** If we are asked to load the file for a second or further time,
|
|
|
|
|
* (because the file has changed), then we'll have to first reset
|
|
|
|
|
* many of the variables below.
|
|
|
|
|
*/
|
|
|
|
|
void reset();
|
|
|
|
|
|
2002-06-28 11:22:56 +00:00
|
|
|
|
/// The filename we refer too.
|
2006-11-26 21:30:39 +00:00
|
|
|
|
FileName const filename_;
|
2002-07-18 14:01:42 +00:00
|
|
|
|
///
|
|
|
|
|
FileMonitor const monitor_;
|
2002-07-17 16:56:42 +00:00
|
|
|
|
|
2002-06-28 11:22:56 +00:00
|
|
|
|
/// Is the file compressed?
|
|
|
|
|
bool zipped_;
|
|
|
|
|
/// If so, store the uncompressed file in this temporary file.
|
2006-11-26 21:30:39 +00:00
|
|
|
|
FileName unzipped_filename_;
|
2006-11-13 10:27:57 +00:00
|
|
|
|
/// The target format
|
|
|
|
|
string to_;
|
2002-06-28 11:22:56 +00:00
|
|
|
|
/// What file are we trying to load?
|
2006-11-26 21:30:39 +00:00
|
|
|
|
FileName file_to_load_;
|
2002-06-28 11:22:56 +00:00
|
|
|
|
/** Should we delete the file after loading? True if the file is
|
|
|
|
|
* the result of a conversion process.
|
|
|
|
|
*/
|
|
|
|
|
bool remove_loaded_file_;
|
|
|
|
|
|
|
|
|
|
/// The image and its loading status.
|
|
|
|
|
boost::shared_ptr<Image> image_;
|
|
|
|
|
///
|
|
|
|
|
ImageStatus status_;
|
|
|
|
|
|
2002-07-17 16:56:42 +00:00
|
|
|
|
/// This signal is emitted when the image loading status changes.
|
2004-09-26 14:19:47 +00:00
|
|
|
|
boost::signal<void()> statusChanged;
|
2002-07-17 16:56:42 +00:00
|
|
|
|
|
2002-06-28 11:22:56 +00:00
|
|
|
|
/// The connection to the signal Image::finishedLoading
|
|
|
|
|
boost::signals::connection cl_;
|
|
|
|
|
|
|
|
|
|
/// The connection of the signal ConvProcess::finishedConversion,
|
|
|
|
|
boost::signals::connection cc_;
|
|
|
|
|
|
|
|
|
|
///
|
|
|
|
|
boost::scoped_ptr<Converter> converter_;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
2006-11-26 21:30:39 +00:00
|
|
|
|
CacheItem::CacheItem(FileName const & file)
|
2002-07-17 16:56:42 +00:00
|
|
|
|
: pimpl_(new Impl(file))
|
2002-06-25 15:59:10 +00:00
|
|
|
|
{}
|
2002-02-27 09:59:52 +00:00
|
|
|
|
|
2002-07-17 16:56:42 +00:00
|
|
|
|
|
2002-06-28 11:22:56 +00:00
|
|
|
|
CacheItem::~CacheItem()
|
|
|
|
|
{}
|
2002-02-27 09:59:52 +00:00
|
|
|
|
|
2002-06-28 11:22:56 +00:00
|
|
|
|
|
2006-11-26 21:30:39 +00:00
|
|
|
|
FileName const & CacheItem::filename() const
|
2002-02-16 15:59:55 +00:00
|
|
|
|
{
|
2002-06-28 11:22:56 +00:00
|
|
|
|
return pimpl_->filename_;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2002-07-17 16:56:42 +00:00
|
|
|
|
void CacheItem::startLoading() const
|
2002-06-28 11:22:56 +00:00
|
|
|
|
{
|
2002-07-18 14:01:42 +00:00
|
|
|
|
pimpl_->startLoading();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void CacheItem::startMonitoring() const
|
|
|
|
|
{
|
|
|
|
|
if (!pimpl_->monitor_.monitoring())
|
|
|
|
|
pimpl_->monitor_.start();
|
|
|
|
|
}
|
2002-02-27 09:59:52 +00:00
|
|
|
|
|
2002-07-18 14:01:42 +00:00
|
|
|
|
|
|
|
|
|
bool CacheItem::monitoring() const
|
|
|
|
|
{
|
|
|
|
|
return pimpl_->monitor_.monitoring();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
unsigned long CacheItem::checksum() const
|
|
|
|
|
{
|
|
|
|
|
return pimpl_->monitor_.checksum();
|
2002-06-28 11:22:56 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Image const * CacheItem::image() const
|
|
|
|
|
{
|
|
|
|
|
return pimpl_->image_.get();
|
2002-02-27 09:59:52 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2002-06-28 11:22:56 +00:00
|
|
|
|
ImageStatus CacheItem::status() const
|
|
|
|
|
{
|
|
|
|
|
return pimpl_->status_;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2002-07-17 16:56:42 +00:00
|
|
|
|
boost::signals::connection CacheItem::connect(slot_type const & slot) const
|
|
|
|
|
{
|
|
|
|
|
return pimpl_->statusChanged.connect(slot);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2002-06-28 11:22:56 +00:00
|
|
|
|
//------------------------------
|
|
|
|
|
// Implementation details follow
|
|
|
|
|
//------------------------------
|
|
|
|
|
|
|
|
|
|
|
2006-11-26 21:30:39 +00:00
|
|
|
|
CacheItem::Impl::Impl(FileName const & file)
|
2002-07-18 14:01:42 +00:00
|
|
|
|
: filename_(file),
|
|
|
|
|
monitor_(file, 2000),
|
|
|
|
|
zipped_(false),
|
|
|
|
|
remove_loaded_file_(false),
|
|
|
|
|
status_(WaitingToLoad)
|
|
|
|
|
{
|
|
|
|
|
monitor_.connect(boost::bind(&Impl::startLoading, this));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void CacheItem::Impl::startLoading()
|
|
|
|
|
{
|
|
|
|
|
if (status_ != WaitingToLoad)
|
|
|
|
|
reset();
|
|
|
|
|
|
|
|
|
|
convertToDisplayFormat();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void CacheItem::Impl::reset()
|
|
|
|
|
{
|
|
|
|
|
zipped_ = false;
|
|
|
|
|
if (!unzipped_filename_.empty())
|
2003-06-30 23:56:22 +00:00
|
|
|
|
unlink(unzipped_filename_);
|
2002-07-18 21:24:47 +00:00
|
|
|
|
unzipped_filename_.erase();
|
2002-07-18 14:01:42 +00:00
|
|
|
|
|
|
|
|
|
if (remove_loaded_file_ && !file_to_load_.empty())
|
2003-06-30 23:56:22 +00:00
|
|
|
|
unlink(file_to_load_);
|
2002-07-18 14:01:42 +00:00
|
|
|
|
remove_loaded_file_ = false;
|
2002-07-18 21:24:47 +00:00
|
|
|
|
file_to_load_.erase();
|
2006-11-13 10:27:57 +00:00
|
|
|
|
to_.erase();
|
2002-07-18 14:01:42 +00:00
|
|
|
|
|
|
|
|
|
if (image_.get())
|
|
|
|
|
image_.reset();
|
|
|
|
|
|
|
|
|
|
status_ = WaitingToLoad;
|
|
|
|
|
|
|
|
|
|
if (cl_.connected())
|
|
|
|
|
cl_.disconnect();
|
|
|
|
|
|
|
|
|
|
if (cc_.connected())
|
|
|
|
|
cc_.disconnect();
|
|
|
|
|
|
|
|
|
|
if (converter_.get())
|
|
|
|
|
converter_.reset();
|
|
|
|
|
}
|
2002-06-28 11:22:56 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void CacheItem::Impl::setStatus(ImageStatus new_status)
|
2002-02-27 09:59:52 +00:00
|
|
|
|
{
|
2002-06-25 15:59:10 +00:00
|
|
|
|
if (status_ == new_status)
|
2002-02-27 09:59:52 +00:00
|
|
|
|
return;
|
|
|
|
|
|
2002-06-25 15:59:10 +00:00
|
|
|
|
status_ = new_status;
|
2002-07-17 16:56:42 +00:00
|
|
|
|
statusChanged();
|
2002-02-27 09:59:52 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2002-06-28 11:22:56 +00:00
|
|
|
|
void CacheItem::Impl::imageConverted(bool success)
|
2002-02-27 09:59:52 +00:00
|
|
|
|
{
|
|
|
|
|
string const text = success ? "succeeded" : "failed";
|
2007-11-15 20:04:51 +00:00
|
|
|
|
LYXERR(Debug::GRAPHICS, "Image conversion " << text << '.');
|
2002-02-27 09:59:52 +00:00
|
|
|
|
|
2002-06-28 11:22:56 +00:00
|
|
|
|
file_to_load_ = converter_.get() ?
|
2006-11-26 21:30:39 +00:00
|
|
|
|
FileName(converter_->convertedFile()) : FileName();
|
2002-06-28 11:22:56 +00:00
|
|
|
|
converter_.reset();
|
|
|
|
|
cc_.disconnect();
|
2002-07-17 16:56:42 +00:00
|
|
|
|
|
2007-10-18 23:03:51 +00:00
|
|
|
|
success = !file_to_load_.empty() && file_to_load_.isFileReadable();
|
2002-06-28 11:22:56 +00:00
|
|
|
|
|
2002-02-27 09:59:52 +00:00
|
|
|
|
if (!success) {
|
2007-11-15 20:04:51 +00:00
|
|
|
|
LYXERR(Debug::GRAPHICS, "Unable to find converted file!");
|
2002-02-27 09:59:52 +00:00
|
|
|
|
setStatus(ErrorConverting);
|
|
|
|
|
|
|
|
|
|
if (zipped_)
|
2003-06-30 23:56:22 +00:00
|
|
|
|
unlink(unzipped_filename_);
|
2002-02-27 09:59:52 +00:00
|
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2006-11-13 10:27:57 +00:00
|
|
|
|
// Add the converted file to the file cache
|
|
|
|
|
ConverterCache::get().add(filename_, to_, file_to_load_);
|
|
|
|
|
|
2002-02-27 09:59:52 +00:00
|
|
|
|
loadImage();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// This function gets called from the callback after the image has been
|
|
|
|
|
// converted successfully.
|
2002-06-28 11:22:56 +00:00
|
|
|
|
void CacheItem::Impl::loadImage()
|
2002-02-27 09:59:52 +00:00
|
|
|
|
{
|
|
|
|
|
setStatus(Loading);
|
2007-11-15 20:04:51 +00:00
|
|
|
|
LYXERR(Debug::GRAPHICS, "Loading image.");
|
2002-02-27 09:59:52 +00:00
|
|
|
|
|
2002-06-28 11:22:56 +00:00
|
|
|
|
image_ = Image::newImage();
|
2002-02-27 09:59:52 +00:00
|
|
|
|
|
2002-06-28 11:22:56 +00:00
|
|
|
|
cl_.disconnect();
|
|
|
|
|
cl_ = image_->finishedLoading.connect(
|
|
|
|
|
boost::bind(&Impl::imageLoaded, this, _1));
|
|
|
|
|
image_->load(file_to_load_);
|
2002-02-27 09:59:52 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2002-06-28 11:22:56 +00:00
|
|
|
|
void CacheItem::Impl::imageLoaded(bool success)
|
2002-02-27 09:59:52 +00:00
|
|
|
|
{
|
|
|
|
|
string const text = success ? "succeeded" : "failed";
|
2007-11-15 20:04:51 +00:00
|
|
|
|
LYXERR(Debug::GRAPHICS, "Image loading " << text << '.');
|
2002-02-27 09:59:52 +00:00
|
|
|
|
|
|
|
|
|
// Clean up after loading.
|
|
|
|
|
if (zipped_)
|
2003-06-30 23:56:22 +00:00
|
|
|
|
unlink(unzipped_filename_);
|
2002-02-27 09:59:52 +00:00
|
|
|
|
|
|
|
|
|
if (remove_loaded_file_ && unzipped_filename_ != file_to_load_)
|
2003-06-30 23:56:22 +00:00
|
|
|
|
unlink(file_to_load_);
|
2002-02-27 09:59:52 +00:00
|
|
|
|
|
|
|
|
|
cl_.disconnect();
|
|
|
|
|
|
|
|
|
|
if (!success) {
|
|
|
|
|
setStatus(ErrorLoading);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2002-07-17 16:56:42 +00:00
|
|
|
|
// Inform the outside world.
|
2002-02-27 09:59:52 +00:00
|
|
|
|
setStatus(Loaded);
|
2002-04-11 17:40:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
2002-07-17 16:56:42 +00:00
|
|
|
|
|
2006-10-21 00:16:43 +00:00
|
|
|
|
static string const findTargetFormat(string const & from)
|
2001-04-02 19:56:48 +00:00
|
|
|
|
{
|
2003-07-21 21:30:57 +00:00
|
|
|
|
typedef lyx::graphics::Image::FormatList FormatList;
|
|
|
|
|
FormatList const formats = lyx::graphics::Image::loadableFormats();
|
2002-02-27 09:59:52 +00:00
|
|
|
|
|
2006-03-10 12:38:21 +00:00
|
|
|
|
// There must be a format to load from.
|
|
|
|
|
BOOST_ASSERT(!formats.empty());
|
|
|
|
|
|
2006-01-19 21:18:25 +00:00
|
|
|
|
// Use the standard converter if we don't know the format to load
|
|
|
|
|
// from.
|
2006-03-10 12:38:21 +00:00
|
|
|
|
if (from.empty())
|
2006-01-19 21:18:25 +00:00
|
|
|
|
return string("ppm");
|
2001-07-23 16:07:29 +00:00
|
|
|
|
|
2002-02-28 19:55:26 +00:00
|
|
|
|
// First ascertain if we can load directly with no conversion
|
2002-10-18 14:35:42 +00:00
|
|
|
|
FormatList::const_iterator it = formats.begin();
|
2002-02-27 09:59:52 +00:00
|
|
|
|
FormatList::const_iterator end = formats.end();
|
2002-10-18 14:35:42 +00:00
|
|
|
|
for (; it != end; ++it) {
|
|
|
|
|
if (from == *it)
|
|
|
|
|
return *it;
|
2001-04-02 19:56:48 +00:00
|
|
|
|
}
|
2002-02-27 09:59:52 +00:00
|
|
|
|
|
2002-02-28 19:55:26 +00:00
|
|
|
|
// So, we have to convert to a loadable format. Can we?
|
2002-10-18 14:35:42 +00:00
|
|
|
|
it = formats.begin();
|
|
|
|
|
for (; it != end; ++it) {
|
2003-07-21 21:30:57 +00:00
|
|
|
|
if (lyx::graphics::Converter::isReachable(from, *it))
|
2002-10-18 14:35:42 +00:00
|
|
|
|
return *it;
|
|
|
|
|
else
|
2007-11-15 20:04:51 +00:00
|
|
|
|
LYXERR(Debug::GRAPHICS, "Unable to convert from " << from
|
|
|
|
|
<< " to " << *it);
|
2002-02-28 19:55:26 +00:00
|
|
|
|
}
|
2002-02-27 09:59:52 +00:00
|
|
|
|
|
2003-01-13 23:03:48 +00:00
|
|
|
|
// Failed! so we have to try to convert it to PPM format
|
2002-06-18 20:47:49 +00:00
|
|
|
|
// with the standard converter
|
2003-01-13 23:03:48 +00:00
|
|
|
|
return string("ppm");
|
2000-10-12 10:46:06 +00:00
|
|
|
|
}
|
2000-09-14 17:53:12 +00:00
|
|
|
|
|
2002-06-28 11:22:56 +00:00
|
|
|
|
|
|
|
|
|
void CacheItem::Impl::convertToDisplayFormat()
|
2000-08-08 09:18:39 +00:00
|
|
|
|
{
|
2002-02-27 09:59:52 +00:00
|
|
|
|
setStatus(Converting);
|
2002-07-18 14:01:42 +00:00
|
|
|
|
|
|
|
|
|
// First, check that the file exists!
|
2007-10-18 23:03:51 +00:00
|
|
|
|
if (!filename_.isFileReadable()) {
|
2002-07-18 14:01:42 +00:00
|
|
|
|
if (status_ != ErrorNoFile) {
|
|
|
|
|
setStatus(ErrorNoFile);
|
2007-11-15 20:04:51 +00:00
|
|
|
|
LYXERR(Debug::GRAPHICS, "\tThe file is not readable");
|
2002-07-18 14:01:42 +00:00
|
|
|
|
}
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2002-06-18 20:47:49 +00:00
|
|
|
|
// Make a local copy in case we unzip it
|
2006-11-26 21:30:39 +00:00
|
|
|
|
FileName filename;
|
2007-10-20 17:35:27 +00:00
|
|
|
|
zipped_ = filename_.isZippedFile();
|
2005-11-02 20:11:36 +00:00
|
|
|
|
if (zipped_) {
|
2006-12-27 10:56:11 +00:00
|
|
|
|
unzipped_filename_ = tempName(FileName(), filename_.toFilesystemEncoding());
|
2004-02-25 12:00:53 +00:00
|
|
|
|
if (unzipped_filename_.empty()) {
|
|
|
|
|
setStatus(ErrorConverting);
|
2007-11-15 20:04:51 +00:00
|
|
|
|
LYXERR(Debug::GRAPHICS, "\tCould not create temporary file.");
|
2004-02-25 12:00:53 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
2006-11-26 21:30:39 +00:00
|
|
|
|
filename = unzipFile(filename_, unzipped_filename_.toFilesystemEncoding());
|
2007-10-20 17:35:27 +00:00
|
|
|
|
} else {
|
2004-02-25 12:00:53 +00:00
|
|
|
|
filename = filename_;
|
2007-10-20 17:35:27 +00:00
|
|
|
|
}
|
2004-02-25 12:00:53 +00:00
|
|
|
|
|
2006-11-26 21:30:39 +00:00
|
|
|
|
docstring const displayed_filename = makeDisplayPath(filename_.absFilename());
|
2007-11-15 20:04:51 +00:00
|
|
|
|
LYXERR(Debug::GRAPHICS, "[CacheItem::Impl::convertToDisplayFormat]\n"
|
2002-06-18 20:47:49 +00:00
|
|
|
|
<< "\tAttempting to convert image file: " << filename
|
2007-11-15 20:04:51 +00:00
|
|
|
|
<< "\n\twith displayed filename: " << to_utf8(displayed_filename));
|
2002-02-27 09:59:52 +00:00
|
|
|
|
|
2004-11-09 19:08:34 +00:00
|
|
|
|
string const from = formats.getFormatFromFile(filename);
|
|
|
|
|
if (from.empty()) {
|
|
|
|
|
setStatus(ErrorConverting);
|
2007-11-15 20:04:51 +00:00
|
|
|
|
LYXERR(Debug::GRAPHICS, "\tCould not determine file format.");
|
2004-11-09 19:08:34 +00:00
|
|
|
|
}
|
2007-11-15 20:04:51 +00:00
|
|
|
|
LYXERR(Debug::GRAPHICS, "\n\tThe file contains " << from << " format data.");
|
2006-11-13 10:27:57 +00:00
|
|
|
|
to_ = findTargetFormat(from);
|
2002-02-27 09:59:52 +00:00
|
|
|
|
|
2006-11-13 10:27:57 +00:00
|
|
|
|
if (from == to_) {
|
2001-09-20 13:16:17 +00:00
|
|
|
|
// No conversion needed!
|
2007-11-15 20:04:51 +00:00
|
|
|
|
LYXERR(Debug::GRAPHICS, "\tNo conversion needed (from == to)!");
|
2002-02-27 09:59:52 +00:00
|
|
|
|
file_to_load_ = filename;
|
|
|
|
|
loadImage();
|
|
|
|
|
return;
|
2001-09-20 13:16:17 +00:00
|
|
|
|
}
|
2002-02-27 09:59:52 +00:00
|
|
|
|
|
2006-11-13 10:27:57 +00:00
|
|
|
|
if (ConverterCache::get().inCache(filename, to_)) {
|
2007-11-15 20:04:51 +00:00
|
|
|
|
LYXERR(Debug::GRAPHICS, "\tNo conversion needed (file in file cache)!");
|
2006-11-13 10:27:57 +00:00
|
|
|
|
file_to_load_ = ConverterCache::get().cacheName(filename, to_);
|
|
|
|
|
loadImage();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2007-11-15 20:04:51 +00:00
|
|
|
|
LYXERR(Debug::GRAPHICS, "\tConverting it to " << to_ << " format.");
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2002-02-27 09:59:52 +00:00
|
|
|
|
// Add some stuff to create a uniquely named temporary file.
|
|
|
|
|
// This file is deleted in loadImage after it is loaded into memory.
|
2006-12-27 10:56:11 +00:00
|
|
|
|
FileName const to_file_base(tempName(FileName(), "CacheItem"));
|
2002-02-27 09:59:52 +00:00
|
|
|
|
remove_loaded_file_ = true;
|
|
|
|
|
|
2001-02-22 16:53:59 +00:00
|
|
|
|
// Remove the temp file, we only want the name...
|
2004-02-25 12:00:53 +00:00
|
|
|
|
// FIXME: This is unsafe!
|
2006-12-27 10:56:11 +00:00
|
|
|
|
unlink(to_file_base);
|
2002-02-27 09:59:52 +00:00
|
|
|
|
|
|
|
|
|
// Connect a signal to this->imageConverted and pass this signal to
|
|
|
|
|
// the graphics converter so that we can load the modified file
|
|
|
|
|
// on completion of the conversion process.
|
2006-12-27 10:56:11 +00:00
|
|
|
|
converter_.reset(new Converter(filename, to_file_base.absFilename(), from, to_));
|
2002-07-17 16:56:42 +00:00
|
|
|
|
converter_->connect(boost::bind(&Impl::imageConverted, this, _1));
|
2002-06-28 11:22:56 +00:00
|
|
|
|
converter_->startConversion();
|
2000-08-08 09:18:39 +00:00
|
|
|
|
}
|
|
|
|
|
|
2003-07-04 08:23:23 +00:00
|
|
|
|
} // namespace graphics
|
|
|
|
|
} // namespace lyx
|