]> git.lyx.org Git - lyx.git/blob - src/LyX.h
start the timer in the correct thread
[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         bool readRcFile(std::string const & name);
112         /// read the given languages file
113         bool readLanguagesFile(std::string const & name);
114         /// read the encodings.
115         /// \param enc_name encodings definition file
116         /// \param symbols_name unicode->LaTeX mapping file
117         bool readEncodingsFile(std::string const & enc_name,
118                                std::string const & symbols_name);
119         /// parsing of non-gui LyX options.
120         void easyParse(int & argc, char * argv[]);
121         /// shows up a parsing error on screen
122         void printError(ErrorItem const &);
123
124         ///
125         Messages & messages(std::string const & language);
126
127         /// Use the Pimpl idiom to hide the internals.
128         // Mostly used for singletons.
129         struct Impl;
130         Impl * pimpl_;
131
132         /// has this user started lyx for the first time?
133         bool first_start;
134
135         friend FuncStatus getStatus(FuncRequest const & action);
136         friend void dispatch(FuncRequest const & action);
137         friend void dispatch(FuncRequest const & action, DispatchResult & dr);
138         friend std::vector<std::string> & theFilesToLoad();
139         friend BufferList & theBufferList();
140         friend Server & theServer();
141         friend ServerSocket & theServerSocket();
142         friend Converters & theConverters();
143         friend Converters & theSystemConverters();
144         friend Messages const & getMessages(std::string const & language);
145         friend Messages const & getGuiMessages();
146         friend KeyMap & theTopLevelKeymap();
147         friend Movers & theMovers();
148         friend Mover const & getMover(std::string  const & fmt);
149         friend void setMover(std::string const & fmt, std::string const & command);
150         friend Movers & theSystemMovers();
151         friend frontend::Application * theApp();
152         friend graphics::Previews & thePreviews();
153         friend Session & theSession();
154         friend CmdDef & theTopLevelCmdDef();
155         friend SpellChecker * theSpellChecker();
156         friend void setSpellChecker();
157         friend void setRcGuiLanguage();
158         friend void emergencyCleanup();
159         friend void execBatchCommands();
160         friend void lyx_exit(int exit_code);
161 };
162
163
164 /// in the case of failure
165 void emergencyCleanup();
166 /// Try to exit LyX properly.
167 /// \p exit_code is 0 by default, if a non zero value is passed,
168 /// emergencyCleanup() will be called before exiting.
169 void lyx_exit(int exit_code);
170 /// Set the language defined by the user.
171 void setRcGuiLanguage();
172 /// Execute batch commands if available.
173 void execBatchCommands();
174
175 ///
176 FuncStatus getStatus(FuncRequest const & action);
177
178 ///
179 void dispatch(FuncRequest const & action);
180
181 ///
182 void dispatch(FuncRequest const & action, DispatchResult & dr);
183
184 } // namespace lyx
185
186 #endif // LYX_H
187