]> git.lyx.org Git - lyx.git/blob - src/frontends/qt2/FormPrint.C
implement getLabelList
[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 using Liason::printBuffer;
26 using Liason::getPrinterParams;
27 using std::max;
28
29 FormPrint::FormPrint(LyXView *v, Dialogs *d)
30         : dialog_(0), lv_(v), d_(d), h_(0), u_(0)
31 {
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));
36 }
37
38 FormPrint::~FormPrint()
39 {
40         delete dialog_;
41 }
42
43 // we can safely ignore the parameter because we can always update
44 void FormPrint::update(bool)
45 {
46         if (!lv_->view()->available())
47                return;
48
49         PrinterParams pp(getPrinterParams(lv_->buffer()));
50
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);
58         
59         if (!pp.from_page.empty()) {
60                 dialog_->setFrom(pp.from_page.c_str());
61                 if (pp.to_page)
62                         dialog_->setTo(tostr(pp.to_page).c_str());
63                 else
64                         dialog_->setTo("");
65         } else {
66                 dialog_->setFrom("");
67                 dialog_->setTo("");
68         }
69 }
70  
71 void FormPrint::print()
72 {
73         if (!lv_->view()->available())
74                return;
75
76         string from;
77         int to(0);
78
79         if (strlen(dialog_->getFrom())) {
80                 from = dialog_->getFrom();
81                 if (strlen(dialog_->getTo()))
82                         to = strToInt(dialog_->getTo());
83         }
84         
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)));
89
90         if (!retval) {
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);
95                 msg.raise();
96                 msg.setActiveWindow();
97                 msg.show();
98         }
99 }
100
101 void FormPrint::show()
102 {
103         if (!dialog_)
104                 dialog_ = new PrintDlgImpl(this, 0, _("LyX: Print"));
105  
106         if (!dialog_->isVisible()) {
107                 h_ = d_->hideBufferDependent.connect(SigC::slot(this, &FormPrint::hide));
108                 u_ = d_->updateBufferDependent.connect(SigC::slot(this, &FormPrint::update));
109         }
110
111         dialog_->raise();
112         dialog_->setActiveWindow();
113  
114         update();
115         dialog_->show();
116 }
117
118 void FormPrint::close()
119 {
120         h_.disconnect();
121         u_.disconnect();
122 }
123  
124 void FormPrint::hide()
125 {
126         dialog_->hide();
127         close();
128 }