2002-09-05 11:31:30 +00:00
|
|
|
|
/**
|
2002-02-27 09:59:52 +00:00
|
|
|
|
* \file GraphicsCacheItem.C
|
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
|
|
|
|
|
2001-02-22 16:53:59 +00:00
|
|
|
|
#include "debug.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
|
|
|
|
|
2003-09-04 00:29:22 +00:00
|
|
|
|
namespace support = lyx::support;
|
|
|
|
|
|
|
|
|
|
using support::ChangeExtension;
|
|
|
|
|
using support::FileMonitor;
|
|
|
|
|
using support::IsFileReadable;
|
|
|
|
|
using support::MakeDisplayPath;
|
|
|
|
|
using support::OnlyFilename;
|
|
|
|
|
using support::getExtFromContents;
|
|
|
|
|
using support::tempName;
|
|
|
|
|
using support::unlink;
|
|
|
|
|
using support::unzipFile;
|
2004-02-25 12:00:53 +00:00
|
|
|
|
using support::unzippedFileName;
|
2003-09-04 00:29:22 +00:00
|
|
|
|
using support::zippedFile;
|
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 lyx {
|
|
|
|
|
namespace graphics {
|
2002-02-27 09:59:52 +00:00
|
|
|
|
|
2002-06-28 11:22:56 +00:00
|
|
|
|
struct CacheItem::Impl : public boost::signals::trackable {
|
|
|
|
|
|
|
|
|
|
///
|
2002-07-17 16:56:42 +00:00
|
|
|
|
Impl(string 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.
|
2002-07-17 16:56:42 +00:00
|
|
|
|
string 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.
|
|
|
|
|
string unzipped_filename_;
|
|
|
|
|
/// What file are we trying to load?
|
|
|
|
|
string file_to_load_;
|
|
|
|
|
/** 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.
|
|
|
|
|
boost::signal0<void> statusChanged;
|
|
|
|
|
|
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_;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
CacheItem::CacheItem(string 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
|
|
|
|
|
|
|
|
|
string 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
|
|
|
|
|
//------------------------------
|
|
|
|
|
|
|
|
|
|
|
2002-07-17 16:56:42 +00:00
|
|
|
|
CacheItem::Impl::Impl(string 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();
|
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";
|
2002-11-27 10:30:28 +00:00
|
|
|
|
lyxerr[Debug::GRAPHICS] << "Image conversion " << text << '.' << endl;
|
2002-02-27 09:59:52 +00:00
|
|
|
|
|
2002-06-28 11:22:56 +00:00
|
|
|
|
file_to_load_ = converter_.get() ?
|
|
|
|
|
converter_->convertedFile() : string();
|
|
|
|
|
converter_.reset();
|
|
|
|
|
cc_.disconnect();
|
2002-07-17 16:56:42 +00:00
|
|
|
|
|
2002-06-28 11:22:56 +00:00
|
|
|
|
success = !file_to_load_.empty() && IsFileReadable(file_to_load_);
|
|
|
|
|
|
2002-02-27 09:59:52 +00:00
|
|
|
|
if (!success) {
|
2003-02-25 16:58:57 +00:00
|
|
|
|
lyxerr[Debug::GRAPHICS] << "Unable to find converted file!"
|
|
|
|
|
<< endl;
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
lyxerr[Debug::GRAPHICS] << "Loading image." << endl;
|
|
|
|
|
|
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";
|
2002-11-27 10:30:28 +00:00
|
|
|
|
lyxerr[Debug::GRAPHICS] << "Image loading " << text << '.' << endl;
|
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
|
|
|
|
|
2003-07-04 08:23:23 +00:00
|
|
|
|
} // namespace graphics
|
|
|
|
|
} // namespace lyx
|
2002-06-28 11:22:56 +00:00
|
|
|
|
|
2002-04-11 17:40:44 +00:00
|
|
|
|
|
2001-04-02 19:56:48 +00:00
|
|
|
|
namespace {
|
2001-04-24 15:25:26 +00:00
|
|
|
|
|
2001-04-02 19:56:48 +00:00
|
|
|
|
string const findTargetFormat(string const & from)
|
|
|
|
|
{
|
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
|
|
|
|
|
2002-03-21 17:27:08 +00:00
|
|
|
|
// There must be a format to load from.
|
2003-09-09 17:25:35 +00:00
|
|
|
|
BOOST_ASSERT(!formats.empty());
|
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
|
|
|
|
|
lyxerr[Debug::GRAPHICS]
|
|
|
|
|
<< "Unable to convert from " << from
|
|
|
|
|
<< " to " << *it << std::endl;
|
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
|
|
|
|
|
2001-04-02 19:56:48 +00:00
|
|
|
|
} // anon namespace
|
|
|
|
|
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2003-07-04 08:23:23 +00:00
|
|
|
|
namespace lyx {
|
|
|
|
|
namespace graphics {
|
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!
|
|
|
|
|
if (!IsFileReadable(filename_)) {
|
|
|
|
|
if (status_ != ErrorNoFile) {
|
|
|
|
|
setStatus(ErrorNoFile);
|
|
|
|
|
lyxerr[Debug::GRAPHICS]
|
|
|
|
|
<< "\tThe file is not readable" << endl;
|
|
|
|
|
}
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2002-06-18 20:47:49 +00:00
|
|
|
|
// Make a local copy in case we unzip it
|
2004-02-25 12:00:53 +00:00
|
|
|
|
string filename;
|
|
|
|
|
if ((zipped_ = zippedFile(filename_))) {
|
|
|
|
|
unzipped_filename_ = tempName(string(), filename_);
|
|
|
|
|
if (unzipped_filename_.empty()) {
|
|
|
|
|
setStatus(ErrorConverting);
|
|
|
|
|
lyxerr[Debug::GRAPHICS]
|
|
|
|
|
<< "\tCould not create temporary file." << endl;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
filename = unzipFile(filename_, unzipped_filename_);
|
|
|
|
|
} else
|
|
|
|
|
filename = filename_;
|
|
|
|
|
|
2002-02-27 09:59:52 +00:00
|
|
|
|
string const displayed_filename = MakeDisplayPath(filename_);
|
2002-06-18 20:47:49 +00:00
|
|
|
|
lyxerr[Debug::GRAPHICS] << "[GrahicsCacheItem::convertToDisplayFormat]\n"
|
|
|
|
|
<< "\tAttempting to convert image file: " << filename
|
|
|
|
|
<< "\n\twith displayed filename: " << displayed_filename
|
|
|
|
|
<< endl;
|
2002-02-27 09:59:52 +00:00
|
|
|
|
|
2002-06-18 20:47:49 +00:00
|
|
|
|
string from = getExtFromContents(filename);
|
2002-07-17 17:55:21 +00:00
|
|
|
|
lyxerr[Debug::GRAPHICS]
|
|
|
|
|
<< "\n\tThe file contains " << from << " format data." << endl;
|
2002-06-28 11:22:56 +00:00
|
|
|
|
string const to = findTargetFormat(from);
|
2002-02-27 09:59:52 +00:00
|
|
|
|
|
2001-09-20 13:16:17 +00:00
|
|
|
|
if (from == to) {
|
|
|
|
|
// No conversion needed!
|
2002-06-18 20:47:49 +00:00
|
|
|
|
lyxerr[Debug::GRAPHICS] << "\tNo conversion needed (from == to)!" << endl;
|
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
|
|
|
|
|
2002-06-18 20:47:49 +00:00
|
|
|
|
lyxerr[Debug::GRAPHICS] << "\tConverting it to " << to << " format." << endl;
|
2001-02-22 16:53:59 +00:00
|
|
|
|
// Take only the filename part of the file, without path or extension.
|
2002-02-27 09:59:52 +00:00
|
|
|
|
string const temp = ChangeExtension(OnlyFilename(filename), string());
|
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.
|
2003-06-30 23:56:22 +00:00
|
|
|
|
string const to_file_base = tempName(string(), temp);
|
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!
|
2003-06-30 23:56:22 +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.
|
2002-06-28 11:22:56 +00:00
|
|
|
|
converter_.reset(new Converter(filename, to_file_base, 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
|