1 /* This file is part of
2 * ======================================================
4 * LyX, The Document Processor
6 * Copyright 1995 Matthias Ettrich
7 * Copyright 1995-2000 The LyX Team.
9 * ====================================================== */
14 #pragma implementation
19 #include "BufferView.h"
22 #include "PrinterParams.h"
23 #include "lyx_gui_misc.h"
24 #include "support/lstrings.h"
25 #include "support/filetools.h"
26 #include "support/path.h"
28 #include "converter.h"
29 #include "minibuffer.h"
30 #include "support/syscall.h"
36 extern bool RunScript(Buffer * buffer, bool wait, string const & command,
37 string const & orgname = string(), bool need_shell=true);
40 #ifdef CXX_WORKING_NAMESPACES
45 PrinterParams getPrinterParams(Buffer * buffer)
47 return PrinterParams(PrinterParams::PRINTER,
49 ChangeExtension(buffer->fileName(),
50 lyxrc.print_file_extension));
54 bool printBuffer(Buffer * buffer, PrinterParams const & pp)
59 string command(lyxrc.print_command + ' ');
61 if (pp.target == PrinterParams::PRINTER
62 && lyxrc.print_adapt_output // dvips wants a printer name
63 && !pp.printer_name.empty()) {// printer name given
64 command += lyxrc.print_to_printer
69 switch (pp.which_pages) {
70 case PrinterParams::EVEN:
71 command += lyxrc.print_evenpage_flag + ' ';
74 case PrinterParams::ODD:
75 command += lyxrc.print_oddpage_flag + ' ';
79 // only option left is print all of them
83 if (!pp.from_page.empty()) {
84 command += lyxrc.print_pagerange_flag + ' ';
85 command += pp.from_page;
87 // we have a range "from-to"
89 command += tostr(pp.to_page);
94 if (pp.reverse_order) {
95 command += lyxrc.print_reverse_flag + ' ';
98 if (1 < pp.count_copies) {
99 if (pp.unsorted_copies) {
100 command += lyxrc.print_copies_flag;
102 command += lyxrc.print_collcopies_flag;
105 command += tostr(pp.count_copies);
109 if (!lyxrc.print_extra_options.empty()) {
110 command += lyxrc.print_extra_options + ' ';
113 command += Converter::dvips_options(buffer) + ' ';
116 if (!Exporter::Export(buffer, "dvi", true))
119 // Push directory path.
120 string path = OnlyPath(buffer->fileName());
121 if (lyxrc.use_tempdir || (IsDirWriteable(path) < 1)) {
122 path = buffer->tmppath;
126 // there are three cases here:
127 // 1. we print to a file
128 // 2. we print direct to a printer
129 // 3. we print using a spool command (print to file first)
132 string dviname = ChangeExtension(buffer->getLatexName(true), "dvi");
134 case PrinterParams::PRINTER:
135 if (!lyxrc.print_spool_command.empty()) {
137 string psname = ChangeExtension(dviname, ".ps");
138 command += lyxrc.print_to_file
139 + QuoteName(psname) + ' ';
140 command += QuoteName(dviname);
141 string command2 = lyxrc.print_spool_command + ' ';
142 if (!pp.printer_name.empty())
143 command2 += lyxrc.print_spool_printerprefix
144 + pp.printer_name + ' ';
145 command2 += QuoteName(psname);
147 // If successful, then spool command
148 lyxerr << "command1 = " << command << endl;
149 lyxerr << "command2 = " << command2 << endl;
150 res = one.startscript(Systemcalls::System, command);
152 res = one.startscript(Systemcalls::SystemDontWait,
156 res = one.startscript(Systemcalls::SystemDontWait, command);
159 case PrinterParams::FILE:
161 command += lyxrc.print_to_file
162 + QuoteName(MakeAbsPath(pp.file_name, path));
163 command += ' ' + QuoteName(dviname);
164 lyxerr << "command1 = " << command << endl;
165 res = one.startscript(Systemcalls::SystemDontWait, command);
170 // Push directory path if necessary.
171 // PS file should go where the source file is unless it's a
172 // read-only directory in which case we write it to tmpdir.
173 // All temporary files go in tmpdir (like spool files).
174 string path = OnlyPath(buffer->fileName());
175 if ((pp.target != PrinterParams::FILE
176 && lyxrc.use_tempdir)
177 || (IsDirWriteable(path) < 1)) {
178 path = buffer->tmppath;
182 // there are three cases here:
183 // 1. we print to a file
184 // 2. we print direct to a printer
185 // 3. we print using a spool command (print to file first)
187 case PrinterParams::PRINTER:
188 if (!lyxrc.print_spool_command.empty()) {
190 command += lyxrc.print_to_file
191 + QuoteName(pp.file_name);
192 string command2 = lyxrc.print_spool_command
194 if (!pp.printer_name.empty()) {
195 command2 += lyxrc.print_spool_printerprefix
199 // If successful, then spool command
200 if (result = RunScript(buffer, true, command)) {
201 result = RunScript(buffer, false,
203 QuoteName(pp.file_name));
207 result = RunScript(buffer, false, command);
211 case PrinterParams::FILE:
213 command += lyxrc.print_to_file
214 + QuoteName(MakeAbsPath(pp.file_name, path));
215 result = RunScript(buffer, false, command);
222 void setMinibuffer(LyXView * lv, char const * msg)
224 lv->getMiniBuffer()->Set(msg);
227 #ifdef CXX_WORKING_NAMESPACES