3 * Copyright 2001 LyX Team
6 * \author John Levon, moz@compsoc.man.ac.uk
11 #include "printdlgimpl.h"
12 #include "FormPrint.h"
17 #include "QtLyXView.h"
19 #include "PrinterParams.h"
21 #include "BufferView.h"
22 #include "support/lstrings.h"
23 #include "qmessagebox.h"
25 #ifdef SIGC_CXX_NAMESPACES
29 #ifdef CXX_WORKING_NAMESPACES
30 using Liason::printBuffer;
31 using Liason::getPrinterParams;
35 FormPrint::FormPrint(LyXView *v, Dialogs *d)
36 : dialog_(0), lv_(v), d_(d), h_(0), u_(0)
38 // let the dialog be shown
39 // This is a permanent connection so we won't bother
40 // storing a copy because we won't be disconnecting.
41 d->showPrint.connect(slot(this, &FormPrint::show));
44 FormPrint::~FormPrint()
49 // we can safely ignore the parameter because we can always update
50 void FormPrint::update(bool)
52 if (!lv_->view()->available())
55 PrinterParams pp(getPrinterParams(lv_->buffer()));
57 dialog_->setTarget(pp.target);
58 dialog_->setPrinter(pp.printer_name.c_str());
59 dialog_->setFile(pp.file_name.c_str());
60 dialog_->setWhichPages(pp.which_pages);
61 dialog_->setReverse(pp.reverse_order);
62 dialog_->setSort(pp.unsorted_copies);
63 dialog_->setCount(pp.count_copies);
65 if (!pp.from_page.empty()) {
66 dialog_->setFrom(pp.from_page.c_str());
68 dialog_->setTo(tostr(pp.to_page).c_str());
77 void FormPrint::print()
79 if (!lv_->view()->available())
85 if (strlen(dialog_->getFrom())) {
86 from = dialog_->getFrom();
87 if (strlen(dialog_->getTo()))
88 to = strToInt(dialog_->getTo());
92 retval = printBuffer(lv_->buffer(), PrinterParams(dialog_->getTarget(),
93 string(dialog_->getPrinter()), string(dialog_->getFile()),
94 dialog_->getWhichPages(), from, to, dialog_->getReverse(),
95 dialog_->getSort(), max(strToInt(dialog_->getCount()),1)));
98 // FIXME: should have a utility class for this
99 string message(_("An error occured while printing.\n\n"));
100 message += _("Check the parameters are correct.\n");
101 QMessageBox msg( _("LyX: Print Error"), message.c_str(), QMessageBox::Warning, 1,0,0);
103 msg.setActiveWindow();
108 void FormPrint::show()
111 dialog_ = new PrintDlgImpl(this, 0, _("LyX: Print"));
113 if (!dialog_->isVisible()) {
114 h_ = d_->hideBufferDependent.connect(slot(this, &FormPrint::hide));
115 u_ = d_->updateBufferDependent.connect(slot(this, &FormPrint::update));
119 dialog_->setActiveWindow();
125 void FormPrint::close()
131 void FormPrint::hide()