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"
34 extern bool RunScript(Buffer * buffer, bool wait, string const & command,
35 string const & orgname = string(), bool need_shell=true);
38 #ifdef CXX_WORKING_NAMESPACES
43 PrinterParams getPrinterParams(Buffer * buffer)
45 return PrinterParams(PrinterParams::PRINTER,
47 ChangeExtension(buffer->fileName(),
48 lyxrc.print_file_extension));
52 bool printBuffer(Buffer * buffer, PrinterParams const & pp)
57 string command(lyxrc.print_command + ' ');
59 if (pp.target == PrinterParams::PRINTER
60 && lyxrc.print_adapt_output // dvips wants a printer name
61 && !pp.printer_name.empty()) {// printer name given
62 command += lyxrc.print_to_printer
67 switch (pp.which_pages) {
68 case PrinterParams::EVEN:
69 command += lyxrc.print_evenpage_flag + ' ';
72 case PrinterParams::ODD:
73 command += lyxrc.print_oddpage_flag + ' ';
77 // only option left is print all of them
81 if (!pp.from_page.empty()) {
82 command += lyxrc.print_pagerange_flag + ' ';
83 command += pp.from_page;
85 // we have a range "from-to"
87 command += tostr(pp.to_page);
92 if (pp.reverse_order) {
93 command += lyxrc.print_reverse_flag + ' ';
96 if (1 < pp.count_copies) {
97 if (pp.unsorted_copies) {
98 command += lyxrc.print_copies_flag;
100 command += lyxrc.print_collcopies_flag;
103 command += tostr(pp.count_copies);
107 if (!lyxrc.print_extra_options.empty()) {
108 command += lyxrc.print_extra_options + ' ';
111 command += Converter::dvips_options(buffer) + ' ';
114 if (!Exporter::Export(buffer, "dvi", true))
117 // Push directory path.
118 string path = OnlyPath(buffer->fileName());
119 if (lyxrc.use_tempdir || (IsDirWriteable(path) < 1)) {
120 path = buffer->tmppath;
124 // there are three cases here:
125 // 1. we print to a file
126 // 2. we print direct to a printer
127 // 3. we print using a spool command (print to file first)
130 string dviname = ChangeExtension(buffer->getLatexName(true), "dvi");
132 case PrinterParams::PRINTER:
133 if (!lyxrc.print_spool_command.empty()) {
135 string psname = ChangeExtension(dviname, ".ps");
136 command += lyxrc.print_to_file
137 + QuoteName(psname) + ' ';
138 command += QuoteName(dviname);
139 string command2 = lyxrc.print_spool_command + ' ';
140 if (!pp.printer_name.empty())
141 command2 += lyxrc.print_spool_printerprefix
142 + pp.printer_name + ' ';
143 command2 += QuoteName(psname);
145 // If successful, then spool command
146 lyxerr << "command1 = " << command << endl;
147 lyxerr << "command2 = " << command2 << endl;
148 res = one.startscript(Systemcalls::System, command);
150 res = one.startscript(Systemcalls::SystemDontWait,
154 res = one.startscript(Systemcalls::SystemDontWait, command);
157 case PrinterParams::FILE:
159 command += lyxrc.print_to_file
160 + QuoteName(MakeAbsPath(pp.file_name, path));
161 command += ' ' + QuoteName(dviname);
162 lyxerr << "command1 = " << command << endl;
163 res = one.startscript(Systemcalls::SystemDontWait, command);
168 // Push directory path if necessary.
169 // PS file should go where the source file is unless it's a
170 // read-only directory in which case we write it to tmpdir.
171 // All temporary files go in tmpdir (like spool files).
172 string path = OnlyPath(buffer->fileName());
173 if ((pp.target != PrinterParams::FILE
174 && lyxrc.use_tempdir)
175 || (IsDirWriteable(path) < 1)) {
176 path = buffer->tmppath;
180 // there are three cases here:
181 // 1. we print to a file
182 // 2. we print direct to a printer
183 // 3. we print using a spool command (print to file first)
185 case PrinterParams::PRINTER:
186 if (!lyxrc.print_spool_command.empty()) {
188 command += lyxrc.print_to_file
189 + QuoteName(pp.file_name);
190 string command2 = lyxrc.print_spool_command
192 if (!pp.printer_name.empty()) {
193 command2 += lyxrc.print_spool_printerprefix
197 // If successful, then spool command
198 if (result = RunScript(buffer, true, command)) {
199 result = RunScript(buffer, false,
201 QuoteName(pp.file_name));
205 result = RunScript(buffer, false, command);
209 case PrinterParams::FILE:
211 command += lyxrc.print_to_file
212 + QuoteName(MakeAbsPath(pp.file_name, path));
213 result = RunScript(buffer, false, command);
220 void setMinibuffer(LyXView * lv, char const * msg)
222 lv->getMiniBuffer()->Set(msg);
225 #ifdef CXX_WORKING_NAMESPACES