4 * This file is part of LyX, the document processor.
5 * Licence details can be found in the file COPYING.
9 * Full author contact details are available in file CREDITS.
15 #include "OutputParams.h"
17 #include "support/strfwd.h"
23 namespace support { class FileName; }
29 /// Flags for some format properties
32 /// Set if this format is a document format (as opposed to
33 /// e.g. image formats).
34 /// Some formats are both (e.g. pdf), they have this flag set.
36 /// Set if this format can contain vector graphics.
38 /// This format should appear in the File > Export menu
40 /// This may be a compressed file but doesn't need decompression
42 /// This format should not appear in a menu at all
46 Format(std::string const & n, std::string const & e, docstring const & p,
47 std::string const & s, std::string const & v, std::string const & ed,
48 std::string const & m, int);
51 /// Is \p ext a valid filename extension for this format?
52 bool hasExtension(std::string const & ext) const;
53 /// Tell whether this format is a child format.
54 /// Child formats inherit settings like the viewer from their parent.
55 bool isChildFormat() const;
56 /// Name fo the parent format
57 std::string const parentFormat() const;
59 std::string const name() const { return name_; }
61 void setName(std::string const & v) { name_ = v; }
63 std::string const extension() const
65 return extension_list_.empty() ? empty_string() : extension_list_[0];
68 std::string const extensions() const;
70 void setExtensions(std::string const & v);
72 docstring const prettyname() const { return prettyname_; }
74 void setPrettyname(docstring const & v) { prettyname_ = v; }
76 std::string const shortcut() const { return shortcut_; }
78 void setShortcut(std::string const & v) { shortcut_ = v; }
80 std::string const viewer() const { return viewer_; }
82 void setViewer(std::string const & v) { viewer_ = v; }
84 std::string const editor() const { return editor_; }
86 void setEditor(std::string const & v) { editor_ = v; }
88 std::string const mime() const { return mime_; }
90 void setMime(std::string const & m) { mime_ = m; }
92 bool documentFormat() const { return flags_ & document; }
94 bool vectorFormat() const { return flags_ & vector; }
96 void setFlags(int v) { flags_ = v; }
98 bool inExportMenu() const { return flags_ & export_menu; }
100 bool noMenu() const { return flags_ & no_menu; }
102 bool zippedNative() const { return flags_ & zipped_native; }
104 static bool formatSorter(Format const * lhs, Format const * rhs);
107 /// Internal name. Needs to be unique.
109 /// Filename extensions, the first one being the default
110 std::vector<std::string> extension_list_;
111 /// Name presented to the user. Needs to be unique.
112 trivdocstring prettyname_;
113 /// Keyboard shortcut for the View and Export menu.
114 trivstring shortcut_;
116 * Viewer for this format. Needs to be in the PATH or an absolute
118 * This format cannot be viewed if \c viewer_ is empty.
119 * If it is \c auto the default viewer of the OS for this format is
123 /// Editor for this format. \sa viewer_.
126 * Full MIME type, e.g. "text/x-tex".
127 * Only types listed by the shared MIME database of freedesktop.org
129 * This field may be empty, but it must be unique across all formats
138 bool operator<(Format const & a, Format const & b);
145 typedef std::vector<Format> FormatList;
147 typedef FormatList::const_iterator const_iterator;
149 Format const & get(FormatList::size_type i) const { return formatlist_[i]; }
151 Format & get(FormatList::size_type i) { return formatlist_[i]; }
152 /// \returns format named \p name if it exists, otherwise 0
153 Format const * getFormat(std::string const & name) const;
154 /// \returns format named \p name if it exists, otherwise 0
155 Format * getFormat(std::string const & name);
157 * Get the format of \p filename from file contents or, if this
158 * fails, from file extension.
159 * \returns file format if it could be found, otherwise an empty
161 * This function is expensive.
163 std::string getFormatFromFile(support::FileName const & filename) const;
164 /// Finds a format from a file extension. Returns string() if not found.
165 std::string getFormatFromExtension(std::string const & ext) const;
166 /** Returns true if the file referenced by \p filename is zipped and
167 ** needs to be unzipped for being handled
168 ** @note For natively zipped formats, such as dia/odg, this returns false.
170 bool isZippedFile(support::FileName const & filename) const;
171 /// check for zipped file format
172 static bool isZippedFileFormat(std::string const & format);
173 /// check for PostScript file format
174 static bool isPostScriptFileFormat(std::string const & format);
175 /// Set editor and/or viewer to "auto" for formats that can be
176 /// opened by the OS.
179 int getNumber(std::string const & name) const;
181 void add(std::string const & name);
183 void add(std::string const & name, std::string const & extensions,
184 docstring const & prettyname, std::string const & shortcut,
185 std::string const & viewer, std::string const & editor,
186 std::string const & mime, int flags);
188 void erase(std::string const & name);
192 void setViewer(std::string const & name, std::string const & command);
194 void setEditor(std::string const & name, std::string const & command);
195 /// View the given file. Buffer used for DVI's paper orientation.
196 bool view(Buffer const & buffer, support::FileName const & filename,
197 std::string const & format_name) const;
199 bool edit(Buffer const & buffer, support::FileName const & filename,
200 std::string const & format_name) const;
202 docstring const prettyName(std::string const & name) const;
204 std::string const extension(std::string const & name) const;
206 std::string const extensions(std::string const & name) const;
208 const_iterator begin() const { return formatlist_.begin(); }
210 const_iterator end() const { return formatlist_.end(); }
212 bool empty() const { return formatlist_.empty(); }
214 FormatList::size_type size() const { return formatlist_.size(); }
217 FormatList formatlist_;
221 std::string flavor2format(OutputParams::FLAVOR flavor);
222 // Not currently used.
223 // OutputParams::FLAVOR format2flavor(std::string fmt);
225 /// The global instance.
226 /// Implementation is in LyX.cpp.
227 extern Formats & theFormats();
229 /// The global copy after reading lyxrc.defaults.
230 /// Implementation is in LyX.cpp.
231 extern Formats & theSystemFormats();