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 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 // let the dialog be shown
33 // This is a permanent connection so we won't bother
34 // storing a copy because we won't be disconnecting.
35 d->showPrint.connect(SigC::slot(this, &FormPrint::show));
38 FormPrint::~FormPrint()
43 // we can safely ignore the parameter because we can always update
44 void FormPrint::update(bool)
46 if (!lv_->view()->available())
49 PrinterParams pp(getPrinterParams(lv_->buffer()));
51 dialog_->setTarget(pp.target);
52 dialog_->setPrinter(pp.printer_name.c_str());
53 dialog_->setFile(pp.file_name.c_str());
54 dialog_->setWhichPages(pp.which_pages);
55 dialog_->setReverse(pp.reverse_order);
56 dialog_->setSort(pp.unsorted_copies);
57 dialog_->setCount(pp.count_copies);
59 if (!pp.from_page.empty()) {
60 dialog_->setFrom(pp.from_page.c_str());
62 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 QMessageBox msg( _("LyX: Print Error"), message.c_str(), QMessageBox::Warning, 1,0,0);
96 msg.setActiveWindow();
101 void FormPrint::show()
104 dialog_ = new PrintDlgImpl(this, 0, _("LyX: Print"));
106 if (!dialog_->isVisible()) {
107 h_ = d_->hideBufferDependent.connect(SigC::slot(this, &FormPrint::hide));
108 u_ = d_->updateBufferDependent.connect(SigC::slot(this, &FormPrint::update));
112 dialog_->setActiveWindow();
118 void FormPrint::close()
124 void FormPrint::hide()