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 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 res = one.startscript(Systemcalls::SystemDontWait, command);
167 // Push directory path if necessary.
168 // PS file should go where the source file is unless it's a
169 // read-only directory in which case we write it to tmpdir.
170 // All temporary files go in tmpdir (like spool files).
171 string path = OnlyPath(buffer->fileName());
172 if ((pp.target != PrinterParams::FILE
173 && lyxrc.use_tempdir)
174 || (IsDirWriteable(path) < 1)) {
175 path = buffer->tmppath;
179 // there are three cases here:
180 // 1. we print to a file
181 // 2. we print direct to a printer
182 // 3. we print using a spool command (print to file first)
184 case PrinterParams::PRINTER:
185 if (!lyxrc.print_spool_command.empty()) {
187 command += lyxrc.print_to_file
188 + QuoteName(pp.file_name);
189 string command2 = lyxrc.print_spool_command
191 if (!pp.printer_name.empty()) {
192 command2 += lyxrc.print_spool_printerprefix
196 // If successful, then spool command
197 if (result = RunScript(buffer, true, command)) {
198 result = RunScript(buffer, false,
200 QuoteName(pp.file_name));
204 result = RunScript(buffer, false, command);
208 case PrinterParams::FILE:
210 command += lyxrc.print_to_file
211 + QuoteName(MakeAbsPath(pp.file_name, path));
212 result = RunScript(buffer, false, command);
219 void setMinibuffer(LyXView * lv, char const * msg)
221 lv->getMiniBuffer()->Set(msg);
224 #ifdef CXX_WORKING_NAMESPACES