* de.po: sync with branch.
[lyx.git] / src / Mover.h
blob4d1c1c79006ff8817e1f02603fd2e11cef72a53c
1 // -*- C++ -*-
2 /**
3 * \file Mover.h
4 * This file is part of LyX, the document processor.
5 * Licence details can be found in the file COPYING.
7 * \author Angus Leeming
9 * Full author contact details are available in file CREDITS.
12 #ifndef MOVER_H
13 #define MOVER_H
15 #include <map>
16 #include <string>
19 namespace lyx {
21 namespace support { class FileName; }
23 /**
24 * Utility to copy a file of a specified format from one place to another.
25 * This base class simply invokes the command support::copy().
27 class Mover
29 public:
30 virtual ~Mover() {}
32 /** Copy file @c from to @c to.
33 * This version should be used to copy files from the original
34 * location to the temporary directory.
35 * \returns true if successful.
37 bool
38 copy(support::FileName const & from, support::FileName const & to) const;
40 /** Copy file @c from to @c to.
41 * \see SpecialisedMover::SpecialisedMover() for an explanation of
42 * @c latex.
43 * This version should be used to copy files from the temporary
44 * directory to the export location, since @c to and @c latex may
45 * not be equal in this case.
46 * \returns true if successful.
47 * NOTE: Although this routine simply calls do_copy() and
48 * Mover::do_copy() does not itself make any use of the @c latex argument,
49 * SpecialisedMover overrides do_copy(), so SpecialisedMover::copy(), which
50 * is just Mover::copy(), calls SpecialisedMover::do_copy(), and the @c latex
51 * argument IS in that case used.
53 bool
54 copy(support::FileName const & from, support::FileName const & to,
55 std::string const & latex) const
57 return do_copy(from, to, latex);
60 /** Rename file @c from as @c to.
61 * This version should be used to move files from the original
62 * location to the temporary directory.
63 * \returns true if successful.
65 bool
66 rename(support::FileName const & from, support::FileName const & to) const;
68 /** Rename file @c from as @c to.
69 * \see SpecialisedMover::SpecialisedMover() for an explanation of
70 * @c latex.
71 * This version should be used to move files from the temporary
72 * directory to the export location, since @c to and @c latex may
73 * not be equal in this case.
74 * \returns true if successful.
76 bool
77 rename(support::FileName const & from, support::FileName const & to,
78 std::string const & latex) const
80 return do_rename(from, to, latex);
83 protected:
84 virtual bool
85 do_copy(support::FileName const & from, support::FileName const & to,
86 std::string const &) const;
88 virtual bool
89 do_rename(support::FileName const & from, support::FileName const & to,
90 std::string const &) const;
94 /**
95 * Specialisation of the Mover concept that uses an external command
96 * to copy a file.
98 * For example, an Xfig .fig file can contain references to external
99 * picture files. If such a reference has a relative path, then the
100 * copied .fig file will require a transformation of the picture file
101 * reference if it is to be found by Xfig.
103 * So, in this case, we need three arguments:
104 * (i) @c from the location of the file to be moved
105 * (ii) @c to the location to which it should be moved
106 * (iii) @c latex the identifier that should be used in the sort of
107 * transformation just mentioned.
109 class SpecialisedMover : public Mover
111 public:
112 SpecialisedMover() {}
114 virtual ~SpecialisedMover() {}
116 /** @c command should be of the form
117 * <code>
118 * python $$s/scripts/fig_copy.py $$i $$o $$l
119 * </code>
120 * where $$s is a placeholder for the lyx support directory,
121 * $$i is a placeholder for the name of the file to be moved,
122 * $$o is a placeholder for the name of the file after moving,
123 * $$l is a placeholder for the latex argument, as explained above.
124 * $$o and $$l can only differ if the file is copied from the temporary
125 * directory to the export location. If it is copied from the original
126 * location to the temporary directory, they are the same, so $$l may be
127 * ignored in this case, as it is in the Mover baseclass.
129 SpecialisedMover(std::string const & command)
130 : command_(command) {}
132 /// The template used to launch the external command.
133 std::string const & command() const { return command_; }
135 private:
136 virtual bool
137 do_copy(support::FileName const & from, support::FileName const & to,
138 std::string const & latex) const;
140 virtual bool
141 do_rename(support::FileName const & from, support::FileName const & to,
142 std::string const & latex) const;
144 std::string command_;
149 * Manage the store of (Mover)s.
151 class Movers
153 public:
154 /** Register a specialised @c command to be used to copy a file
155 * of format @c fmt.
157 void set(std::string const & fmt, std::string const & command);
159 /// @c returns the Mover registered for format @c fmt.
160 Mover const & operator()(std::string const & fmt) const;
162 /** @returns the command template if @c fmt 'finds' a
163 * SpecialisedMover. Otherwise, returns an empty string.
165 std::string const command(std::string const & fmt) const;
167 private:
168 typedef std::map<std::string, SpecialisedMover> SpecialsMap;
170 public:
171 typedef SpecialsMap::const_iterator const_iterator;
172 const_iterator begin() const { return specials_.begin(); }
173 const_iterator end() const { return specials_.end(); }
175 private:
176 Mover default_;
177 SpecialsMap specials_;
181 extern Movers & theMovers();
182 /// @c returns the Mover registered for format @c fmt.
183 extern Mover const & getMover(std::string const & fmt);
184 /** Register a specialised @c command to be used to copy a file
185 * of format @c fmt.
187 extern void setMover(std::string const & fmt, std::string const & command);
188 extern Movers & theSystemMovers();
191 } // namespace lyx
193 #endif // MOVER_H