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 #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 d->showPrint.connect(slot(this, &FormPrint::show));
42 FormPrint::~FormPrint()
48 // we can safely ignore the parameter because we can always update
49 void FormPrint::update(bool)
51 if (!lv_->view()->available())
54 PrinterParams pp(getPrinterParams(lv_->buffer()));
56 dialog_->setTarget(pp.target);
57 dialog_->setPrinter(pp.printer_name.c_str());
58 dialog_->setFile(pp.file_name.c_str());
59 dialog_->setWhichPages(pp.which_pages);
60 dialog_->setReverse(pp.reverse_order);
61 dialog_->setSort(pp.unsorted_copies);
62 dialog_->setCount(pp.count_copies);
64 if (!pp.from_page.empty()) {
65 dialog_->setFrom(pp.from_page.c_str());
67 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 KMsgBox msg(0, _("LyX: Print Error"), message.c_str(), KMsgBox::EXCLAMATION, _("&OK"));
103 msg.setActiveWindow();
109 void FormPrint::show()
112 dialog_ = new PrintDialog(this, 0, _("LyX: Print"));
114 if (!dialog_->isVisible()) {
115 h_ = d_->hideBufferDependent.connect(slot(this, &FormPrint::hide));
116 u_ = d_->updateBufferDependent.connect(slot(this, &FormPrint::update));
120 dialog_->setActiveWindow();
127 void FormPrint::close()
134 void FormPrint::hide()