]> git.lyx.org Git - lyx.git/blob - src/frontends/qt2/FormPrint.C
John's FormExternal patch, Edwin's Qt2 patch and Baruch's gnome patch.
[lyx.git] / src / frontends / qt2 / FormPrint.C
1 /**
2  * \file FormPrint.C
3  * Copyright 2001 LyX Team
4  * see the file COPYING
5  *
6  * \author John Levon, moz@compsoc.man.ac.uk
7  */
8
9 #include <config.h>
10
11 #include "printdlgimpl.h"
12 #include "FormPrint.h"
13 #include "Dialogs.h"
14 #include "gettext.h"
15 #include "buffer.h"
16 #include "lyxrc.h" 
17 #include "QtLyXView.h" 
18
19 #include "PrinterParams.h" 
20 #include "Liason.h" 
21 #include "BufferView.h" 
22 #include "support/lstrings.h"
23 #include "qmessagebox.h"
24
25 #ifdef SIGC_CXX_NAMESPACES
26 using SigC::slot;
27 #endif
28
29 #ifdef CXX_WORKING_NAMESPACES
30 using Liason::printBuffer;
31 using Liason::getPrinterParams;
32 using std::max;
33 #endif
34
35 FormPrint::FormPrint(LyXView *v, Dialogs *d)
36         : dialog_(0), lv_(v), d_(d), h_(0), u_(0)
37 {
38         // let the dialog be shown
39         // This is a permanent connection so we won't bother
40         // storing a copy because we won't be disconnecting.
41         d->showPrint.connect(slot(this, &FormPrint::show));
42 }
43
44 FormPrint::~FormPrint()
45 {
46         delete dialog_;
47 }
48
49 // we can safely ignore the parameter because we can always update
50 void FormPrint::update(bool)
51 {
52         if (!lv_->view()->available())
53                return;
54
55         PrinterParams pp(getPrinterParams(lv_->buffer()));
56
57         dialog_->setTarget(pp.target);
58         dialog_->setPrinter(pp.printer_name.c_str());
59         dialog_->setFile(pp.file_name.c_str());
60         dialog_->setWhichPages(pp.which_pages);
61         dialog_->setReverse(pp.reverse_order);
62         dialog_->setSort(pp.unsorted_copies);
63         dialog_->setCount(pp.count_copies);
64         
65         if (!pp.from_page.empty()) {
66                 dialog_->setFrom(pp.from_page.c_str());
67                 if (pp.to_page)
68                         dialog_->setTo(tostr(pp.to_page).c_str());
69                 else
70                         dialog_->setTo("");
71         } else {
72                 dialog_->setFrom("");
73                 dialog_->setTo("");
74         }
75 }
76  
77 void FormPrint::print()
78 {
79         if (!lv_->view()->available())
80                return;
81
82         string from;
83         int to(0);
84
85         if (strlen(dialog_->getFrom())) {
86                 from = dialog_->getFrom();
87                 if (strlen(dialog_->getTo()))
88                         to = strToInt(dialog_->getTo());
89         }
90         
91         int retval; 
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)));
96
97         if (!retval) {
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                 QMessageBox msg( _("LyX: Print Error"), message.c_str(), QMessageBox::Warning, 1,0,0);
102                 msg.raise();
103                 msg.setActiveWindow();
104                 msg.show();
105         }
106 }
107
108 void FormPrint::show()
109 {
110         if (!dialog_)
111                 dialog_ = new PrintDlgImpl(this, 0, _("LyX: Print"));
112  
113         if (!dialog_->isVisible()) {
114                 h_ = d_->hideBufferDependent.connect(slot(this, &FormPrint::hide));
115                 u_ = d_->updateBufferDependent.connect(slot(this, &FormPrint::update));
116         }
117
118         dialog_->raise();
119         dialog_->setActiveWindow();
120  
121         update();
122         dialog_->show();
123 }
124
125 void FormPrint::close()
126 {
127         h_.disconnect();
128         u_.disconnect();
129 }
130  
131 void FormPrint::hide()
132 {
133         dialog_->hide();
134         close();
135 }