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 void FormPrint::update()
57 if (!lv_->view()->available())
60 PrinterParams pp(getPrinterParams(lv_->buffer()));
62 dialog_->setTarget(pp.target);
63 dialog_->setPrinter(pp.printer_name.c_str());
64 dialog_->setFile(pp.file_name.c_str());
65 dialog_->setWhichPages(pp.which_pages);
66 dialog_->setReverse(pp.reverse_order);
67 dialog_->setSort(pp.unsorted_copies);
68 dialog_->setCount(tostr(pp.count_copies).c_str());
70 if (!pp.from_page.empty()) {
71 dialog_->setFrom(pp.from_page.c_str());
73 dialog_->setTo(tostr(pp.to_page).c_str());
82 void FormPrint::print()
84 if (!lv_->view()->available())
90 if (strlen(dialog_->getFrom())) {
91 from = dialog_->getFrom();
92 if (strlen(dialog_->getTo()))
93 to = strToInt(dialog_->getTo());
97 retval = printBuffer(lv_->buffer(), PrinterParams(dialog_->getTarget(),
98 string(dialog_->getPrinter()), string(dialog_->getFile()),
99 dialog_->getWhichPages(), from, to, dialog_->getReverse(),
100 dialog_->getSort(), strToInt(dialog_->getCount())));
103 // FIXME: should have a utility class for this
104 string message(_("The error :\n\n"));
105 message += strerror(retval);
106 message += _("\n\noccurred while printing.\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 FormPrintDialog(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()