lyx_mirror/src/mover.h

186 lines
5.0 KiB
C
Raw Normal View History

// -*- C++ -*-
/**
* \file mover.h
* This file is part of LyX, the document processor.
* Licence details can be found in the file COPYING.
*
* \author Angus Leeming
*
* Full author contact details are available in file CREDITS.
*/
#ifndef MOVER_H
#define MOVER_H
#include <map>
#include <string>
namespace lyx {
/**
* Utility to copy a file of a specified format from one place to another.
* This base class simply invokes the command support::copy().
*/
class Mover
{
public:
virtual ~Mover() {}
/** Copy file @c from to @c to.
* This version should be used to copy files from the original
* location to the temporary directory, since @c to and @c latex
* would be equal in this case.
* \returns true if successful.
*/
bool
Add a cache for converted image files. This needs to be enabled in the preferences file with \use_converter_cache true. It is disabled by default, and no GUI support for changing the preferences is yet implemented. * src/insets/insetgraphics.C (InsetGraphics::prepareFile): Use image file cache * src/insets/ExternalSupport.C (updateExternal): Use image file cache * src/exporter.C (Exporter::Export): Do not use image file cache * src/graphics/GraphicsCacheItem.C (CacheItem::Impl::imageConverted): Add the converted file to the image file cache (CacheItem::Impl::convertToDisplayFo): Use image file cache * src/converter.C (Converters::convert): Use image file cache if the caller allowed that * src/converter.h (Converters::convert): Adjust arguments * src/Makefile.am: Add new files * src/support/lyxlib.h (chmod): new function (copy): add mode argument * src/support/copy.C (chmod): new function (copy): implement mode argument * src/support/mkdir.C (lyx::support::mkdir): Add warning if permissions are ignored * src/lyxrc.[Ch]: Add new settings \converter_cache_maxage and \use_converter_cache * src/ConverterCache.[Ch]: New image file cache * src/importer.C (Importer::Import): Do nut use the image file cache * src/lyx_main.C (LyX::init): Initialize the image file cache * src/mover.[Ch] (Mover::do_copy): Add mode argument (SpecialisedMover::do_copy): ditto * configure.ac: Check for chmod * development/cmake/ConfigureChecks.cmake: ditto * development/cmake/config.h.cmake: ditto * development/scons/SConstruct: ditto * development/scons/scons_manifest.py: Add new files git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@15897 a592a061-630c-0410-9148-cb99ea01b6c8
2006-11-13 10:27:57 +00:00
copy(std::string const & from, std::string const & to,
unsigned long int mode = (unsigned long int)-1) const
{
Add a cache for converted image files. This needs to be enabled in the preferences file with \use_converter_cache true. It is disabled by default, and no GUI support for changing the preferences is yet implemented. * src/insets/insetgraphics.C (InsetGraphics::prepareFile): Use image file cache * src/insets/ExternalSupport.C (updateExternal): Use image file cache * src/exporter.C (Exporter::Export): Do not use image file cache * src/graphics/GraphicsCacheItem.C (CacheItem::Impl::imageConverted): Add the converted file to the image file cache (CacheItem::Impl::convertToDisplayFo): Use image file cache * src/converter.C (Converters::convert): Use image file cache if the caller allowed that * src/converter.h (Converters::convert): Adjust arguments * src/Makefile.am: Add new files * src/support/lyxlib.h (chmod): new function (copy): add mode argument * src/support/copy.C (chmod): new function (copy): implement mode argument * src/support/mkdir.C (lyx::support::mkdir): Add warning if permissions are ignored * src/lyxrc.[Ch]: Add new settings \converter_cache_maxage and \use_converter_cache * src/ConverterCache.[Ch]: New image file cache * src/importer.C (Importer::Import): Do nut use the image file cache * src/lyx_main.C (LyX::init): Initialize the image file cache * src/mover.[Ch] (Mover::do_copy): Add mode argument (SpecialisedMover::do_copy): ditto * configure.ac: Check for chmod * development/cmake/ConfigureChecks.cmake: ditto * development/cmake/config.h.cmake: ditto * development/scons/SConstruct: ditto * development/scons/scons_manifest.py: Add new files git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@15897 a592a061-630c-0410-9148-cb99ea01b6c8
2006-11-13 10:27:57 +00:00
return do_copy(from, to, to, mode);
}
/** Copy file @c from to @c to.
* \see SpecialisedMover::SpecialisedMover() for an explanation of
* @c latex.
* This version should be used to copy files from the temporary
* directory to the export location, since @c to and @c latex may
* not be equal in this case.
* \returns true if successful.
*/
bool
copy(std::string const & from, std::string const & to,
Add a cache for converted image files. This needs to be enabled in the preferences file with \use_converter_cache true. It is disabled by default, and no GUI support for changing the preferences is yet implemented. * src/insets/insetgraphics.C (InsetGraphics::prepareFile): Use image file cache * src/insets/ExternalSupport.C (updateExternal): Use image file cache * src/exporter.C (Exporter::Export): Do not use image file cache * src/graphics/GraphicsCacheItem.C (CacheItem::Impl::imageConverted): Add the converted file to the image file cache (CacheItem::Impl::convertToDisplayFo): Use image file cache * src/converter.C (Converters::convert): Use image file cache if the caller allowed that * src/converter.h (Converters::convert): Adjust arguments * src/Makefile.am: Add new files * src/support/lyxlib.h (chmod): new function (copy): add mode argument * src/support/copy.C (chmod): new function (copy): implement mode argument * src/support/mkdir.C (lyx::support::mkdir): Add warning if permissions are ignored * src/lyxrc.[Ch]: Add new settings \converter_cache_maxage and \use_converter_cache * src/ConverterCache.[Ch]: New image file cache * src/importer.C (Importer::Import): Do nut use the image file cache * src/lyx_main.C (LyX::init): Initialize the image file cache * src/mover.[Ch] (Mover::do_copy): Add mode argument (SpecialisedMover::do_copy): ditto * configure.ac: Check for chmod * development/cmake/ConfigureChecks.cmake: ditto * development/cmake/config.h.cmake: ditto * development/scons/SConstruct: ditto * development/scons/scons_manifest.py: Add new files git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@15897 a592a061-630c-0410-9148-cb99ea01b6c8
2006-11-13 10:27:57 +00:00
std::string const & latex,
unsigned long int mode = (unsigned long int)-1) const
{
Add a cache for converted image files. This needs to be enabled in the preferences file with \use_converter_cache true. It is disabled by default, and no GUI support for changing the preferences is yet implemented. * src/insets/insetgraphics.C (InsetGraphics::prepareFile): Use image file cache * src/insets/ExternalSupport.C (updateExternal): Use image file cache * src/exporter.C (Exporter::Export): Do not use image file cache * src/graphics/GraphicsCacheItem.C (CacheItem::Impl::imageConverted): Add the converted file to the image file cache (CacheItem::Impl::convertToDisplayFo): Use image file cache * src/converter.C (Converters::convert): Use image file cache if the caller allowed that * src/converter.h (Converters::convert): Adjust arguments * src/Makefile.am: Add new files * src/support/lyxlib.h (chmod): new function (copy): add mode argument * src/support/copy.C (chmod): new function (copy): implement mode argument * src/support/mkdir.C (lyx::support::mkdir): Add warning if permissions are ignored * src/lyxrc.[Ch]: Add new settings \converter_cache_maxage and \use_converter_cache * src/ConverterCache.[Ch]: New image file cache * src/importer.C (Importer::Import): Do nut use the image file cache * src/lyx_main.C (LyX::init): Initialize the image file cache * src/mover.[Ch] (Mover::do_copy): Add mode argument (SpecialisedMover::do_copy): ditto * configure.ac: Check for chmod * development/cmake/ConfigureChecks.cmake: ditto * development/cmake/config.h.cmake: ditto * development/scons/SConstruct: ditto * development/scons/scons_manifest.py: Add new files git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@15897 a592a061-630c-0410-9148-cb99ea01b6c8
2006-11-13 10:27:57 +00:00
return do_copy(from, to, latex, mode);
}
/** Rename file @c from as @c to.
* This version should be used to move files from the original
* location to the temporary directory, since @c to and @c latex
* would be equal in this case.
* \returns true if successful.
*/
bool
rename(std::string const & from, std::string const & to) const
{
return do_rename(from, to, to);
}
/** Rename file @c from as @c to.
* \see SpecialisedMover::SpecialisedMover() for an explanation of
* @c latex.
* This version should be used to move files from the temporary
* directory to the export location, since @c to and @c latex may
* not be equal in this case.
* \returns true if successful.
*/
bool
rename(std::string const & from, std::string const & to,
std::string const & latex) const
{
return do_rename(from, to, latex);
}
protected:
virtual bool
do_copy(std::string const & from, std::string const & to,
Add a cache for converted image files. This needs to be enabled in the preferences file with \use_converter_cache true. It is disabled by default, and no GUI support for changing the preferences is yet implemented. * src/insets/insetgraphics.C (InsetGraphics::prepareFile): Use image file cache * src/insets/ExternalSupport.C (updateExternal): Use image file cache * src/exporter.C (Exporter::Export): Do not use image file cache * src/graphics/GraphicsCacheItem.C (CacheItem::Impl::imageConverted): Add the converted file to the image file cache (CacheItem::Impl::convertToDisplayFo): Use image file cache * src/converter.C (Converters::convert): Use image file cache if the caller allowed that * src/converter.h (Converters::convert): Adjust arguments * src/Makefile.am: Add new files * src/support/lyxlib.h (chmod): new function (copy): add mode argument * src/support/copy.C (chmod): new function (copy): implement mode argument * src/support/mkdir.C (lyx::support::mkdir): Add warning if permissions are ignored * src/lyxrc.[Ch]: Add new settings \converter_cache_maxage and \use_converter_cache * src/ConverterCache.[Ch]: New image file cache * src/importer.C (Importer::Import): Do nut use the image file cache * src/lyx_main.C (LyX::init): Initialize the image file cache * src/mover.[Ch] (Mover::do_copy): Add mode argument (SpecialisedMover::do_copy): ditto * configure.ac: Check for chmod * development/cmake/ConfigureChecks.cmake: ditto * development/cmake/config.h.cmake: ditto * development/scons/SConstruct: ditto * development/scons/scons_manifest.py: Add new files git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@15897 a592a061-630c-0410-9148-cb99ea01b6c8
2006-11-13 10:27:57 +00:00
std::string const &, unsigned long int mode) const;
virtual bool
do_rename(std::string const & from, std::string const & to,
std::string const &) const;
};
/**
* Specialisation of the Mover concept that uses an external command
* to copy a file.
*
* For example, an XFig .fig file can contain references to external
* picture files. If such a reference has a relative path, then the
* copied .fig file will require a transformation of the picture file
* reference if it is to be found by XFig.
*/
class SpecialisedMover : public Mover
{
public:
SpecialisedMover() {}
/** @c command should be of the form
* <code>
* python $$s/scripts/fig_copy.py $$i $$o $$l
* </code>
* where $$s is a placeholder for the lyx support directory,
* $$i is a placeholder for the name of the file to be moved,
* $$o is a placeholder for the name of the file after moving,
* $$l is a placeholder for the name of the file after moving,
* suitable as argument to a latex include command. This is
* either an absolute filename or relative to the master
* document.
* $$o and $$l can only differ if the file is copied from the
* temporary directory to the export location. If it is copied
* from the original location to the temporary directory, they
* are the same, so $$l may be ommitted in this case.
*/
SpecialisedMover(std::string const & command)
: command_(command) {}
/// The template used to launch the external command.
std::string const & command() const { return command_; }
private:
virtual bool
do_copy(std::string const & from, std::string const & to,
Add a cache for converted image files. This needs to be enabled in the preferences file with \use_converter_cache true. It is disabled by default, and no GUI support for changing the preferences is yet implemented. * src/insets/insetgraphics.C (InsetGraphics::prepareFile): Use image file cache * src/insets/ExternalSupport.C (updateExternal): Use image file cache * src/exporter.C (Exporter::Export): Do not use image file cache * src/graphics/GraphicsCacheItem.C (CacheItem::Impl::imageConverted): Add the converted file to the image file cache (CacheItem::Impl::convertToDisplayFo): Use image file cache * src/converter.C (Converters::convert): Use image file cache if the caller allowed that * src/converter.h (Converters::convert): Adjust arguments * src/Makefile.am: Add new files * src/support/lyxlib.h (chmod): new function (copy): add mode argument * src/support/copy.C (chmod): new function (copy): implement mode argument * src/support/mkdir.C (lyx::support::mkdir): Add warning if permissions are ignored * src/lyxrc.[Ch]: Add new settings \converter_cache_maxage and \use_converter_cache * src/ConverterCache.[Ch]: New image file cache * src/importer.C (Importer::Import): Do nut use the image file cache * src/lyx_main.C (LyX::init): Initialize the image file cache * src/mover.[Ch] (Mover::do_copy): Add mode argument (SpecialisedMover::do_copy): ditto * configure.ac: Check for chmod * development/cmake/ConfigureChecks.cmake: ditto * development/cmake/config.h.cmake: ditto * development/scons/SConstruct: ditto * development/scons/scons_manifest.py: Add new files git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@15897 a592a061-630c-0410-9148-cb99ea01b6c8
2006-11-13 10:27:57 +00:00
std::string const & latex, unsigned long int mode) const;
virtual bool
do_rename(std::string const & from, std::string const & to,
std::string const & latex) const;
std::string command_;
};
/**
* Manage the store of (Mover)s.
*/
class Movers
{
public:
/** Register a specialised @c command to be used to copy a file
* of format @c fmt.
*/
void set(std::string const & fmt, std::string const & command);
/// @c returns the Mover registered for format @c fmt.
Mover const & operator()(std::string const & fmt) const;
/** @returns the command template if @c fmt 'finds' a
* SpecialisedMover. Otherwise, returns an empty string.
*/
std::string const command(std::string const & fmt) const;
private:
typedef std::map<std::string, SpecialisedMover> SpecialsMap;
public:
typedef SpecialsMap::const_iterator iterator;
iterator begin() const { return specials_.begin(); }
iterator end() const { return specials_.end(); }
private:
Mover default_;
SpecialsMap specials_;
};
extern Movers movers;
extern Movers system_movers;
} // namespace lyx
#endif // MOVER_H