4 * John Levon, moz@compsoc.man.ac.uk
7 /***************************************************************************
9 * This program is free software; you can redistribute it and/or modify *
10 * it under the terms of the GNU General Public License as published by *
11 * the Free Software Foundation; either version 2 of the License, or *
12 * (at your option) any later version. *
14 ***************************************************************************/
20 #include "FormPrint.h"
24 #include "QtLyXView.h"
25 #include "PrinterParams.h"
27 #include "BufferView.h"
28 #include "support/lstrings.h"
32 #ifdef SIGC_CXX_NAMESPACES
36 #ifdef CXX_WORKING_NAMESPACES
37 using Liason::printBuffer;
38 using Liason::getPrinterParams;
42 FormPrint::FormPrint(LyXView *v, Dialogs *d)
43 : dialog_(0), lv_(v), d_(d), h_(0), u_(0)
45 // let the dialog be shown
46 // This is a permanent connection so we won't bother
47 // storing a copy because we won't be disconnecting.
48 d->showPrint.connect(slot(this, &FormPrint::show));
51 FormPrint::~FormPrint()
56 // we can safely ignore the parameter because we can always update
57 void FormPrint::update(bool)
59 if (!lv_->view()->available())
62 PrinterParams pp(getPrinterParams(lv_->buffer()));
64 dialog_->setTarget(pp.target);
65 dialog_->setPrinter(pp.printer_name.c_str());
66 dialog_->setFile(pp.file_name.c_str());
67 dialog_->setWhichPages(pp.which_pages);
68 dialog_->setReverse(pp.reverse_order);
69 dialog_->setSort(pp.unsorted_copies);
70 dialog_->setCount(pp.count_copies);
72 if (!pp.from_page.empty()) {
73 dialog_->setFrom(pp.from_page.c_str());
75 dialog_->setTo(tostr(pp.to_page).c_str());
84 void FormPrint::print()
86 if (!lv_->view()->available())
92 if (strlen(dialog_->getFrom())) {
93 from = dialog_->getFrom();
94 if (strlen(dialog_->getTo()))
95 to = strToInt(dialog_->getTo());
99 retval = printBuffer(lv_->buffer(), PrinterParams(dialog_->getTarget(),
100 string(dialog_->getPrinter()), string(dialog_->getFile()),
101 dialog_->getWhichPages(), from, to, dialog_->getReverse(),
102 dialog_->getSort(), max(strToInt(dialog_->getCount()),1)));
105 // FIXME: should have a utility class for this
106 string message(_("An error occured while printing.\n\n"));
107 message += _("Check the parameters are correct.\n");
108 KMsgBox msg(0, _("LyX: Print Error"), message.c_str(), KMsgBox::EXCLAMATION, _("&OK"));
110 msg.setActiveWindow();
115 void FormPrint::show()
118 dialog_ = new PrintDialog(this, 0, _("LyX: Print"));
120 if (!dialog_->isVisible()) {
121 h_ = d_->hideBufferDependent.connect(slot(this, &FormPrint::hide));
122 u_ = d_->updateBufferDependent.connect(slot(this, &FormPrint::update));
126 dialog_->setActiveWindow();
132 void FormPrint::close()
138 void FormPrint::hide()