]> git.lyx.org Git - lyx.git/blob - src/frontends/Liason.C
fix typo that put too many include paths for most people
[lyx.git] / src / frontends / Liason.C
1 /* This file is part of
2  * ======================================================
3  *
4  *           LyX, The Document Processor
5  *
6  *           Copyright 1995 Matthias Ettrich
7  *           Copyright 1995-2001 The LyX Team.
8  *
9  * ====================================================== */
10
11 #include <config.h>
12
13 #ifdef __GNUG__
14 #pragma implementation
15 #endif
16
17 #include "Liason.h"
18 #include "lyxrc.h"
19 #include "PrinterParams.h"
20
21 #include "LyXView.h"
22 #include "BufferView.h"
23 #include "buffer.h"
24 #include "exporter.h"
25 #include "converter.h"
26
27 #include "support/LAssert.h"
28 #include "support/lstrings.h"
29 #include "support/filetools.h"
30 #include "support/path.h"
31 #include "support/systemcall.h"
32
33 using std::endl;
34
35 extern LyXRC lyxrc;
36
37 namespace Liason {
38
39 PrinterParams getPrinterParams(Buffer * buffer)
40 {
41         return PrinterParams(PrinterParams::PRINTER,
42                              lyxrc.printer,
43                              ChangeExtension(buffer->fileName(),
44                                              lyxrc.print_file_extension));
45 }
46
47
48 bool printBuffer(Buffer * buffer, PrinterParams const & pp)
49 {
50         string command(lyxrc.print_command + ' ');
51
52         if (pp.target == PrinterParams::PRINTER
53             && lyxrc.print_adapt_output  // dvips wants a printer name
54             && !pp.printer_name.empty()) {// printer name given
55                 command += lyxrc.print_to_printer
56                         + pp.printer_name
57                         + ' ';
58         }
59
60         switch (pp.which_pages) {
61         case PrinterParams::EVEN:
62                 command += lyxrc.print_evenpage_flag + ' ';
63                 break;
64
65         case PrinterParams::ODD:
66                 command += lyxrc.print_oddpage_flag + ' ';
67                 break;
68
69         default:
70                 // only option left is print all of them
71                 break;
72         }
73
74         if (!pp.from_page.empty()) {
75                 command += lyxrc.print_pagerange_flag + ' ';
76                 command += pp.from_page;
77                 if (pp.to_page) {
78                                 // we have a range "from-to"
79                         command += '-';
80                         command += tostr(pp.to_page);
81                 }
82                 command += ' ';
83         }
84
85         if (pp.reverse_order) {
86                 command += lyxrc.print_reverse_flag + ' ';
87         }
88
89         if (1 < pp.count_copies) {
90                 if (pp.unsorted_copies) {
91                         command += lyxrc.print_copies_flag;
92                 } else {
93                         command += lyxrc.print_collcopies_flag;
94                 }
95                 command += ' ';
96                 command += tostr(pp.count_copies);
97                 command += ' ';
98         }
99
100         if (!lyxrc.print_extra_options.empty()) {
101                 command += lyxrc.print_extra_options + ' ';
102         }
103
104         command += converters.dvips_options(buffer) + ' ';
105
106         if (!Exporter::Export(buffer, "dvi", true))
107                 return false;
108
109         // Push directory path.
110         string path = buffer->filePath();
111         if (lyxrc.use_tempdir || !IsDirWriteable(path)) {
112                 path = buffer->tmppath;
113         }
114         Path p(path);
115
116         // there are three cases here:
117         // 1. we print to a file
118         // 2. we print direct to a printer
119         // 3. we print using a spool command (print to file first)
120         Systemcall one;
121         int res = 0;
122         string dviname = ChangeExtension(buffer->getLatexName(true), "dvi");
123         switch (pp.target) {
124         case PrinterParams::PRINTER:
125                 if (!lyxrc.print_spool_command.empty()) {
126                         // case 3
127                         string psname = ChangeExtension(dviname, ".ps");
128                         command += lyxrc.print_to_file
129                                 + QuoteName(psname) + ' ';
130                         command += QuoteName(dviname);
131                         string command2 = lyxrc.print_spool_command + ' ';
132                         if (!pp.printer_name.empty())
133                                 command2 += lyxrc.print_spool_printerprefix
134                                         + pp.printer_name + ' ';
135                         command2 += QuoteName(psname);
136                         // First run dvips.
137                         // If successful, then spool command
138                         res = one.startscript(Systemcall::Wait, command);
139                         if (res == 0)
140                                 res = one.startscript(Systemcall::DontWait,
141                                                       command2);
142                 } else
143                         // case 2
144                         res = one.startscript(Systemcall::DontWait,
145                                               command + QuoteName(dviname));
146                 break;
147
148         case PrinterParams::FILE:
149                 // case 1
150                 command += lyxrc.print_to_file
151                         + QuoteName(MakeAbsPath(pp.file_name, path));
152                 command += ' ' + QuoteName(dviname);
153                 res = one.startscript(Systemcall::DontWait, command);
154                 break;
155         }
156         return res == 0;
157 }
158
159
160 void setMinibuffer(LyXView * lv, string const & msg)
161 {
162         lyx::Assert(lv);
163         lv->message(msg);
164 }
165
166 } // namespace Liason