3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
6 * \author Angus Leeming
8 * Full author contact details are available in file CREDITS.
13 #include "ControlPrint.h"
15 #include "ButtonController.h"
16 #include "helper_funcs.h"
19 #include "bufferparams.h"
20 #include "funcrequest.h"
22 #include "PrinterParams.h"
24 #include "support/convert.h"
25 #include "support/filefilterlist.h"
26 #include "support/filetools.h"
32 using support::changeExtension;
33 using support::FileFilterList;
38 ControlPrint::ControlPrint(Dialog & parent)
39 : Dialog::Controller(parent),
44 bool ControlPrint::initialiseParams(std::string const &)
46 /// get global printer parameters
47 string const name = changeExtension(kernel().buffer().fileName(),
48 lyxrc.print_file_extension);
49 params_.reset(new PrinterParams(PrinterParams::PRINTER,
50 lyxrc.printer, name));
52 dialog().bc().valid(); // so that the user can press Ok
57 void ControlPrint::clearParams()
63 PrinterParams & ControlPrint::params() const
65 BOOST_ASSERT(params_.get());
70 string const ControlPrint::browse(string const & in_name) const
73 return browseRelFile(in_name, kernel().buffer().filePath(),
74 lyx::to_utf8(_("Print to file")),
75 FileFilterList(lyx::to_utf8(_("PostScript files (*.ps)"))),
80 /// print the current buffer
81 void ControlPrint::dispatchParams()
83 PrinterParams const pp = params();
84 string command(lyxrc.print_command + ' ');
86 if (pp.target == PrinterParams::PRINTER
87 && lyxrc.print_adapt_output // dvips wants a printer name
88 && !pp.printer_name.empty()) {// printer name given
89 command += lyxrc.print_to_printer
94 if (!pp.all_pages && pp.from_page) {
95 command += lyxrc.print_pagerange_flag + ' ';
96 command += convert<string>(pp.from_page);
98 // we have a range "from-to"
100 + convert<string>(pp.to_page);
105 // If both are, or both are not selected, then skip the odd/even printing
106 if (pp.odd_pages != pp.even_pages) {
108 command += lyxrc.print_oddpage_flag + ' ';
109 } else if (pp.even_pages) {
110 command += lyxrc.print_evenpage_flag + ' ';
114 if (pp.count_copies > 1) {
115 if (pp.sorted_copies) {
116 command += lyxrc.print_collcopies_flag;
118 command += lyxrc.print_copies_flag;
121 + convert<string>(pp.count_copies)
125 if (pp.reverse_order) {
126 command += lyxrc.print_reverse_flag + ' ';
129 if (!lyxrc.print_extra_options.empty()) {
130 command += lyxrc.print_extra_options + ' ';
133 command += kernel().buffer().params().dvips_options() + ' ';
135 string const target = (pp.target == PrinterParams::PRINTER) ?
138 string const target_name = (pp.target == PrinterParams::PRINTER) ?
139 (pp.printer_name.empty() ? "default" : pp.printer_name) :
142 string const data = target + " " + target_name + " " + command;
143 kernel().dispatch(FuncRequest(getLfun(), data));
146 } // namespace frontend