3 * Copyright 2001 the LyX Team
4 * Read the file COPYING
13 #include "FormPrint.h"
17 #include "QtLyXView.h"
18 #include "PrinterParams.h"
20 #include "BufferView.h"
21 #include "support/lstrings.h"
25 using Liason::printBuffer;
26 using Liason::getPrinterParams;
29 FormPrint::FormPrint(LyXView *v, Dialogs *d)
30 : dialog_(0), lv_(v), d_(d), h_(0), u_(0)
32 d->showPrint.connect(SigC::slot(this, &FormPrint::show));
36 FormPrint::~FormPrint()
42 // we can safely ignore the parameter because we can always update
43 void FormPrint::update(bool)
45 if (!lv_->view()->available())
48 PrinterParams pp(getPrinterParams(lv_->buffer()));
50 dialog_->setTarget(pp.target);
51 dialog_->setPrinter(pp.printer_name.c_str());
52 dialog_->setFile(pp.file_name.c_str());
53 dialog_->setWhichPages(pp.which_pages);
54 dialog_->setReverse(pp.reverse_order);
55 dialog_->setSort(pp.unsorted_copies);
56 dialog_->setCount(pp.count_copies);
58 if (!pp.from_page.empty()) {
59 dialog_->setFrom(pp.from_page.c_str());
61 dialog_->setTo(tostr(pp.to_page).c_str());
71 void FormPrint::print()
73 if (!lv_->view()->available())
79 if (strlen(dialog_->getFrom())) {
80 from = dialog_->getFrom();
81 if (strlen(dialog_->getTo()))
82 to = strToInt(dialog_->getTo());
85 int retval = printBuffer(lv_->buffer(), PrinterParams(dialog_->getTarget(),
86 string(dialog_->getPrinter()), string(dialog_->getFile()),
87 dialog_->getWhichPages(), from, to, dialog_->getReverse(),
88 dialog_->getSort(), max(strToInt(dialog_->getCount()),1)));
91 // FIXME: should have a utility class for this
92 string message(_("An error occured while printing.\n\n"));
93 message += _("Check the parameters are correct.\n");
94 KMsgBox msg(0, _("LyX: Print Error"), message.c_str(), KMsgBox::EXCLAMATION, _("&OK"));
96 msg.setActiveWindow();
102 void FormPrint::show()
105 dialog_ = new PrintDialog(this, 0, _("LyX: Print"));
107 if (!dialog_->isVisible()) {
108 h_ = d_->hideBufferDependent.connect(SigC::slot(this, &FormPrint::hide));
109 u_ = d_->updateBufferDependent.connect(SigC::slot(this, &FormPrint::update));
113 dialog_->setActiveWindow();
120 void FormPrint::close()
127 void FormPrint::hide()