]> git.lyx.org Git - lyx.git/blob - src/frontends/kde/FormPrint.C
Added Ascii export for tabulars + small fixes
[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 "formprintdialog.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 #endif
40
41 FormPrint::FormPrint(LyXView *v, Dialogs *d)
42         : dialog_(0), lv_(v), d_(d), h_(0), u_(0)
43 {
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));
48 }
49
50 FormPrint::~FormPrint()
51 {
52         delete dialog_;
53 }
54
55 void FormPrint::update()
56 {
57         if (!lv_->view()->available())
58                return;
59
60         PrinterParams pp(getPrinterParams(lv_->buffer()));
61
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());
69         
70         if (!pp.from_page.empty()) {
71                 dialog_->setFrom(pp.from_page.c_str());
72                 if (pp.to_page)
73                         dialog_->setTo(tostr(pp.to_page).c_str());
74                 else
75                         dialog_->setTo("");
76         } else {
77                 dialog_->setFrom("");
78                 dialog_->setTo("");
79         }
80 }
81  
82 void FormPrint::print()
83 {
84         if (!lv_->view()->available())
85                return;
86
87         string from;
88         int to(0);
89
90         if (strlen(dialog_->getFrom())) {
91                 from = dialog_->getFrom();
92                 if (strlen(dialog_->getTo()))
93                         to = strToInt(dialog_->getTo());
94         }
95         
96         int retval; 
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())));
101
102         if (!retval) {
103                 // FIXME: should have a utility class for this
104                 string message(_("An error occured while printing.\n\n"));
105                 message += _("Check the parameters are correct.\n");
106                 KMsgBox msg(0, _("LyX: Print Error"), message.c_str(), KMsgBox::EXCLAMATION, _("&OK"));
107                 msg.raise();
108                 msg.setActiveWindow();
109                 msg.show();
110         }
111 }
112
113 void FormPrint::show()
114 {
115         if (!dialog_)
116                 dialog_ = new FormPrintDialog(this, 0, _("LyX: Print"));
117  
118         if (!dialog_->isVisible()) {
119                 h_ = d_->hideBufferDependent.connect(slot(this, &FormPrint::hide));
120                 u_ = d_->updateBufferDependent.connect(slot(this, &FormPrint::update));
121         }
122
123         dialog_->raise();
124         dialog_->setActiveWindow();
125  
126         update();
127         dialog_->show();
128 }
129
130 void FormPrint::close()
131 {
132         h_.disconnect();
133         u_.disconnect();
134 }
135  
136 void FormPrint::hide()
137 {
138         dialog_->hide();
139         close();
140 }