]> git.lyx.org Git - lyx.git/blob - src/frontends/qt2/lyx_gui.C
make lyxserver work
[lyx.git] / src / frontends / qt2 / lyx_gui.C
1 /**
2  * \file lyx_gui.C
3  * Copyright 2002 the LyX Team
4  * Read the file COPYING
5  *
6  * \author unknown
7  * \author John Levon <moz@compsoc.man.ac.uk>
8  */
9
10 #include <config.h>
11  
12 #include "support/lyxlib.h"
13 #include "support/os.h"
14 #include "support/filetools.h"
15 #include "debug.h"
16 #include "gettext.h"
17  
18 #include <fcntl.h>
19 #include <boost/bind.hpp>
20  
21 #include "lyx_gui.h"
22 #include "lyx_main.h"
23 #include "lyxrc.h"
24 #include "lyxfont.h"
25  
26 // FIXME: move this stuff out again
27 #include "bufferlist.h"
28 #include "lyxfunc.h"
29 #include "lyxserver.h"
30 #include "BufferView.h"
31
32 // Dear Lord, deliver us from Evil,
33 // aka the Qt headers
34 #include <boost/shared_ptr.hpp>
35 #include <boost/function/function0.hpp>
36 #include <boost/signals/signal1.hpp>
37  
38 #include "QtView.h"
39 #include "QLImage.h"
40 #include "qfont_loader.h"
41 #include "io_callback.h" 
42  
43 #include <qapplication.h>
44  
45 #ifndef CXX_GLOBAL_CSTD
46 using std::exit;
47 #endif
48
49 using std::vector;
50 using std::hex;
51 using std::endl;
52  
53 extern bool finished;
54 extern BufferList bufferlist;
55  
56 // FIXME: wrong place !
57 LyXServer * lyxserver;
58  
59 void lyx_gui::parse_init(int & argc, char * argv[])
60 {
61         static QApplication a(argc, argv);
62  
63         using namespace grfx;
64
65         Image::newImage = boost::bind(&QLImage::newImage);
66         Image::loadableFormats = boost::bind(&QLImage::loadableFormats);
67 }
68  
69
70 void lyx_gui::parse_lyxrc()
71 {
72         // FIXME !!!! 
73         lyxrc.dpi = 95;
74 }
75
76  
77 void lyx_gui::start(string const & batch, vector<string> files)
78 {
79         // initial geometry
80         int xpos = -1;
81         int ypos = -1;
82         unsigned int width = 690;
83         unsigned int height = 510;
84  
85         QtView view(width, height);
86         view.show(xpos, ypos, "LyX");
87         view.init();
88
89         Buffer * last = 0;
90  
91         // FIXME: some code below needs moving
92
93         lyxserver = new LyXServer(view.getLyXFunc(), lyxrc.lyxpipes);
94  
95         vector<string>::const_iterator cit = files.begin();
96         vector<string>::const_iterator end = files.end();
97         for (; cit != end; ++cit) {
98                 Buffer * b = bufferlist.loadLyXFile(*cit);
99                 if (b) {
100                         last = b;
101                 }
102         }
103
104         // switch to the last buffer successfully loaded
105         if (last) {
106                 view.view()->buffer(last);
107         }
108
109         // handle the batch commands the user asked for
110         if (!batch.empty()) {
111                 view.getLyXFunc()->verboseDispatch(batch, false);
112         }
113
114         while (!finished) {
115                 qApp->processEvents();
116         }
117                  
118         // FIXME 
119         delete lyxserver;
120 }
121  
122  
123 string const lyx_gui::hexname(LColor::color col)
124 {
125         QColor color(lcolor.getX11Name(col).c_str());
126         return color.name().latin1();
127 }
128
129
130 void lyx_gui::update_color(LColor::color)
131 {
132         // no need
133 }
134
135
136 void lyx_gui::update_fonts()
137 {
138         fontloader.update();
139 }
140
141
142 bool lyx_gui::font_available(LyXFont const & font)
143 {
144         return fontloader.available(font);
145 }
146
147
148 void lyx_gui::set_read_callback(int fd, LyXComm * comm)
149 {
150         // FIXME: "leak"
151         new io_callback(fd, comm);
152 }