2003-02-28 09:49:49 +00:00
|
|
|
// -*- C++ -*-
|
|
|
|
/**
|
2007-04-26 04:41:58 +00:00
|
|
|
* \file Format.h
|
2003-02-28 09:49:49 +00:00
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
* Licence details can be found in the file COPYING.
|
|
|
|
*
|
|
|
|
* \author Dekel Tsur
|
|
|
|
*
|
2003-08-23 00:17:00 +00:00
|
|
|
* Full author contact details are available in file CREDITS.
|
2003-02-28 09:49:49 +00:00
|
|
|
*/
|
|
|
|
|
2003-08-23 00:17:00 +00:00
|
|
|
#ifndef FORMAT_H
|
|
|
|
#define FORMAT_H
|
2003-02-28 09:49:49 +00:00
|
|
|
|
2006-09-11 08:54:10 +00:00
|
|
|
#include "support/docstring.h"
|
|
|
|
|
2011-04-14 18:32:42 +00:00
|
|
|
#include "OutputParams.h"
|
|
|
|
|
2003-02-28 09:49:49 +00:00
|
|
|
#include <vector>
|
2006-10-21 00:16:43 +00:00
|
|
|
|
|
|
|
namespace lyx {
|
|
|
|
|
2006-11-26 21:30:39 +00:00
|
|
|
namespace support { class FileName; }
|
|
|
|
|
2003-05-23 13:54:09 +00:00
|
|
|
class Buffer;
|
|
|
|
|
2003-02-28 09:49:49 +00:00
|
|
|
class Format {
|
|
|
|
public:
|
2006-10-03 08:34:59 +00:00
|
|
|
/// Flags for some format properties
|
|
|
|
enum Flags {
|
|
|
|
none = 0,
|
|
|
|
/// Set if this format is a document format (as opposed to
|
|
|
|
/// e.g. image formats).
|
|
|
|
/// Some formats are both (e.g. pdf), they have this flag set.
|
|
|
|
document = 1,
|
|
|
|
/// Set if this format can contain vector graphics.
|
2011-02-13 09:34:10 +00:00
|
|
|
vector = 2,
|
|
|
|
/// This format should appear in the File > Export menu
|
2011-09-19 00:12:09 +00:00
|
|
|
export_menu = 4,
|
|
|
|
/// This may be a compressed file but doesn't need decompression
|
|
|
|
zipped_native = 8
|
2006-10-03 08:34:59 +00:00
|
|
|
};
|
2003-02-28 09:49:49 +00:00
|
|
|
///
|
2003-10-06 15:43:21 +00:00
|
|
|
Format(std::string const & n, std::string const & e, std::string const & p,
|
2006-05-20 12:03:40 +00:00
|
|
|
std::string const & s, std::string const & v, std::string const & ed,
|
2012-02-21 20:29:44 +00:00
|
|
|
std::string const & m, int);
|
2003-02-28 09:49:49 +00:00
|
|
|
///
|
|
|
|
bool dummy() const;
|
2011-09-13 20:42:23 +00:00
|
|
|
/// Is \p ext a valid filename extension for this format?
|
|
|
|
bool hasExtension(std::string const & ext) const;
|
2006-05-20 12:03:40 +00:00
|
|
|
/// Tell whether this format is a child format.
|
|
|
|
/// Child formats inherit settings like the viewer from their parent.
|
2003-02-28 09:49:49 +00:00
|
|
|
bool isChildFormat() const;
|
2006-05-20 12:03:40 +00:00
|
|
|
/// Name fo the parent format
|
2003-10-06 15:43:21 +00:00
|
|
|
std::string const parentFormat() const;
|
2003-02-28 09:49:49 +00:00
|
|
|
///
|
2007-09-15 17:09:57 +00:00
|
|
|
std::string const & name() const { return name_; }
|
2003-02-28 09:49:49 +00:00
|
|
|
///
|
2007-09-15 17:09:57 +00:00
|
|
|
void setName(std::string const & v) { name_ = v; }
|
2003-02-28 09:49:49 +00:00
|
|
|
///
|
2011-09-13 20:42:23 +00:00
|
|
|
std::string const & extension() const
|
|
|
|
{
|
|
|
|
return extension_list_.empty() ? empty_string() : extension_list_[0];
|
|
|
|
}
|
2003-02-28 09:49:49 +00:00
|
|
|
///
|
2011-09-20 17:25:07 +00:00
|
|
|
std::string const extensions() const;
|
2011-09-13 20:42:23 +00:00
|
|
|
///
|
|
|
|
void setExtensions(std::string const & v);
|
2003-02-28 09:49:49 +00:00
|
|
|
///
|
2007-09-15 17:09:57 +00:00
|
|
|
std::string const & prettyname() const { return prettyname_; }
|
2003-02-28 09:49:49 +00:00
|
|
|
///
|
2007-09-15 17:09:57 +00:00
|
|
|
void setPrettyname(std::string const & v) { prettyname_ = v; }
|
2004-04-13 10:36:09 +00:00
|
|
|
///
|
2007-09-15 17:09:57 +00:00
|
|
|
std::string const & shortcut() const { return shortcut_; }
|
2006-05-17 22:13:33 +00:00
|
|
|
///
|
2007-09-15 17:09:57 +00:00
|
|
|
void setShortcut(std::string const & v) { shortcut_ = v; }
|
2006-05-20 12:03:40 +00:00
|
|
|
///
|
2007-09-15 17:09:57 +00:00
|
|
|
std::string const & viewer() const { return viewer_; }
|
2006-10-03 08:34:59 +00:00
|
|
|
///
|
2007-09-15 17:09:57 +00:00
|
|
|
void setViewer(std::string const & v) { viewer_ = v; }
|
|
|
|
///
|
|
|
|
std::string const & editor() const { return editor_; }
|
|
|
|
///
|
|
|
|
void setEditor(std::string const & v) { editor_ = v; }
|
|
|
|
///
|
2012-02-21 20:29:44 +00:00
|
|
|
std::string const & mime() const { return mime_; }
|
|
|
|
///
|
|
|
|
void setMime(std::string const & m) { mime_ = m; }
|
|
|
|
///
|
2007-09-15 17:09:57 +00:00
|
|
|
bool documentFormat() const { return flags_ & document; }
|
|
|
|
///
|
|
|
|
bool vectorFormat() const { return flags_ & vector; }
|
|
|
|
///
|
|
|
|
void setFlags(int v) { flags_ = v; }
|
2011-02-13 09:34:10 +00:00
|
|
|
///
|
|
|
|
bool inExportMenu() const { return flags_ & export_menu; }
|
2011-09-19 00:12:09 +00:00
|
|
|
///
|
|
|
|
bool zippedNative() const { return flags_ & zipped_native; }
|
2003-02-28 09:49:49 +00:00
|
|
|
private:
|
2006-05-20 12:03:40 +00:00
|
|
|
/// Internal name. Needs to be unique.
|
2003-10-06 15:43:21 +00:00
|
|
|
std::string name_;
|
2011-09-13 20:42:23 +00:00
|
|
|
/// Filename extensions, the first one being the default
|
2011-09-20 17:25:07 +00:00
|
|
|
std::vector<std::string> extension_list_;
|
2006-05-20 12:03:40 +00:00
|
|
|
/// Name presented to the user. Needs to be unique.
|
2003-10-06 15:43:21 +00:00
|
|
|
std::string prettyname_;
|
2006-05-20 12:03:40 +00:00
|
|
|
/// Keyboard shortcut for the View and Export menu.
|
2003-10-06 15:43:21 +00:00
|
|
|
std::string shortcut_;
|
2006-05-20 12:03:40 +00:00
|
|
|
/*!
|
|
|
|
* Viewer for this format. Needs to be in the PATH or an absolute
|
|
|
|
* filename.
|
|
|
|
* This format cannot be viewed if \c viewer_ is empty.
|
|
|
|
* If it is \c auto the default viewer of the OS for this format is
|
|
|
|
* used.
|
|
|
|
*/
|
2003-10-06 15:43:21 +00:00
|
|
|
std::string viewer_;
|
2006-05-20 12:03:40 +00:00
|
|
|
/// Editor for this format. \sa viewer_.
|
2004-04-13 10:36:09 +00:00
|
|
|
std::string editor_;
|
2012-02-21 20:29:44 +00:00
|
|
|
/*!
|
|
|
|
* Full MIME type, e.g. "text/x-tex".
|
|
|
|
* Only types listed by the shared MIME database of freedesktop.org
|
|
|
|
* should be added.
|
|
|
|
* This field may be empty, but it must be unique across all formats
|
|
|
|
* if it is set.
|
|
|
|
*/
|
|
|
|
std::string mime_;
|
2006-10-03 08:34:59 +00:00
|
|
|
///
|
|
|
|
int flags_;
|
2003-02-28 09:49:49 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
bool operator<(Format const & a, Format const & b);
|
|
|
|
|
2006-10-03 08:34:59 +00:00
|
|
|
|
2003-02-28 09:49:49 +00:00
|
|
|
///
|
|
|
|
class Formats {
|
|
|
|
public:
|
|
|
|
///
|
|
|
|
typedef std::vector<Format> FormatList;
|
|
|
|
///
|
|
|
|
typedef FormatList::const_iterator const_iterator;
|
|
|
|
///
|
2007-09-15 17:09:57 +00:00
|
|
|
Format const & get(FormatList::size_type i) const { return formatlist[i]; }
|
|
|
|
///
|
|
|
|
Format & get(FormatList::size_type i) { return formatlist[i]; }
|
2004-10-29 15:47:55 +00:00
|
|
|
/// \returns format named \p name if it exists, otherwise 0
|
2003-10-06 15:43:21 +00:00
|
|
|
Format const * getFormat(std::string const & name) const;
|
2004-11-09 19:08:34 +00:00
|
|
|
/*!
|
|
|
|
* Get the format of \p filename from file contents or, if this
|
|
|
|
* fails, from file extension.
|
|
|
|
* \returns file format if it could be found, otherwise an empty
|
|
|
|
* string.
|
|
|
|
*/
|
2006-11-26 21:30:39 +00:00
|
|
|
std::string getFormatFromFile(support::FileName const & filename) const;
|
2011-09-19 00:12:09 +00:00
|
|
|
/// Finds a format from a file extension. Returns string() if not found.
|
|
|
|
std::string getFormatFromExtension(std::string const & ext) const;
|
2011-10-07 08:21:31 +00:00
|
|
|
/// Finds a format by pretty name. Returns string() if not found.
|
|
|
|
std::string getFormatFromPrettyName(std::string const & prettyname) const;
|
2011-09-19 00:12:09 +00:00
|
|
|
/** Returns true if the file referenced by \p filename is zipped and
|
|
|
|
** needs to be unzipped for being handled
|
|
|
|
** @note For natively zipped formats, such as dia/odg, this returns false.
|
|
|
|
**/
|
|
|
|
bool isZippedFile(support::FileName const & filename) const;
|
2012-02-21 20:29:44 +00:00
|
|
|
/// check for zipped file format
|
|
|
|
static bool isZippedFileFormat(std::string const & format);
|
|
|
|
/// check for PostScript file format
|
|
|
|
static bool isPostScriptFileFormat(std::string const & format);
|
2006-05-17 22:13:33 +00:00
|
|
|
/// Set editor and/or viewer to "auto" for formats that can be
|
|
|
|
/// opened by the OS.
|
|
|
|
void setAutoOpen();
|
2003-02-28 09:49:49 +00:00
|
|
|
///
|
2003-10-06 15:43:21 +00:00
|
|
|
int getNumber(std::string const & name) const;
|
2003-02-28 09:49:49 +00:00
|
|
|
///
|
2003-10-06 15:43:21 +00:00
|
|
|
void add(std::string const & name);
|
2003-02-28 09:49:49 +00:00
|
|
|
///
|
2011-09-13 20:42:23 +00:00
|
|
|
void add(std::string const & name, std::string const & extensions,
|
2007-05-28 22:27:45 +00:00
|
|
|
std::string const & prettyname, std::string const & shortcut,
|
|
|
|
std::string const & viewer, std::string const & editor,
|
2012-02-21 20:29:44 +00:00
|
|
|
std::string const & mime, int flags);
|
2003-02-28 09:49:49 +00:00
|
|
|
///
|
2003-10-06 15:43:21 +00:00
|
|
|
void erase(std::string const & name);
|
2003-02-28 09:49:49 +00:00
|
|
|
///
|
|
|
|
void sort();
|
|
|
|
///
|
2003-10-06 15:43:21 +00:00
|
|
|
void setViewer(std::string const & name, std::string const & command);
|
2003-02-28 09:49:49 +00:00
|
|
|
///
|
2009-11-19 23:37:16 +00:00
|
|
|
void setEditor(std::string const & name, std::string const & command);
|
2010-08-30 12:08:10 +00:00
|
|
|
/// View the given file. Buffer used for DVI's paper orientation.
|
2006-11-26 21:30:39 +00:00
|
|
|
bool view(Buffer const & buffer, support::FileName const & filename,
|
2003-10-06 15:43:21 +00:00
|
|
|
std::string const & format_name) const;
|
2003-02-28 09:49:49 +00:00
|
|
|
///
|
2006-11-26 21:30:39 +00:00
|
|
|
bool edit(Buffer const & buffer, support::FileName const & filename,
|
2004-04-13 10:36:09 +00:00
|
|
|
std::string const & format_name) const;
|
|
|
|
///
|
2006-10-21 00:16:43 +00:00
|
|
|
docstring const prettyName(std::string const & name) const;
|
2003-02-28 09:49:49 +00:00
|
|
|
///
|
2003-10-06 15:43:21 +00:00
|
|
|
std::string const extension(std::string const & name) const;
|
2003-02-28 09:49:49 +00:00
|
|
|
///
|
2011-09-13 20:42:23 +00:00
|
|
|
std::string const extensions(std::string const & name) const;
|
|
|
|
///
|
2006-10-21 00:16:43 +00:00
|
|
|
const_iterator begin() const { return formatlist.begin(); }
|
2003-02-28 09:49:49 +00:00
|
|
|
///
|
2006-10-21 00:16:43 +00:00
|
|
|
const_iterator end() const { return formatlist.end(); }
|
2003-02-28 09:49:49 +00:00
|
|
|
///
|
2006-10-21 00:16:43 +00:00
|
|
|
FormatList::size_type size() const { return formatlist.size(); }
|
2003-02-28 09:49:49 +00:00
|
|
|
private:
|
|
|
|
///
|
|
|
|
FormatList formatlist;
|
|
|
|
};
|
|
|
|
|
2011-04-14 18:32:42 +00:00
|
|
|
///
|
|
|
|
std::string flavor2format(OutputParams::FLAVOR flavor);
|
|
|
|
// Not currently used.
|
|
|
|
// OutputParams::FLAVOR format2flavor(std::string fmt);
|
|
|
|
|
2003-02-28 09:49:49 +00:00
|
|
|
extern Formats formats;
|
|
|
|
|
|
|
|
extern Formats system_formats;
|
|
|
|
|
2006-10-21 00:16:43 +00:00
|
|
|
|
|
|
|
} // namespace lyx
|
|
|
|
|
2003-02-28 09:49:49 +00:00
|
|
|
#endif //FORMAT_H
|