]> git.lyx.org Git - lyx.git/blob - src/support/package.h
Fix bug 2285 (tex2lyx is not found by lib/configure when compiling with
[lyx.git] / src / support / package.h
1 // -*- C++ -*-
2 /**
3  * \file package.h
4  * This file is part of LyX, the document processor.
5  * Licence details can be found in the file COPYING.
6  *
7  * \author Angus Leeming
8  *
9  * Full author contact details are available in file CREDITS.
10  *
11  * A store of the paths to the various different directoies used
12  * by LyX. These paths differ markedly from one OS to another,
13  * following the local Windows, MacOS X or Posix conventions.
14  */
15 #ifndef LYX_PACHAGE_H
16 #define LYX_PACHAGE_H
17
18 #include <string>
19
20 namespace lyx {
21 namespace support {
22
23 class Package;
24
25 /** When run in-place <build-dir>/src/lyx is one level up from
26  *  the <build-dir> whilst <build-dir>/src/tex2lyx/tex2lyx is
27  *  two levels up.
28  */
29 enum exe_build_dir_to_top_build_dir {
30         top_build_dir_is_one_level_up,
31         top_build_dir_is_two_levels_up
32 };
33
34
35 /** Initialise package() with the command line data.
36  *  This data is exactly as it was passed in the argv[] array.
37  *
38  *  @param command_line_arg0 argv[0], the name of the LyX executable
39  *  as passed on the command line.
40  *
41  *  @param command_line_system_support_dir, the LyX system dir,
42  *  as specified on the command line with "-sysdir <path to dir>".
43  *
44  *  @param command_line_user_support_dir, the LyX user dir,
45  *  as specified on the command line with "-userdir <path to dir>".
46  */
47 void init_package(std::string const & command_line_arg0,
48                   std::string const & command_line_system_support_dir,
49                   std::string const & command_line_user_support_dir,
50                   exe_build_dir_to_top_build_dir);
51
52 /** Accessor to the global data.
53  *  Asserts that init_package() has been called first.
54  */
55 Package const & package();
56
57 class Package {
58 public:
59         /// Default constructor does not lead to the paths being set.
60         Package();
61
62         /** Called by init_package, above.
63          *  All paths will be initialized.
64          */
65         Package(std::string const & command_line_arg0,
66                 std::string const & command_line_system_support_dir,
67                 std::string const & command_line_user_support_dir,
68                 exe_build_dir_to_top_build_dir);
69
70         /** The directory containing the LyX executable.
71          */
72         std::string const & binary_dir() const;
73
74         /** The top of the LyX source code tree.
75          *  Used by the GTK frontend when searching for .glade files.
76          */
77         std::string const & top_srcdir() const;
78
79         /** The path to the system-level support files
80          *  we're actually going to use.
81          */
82         std::string const & system_support() const;
83
84         /** The path to the autogenerated support files
85          *  when running in-place.
86          */
87         std::string const & build_support() const;
88
89         /** The path to the user-level support files.
90          */
91         std::string const & user_support() const;
92
93         /** The user_support directory was set explicitly using either
94          *  the -userdir command line switch or
95          *  the LYX_USERDIR_14x environment variable.
96          */
97         bool explicit_user_support() const;
98
99         /** The path to the locale directory.
100          */
101         std::string const & locale_dir() const;
102
103         /** The default document directory.
104          *  Can be reset by LyXRC.
105          */
106         std::string & document_dir() const;
107
108         /** The path to the temporary directory.
109          *  (Eg /tmp on *nix.)
110          *  Can be reset by LyXRC.
111          */
112         std::string & temp_dir() const;
113
114         /** Used when setting the user_support directory.
115          *  Used also when expanding "~/" or contracting to "~/". (filetools.C)
116          *  Used by the XForms file dialog.
117          *  Used in emergencyWrite (bufferlist.C) as one possible location
118          *  for the dump.
119          *  This may be empty (e. g. when run under a CGI environment)
120          */
121         std::string const & home_dir() const;
122
123         /// Command to run the configure script
124         std::string const & configure_command() const;
125
126 private:
127         std::string binary_dir_;
128         std::string system_support_dir_;
129         std::string build_support_dir_;
130         std::string user_support_dir_;
131         std::string locale_dir_;
132         mutable std::string document_dir_;
133         mutable std::string temp_dir_;
134         std::string home_dir_;
135         std::string configure_command_;
136         bool explicit_user_support_dir_;
137 };
138
139
140 inline
141 Package::Package() {}
142
143 inline
144 std::string const & Package::binary_dir() const
145 {
146         return binary_dir_;
147 }
148
149 inline
150 std::string const & Package::system_support() const
151 {
152         return system_support_dir_;
153 }
154
155 inline
156 std::string const & Package::build_support() const
157 {
158         return build_support_dir_;
159 }
160
161 inline
162 std::string const & Package::user_support() const
163 {
164         return user_support_dir_;
165 }
166
167 inline
168 bool Package::explicit_user_support() const
169 {
170         return explicit_user_support_dir_;
171 }
172
173 inline
174 std::string const & Package::locale_dir() const
175 {
176         return locale_dir_;
177 }
178
179 inline
180 std::string & Package::document_dir() const
181 {
182         return document_dir_;
183 }
184
185 inline
186 std::string & Package::temp_dir() const
187 {
188         return temp_dir_;
189 }
190
191 inline
192 std::string const & Package::home_dir() const
193 {
194         return home_dir_;
195 }
196
197 inline
198 std::string const & Package::configure_command() const
199 {
200         return configure_command_;
201 }
202
203 } // namespace support
204 } // namespace lyx
205
206 #endif // LYX_PACHAGE_H