]> git.lyx.org Git - lyx.git/blob - src/LyX.h
safeguards:
[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 namespace lyx {
20
21 class BufferList;
22 class CmdDef;
23 class Converters;
24 class ErrorItem;
25 class KeyMap;
26 class LyXFunc;
27 class Messages;
28 class Mover;
29 class Movers;
30 class Server;
31 class ServerSocket;
32 class Session;
33
34 extern bool use_gui;
35
36 namespace frontend {
37 class Application;
38 class LyXView;
39 }
40
41 namespace graphics {
42 class Previews;
43 }
44
45 /// initial startup
46 class LyX {
47 public:
48
49         LyX();
50         ~LyX();
51
52         /// Execute LyX.
53         int exec(int & argc, char * argv[]);
54
55         /// Try to exit LyX properly.
56         /// \p exit_code is 0 by default, if a non zero value is passed,
57         /// emergencyCleanup() will be called before exiting.
58         void exit(int exit_code = 0) const;
59
60         static LyX & ref();
61         static LyX const & cref();
62
63         /// in the case of failure
64         void emergencyCleanup() const;
65
66         ///
67         BufferList & bufferList();
68         BufferList const & bufferList() const;
69         ///
70         Session & session();
71         Session const & session() const;
72         ///
73         LyXFunc & lyxFunc();
74         LyXFunc const & lyxFunc() const;
75         ///
76         Server & server();
77         Server const & server() const;
78         ///
79         ServerSocket & socket();
80         ServerSocket const & socket() const;
81
82         ///
83         frontend::Application & application();
84         frontend::Application const & application() const;
85
86         ///
87         CmdDef & topLevelCmdDef();
88
89         ///
90         Converters & converters();
91         Converters & systemConverters();
92
93         ///
94         Messages & getMessages(std::string const & language);
95         ///
96         Messages & getGuiMessages();
97         ///
98         void setRcGuiLanguage();
99
100         ///
101         frontend::LyXView * newLyXView();
102
103         /// Execute batch commands if available.
104         void execBatchCommands();
105
106 private:
107         /// noncopyable
108         LyX(LyX const &);
109         void operator=(LyX const &);
110
111         /// Do some cleanup in preparation of an exit.
112         void prepareExit();
113
114         /// Early exit during the initialisation process.
115         void earlyExit(int status);
116
117         /// Initialise LyX and fills-in the vector of files to be loaded.
118         /**
119         \return exit code failure if any.
120         */
121         int init(int & argc, char * argv[]);
122
123         /// Load files passed at command-line.
124         /// return true on success false if we encounter an error
125         /**
126         This method is used only in non-GUI mode.
127         */
128         bool loadFiles();
129
130         /// initial LyX set up
131         bool init();
132         /** Check for the existence of the user's support directory and,
133          *  if not present, create it. Exits the program if the directory
134          *  cannot be created.
135          *  \returns true if the user-side configuration script
136          *  (lib/configure) should be re-run in this directory.
137          */
138         bool queryUserLyXDir(bool explicit_userdir);
139         /// read lyxrc/preferences
140         bool readRcFile(std::string const & name);
141         /// read the given languages file
142         bool readLanguagesFile(std::string const & name);
143         /// read the encodings.
144         /// \param enc_name encodings definition file
145         /// \param symbols_name unicode->LaTeX mapping file
146         bool readEncodingsFile(std::string const & enc_name,
147                                std::string const & symbols_name);
148         /// parsing of non-gui LyX options.
149         void easyParse(int & argc, char * argv[]);
150         /// shows up a parsing error on screen
151         void printError(ErrorItem const &);
152
153         /// Use the Pimpl idiom to hide the internals.
154         // Mostly used for singletons.
155         struct Impl;
156         Impl * pimpl_;
157
158         /// has this user started lyx for the first time?
159         bool first_start;
160
161         friend Movers & theMovers();
162         friend Mover const & getMover(std::string  const & fmt);
163         friend void setMover(std::string const & fmt, std::string const & command);
164         friend Movers & theSystemMovers();
165         friend frontend::Application * theApp();
166         friend KeyMap & theTopLevelKeymap();
167         friend graphics::Previews * thePreviews();
168 };
169
170 } // namespace lyx
171
172 #endif // LYX_H