2000-07-24 13:53:19 +00:00
|
|
|
/* This file is part of
|
|
|
|
* ======================================================
|
|
|
|
*
|
|
|
|
* LyX, The Document Processor
|
|
|
|
*
|
|
|
|
* Copyright 1995 Matthias Ettrich
|
2001-05-30 13:53:44 +00:00
|
|
|
* Copyright 1995-2001 The LyX Team.
|
2000-07-24 13:53:19 +00:00
|
|
|
*
|
|
|
|
* ====================================================== */
|
|
|
|
|
2000-06-12 11:55:12 +00:00
|
|
|
#include <config.h>
|
|
|
|
|
2000-07-24 13:53:19 +00:00
|
|
|
#ifdef __GNUG__
|
|
|
|
#pragma implementation
|
|
|
|
#endif
|
|
|
|
|
2000-06-12 11:55:12 +00:00
|
|
|
#include "Liason.h"
|
2000-08-11 14:42:20 +00:00
|
|
|
#include "LyXView.h"
|
2000-06-12 11:55:12 +00:00
|
|
|
#include "BufferView.h"
|
|
|
|
#include "buffer.h"
|
|
|
|
#include "lyxrc.h"
|
|
|
|
#include "PrinterParams.h"
|
|
|
|
#include "lyx_gui_misc.h"
|
2001-07-30 10:50:37 +00:00
|
|
|
#include "support/LAssert.h"
|
2000-06-12 11:55:12 +00:00
|
|
|
#include "support/lstrings.h"
|
|
|
|
#include "support/filetools.h"
|
|
|
|
#include "support/path.h"
|
2000-08-30 03:40:51 +00:00
|
|
|
#include "exporter.h"
|
2000-09-05 13:16:19 +00:00
|
|
|
#include "converter.h"
|
|
|
|
#include "support/syscall.h"
|
2000-06-12 11:55:12 +00:00
|
|
|
|
2000-09-05 14:15:09 +00:00
|
|
|
using std::endl;
|
|
|
|
|
2000-06-12 11:55:12 +00:00
|
|
|
extern LyXRC lyxrc;
|
|
|
|
|
2001-03-15 18:21:56 +00:00
|
|
|
namespace Liason {
|
2000-06-12 11:55:12 +00:00
|
|
|
|
|
|
|
PrinterParams getPrinterParams(Buffer * buffer)
|
|
|
|
{
|
|
|
|
return PrinterParams(PrinterParams::PRINTER,
|
|
|
|
lyxrc.printer,
|
|
|
|
ChangeExtension(buffer->fileName(),
|
|
|
|
lyxrc.print_file_extension));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool printBuffer(Buffer * buffer, PrinterParams const & pp)
|
|
|
|
{
|
|
|
|
string command(lyxrc.print_command + ' ');
|
|
|
|
|
|
|
|
if (pp.target == PrinterParams::PRINTER
|
|
|
|
&& lyxrc.print_adapt_output // dvips wants a printer name
|
|
|
|
&& !pp.printer_name.empty()) {// printer name given
|
|
|
|
command += lyxrc.print_to_printer
|
|
|
|
+ pp.printer_name
|
|
|
|
+ ' ';
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (pp.which_pages) {
|
|
|
|
case PrinterParams::EVEN:
|
|
|
|
command += lyxrc.print_evenpage_flag + ' ';
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PrinterParams::ODD:
|
|
|
|
command += lyxrc.print_oddpage_flag + ' ';
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
// only option left is print all of them
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!pp.from_page.empty()) {
|
|
|
|
command += lyxrc.print_pagerange_flag + ' ';
|
|
|
|
command += pp.from_page;
|
|
|
|
if (pp.to_page) {
|
|
|
|
// we have a range "from-to"
|
|
|
|
command += '-';
|
|
|
|
command += tostr(pp.to_page);
|
|
|
|
}
|
|
|
|
command += ' ';
|
|
|
|
}
|
|
|
|
|
|
|
|
if (pp.reverse_order) {
|
|
|
|
command += lyxrc.print_reverse_flag + ' ';
|
|
|
|
}
|
|
|
|
|
|
|
|
if (1 < pp.count_copies) {
|
|
|
|
if (pp.unsorted_copies) {
|
|
|
|
command += lyxrc.print_copies_flag;
|
|
|
|
} else {
|
|
|
|
command += lyxrc.print_collcopies_flag;
|
|
|
|
}
|
|
|
|
command += ' ';
|
|
|
|
command += tostr(pp.count_copies);
|
|
|
|
command += ' ';
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!lyxrc.print_extra_options.empty()) {
|
|
|
|
command += lyxrc.print_extra_options + ' ';
|
|
|
|
}
|
|
|
|
|
2000-11-13 10:35:02 +00:00
|
|
|
command += converters.dvips_options(buffer) + ' ';
|
2000-06-12 11:55:12 +00:00
|
|
|
|
2000-09-05 13:16:19 +00:00
|
|
|
if (!Exporter::Export(buffer, "dvi", true))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
// Push directory path.
|
2002-01-14 23:31:23 +00:00
|
|
|
string path = buffer->filePath();
|
2001-08-01 10:08:53 +00:00
|
|
|
if (lyxrc.use_tempdir || !IsDirWriteable(path)) {
|
2000-09-05 13:16:19 +00:00
|
|
|
path = buffer->tmppath;
|
2000-06-12 11:55:12 +00:00
|
|
|
}
|
2000-09-05 13:16:19 +00:00
|
|
|
Path p(path);
|
|
|
|
|
|
|
|
// there are three cases here:
|
|
|
|
// 1. we print to a file
|
|
|
|
// 2. we print direct to a printer
|
|
|
|
// 3. we print using a spool command (print to file first)
|
|
|
|
Systemcalls one;
|
|
|
|
int res = 0;
|
|
|
|
string dviname = ChangeExtension(buffer->getLatexName(true), "dvi");
|
|
|
|
switch (pp.target) {
|
|
|
|
case PrinterParams::PRINTER:
|
|
|
|
if (!lyxrc.print_spool_command.empty()) {
|
|
|
|
// case 3
|
|
|
|
string psname = ChangeExtension(dviname, ".ps");
|
|
|
|
command += lyxrc.print_to_file
|
|
|
|
+ QuoteName(psname) + ' ';
|
|
|
|
command += QuoteName(dviname);
|
|
|
|
string command2 = lyxrc.print_spool_command + ' ';
|
|
|
|
if (!pp.printer_name.empty())
|
|
|
|
command2 += lyxrc.print_spool_printerprefix
|
|
|
|
+ pp.printer_name + ' ';
|
|
|
|
command2 += QuoteName(psname);
|
|
|
|
// First run dvips.
|
|
|
|
// If successful, then spool command
|
2002-02-16 12:39:47 +00:00
|
|
|
res = one.startscript(Systemcalls::Wait, command);
|
2000-09-05 13:16:19 +00:00
|
|
|
if (res == 0)
|
2002-02-16 12:39:47 +00:00
|
|
|
res = one.startscript(Systemcalls::DontWait,
|
2000-09-05 13:16:19 +00:00
|
|
|
command2);
|
|
|
|
} else
|
|
|
|
// case 2
|
2002-02-16 12:39:47 +00:00
|
|
|
res = one.startscript(Systemcalls::DontWait,
|
2001-03-23 15:16:03 +00:00
|
|
|
command + QuoteName(dviname));
|
2000-09-05 13:16:19 +00:00
|
|
|
break;
|
2000-06-12 11:55:12 +00:00
|
|
|
|
2000-09-05 13:16:19 +00:00
|
|
|
case PrinterParams::FILE:
|
|
|
|
// case 1
|
|
|
|
command += lyxrc.print_to_file
|
|
|
|
+ QuoteName(MakeAbsPath(pp.file_name, path));
|
|
|
|
command += ' ' + QuoteName(dviname);
|
2002-02-16 12:39:47 +00:00
|
|
|
res = one.startscript(Systemcalls::DontWait, command);
|
2000-09-05 13:16:19 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
return res == 0;
|
2000-06-12 11:55:12 +00:00
|
|
|
}
|
|
|
|
|
2001-04-17 14:02:45 +00:00
|
|
|
|
|
|
|
void setMinibuffer(LyXView * lv, string const & msg)
|
2000-08-11 14:42:20 +00:00
|
|
|
{
|
2001-04-24 15:25:26 +00:00
|
|
|
lyx::Assert(lv);
|
2001-04-17 14:02:45 +00:00
|
|
|
lv->message(msg);
|
2000-08-11 14:42:20 +00:00
|
|
|
}
|
|
|
|
|
2001-03-15 18:21:56 +00:00
|
|
|
} // namespace Liason
|