]> git.lyx.org Git - lyx.git/blob - src/support/Package.h
#7407, home_dir could be a static function and also be called by the
[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
16 #ifndef PACKAGE_H
17 #define PACKAGE_H
18
19 #include "support/FileName.h"
20
21 #include <string>
22
23 namespace lyx {
24 namespace support {
25
26 class Package;
27
28 /** When run in-place <build-dir>/src/lyx is one level up from
29  *  the <build-dir> whilst <build-dir>/src/tex2lyx/tex2lyx is
30  *  two levels up.
31  */
32 enum exe_build_dir_to_top_build_dir {
33         top_build_dir_is_one_level_up,
34         top_build_dir_is_two_levels_up
35 };
36
37
38 /** Initialise package() with the command line data.
39  *  This data is exactly as it was passed in the argv[] array.
40  *
41  *  @param command_line_arg0 argv[0], the name of the LyX executable
42  *  as passed on the command line.
43  *
44  *  @param command_line_system_support_dir, the LyX system dir,
45  *  as specified on the command line with "-sysdir <path to dir>".
46  *
47  *  @param command_line_user_support_dir, the LyX user dir,
48  *  as specified on the command line with "-userdir <path to dir>".
49  */
50 void init_package(std::string const & command_line_arg0,
51                   std::string const & command_line_system_support_dir,
52                   std::string const & command_line_user_support_dir,
53                   exe_build_dir_to_top_build_dir);
54
55 bool packageInitialized();
56
57 /** Accessor to the global data.
58  *  Asserts that init_package() has been called first.
59  */
60 Package const & package();
61
62 class Package {
63 public:
64         /// Default constructor does not lead to the paths being set.
65         Package() {}
66
67         /** Called by init_package, above.
68          *  All paths will be initialized.
69          */
70         Package(std::string const & command_line_arg0,
71                 std::string const & command_line_system_support_dir,
72                 std::string const & command_line_user_support_dir,
73                 exe_build_dir_to_top_build_dir);
74
75         /** The directory containing the main executable (LyX or tex2lyx).
76          */
77         FileName const & binary_dir() const { return binary_dir_; }
78
79         /** The absolute path to the LyX executable.
80          */
81         FileName const & lyx_binary() const { return lyx_binary_; }
82
83         /** The absolute path to the LyX package directory.
84          *  This is one level up from the binary dir.
85          */
86         FileName const & lyx_dir() const { return lyx_dir_; }
87
88         /** The top of the LyX source code tree.
89          */
90         static FileName const & top_srcdir();
91
92         /** The path to the system-level support files
93          *  we're actually going to use.
94          */
95         FileName const & system_support() const { return system_support_dir_; }
96
97         /** The path to the autogenerated support files
98          *  when running in-place.
99          */
100         FileName const & build_support() const { return build_support_dir_; }
101
102         /** The path to the user-level support files.
103          */
104         FileName const & user_support() const { return user_support_dir_; }
105
106         /** The user_support directory was set explicitly using either
107          *  the -userdir command line switch or
108          *  the LYX_USERDIR_${major}${minor}x environment variable.
109          */
110         bool explicit_user_support() const { return explicit_user_support_dir_; }
111
112         /** The path to the locale directory.
113          */
114         FileName const & locale_dir() const { return locale_dir_; }
115
116         /** The default document directory.
117          *  Can be reset by LyXRC.
118          */
119         FileName & document_dir() const { return document_dir_; }
120
121         /** The path to the system temporary directory.
122          *  (Eg /tmp on *nix.)
123          */
124         FileName const & system_temp_dir() const { return system_temp_dir_; }
125
126         //@{
127         /** The path to the temporary directory used by %LyX.
128          *  (Eg /tmp/lyx_tmpdir800nBI1z9 on *nix.)
129          *  Can be reset by LyXRC.
130          */
131         FileName const & temp_dir() const { return temp_dir_; }
132         void set_temp_dir(FileName const & temp_dir) const;
133         //@}
134
135         /** Used when setting the user_support directory.
136          *  Used also when expanding "~/" or contracting to "~/". (filetools.cpp)
137          *  Used in emergencyWrite (BufferList.cpp) as one possible location
138          *  for the dump.
139          *  This may be empty (e. g. when run under a CGI environment)
140          */
141         static FileName const & get_home_dir();
142
143         /** Command to run the configure script.
144          *  Caution: This is "ready-to-run", i.e. in the locale encoding, not
145          *  utf8.
146          */
147         std::string const & configure_command() const { return configure_command_; }
148
149 private:
150         FileName binary_dir_;
151         FileName lyx_binary_;
152         FileName lyx_dir_;
153         FileName system_support_dir_;
154         FileName build_support_dir_;
155         FileName user_support_dir_;
156         FileName locale_dir_;
157         mutable FileName document_dir_;
158         mutable FileName temp_dir_;
159         FileName system_temp_dir_;
160         std::string configure_command_;
161         bool explicit_user_support_dir_;
162 };
163
164 } // namespace support
165 } // namespace lyx
166
167 #endif // PACKAGE_H