]> git.lyx.org Git - lyx.git/blob - src/LyX.h
* pl.po remerge by autotools
[lyx.git] / src / LyX.h
1 // -*- C++ -*-
2 /**
3  * \file LyX.h
4  * This file is part of LyX, the document processor.
5  * Licence details can be found in the file COPYING.
6  *
7  * \author Lars Gullik Bjønnes
8  * \author Jean-Marc Lasgouttes
9  * \author John Levon
10  *
11  * Full author contact details are available in file CREDITS.
12  */
13
14 #ifndef LYX_H
15 #define LYX_H
16
17 #include "support/strfwd.h"
18
19 #include <vector>
20
21 namespace lyx {
22
23 class BufferList;
24 class CmdDef;
25 class Converters;
26 class DispatchResult;
27 class ErrorItem;
28 class FuncRequest;
29 class FuncStatus;
30 class KeyMap;
31 class Messages;
32 class Mover;
33 class Movers;
34 class Server;
35 class ServerSocket;
36 class Session;
37 class SpellChecker;
38
39 enum RunMode {
40         NEW_INSTANCE,
41         USE_REMOTE,
42         PREFERRED
43 };
44
45 enum OverwriteFiles {
46         NO_FILES,
47         MAIN_FILE,
48         ALL_FILES,
49         UNSPECIFIED
50 };
51
52 extern bool use_gui;
53 extern RunMode run_mode;
54 extern OverwriteFiles force_overwrite;
55
56 namespace frontend {
57 class Application;
58 }
59
60 namespace graphics {
61 class Previews;
62 }
63
64 /// initial startup
65 class LyX {
66 public:
67
68         LyX();
69         ~LyX();
70
71         /// Execute LyX.
72         int exec(int & argc, char * argv[]);
73
74 private:
75         /// noncopyable
76         LyX(LyX const &);
77         void operator=(LyX const &);
78
79         /// Do some cleanup in preparation of an exit.
80         void prepareExit();
81
82         /// Early exit during the initialisation process.
83         void earlyExit(int status);
84
85         /// Initialise LyX and fills-in the vector of files to be loaded.
86         /**
87         \return exit code failure if any.
88         */
89         int init(int & argc, char * argv[]);
90
91         /// Execute batch commands if available.
92         void execCommands();
93
94         /// Load files passed at command-line.
95         /// return true on success false if we encounter an error
96         /**
97         This method is used only in non-GUI mode.
98         */
99         bool loadFiles();
100
101         /// initial LyX set up
102         bool init();
103         /** Check for the existence of the user's support directory and,
104          *  if not present, create it. Exits the program if the directory
105          *  cannot be created.
106          *  \returns true if the user-side configuration script
107          *  (lib/configure) should be re-run in this directory.
108          */
109         bool queryUserLyXDir(bool explicit_userdir);
110         /// read lyxrc/preferences
111         /// \param check_format: whether to try to convert the format of
112         /// the file, if there is a mismatch.
113         bool readRcFile(std::string const & name, bool check_format = false);
114         /// read the given languages file
115         bool readLanguagesFile(std::string const & name);
116         /// read the encodings.
117         /// \param enc_name encodings definition file
118         /// \param symbols_name unicode->LaTeX mapping file
119         bool readEncodingsFile(std::string const & enc_name,
120                                std::string const & symbols_name);
121         /// parsing of non-gui LyX options.
122         void easyParse(int & argc, char * argv[]);
123         /// shows up a parsing error on screen
124         void printError(ErrorItem const &);
125
126         ///
127         Messages & messages(std::string const & language);
128
129         /// Use the Pimpl idiom to hide the internals.
130         // Mostly used for singletons.
131         struct Impl;
132         Impl * pimpl_;
133
134         /// has this user started lyx for the first time?
135         bool first_start;
136
137         friend FuncStatus getStatus(FuncRequest const & action);
138         friend void dispatch(FuncRequest const & action);
139         friend void dispatch(FuncRequest const & action, DispatchResult & dr);
140         friend std::vector<std::string> & theFilesToLoad();
141         friend BufferList & theBufferList();
142         friend Server & theServer();
143         friend ServerSocket & theServerSocket();
144         friend Converters & theConverters();
145         friend Converters & theSystemConverters();
146         friend Messages const & getMessages(std::string const & language);
147         friend Messages const & getGuiMessages();
148         friend KeyMap & theTopLevelKeymap();
149         friend Movers & theMovers();
150         friend Mover const & getMover(std::string  const & fmt);
151         friend void setMover(std::string const & fmt, std::string const & command);
152         friend Movers & theSystemMovers();
153         friend frontend::Application * theApp();
154         friend graphics::Previews & thePreviews();
155         friend Session & theSession();
156         friend CmdDef & theTopLevelCmdDef();
157         friend SpellChecker * theSpellChecker();
158         friend void setSpellChecker();
159         friend void setRcGuiLanguage();
160         friend void emergencyCleanup();
161         friend void execBatchCommands();
162         friend void lyx_exit(int exit_code);
163 };
164
165
166 /// in the case of failure
167 void emergencyCleanup();
168 /// Try to exit LyX properly.
169 /// \p exit_code is 0 by default, if a non zero value is passed,
170 /// emergencyCleanup() will be called before exiting.
171 void lyx_exit(int exit_code);
172 /// Set the language defined by the user.
173 void setRcGuiLanguage();
174 /// Execute batch commands if available.
175 void execBatchCommands();
176
177 ///
178 FuncStatus getStatus(FuncRequest const & action);
179
180 ///
181 void dispatch(FuncRequest const & action);
182
183 ///
184 void dispatch(FuncRequest const & action, DispatchResult & dr);
185
186 } // namespace lyx
187
188 #endif // LYX_H
189