]> git.lyx.org Git - lyx.git/blob - src/support/os.h
Display error/warning dialogs if possible.
[lyx.git] / src / support / os.h
1 // -*- C++ -*-
2 /**
3  * \file os.h
4  * This file is part of LyX, the document processor.
5  * Licence details can be found in the file COPYING.
6  *
7  * \author Ruurd A. Reitsma
8  *
9  * Full author contact details are available in file CREDITS.
10  *
11  * wrap OS-specific stuff
12  */
13
14 #ifndef OS_H
15 #define OS_H
16
17 #include "support/docstring.h"
18
19 #include <string>
20
21
22 namespace lyx {
23 namespace support {
24 namespace os {
25
26 enum shell_type {
27         UNIX,   // Do we have to distinguish sh and csh?
28         CMD_EXE
29 };
30
31 /// Do some work just once.
32 void init(int argc, char * argv[]);
33
34 /// Returns the name of the NULL device (/dev/null, null).
35 std::string const & nulldev();
36
37 /// Returns "/" on *nix, "C:/", etc on Windows.
38 std::string current_root();
39
40 ///
41 shell_type shell();
42
43 /// Name of the python interpreter
44 std::string const python();
45
46 /// Extract the path common to both @c p1 and @c p2. DBCS aware!
47 /// \p p1, \p p2 and the return value are encoded in utf8.
48 std::string::size_type common_path(std::string const & p1, std::string const & p2);
49
50 /// Converts a unix style path to host OS style.
51 /// \p p and the return value are encoded in utf8.
52 std::string external_path(std::string const & p);
53
54 /// Converts a host OS style path to unix style.
55 /// \p p and the return value are encoded in utf8.
56 std::string internal_path(std::string const & p);
57
58 /// Converts a unix style path list to host OS style.
59 /// \p p and the return value are encoded in utf8.
60 std::string external_path_list(std::string const & p);
61
62 /// Converts a host OS style path list to unix style.
63 /// \p p and the return value are encoded in utf8.
64 std::string internal_path_list(std::string const & p);
65
66 /**
67  * Converts a unix style path into a form suitable for inclusion in a LaTeX
68  * document.
69  * \p p is encoded in utf8.
70  * Caution: This function handles only the OS specific part of that task.
71  * Never use it directly, use lyx::support::latex_path instead.
72  */
73 std::string latex_path(std::string const & p);
74
75 /// Is the path absolute?
76 /// \p p is encoded in utf8.
77 bool is_absolute_path(std::string const & p);
78
79 /** Returns a string suitable to be passed to popen when
80  *  reading a file.
81  */
82 char const * popen_read_mode();
83
84 /** The character used to separate paths returned by the
85  *  PATH environment variable.
86  */
87 char path_separator();
88
89 /** If @c use_windows_paths is true, LyX will output Windows-style paths to
90  *  latex files rather than posix ones. Obviously, this option is used only
91  *  under Windows.
92  */
93 void windows_style_tex_paths(bool use_windows_paths);
94
95 enum auto_open_mode {
96         VIEW,
97         EDIT
98 };
99
100 /** Check whether or not a file can be opened by a default viewer or editor.
101  *  \param extension (without leading .)
102  *  \param mode can be opened in VIEW or EDIT mode
103  *  \returns whether or not the format can be opened according to \p mode
104  */
105 bool canAutoOpenFile(std::string const & ext, auto_open_mode const mode = VIEW);
106
107 /** View or edit a file with the default viewer or editor.
108  *  \param filename file to open (encoded in utf8)
109  *  \param mode open in VIEW or EDIT mode
110  *  \returns whether or not the file is viewed (or edited) successfully.
111  */
112 bool autoOpenFile(std::string const & filename, auto_open_mode const mode = VIEW);
113
114 /** General font utilities.
115  *  FIXME: only MAC and WIN32 for now but it would be nice to convince
116  *  fontconfig to do the same for linux.
117  */
118
119 /// Add fonts to the font subsystem, must be called before Application
120 /// is initialized.
121 void addFontResources();
122
123 /// Restore original font resources, must be called after Application
124 /// is destroyed.
125 void restoreFontResources();
126
127 } // namespace os
128 } // namespace support
129 } // namespace lyx
130
131 #endif