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 Formats;
29 class FuncRequest;
30 class FuncStatus;
31 class KeyMap;
32 class LaTeXFonts;
33 class Messages;
34 class Mover;
35 class Movers;
36 class Server;
37 class ServerSocket;
38 class Session;
39 class SpellChecker;
40 
41 enum RunMode {
42 	NEW_INSTANCE,
43 	USE_REMOTE,
44 	PREFERRED
45 };
46 
47 enum OverwriteFiles {
48 	NO_FILES,
49 	MAIN_FILE,
50 	ALL_FILES,
51 	UNSPECIFIED
52 };
53 
54 extern bool use_gui;
55 extern bool verbose;
56 extern bool ignore_missing_glyphs;
57 extern RunMode run_mode;
58 extern OverwriteFiles force_overwrite;
59 extern double qt_scale_factor;
60 
61 namespace frontend {
62 class Application;
63 }
64 
65 /// initial startup
66 class LyX {
67 	friend class LyXConsoleApp;
68 public:
69 	LyX();
70 	~LyX();
71 
72 	/// Execute LyX.
73 	int exec(int & argc, char * argv[]);
74 
75 private:
76 	/// noncopyable
77 	LyX(LyX const &);
78 	void operator=(LyX const &);
79 
80 	/// Do some cleanup in preparation of an exit.
81 	void prepareExit();
82 
83 	/// Early exit during the initialisation process.
84 	void earlyExit(int status);
85 
86 	/// Initialise LyX and fills-in the vector of files to be loaded.
87 	/**
88 	\return exit code failure if any.
89 	*/
90 	int init(int & argc, char * argv[]);
91 
92 	/// Execute commandline commands if no GUI was requested.
93 	int execWithoutGui(int & argc, char * argv[]);
94 
95 	/// Execute batch commands if available.
96 	void execCommands();
97 
98 	/// initial LyX set up
99 	bool init();
100 	/** Check for the existence of the user's support directory and,
101 	 *  if not present, create it. Exits the program if the directory
102 	 *  cannot be created.
103 	 *  \returns true if the user-side configuration script
104 	 *  (lib/configure) should be re-run in this directory.
105 	 */
106 	bool queryUserLyXDir(bool explicit_userdir);
107 	/// read lyxrc/preferences
108 	/// \param check_format: whether to try to convert the format of
109 	/// the file, if there is a mismatch.
110 	bool readRcFile(std::string const & name, bool check_format = false);
111 	/// read the given languages file
112 	bool readLanguagesFile(std::string const & name);
113 	/// read the encodings.
114 	/// \param enc_name encodings definition file
115 	/// \param symbols_name unicode->LaTeX mapping file
116 	bool readEncodingsFile(std::string const & enc_name,
117 			       std::string const & symbols_name);
118 	/// parsing of non-gui LyX options.
119 	void easyParse(int & argc, char * argv[]);
120 	/// shows up a parsing error on screen
121 	void printError(ErrorItem const &);
122 
123 	///
124 	Messages & messages(std::string const & language);
125 
126 	/// Use the Pimpl idiom to hide the internals.
127 	// Mostly used for singletons.
128 	struct Impl;
129 	Impl * pimpl_;
130 
131 	/// has this user started lyx for the first time?
132 	bool first_start;
133 
134 	friend FuncStatus getStatus(FuncRequest const & action);
135 	friend DispatchResult const & dispatch(FuncRequest const & action);
136 	friend void dispatch(FuncRequest const & action, DispatchResult & dr);
137 	friend std::vector<std::string> & theFilesToLoad();
138 	friend BufferList & theBufferList();
139 	friend Server & theServer();
140 	friend ServerSocket & theServerSocket();
141 	friend Converters & theConverters();
142 	friend Converters & theSystemConverters();
143 	friend Formats & theFormats();
144 	friend Formats & theSystemFormats();
145 	friend Messages const & getMessages(std::string const & language);
146 	friend Messages const & getGuiMessages();
147 	friend KeyMap & theTopLevelKeymap();
148 	friend Movers & theMovers();
149 	friend Mover const & getMover(std::string const & fmt);
150 	friend void setMover(std::string const & fmt, std::string const & command);
151 	friend Movers & theSystemMovers();
152 	friend frontend::Application * theApp();
153 	friend Session & theSession();
154 	friend LaTeXFonts & theLaTeXFonts();
155 	friend CmdDef & theTopLevelCmdDef();
156 	friend SpellChecker * theSpellChecker();
157 	friend void setSpellChecker();
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 /// Execute batch commands if available.
171 void execBatchCommands();
172 
173 ///
174 FuncStatus getStatus(FuncRequest const & action);
175 
176 ///
177 DispatchResult const & dispatch(FuncRequest const & action);
178 
179 ///
180 void dispatch(FuncRequest const & action, DispatchResult & dr);
181 
182 } // namespace lyx
183 
184 #endif // LYX_H
185