]> git.lyx.org Git - lyx.git/blob - src/support/os.h
add generic helper class for calling functions in gui thread
[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/strfwd.h"
18 #include <cstddef>
19
20
21 namespace lyx {
22 namespace support {
23 namespace os {
24
25 enum shell_type {
26         UNIX,   // Do we have to distinguish sh and csh?
27         CMD_EXE
28 };
29
30 enum path_case {
31         CASE_UNCHANGED,
32         CASE_ADJUSTED
33 };
34
35 enum file_access {
36         EXISTING,
37         CREATE
38 };
39
40 /// Do some work just once.
41 void init(int argc, char * argv[]);
42
43 /// Returns the i-th program argument in utf8 encoding.
44 std::string utf8_argv(int i);
45
46 /// Removes from the internal copy \p num program arguments starting from \p i.
47 void remove_internal_args(int i, int num);
48
49 /// Returns the name of the NULL device (/dev/null, null).
50 std::string const & nulldev();
51
52 /// Returns "/" on *nix, "C:/", etc on Windows.
53 std::string current_root();
54
55 ///
56 shell_type shell();
57
58 /// Name of the python interpreter
59 std::string const python();
60
61 ///
62 bool isFilesystemCaseSensitive();
63
64 /// Extract the path common to both @c p1 and @c p2. DBCS aware!
65 /// \p p1 and \p p2 are encoded in ucs4, \returns the index to the end of
66 /// the last matching path component (the index may be pointing after the
67 /// end of @c p1 or @c p2 if their last char is not the path separator).
68 std::size_t common_path(docstring const & p1, docstring const & p2);
69
70 /// Converts a unix style path to host OS style.
71 /// \p p and the return value are encoded in utf8.
72 std::string external_path(std::string const & p);
73
74 /// Converts a host OS style path to unix style.
75 /// \p p and the return value are encoded in utf8.
76 std::string internal_path(std::string const & p);
77
78 /// Converts a host OS style path to a unicode safe unix style.
79 /// On Windows, this is achieved by using the short form of the path,
80 /// which can be safely passed to standard I/O functions expecting narrow
81 /// char paths even when the path contains non-ascii chars.
82 /// As the short form is only available for existing files, if the file is
83 /// to be accessed for writing, \param how should be set to CREATE.
84 /// \p p and the return value are encoded in utf8.
85 std::string safe_internal_path(std::string const & p, file_access how = EXISTING);
86
87 /// Converts a unix style path list to host OS style.
88 /// \p p and the return value are encoded in utf8.
89 std::string external_path_list(std::string const & p);
90
91 /// Converts a host OS style path list to unix style.
92 /// \p p and the return value are encoded in utf8.
93 std::string internal_path_list(std::string const & p);
94
95 /**
96  * Converts a unix style path into a form suitable for inclusion in a LaTeX
97  * document.
98  * \p p is encoded in utf8.
99  * Caution: This function handles only the OS specific part of that task.
100  * Never use it directly, use lyx::support::latex_path instead.
101  */
102 std::string latex_path(std::string const & p);
103
104 /// Checks if the format string is suitable on the OS
105 bool is_valid_strftime(std::string const & p);
106
107 /** Returns a string suitable to be passed to popen when
108  *  reading a file.
109  */
110 char const * popen_read_mode();
111
112 /** The character used to separate paths returned by the
113  *  PATH environment variable.
114  */
115 char path_separator();
116
117 /** If @c use_windows_paths is true, LyX will output Windows-style paths to
118  *  latex files rather than posix ones. Obviously, this option is used only
119  *  under Windows.
120  */
121 void windows_style_tex_paths(bool use_windows_paths);
122
123 enum auto_open_mode {
124         VIEW,
125         EDIT
126 };
127
128 /** Check whether or not a file can be opened by a default viewer or editor.
129  *  \param extension (without leading .)
130  *  \param mode can be opened in VIEW or EDIT mode
131  *  \returns whether or not the format can be opened according to \p mode
132  */
133 bool canAutoOpenFile(std::string const & ext, auto_open_mode const mode = VIEW);
134
135 /** View or edit a file with the default viewer or editor.
136  *  \param filename file to open (encoded in utf8)
137  *  \param mode open in VIEW or EDIT mode
138  *  \returns whether or not the file is viewed (or edited) successfully.
139  */
140 bool autoOpenFile(std::string const & filename, auto_open_mode const mode = VIEW);
141
142 /** Resolves a path such that it does not contain '.', '..', or symbolic links.
143   * \p path and the return value are encoded in utf8.
144   */
145 std::string real_path(std::string const & path);
146
147 /** Checks whether \param path starts with \param pre, accounting for case
148   * insensitive file systems.
149   */
150 bool path_prefix_is(std::string const & path, std::string const & pre);
151
152 /** Checks whether \param path starts with \param pre, accounting for case
153   * insensitive file systems. If true, the file system is case insensitive,
154   * and \param how == CASE_ADJUSTED, the case of the matching prefix in
155   * @c path is made equal to that of @c pre.
156   */
157 bool path_prefix_is(std::string & path, std::string const & pre, path_case how = CASE_UNCHANGED);
158
159 } // namespace os
160 } // namespace support
161 } // namespace lyx
162
163 #endif