]> git.lyx.org Git - lyx.git/blob - src/frontends/kde/FormPrint.C
More preference work from Angus
[lyx.git] / src / frontends / kde / FormPrint.C
1 /*
2  * FormPrint.C
3  * (C) 2000 LyX Team
4  * John Levon, moz@compsoc.man.ac.uk
5  */
6  
7 /***************************************************************************
8  *                                                                         *
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.                                   *
13  *                                                                         *
14  ***************************************************************************/
15
16 #include <config.h>
17
18 #include "printdlg.h"
19 #include "Dialogs.h"
20 #include "FormPrint.h"
21 #include "gettext.h"
22 #include "buffer.h"
23 #include "lyxrc.h" 
24 #include "QtLyXView.h"
25 #include "PrinterParams.h" 
26 #include "Liason.h" 
27 #include "BufferView.h" 
28 #include "support/lstrings.h"
29
30 #include <kmsgbox.h>
31
32 #ifdef SIGC_CXX_NAMESPACES
33 using SigC::slot;
34 #endif
35
36 #ifdef CXX_WORKING_NAMESPACES
37 using Liason::printBuffer;
38 using Liason::getPrinterParams;
39 using std::max;
40 #endif
41
42 FormPrint::FormPrint(LyXView *v, Dialogs *d)
43         : dialog_(0), lv_(v), d_(d), h_(0), u_(0)
44 {
45         // let the dialog be shown
46         // This is a permanent connection so we won't bother
47         // storing a copy because we won't be disconnecting.
48         d->showPrint.connect(slot(this, &FormPrint::show));
49 }
50
51 FormPrint::~FormPrint()
52 {
53         delete dialog_;
54 }
55
56 // we can safely ignore the parameter because we can always update
57 void FormPrint::update(bool)
58 {
59         if (!lv_->view()->available())
60                return;
61
62         PrinterParams pp(getPrinterParams(lv_->buffer()));
63
64         dialog_->setTarget(pp.target);
65         dialog_->setPrinter(pp.printer_name.c_str());
66         dialog_->setFile(pp.file_name.c_str());
67         dialog_->setWhichPages(pp.which_pages);
68         dialog_->setReverse(pp.reverse_order);
69         dialog_->setSort(pp.unsorted_copies);
70         dialog_->setCount(pp.count_copies);
71         
72         if (!pp.from_page.empty()) {
73                 dialog_->setFrom(pp.from_page.c_str());
74                 if (pp.to_page)
75                         dialog_->setTo(tostr(pp.to_page).c_str());
76                 else
77                         dialog_->setTo("");
78         } else {
79                 dialog_->setFrom("");
80                 dialog_->setTo("");
81         }
82 }
83  
84 void FormPrint::print()
85 {
86         if (!lv_->view()->available())
87                return;
88
89         string from;
90         int to(0);
91
92         if (strlen(dialog_->getFrom())) {
93                 from = dialog_->getFrom();
94                 if (strlen(dialog_->getTo()))
95                         to = strToInt(dialog_->getTo());
96         }
97         
98         int retval; 
99         retval = printBuffer(lv_->buffer(), PrinterParams(dialog_->getTarget(),
100                 string(dialog_->getPrinter()), string(dialog_->getFile()), 
101                 dialog_->getWhichPages(), from, to, dialog_->getReverse(), 
102                 dialog_->getSort(), max(strToInt(dialog_->getCount()),1)));
103
104         if (!retval) {
105                 // FIXME: should have a utility class for this
106                 string message(_("An error occured while printing.\n\n"));
107                 message += _("Check the parameters are correct.\n");
108                 KMsgBox msg(0, _("LyX: Print Error"), message.c_str(), KMsgBox::EXCLAMATION, _("&OK"));
109                 msg.raise();
110                 msg.setActiveWindow();
111                 msg.show();
112         }
113 }
114
115 void FormPrint::show()
116 {
117         if (!dialog_)
118                 dialog_ = new PrintDialog(this, 0, _("LyX: Print"));
119  
120         if (!dialog_->isVisible()) {
121                 h_ = d_->hideBufferDependent.connect(slot(this, &FormPrint::hide));
122                 u_ = d_->updateBufferDependent.connect(slot(this, &FormPrint::update));
123         }
124
125         dialog_->raise();
126         dialog_->setActiveWindow();
127  
128         update();
129         dialog_->show();
130 }
131
132 void FormPrint::close()
133 {
134         h_.disconnect();
135         u_.disconnect();
136 }
137  
138 void FormPrint::hide()
139 {
140         dialog_->hide();
141         close();
142 }