2 * \file ControlPrint.cpp
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 "frontend_helpers.h"
18 #include "BufferParams.h"
19 #include "FuncRequest.h"
22 #include "support/convert.h"
23 #include "support/FileFilterList.h"
24 #include "support/filetools.h"
30 using support::changeExtension;
31 using support::FileFilterList;
36 ControlPrint::ControlPrint(Dialog & parent)
41 bool ControlPrint::initialiseParams(std::string const &)
43 /// get global printer parameters
44 string const name = changeExtension(buffer().fileName(),
45 lyxrc.print_file_extension);
46 params_ = PrinterParams(PrinterParams::PRINTER, lyxrc.printer, name);
48 dialog().setButtonsValid(true); // so that the user can press Ok
53 void ControlPrint::clearParams()
55 params_ = PrinterParams();
59 docstring const ControlPrint::browse(docstring const & in_name) const
61 return browseRelFile(in_name, lyx::from_utf8(buffer().filePath()),
63 FileFilterList(_("PostScript files (*.ps)")),
68 /// print the current buffer
69 void ControlPrint::dispatchParams()
71 PrinterParams const pp = params();
72 string command(lyxrc.print_command + ' ');
74 if (pp.target == PrinterParams::PRINTER
75 && lyxrc.print_adapt_output // dvips wants a printer name
76 && !pp.printer_name.empty()) {// printer name given
77 command += lyxrc.print_to_printer
82 if (!pp.all_pages && pp.from_page) {
83 command += lyxrc.print_pagerange_flag + ' ';
84 command += convert<string>(pp.from_page);
86 // we have a range "from-to"
88 + convert<string>(pp.to_page);
93 // If both are, or both are not selected, then skip the odd/even printing
94 if (pp.odd_pages != pp.even_pages) {
96 command += lyxrc.print_oddpage_flag + ' ';
97 } else if (pp.even_pages) {
98 command += lyxrc.print_evenpage_flag + ' ';
102 if (pp.count_copies > 1) {
103 if (pp.sorted_copies) {
104 command += lyxrc.print_collcopies_flag;
106 command += lyxrc.print_copies_flag;
109 + convert<string>(pp.count_copies)
113 if (pp.reverse_order) {
114 command += lyxrc.print_reverse_flag + ' ';
117 if (!lyxrc.print_extra_options.empty()) {
118 command += lyxrc.print_extra_options + ' ';
121 command += buffer().params().dvips_options();
123 string const target = (pp.target == PrinterParams::PRINTER) ?
126 string const target_name = (pp.target == PrinterParams::PRINTER) ?
127 (pp.printer_name.empty() ? "default" : pp.printer_name) :
130 string const data = target + " \"" + target_name + "\" \"" + command + '"';
131 dispatch(FuncRequest(getLfun(), data));
134 } // namespace frontend