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