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