]> git.lyx.org Git - lyx.git/blob - src/frontends/kde/FormPrint.C
Angus's FormInset work; Dekel's languages patch; my reworking of Angus's stuff +...
[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 // we can safely ignore the parameter because we can always update
56 void FormPrint::update(bool)
57 {
58         if (!lv_->view()->available())
59                return;
60
61         PrinterParams pp(getPrinterParams(lv_->buffer()));
62
63         dialog_->setTarget(pp.target);
64         dialog_->setPrinter(pp.printer_name.c_str());
65         dialog_->setFile(pp.file_name.c_str());
66         dialog_->setWhichPages(pp.which_pages);
67         dialog_->setReverse(pp.reverse_order);
68         dialog_->setSort(pp.unsorted_copies);
69         dialog_->setCount(tostr(pp.count_copies).c_str());
70         
71         if (!pp.from_page.empty()) {
72                 dialog_->setFrom(pp.from_page.c_str());
73                 if (pp.to_page)
74                         dialog_->setTo(tostr(pp.to_page).c_str());
75                 else
76                         dialog_->setTo("");
77         } else {
78                 dialog_->setFrom("");
79                 dialog_->setTo("");
80         }
81 }
82  
83 void FormPrint::print()
84 {
85         if (!lv_->view()->available())
86                return;
87
88         string from;
89         int to(0);
90
91         if (strlen(dialog_->getFrom())) {
92                 from = dialog_->getFrom();
93                 if (strlen(dialog_->getTo()))
94                         to = strToInt(dialog_->getTo());
95         }
96         
97         int retval; 
98         retval = printBuffer(lv_->buffer(), PrinterParams(dialog_->getTarget(),
99                 string(dialog_->getPrinter()), string(dialog_->getFile()), 
100                 dialog_->getWhichPages(), from, to, dialog_->getReverse(), 
101                 dialog_->getSort(), strToInt(dialog_->getCount())));
102
103         if (!retval) {
104                 // FIXME: should have a utility class for this
105                 string message(_("An error occured while printing.\n\n"));
106                 message += _("Check the parameters are correct.\n");
107                 KMsgBox msg(0, _("LyX: Print Error"), message.c_str(), KMsgBox::EXCLAMATION, _("&OK"));
108                 msg.raise();
109                 msg.setActiveWindow();
110                 msg.show();
111         }
112 }
113
114 void FormPrint::show()
115 {
116         if (!dialog_)
117                 dialog_ = new FormPrintDialog(this, 0, _("LyX: Print"));
118  
119         if (!dialog_->isVisible()) {
120                 h_ = d_->hideBufferDependent.connect(slot(this, &FormPrint::hide));
121                 u_ = d_->updateBufferDependent.connect(slot(this, &FormPrint::update));
122         }
123
124         dialog_->raise();
125         dialog_->setActiveWindow();
126  
127         update();
128         dialog_->show();
129 }
130
131 void FormPrint::close()
132 {
133         h_.disconnect();
134         u_.disconnect();
135 }
136  
137 void FormPrint::hide()
138 {
139         dialog_->hide();
140         close();
141 }