]> git.lyx.org Git - lyx.git/blob - src/Converter.h
prepare Qt 5.6 builds
[lyx.git] / src / Converter.h
1 // -*- C++ -*-
2 /**
3  * \file Converter.h
4  * This file is part of LyX, the document processor.
5  * Licence details can be found in the file COPYING.
6  *
7  * \author Dekel Tsur
8  *
9  * Full author contact details are available in file CREDITS.
10  */
11
12 #ifndef CONVERTER_H
13 #define CONVERTER_H
14
15 #include "Graph.h"
16 #include "OutputParams.h"
17 #include "support/trivstring.h"
18
19 #include <vector>
20 #include <set>
21 #include <string>
22
23
24 namespace lyx {
25
26 namespace support { class FileName; }
27
28 class Buffer;
29 class ErrorList;
30 class Format;
31 class Formats;
32 class OutputParams;
33
34
35 ///
36 class Converter {
37 public:
38         ///
39         Converter(std::string const & f, std::string const & t, std::string const & c,
40                   std::string const & l);
41         ///
42         void readFlags();
43         ///
44         std::string const from() const { return from_; }
45         ///
46         std::string const to() const { return to_; }
47         ///
48         std::string const command() const { return command_; }
49         ///
50         void setCommand(std::string const & command) { command_ = command; }
51         ///
52         std::string const flags() const { return flags_; }
53         ///
54         void setFlags(std::string const & flags) { flags_ = flags; }
55         ///
56         Format const * From() const { return From_; }
57         ///
58         void setFrom(Format const * From) { From_ = From; }
59         ///
60         void setTo(Format const * To) { To_ = To; }
61         ///
62         Format const * To() const { return To_; }
63         ///
64         bool latex() const { return latex_; }
65         ///
66         std::string const latex_flavor() const { return latex_flavor_; }
67         ///
68         bool xml() const { return xml_; }
69         ///
70         bool need_aux() const { return need_aux_; }
71         ///
72         bool nice() const { return nice_; }
73         ///
74         std::string const result_dir() const { return result_dir_; }
75         ///
76         std::string const result_file() const { return result_file_; }
77         ///
78         std::string const parselog() const { return parselog_; }
79 private:
80         ///
81         trivstring from_;
82         ///
83         trivstring to_;
84         ///
85         trivstring command_;
86         ///
87         trivstring flags_;
88         ///
89         Format const * From_;
90         ///
91         Format const * To_;
92
93         /// The converter is latex or its derivatives
94         bool latex_;
95         /// The latex derivate
96         trivstring latex_flavor_;
97         /// The converter is xml
98         bool xml_;
99         /// This converter needs the .aux files
100         bool need_aux_;
101         /// we need a "nice" file from the backend, c.f. OutputParams.nice.
102         bool nice_;
103         /// If the converter put the result in a directory, then result_dir
104         /// is the name of the directory
105         trivstring result_dir_;
106         /// If the converter put the result in a directory, then result_file
107         /// is the name of the main file in that directory
108         trivstring result_file_;
109         /// Command to convert the program output to a LaTeX log file format
110         trivstring parselog_;
111 };
112
113
114 ///
115 class Converters {
116 public:
117         ///
118         typedef std::vector<Converter> ConverterList;
119         ///
120         typedef ConverterList::const_iterator const_iterator;
121
122         ///
123         Converter const & get(int i) const { return converterlist_[i]; }
124         ///
125         Converter const * getConverter(std::string const & from,
126                                        std::string const & to) const;
127         ///
128         int getNumber(std::string const & from, std::string const & to) const;
129         ///
130         void add(std::string const & from, std::string const & to,
131                  std::string const & command, std::string const & flags);
132         //
133         void erase(std::string const & from, std::string const & to);
134         ///
135         std::vector<Format const *> const
136         getReachableTo(std::string const & target, bool clear_visited);
137         ///
138         std::vector<Format const *> const
139         getReachable(std::string const & from, bool only_viewable,
140                bool clear_visited,
141                std::set<std::string> const & excludes = std::set<std::string>());
142
143         std::vector<Format const *> importableFormats();
144         std::vector<Format const *> exportableFormats(bool only_viewable);
145
146         std::vector<std::string> loaders() const;
147         std::vector<std::string> savers() const;
148
149         /// Does a conversion path from format \p from to format \p to exist?
150         bool isReachable(std::string const & from, std::string const & to);
151         ///
152         Graph::EdgePath getPath(std::string const & from, std::string const & to);
153         ///
154         OutputParams::FLAVOR getFlavor(Graph::EdgePath const & path,
155                                        Buffer const * buffer = 0);
156         /// Flags for converting files
157         enum ConversionFlags {
158                 /// No special flags
159                 none = 0,
160                 /// Use the default converter if no converter is defined
161                 try_default = 1 << 0,
162                 /// Get the converted file from cache if possible
163                 try_cache = 1 << 1
164         };
165         ///
166         bool convert(Buffer const * buffer,
167                      support::FileName const & from_file, support::FileName const & to_file,
168                      support::FileName const & orig_from,
169                      std::string const & from_format, std::string const & to_format,
170                      ErrorList & errorList, int conversionflags = none);
171         ///
172         void update(Formats const & formats);
173         ///
174         void updateLast(Formats const & formats);
175         ///
176         bool formatIsUsed(std::string const & format);
177         ///
178         const_iterator begin() const { return converterlist_.begin(); }
179         ///
180         const_iterator end() const { return converterlist_.end(); }
181         ///
182         void buildGraph();
183 private:
184         ///
185         std::vector<Format const *> const
186         intToFormat(std::vector<int> const & input);
187         ///
188         bool scanLog(Buffer const & buffer, std::string const & command,
189                      support::FileName const & filename, ErrorList & errorList);
190         ///
191         bool runLaTeX(Buffer const & buffer, std::string const & command,
192                       OutputParams const &, ErrorList & errorList);
193         ///
194         ConverterList converterlist_;
195         ///
196         trivstring latex_command_;
197         ///
198         trivstring dvilualatex_command_;
199         ///
200         trivstring lualatex_command_;
201         ///
202         trivstring pdflatex_command_;
203         ///
204         trivstring xelatex_command_;
205         /// If \p from = /path/file.ext and \p to = /path2/file2.ext2 then
206         /// this method moves each /path/file*.ext file to /path2/file2*.ext2
207         bool move(std::string const & fmt,
208                   support::FileName const & from, support::FileName const & to,
209                   bool copy);
210         ///
211         Graph G_;
212 };
213
214 /// The global instance.
215 /// Implementation is in LyX.cpp.
216 extern Converters & theConverters();
217
218 /// The global copy after reading lyxrc.defaults.
219 /// Implementation is in LyX.cpp.
220 extern Converters & theSystemConverters();
221
222 } // namespace lyx
223
224 #endif //CONVERTER_H