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 ***************************************************************************/
18 #include "formprintdialog.h"
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;
41 FormPrint::FormPrint(LyXView *v, Dialogs *d)
42 : dialog_(0), lv_(v), d_(d), h_(0), u_(0)
44 // let the dialog be shown
45 // This is a permanent connection so we won't bother
46 // storing a copy because we won't be disconnecting.
47 d->showPrint.connect(slot(this, &FormPrint::show));
50 FormPrint::~FormPrint()
55 // we can safely ignore the parameter because we can always update
56 void FormPrint::update(bool)
58 if (!lv_->view()->available())
61 PrinterParams pp(getPrinterParams(lv_->buffer()));
63 dialog_->setTarget(pp.target);
64 dialog_->setPrinter(pp.printer_name.c_str());
65 dialog_->setFile(pp.file_name.c_str());
66 dialog_->setWhichPages(pp.which_pages);
67 dialog_->setReverse(pp.reverse_order);
68 dialog_->setSort(pp.unsorted_copies);
69 dialog_->setCount(tostr(pp.count_copies).c_str());
71 if (!pp.from_page.empty()) {
72 dialog_->setFrom(pp.from_page.c_str());
74 dialog_->setTo(tostr(pp.to_page).c_str());
83 void FormPrint::print()
85 if (!lv_->view()->available())
91 if (strlen(dialog_->getFrom())) {
92 from = dialog_->getFrom();
93 if (strlen(dialog_->getTo()))
94 to = strToInt(dialog_->getTo());
98 retval = printBuffer(lv_->buffer(), PrinterParams(dialog_->getTarget(),
99 string(dialog_->getPrinter()), string(dialog_->getFile()),
100 dialog_->getWhichPages(), from, to, dialog_->getReverse(),
101 dialog_->getSort(), strToInt(dialog_->getCount())));
104 // FIXME: should have a utility class for this
105 string message(_("An error occured while printing.\n\n"));
106 message += _("Check the parameters are correct.\n");
107 KMsgBox msg(0, _("LyX: Print Error"), message.c_str(), KMsgBox::EXCLAMATION, _("&OK"));
109 msg.setActiveWindow();
114 void FormPrint::show()
117 dialog_ = new FormPrintDialog(this, 0, _("LyX: Print"));
119 if (!dialog_->isVisible()) {
120 h_ = d_->hideBufferDependent.connect(slot(this, &FormPrint::hide));
121 u_ = d_->updateBufferDependent.connect(slot(this, &FormPrint::update));
125 dialog_->setActiveWindow();
131 void FormPrint::close()
137 void FormPrint::hide()