]> git.lyx.org Git - lyx.git/blob - src/frontends/kde/FormPrint.C
small cleanup, doxygen, formatting changes
[lyx.git] / src / frontends / kde / FormPrint.C
1 /**
2  * \file FormPrint.C
3  * Copyright 2001 the LyX Team
4  * Read the file COPYING
5  *
6  * \author John Levon
7  */
8
9 #include <config.h>
10
11 #include "printdlg.h"
12 #include "Dialogs.h"
13 #include "FormPrint.h"
14 #include "gettext.h"
15 #include "buffer.h"
16 #include "lyxrc.h" 
17 #include "QtLyXView.h"
18 #include "PrinterParams.h" 
19 #include "Liason.h" 
20 #include "BufferView.h" 
21 #include "support/lstrings.h"
22
23 #include <kmsgbox.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         d->showPrint.connect(slot(this, &FormPrint::show));
39 }
40
41
42 FormPrint::~FormPrint()
43 {
44         delete dialog_;
45 }
46
47
48 // we can safely ignore the parameter because we can always update
49 void FormPrint::update(bool)
50 {
51         if (!lv_->view()->available())
52                return;
53
54         PrinterParams pp(getPrinterParams(lv_->buffer()));
55
56         dialog_->setTarget(pp.target);
57         dialog_->setPrinter(pp.printer_name.c_str());
58         dialog_->setFile(pp.file_name.c_str());
59         dialog_->setWhichPages(pp.which_pages);
60         dialog_->setReverse(pp.reverse_order);
61         dialog_->setSort(pp.unsorted_copies);
62         dialog_->setCount(pp.count_copies);
63         
64         if (!pp.from_page.empty()) {
65                 dialog_->setFrom(pp.from_page.c_str());
66                 if (pp.to_page)
67                         dialog_->setTo(tostr(pp.to_page).c_str());
68                 else
69                         dialog_->setTo("");
70         } else {
71                 dialog_->setFrom("");
72                 dialog_->setTo("");
73         }
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                 KMsgBox msg(0, _("LyX: Print Error"), message.c_str(), KMsgBox::EXCLAMATION, _("&OK"));
102                 msg.raise();
103                 msg.setActiveWindow();
104                 msg.show();
105         }
106 }
107
108
109 void FormPrint::show()
110 {
111         if (!dialog_)
112                 dialog_ = new PrintDialog(this, 0, _("LyX: Print"));
113  
114         if (!dialog_->isVisible()) {
115                 h_ = d_->hideBufferDependent.connect(slot(this, &FormPrint::hide));
116                 u_ = d_->updateBufferDependent.connect(slot(this, &FormPrint::update));
117         }
118
119         dialog_->raise();
120         dialog_->setActiveWindow();
121  
122         update();
123         dialog_->show();
124 }
125
126
127 void FormPrint::close()
128 {
129         h_.disconnect();
130         u_.disconnect();
131 }
132
133  
134 void FormPrint::hide()
135 {
136         dialog_->hide();
137         close();
138 }