• Skip to content
  • Skip to link menu
Trinity API Reference
  • Trinity API Reference
  • tdeprint
 

tdeprint

  • tdeprint
kprintdialog.cpp
1/*
2 * This file is part of the KDE libraries
3 * Copyright (c) 2001 Michael Goffioul <tdeprint@swing.be>
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public
7 * License version 2 as published by the Free Software Foundation.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
13 *
14 * You should have received a copy of the GNU Library General Public License
15 * along with this library; see the file COPYING.LIB. If not, write to
16 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
18 **/
19
20/*
21 * "WhatsThis" help items added by Kurt Pfeifle, August 2003,
22 * same copyright as above.
23 **/
24
25#include "kprintdialog.h"
26#include "kprinter.h"
27#include "kprinterimpl.h"
28#include "kmfactory.h"
29#include "kmuimanager.h"
30#include "kmmanager.h"
31#include "kmprinter.h"
32#include "kmvirtualmanager.h"
33#include "kprintdialogpage.h"
34#include "kprinterpropertydialog.h"
35#include "plugincombobox.h"
36#include "kpcopiespage.h"
37#include "treecombobox.h"
38#include "messagewindow.h"
39
40#include <tqgroupbox.h>
41#include <tqcheckbox.h>
42#include <kpushbutton.h>
43#include <tqlabel.h>
44#include <tqcombobox.h>
45#include <tqtabwidget.h>
46#include <tqvbox.h>
47#include <tqlayout.h>
48#include <tqregexp.h>
49#include <tdemessagebox.h>
50#include <tqdir.h>
51#include <tqtooltip.h>
52#include <tqwhatsthis.h>
53
54#include <tdelocale.h>
55#include <kiconloader.h>
56#include <tdefiledialog.h>
57#include <kurlrequester.h>
58#include <klineedit.h>
59#include <kdebug.h>
60#include <tdeglobal.h>
61#include <tdeconfig.h>
62#include <kguiitem.h>
63#include <kstdguiitem.h>
64#include <tdeapplication.h>
65#include <tdeio/renamedlg.h>
66
67#include <time.h>
68
69#define SHOWHIDE(widget,on) if (on) widget->show(); else widget->hide();
70
71class KPrintDialog::KPrintDialogPrivate
72{
73public:
74 TQLabel *m_type, *m_state, *m_comment, *m_location, *m_cmdlabel, *m_filelabel;
75 KPushButton *m_properties, *m_default, *m_options, *m_ok, *m_extbtn;
76 TQPushButton *m_wizard, *m_filter;
77 TQCheckBox *m_preview;
78 TQLineEdit *m_cmd;
79 TreeComboBox *m_printers;
80 TQVBox *m_dummy;
81 PluginComboBox *m_plugin;
82 KURLRequester *m_file;
83 TQCheckBox *m_persistent;
84 bool m_reduced;
85
86 TQPtrList<KPrintDialogPage> m_pages;
87 KPrinter *m_printer;
88 bool b_optionsEnabled;
89 bool b_propertiesEnabled;
90 bool b_systemEnabled;
91};
92
93KPrintDialog::KPrintDialog(TQWidget *parent, const char *name)
94: KDialog(parent,name,true)
95{
96 //WhatsThis strings.... (added by pfeifle@kde.org)
97 TQString whatsThisLocationLabel = i18n( " <qt><b>Printer Location:</b> The <em>Location</em> may describe where the"
98 " selected printer is located. The Location description is created"
99 " by the administrator of the print system (or may be"
100 " left empty)."
101 " </qt>" );
102 TQString whatsThisPrinterType = i18n( " <qt><b>Printer Type:</b> The <em>Type</em> indicates your printer type."
103 " </qt>" );
104 TQString whatsThisPrinterState = i18n( " <qt><b>Printer State:</b> The <em>State</em> indicates the state of the"
105 " print queue on the print server (which could be your localhost). The"
106 " state may be 'Idle', 'Processing', 'Stopped', 'Paused' or similar."
107 " </qt>" );
108 TQString whatsThisPrinterComment = i18n( " <qt><b>Printer Comment:</b> The <em>Comment</em> may describe the selected"
109 " printer. This comment is created by the administrator"
110 " of the print system (or may be left empty)."
111 " </qt>" );
112 TQString whatsThisPrinterSelect = i18n( " <qt><b>Printer Selection Menu:</b> "
113 " <p>Use this combo box to select the printer to which you want to print."
114 " Initially (if you run TDEPrint for the first time), you may only find the "
115 " <em>TDE special printers</em> (which save"
116 " jobs to disk [as PostScript- or PDF-files], or deliver jobs via"
117 " email (as a PDF"
118 " attachment). If you are missing a real printer, you need to..."
119 " <ul>"
120 " <li>...either create a local printer with the help of the <em>TDE Add"
121 " Printer Wizard</em>. The Wizard is available for the CUPS and RLPR printing"
122 " systems (click button to the left of the <em>'Properties'</em> button),</li>"
123 " <li>...or try to connect to an existing remote"
124 " CUPS print server. You can connect by clicking the <em>'System Options'</em> button"
125 " below. A new dialog opens: click on the <em>'CUPS server'</em>"
126 " icon: Fill in the information required to use the remote"
127 " server. </li> "
128 " </ul>"
129 " <p><b>Note:</b> It may happen that you successfully connected to a remote CUPS "
130 " server and still do not get a printer list. If this happens: force TDEPrint to "
131 " re-load its configuration files."
132 " To reload the configuration files, either start kprinter again, or use the "
133 " switch the print system away from CUPS and back again once. The print system switch "
134 " can be made through a selection in the drop-down menu at bottom of this dialog when "
135 " fully expanded). </p> "
136 " </qt>" );
137 TQString whatsThisPrintJobProperties = i18n( " <qt><b>Print Job Properties:</b> "
138 " <p>This button opens a dialog where you can make decisions"
139 " regarding all supported print job options."
140 " </qt>" );
141 TQString whatsThisPrinterFilter = i18n( " <qt><b>Selective View on List of Printers:</b>"
142 " <p> This button reduces the list of visible printers"
143 " to a shorter, more convenient, pre-defined list.</p>"
144 " <p>This is particularly useful in enterprise environments"
145 " with lots of printers. The default is to show <b>all</b> printers.</p>"
146 " <p>To create a personal <em>'selective view list'</em>, click on the"
147 " <em>'System Options'</em> button at the bottom of this dialog."
148 " Then, in the new dialog, select <em>'Filter'</em> (left column in the"
149 " <em>TDE Print Configuration</em> dialog) and setup your selection..</p>"
150 " <p><b>Warning:</b> Clicking this button without prior creation of a personal "
151 " <em>'selective view list'</em> will make all printers dissappear from the "
152 " view. (To re-enable all printers, just click this button again.) </p> "
153 " </qt>" );
154 TQString whatsThisAddPrinterWizard = i18n( "<qt><b>TDE Add Printer Wizard</b>"
155 " <p>This button starts the <em>TDE Add Printer Wizard</em>.</p>"
156 " <p>Use the Wizard (with <em>\"CUPS\"</em> or <em>\"RLPR\"</em>) to add locally"
157 " defined printers to your system. </p>"
158 " <p><b>Note:</b> The <em>TDE Add Printer Wizard</em> does <b>not</b> work, "
159 " and this button is disabled if you use "
160 " <em>\"Generic LPD</em>\", <em>\"LPRng\"</em>, or <em>\"Print Through "
161 " an External Program</em>\".) </p> "
162 " </qt>" );
163 TQString whatsThisExternalPrintCommand = i18n( " <qt><b>External Print Command</b>"
164 " <p>Here you can enter any command that would also print for you in "
165 " a <em>konsole</em> window. </p>"
166 " <b>Example:</b> <pre>a2ps -P &lt;printername&gt; --medium=A3</pre>."
167 " </qt>" );
168 TQString whatsThisOptions = i18n( " <qt><b>Additional Print Job Options</b>"
169 " <p>This button shows or hides additional printing options.</qt>" );
170 TQString whatsThisSystemOptions = i18n( " <qt><b>System Options:</b> "
171 " <p>This button starts a new dialog where you can adjust various"
172 " settings of your printing system. Amongst them:"
173 " <ul><li> Should \tDE"
174 " applications embed all fonts into the PostScript they"
175 " generate for printing?"
176 " <li> Should TDE use an external PostScript viewer"
177 " like <em>gv</em> for print page previews?"
178 " <li> Should TDEPrint use a local or a remote CUPS server?,"
179 " </ul> and many more.... "
180 " </qt>" );
181
182 TQString whatsThisHelpButton = i18n( " <qt><b>Help:</b> This button takes you to the complete <em>TDEPrint"
183 " Manual</em>."
184 " </qt>" );
185
186 TQString whatsThisCancelButton = i18n( " <qt><b>Cancel:</b> This button cancels your print job and quits the"
187 " kprinter dialog."
188 " </qt>" );
189
190 TQString whatsThisPrintButton = i18n( " <qt><b>Print:</b> This button sends the job to the printing process."
191 " If you are sending non-PostScript files, you may be"
192 " asked if you want TDE to convert the files into PostScript,"
193 " or if you want your print subsystem (like CUPS) to do this."
194 " </qt>" );
195
196 TQString whatsThisKeepDialogOpenCheckbox = i18n( " <qt><b>Keep Printing Dialog Open</b>"
197 "<p>If you enable this checkbox, the printing dialog"
198 " stays open after you hit the <em>Print</em> button.</p>"
199 " <p> This is"
200 " especially useful, if you need to test various"
201 " print settings (like color matching for an inkjet printer)"
202 " or if you want to send your job to multiple printers (one after"
203 " the other) to have it finished more quickly.</p>"
204 " </qt>" );
205
206 TQString whatsThisOutputFileLabel = i18n(" <qt><b>Output File Name and Path:</b> The \"Output file:\" shows "
207 " you where your file will be"
208 " saved if you decide to \"Print to File\" your job, using one of the"
209 " TDE <em>Special Printers</em> named \"Print to File (PostScript)\""
210 " or \"Print to File (PDF)\". Choose a name and location that suits"
211 " your need by using the button and/or editing the line on the right."
212 " </qt>" );
213
214 TQString whatsThisOutputFileLineedit = i18n(" <qt><b>Output File Name and Path:</b> Edit this line to create a "
215 " path and filename that suits your needs."
216 " (Button and Lineedit field are only available if you \"Print to File\")"
217 " </qt>" );
218
219 TQString whatsThisOutputFileButton = i18n(" <qt><b>Browse Directories button:<b> This button calls "
220 " the \"File Open / Browsed Directories\" dialog to let you"
221 " choose a directory and file name where your \"Print-to-File\""
222 " job should be saved."
223 " </qt>" );
224
225 TQString whatsThisAddFileButton = i18n( " <qt><b>Add File to Job</b>"
226 " <p>This button calls the \"File Open / Browse Directories\" dialog to allow you"
227 " to select a file for printing. Note, that "
228 " <ul><li>you can select ASCII or International Text, PDF,"
229 " PostScript, JPEG, TIFF, PNG, GIF and many other graphical"
230 " formats."
231 " <li>you can select various files from different paths"
232 " and send them as one \"multi-file job\" to the printing"
233 " system."
234 " </ul>"
235 " </qt>" );
236
237 TQString whatsThisPreviewCheckBox = i18n(" <qt><b>Print Preview</b>"
238 " Enable this checkbox if you want to see a preview of"
239 " your printout. A preview lets you check if, for instance,"
240 " your intended \"poster\" or \"pamphlet\" layout"
241 " looks like you expected, without wasting paper first. It"
242 " also lets you cancel the job if something looks wrong. "
243 " <p><b>Note:</b> The preview feature (and therefore this checkbox) "
244 " is only visible for printjobs created from inside TDE applications. "
245 " If you start kprinter from the commandline, or if you use kprinter "
246 " as a print command for non-TDE applications (like Acrobat Reader, "
247 " Firefox or OpenOffice), print preview is not available here. "
248 " </qt>" );
249
250 TQString whatsThisSetDefaultPrinter = i18n(" <qt><b>Set as Default Printer</b>"
251 " This button sets the current printer as the user's"
252 " default. "
253 " <p><b>Note:</b> (Button is only visible if the checkbox for "
254 " <em>System Options</em>"
255 " --> <em>General</em> --> <em>Miscellaneous</em>: <em>\"Defaults"
256 " to the last printer used in the application\"</em> is disabled.)"
257 " </qt>" );
258 d = new KPrintDialogPrivate;
259
260 d->m_pages.setAutoDelete(false);
261 d->m_printer = 0;
262 setCaption(i18n("Print"));
263
264 // widget creation
265 TQGroupBox *m_pbox = new TQGroupBox(0,TQt::Vertical,i18n("Printer"), this);
266 d->m_type = new TQLabel(m_pbox);
267 TQWhatsThis::add(d->m_type, whatsThisPrinterType);
268 d->m_state = new TQLabel(m_pbox);
269 TQWhatsThis::add(d->m_state, whatsThisPrinterState);
270 d->m_comment = new TQLabel(m_pbox);
271 TQWhatsThis::add(d->m_comment, whatsThisPrinterComment);
272 d->m_location = new TQLabel(m_pbox);
273 TQWhatsThis::add(d->m_location, whatsThisLocationLabel);
274
275 d->m_printers = new TreeComboBox(m_pbox);
276 TQWhatsThis::add(d->m_printers, whatsThisPrinterSelect);
277 d->m_printers->setMinimumHeight(25);
278 TQLabel *m_printerlabel = new TQLabel(i18n("&Name:"), m_pbox);
279 TQWhatsThis::add(m_printerlabel, whatsThisPrinterSelect);
280 TQLabel *m_statelabel = new TQLabel(i18n("Status", "State:"), m_pbox);
281 TQWhatsThis::add(m_statelabel, whatsThisPrinterState);
282 TQLabel *m_typelabel = new TQLabel(i18n("Type:"), m_pbox);
283 TQWhatsThis::add(m_typelabel, whatsThisPrinterType);
284 TQLabel *m_locationlabel = new TQLabel(i18n("Location:"), m_pbox);
285 TQWhatsThis::add(m_locationlabel, whatsThisLocationLabel);
286 TQLabel *m_commentlabel = new TQLabel(i18n("Comment:"), m_pbox);
287 TQWhatsThis::add(m_commentlabel, whatsThisPrinterComment);
288 m_printerlabel->setBuddy(d->m_printers);
289 d->m_properties = new KPushButton(KGuiItem(i18n("P&roperties"), "edit"), m_pbox);
290 TQWhatsThis::add( d->m_properties, whatsThisPrintJobProperties);
291 d->m_options = new KPushButton(KGuiItem(i18n("System Op&tions"), "tdeprint_configmgr"), this);
292 TQWhatsThis::add(d->m_options,whatsThisSystemOptions);
293 d->m_default = new KPushButton(KGuiItem(i18n("Set as &Default"), "tdeprint_defaultsoft"), m_pbox);
294 TQWhatsThis::add(d->m_default,whatsThisSetDefaultPrinter);
295 d->m_filter = new TQPushButton(m_pbox);
296 d->m_filter->setPixmap(SmallIcon("filter"));
297 d->m_filter->setMinimumSize(TQSize(d->m_printers->minimumHeight(),d->m_printers->minimumHeight()));
298 d->m_filter->setToggleButton(true);
299 d->m_filter->setOn(KMManager::self()->isFilterEnabled());
300 TQToolTip::add(d->m_filter, i18n("Toggle selective view on printer list"));
301 TQWhatsThis::add(d->m_filter, whatsThisPrinterFilter);
302 d->m_wizard = new TQPushButton(m_pbox);
303 d->m_wizard->setPixmap(SmallIcon("wizard"));
304 d->m_wizard->setMinimumSize(TQSize(d->m_printers->minimumHeight(),d->m_printers->minimumHeight()));
305 TQToolTip::add(d->m_wizard, i18n("Add printer..."));
306 TQWhatsThis::add(d->m_wizard, whatsThisAddPrinterWizard);
307 d->m_ok = new KPushButton(KGuiItem(i18n("&Print"), "document-print"), this);
308 TQWhatsThis::add( d->m_ok, whatsThisPrintButton);
309 d->m_ok->setDefault(true);
310 d->m_ok->setEnabled( false );
311 TQPushButton *m_cancel = new KPushButton(KStdGuiItem::cancel(), this);
312 TQWhatsThis::add(m_cancel, whatsThisCancelButton);
313 d->m_preview = new TQCheckBox(i18n("Previe&w"), m_pbox);
314 TQWhatsThis::add(d->m_preview, whatsThisPreviewCheckBox);
315 d->m_filelabel = new TQLabel(i18n("O&utput file:"), m_pbox);
316 TQWhatsThis::add(d->m_filelabel,whatsThisOutputFileLabel);
317 d->m_file = new KURLRequester(TQDir::homeDirPath()+"/print.ps", m_pbox);
318 TQWhatsThis::add(d->m_file,whatsThisOutputFileLineedit);
319 d->m_file->setEnabled(false);
320 d->m_filelabel->setBuddy(d->m_file);
321 d->m_cmdlabel = new TQLabel(i18n("Print co&mmand:"), m_pbox);
322 TQWhatsThis::add( d->m_cmdlabel, whatsThisExternalPrintCommand);
323
324 d->m_cmd = new TQLineEdit(m_pbox);
325 TQWhatsThis::add( d->m_cmd, whatsThisExternalPrintCommand);
326 d->m_cmdlabel->setBuddy(d->m_cmd);
327 d->m_dummy = new TQVBox(this);
328 d->m_plugin = new PluginComboBox(this);
329 d->m_extbtn = new KPushButton(this);
330 TQToolTip::add(d->m_extbtn, i18n("Show/hide advanced options"));
331 TQWhatsThis::add(d->m_extbtn, whatsThisOptions);
332 d->m_persistent = new TQCheckBox(i18n("&Keep this dialog open after printing"), this);
333 TQWhatsThis::add( d->m_persistent, whatsThisKeepDialogOpenCheckbox);
334 TQPushButton *m_help = new KPushButton(KStdGuiItem::help(), this);
335 TQWhatsThis::add( m_help, whatsThisHelpButton);
336
337 TQWidget::setTabOrder( d->m_printers, d->m_filter );
338 TQWidget::setTabOrder( d->m_filter, d->m_wizard );
339 TQWidget::setTabOrder( d->m_wizard, d->m_properties );
340 TQWidget::setTabOrder( d->m_properties, d->m_preview );
341 TQWidget::setTabOrder( d->m_preview, d->m_file );
342 TQWidget::setTabOrder( d->m_file, d->m_cmd );
343 TQWidget::setTabOrder( d->m_plugin, d->m_persistent );
344 TQWidget::setTabOrder( d->m_persistent, d->m_extbtn );
345 TQWidget::setTabOrder( d->m_extbtn, d->m_options );
346 TQWidget::setTabOrder( d->m_options, m_help );
347 TQWidget::setTabOrder( m_help, d->m_ok );
348 TQWidget::setTabOrder( d->m_ok, m_cancel );
349
350 // layout creation
351 TQVBoxLayout *l1 = new TQVBoxLayout(this, 10, 10);
352 l1->addWidget(m_pbox,0);
353 l1->addWidget(d->m_dummy,1);
354 l1->addWidget(d->m_plugin,0);
355 l1->addWidget(d->m_persistent);
356 TQHBoxLayout *l2 = new TQHBoxLayout(0, 0, 10);
357 l1->addLayout(l2);
358 l2->addWidget(d->m_extbtn,0);
359 l2->addWidget(d->m_options,0);
360 l2->addWidget(m_help,0);
361 l2->addStretch(1);
362 l2->addWidget(d->m_ok,0);
363 l2->addWidget(m_cancel,0);
364 TQGridLayout *l3 = new TQGridLayout(m_pbox->layout(),3,3,7);
365 l3->setColStretch(1,1);
366 l3->setRowStretch(0,1);
367 TQGridLayout *l4 = new TQGridLayout(0, 5, 2, 0, 5);
368 l3->addMultiCellLayout(l4,0,0,0,1);
369 l4->addWidget(m_printerlabel,0,0);
370 l4->addWidget(m_statelabel,1,0);
371 l4->addWidget(m_typelabel,2,0);
372 l4->addWidget(m_locationlabel,3,0);
373 l4->addWidget(m_commentlabel,4,0);
374 TQHBoxLayout *ll4 = new TQHBoxLayout(0, 0, 3);
375 l4->addLayout(ll4,0,1);
376 ll4->addWidget(d->m_printers,1);
377 ll4->addWidget(d->m_filter,0);
378 ll4->addWidget(d->m_wizard,0);
379 //l4->addWidget(d->m_printers,0,1);
380 l4->addWidget(d->m_state,1,1);
381 l4->addWidget(d->m_type,2,1);
382 l4->addWidget(d->m_location,3,1);
383 l4->addWidget(d->m_comment,4,1);
384 l4->setColStretch(1,1);
385 TQVBoxLayout *l5 = new TQVBoxLayout(0, 0, 10);
386 l3->addLayout(l5,0,2);
387 l5->addWidget(d->m_properties,0);
388 l5->addWidget(d->m_default,0);
389 l5->addWidget(d->m_preview,0);
390 l5->addStretch(1);
391 //***
392 l3->addWidget(d->m_filelabel,1,0);
393 l3->addWidget(d->m_file,1,1);
394 //***
395 l3->addWidget(d->m_cmdlabel,2,0);
396 l3->addMultiCellWidget(d->m_cmd,2,2,1,2);
397
398 // connections
399 connect(d->m_ok,TQ_SIGNAL(clicked()),TQ_SLOT(accept()));
400 connect(m_cancel,TQ_SIGNAL(clicked()),TQ_SLOT(reject()));
401 connect(d->m_properties,TQ_SIGNAL(clicked()),TQ_SLOT(slotProperties()));
402 connect(d->m_default,TQ_SIGNAL(clicked()),TQ_SLOT(slotSetDefault()));
403 connect(d->m_printers,TQ_SIGNAL(activated(int)),TQ_SLOT(slotPrinterSelected(int)));
404 connect(d->m_options,TQ_SIGNAL(clicked()),TQ_SLOT(slotOptions()));
405 connect(d->m_wizard,TQ_SIGNAL(clicked()),TQ_SLOT(slotWizard()));
406 connect(d->m_extbtn, TQ_SIGNAL(clicked()), TQ_SLOT(slotExtensionClicked()));
407 connect(d->m_filter, TQ_SIGNAL(toggled(bool)), TQ_SLOT(slotToggleFilter(bool)));
408 connect(m_help, TQ_SIGNAL(clicked()), TQ_SLOT(slotHelp()));
409 connect(d->m_file, TQ_SIGNAL(urlSelected(const TQString&)), TQ_SLOT(slotOutputFileSelected(const TQString&)));
410 connect( d->m_file, TQ_SIGNAL( openFileDialog( KURLRequester* ) ), TQ_SLOT( slotOpenFileDialog() ) );
411 connect( KMFactory::self()->manager(), TQ_SIGNAL( updatePossible( bool ) ), TQ_SLOT( slotUpdatePossible( bool ) ) );
412
413 d->b_optionsEnabled = tdeApp->authorize("print/options") && tdeApp->authorize("print/selection");
414 d->b_propertiesEnabled = tdeApp->authorize("print/properties") && tdeApp->authorize("print/selection");
415 d->b_systemEnabled = tdeApp->authorize("print/system") && tdeApp->authorize("print/selection");
416
417 if (!d->b_systemEnabled)
418 {
419 d->m_plugin->hide();
420 }
421
422 if (!d->b_optionsEnabled)
423 {
424 d->m_options->hide();
425 }
426
427 if (!d->b_propertiesEnabled)
428 {
429 d->m_properties->hide();
430 d->m_wizard->hide();
431 }
432
433 if (!tdeApp->authorize("print/selection"))
434 {
435 d->m_extbtn->hide();
436 m_pbox->hide();
437
438 expandDialog(true);
439 }
440 else
441 {
442 TDEConfig *config = TDEGlobal::config();
443 config->setGroup("KPrinter Settings");
444 expandDialog(!config->readBoolEntry("DialogReduced", (KMFactory::self()->settings()->application != KPrinter::StandAlone)));
445 }
446}
447
448KPrintDialog::~KPrintDialog()
449{
450 TDEConfig *config = TDEGlobal::config();
451 config->setGroup("KPrinter Settings");
452 config->writeEntry("DialogReduced", d->m_reduced);
453
454 delete d;
455}
456
457void KPrintDialog::setFlags(int f)
458{
459 SHOWHIDE(d->m_properties, (f & KMUiManager::Properties) && d->b_propertiesEnabled)
460 d->m_default->hide();
461 SHOWHIDE(d->m_default, ((f & KMUiManager::Default) && !KMFactory::self()->printConfig("General")->readBoolEntry("UseLast", true)))
462 SHOWHIDE(d->m_preview, (f & KMUiManager::Preview))
463 bool on = (f & KMUiManager::OutputToFile);
464 SHOWHIDE(d->m_filelabel, on)
465 SHOWHIDE(d->m_file, on)
466 on = (f & KMUiManager::PrintCommand);
467 SHOWHIDE(d->m_cmdlabel, on)
468 SHOWHIDE(d->m_cmd, on)
469 SHOWHIDE(d->m_persistent, (f & KMUiManager::Persistent))
470
471 // also update "wizard" button
472 KMManager *mgr = KMFactory::self()->manager();
473 d->m_wizard->setEnabled((mgr->hasManagement() && (mgr->printerOperationMask() & KMManager::PrinterCreation)));
474}
475
476void KPrintDialog::setDialogPages(TQPtrList<KPrintDialogPage> *pages)
477{
478 if (!pages) return;
479 if (pages->count() + d->m_pages.count() == 1)
480 {
481 // only one page, reparent the page to d->m_dummy and remove any
482 // TQTabWidget child if any.
483 if (pages->count() > 0)
484 d->m_pages.append(pages->take(0));
485 d->m_pages.first()->reparent(d->m_dummy, TQPoint(0,0));
486 d->m_pages.first()->show();
487 delete d->m_dummy->child("TabWidget", "TQTabWidget");
488 }
489 else
490 {
491 // more than one page.
492 TQTabWidget *tabs = static_cast<TQTabWidget*>(d->m_dummy->child("TabWidget", "TQTabWidget"));
493 if (!tabs)
494 {
495 // TQTabWidget doesn't exist. Create it and reparent all
496 // already existing pages.
497 tabs = new TQTabWidget(d->m_dummy, "TabWidget");
498 tabs->setMargin(10);
499 for (d->m_pages.first(); d->m_pages.current(); d->m_pages.next())
500 {
501 tabs->addTab(d->m_pages.current(), d->m_pages.current()->title());
502 }
503 }
504 while (pages->count() > 0)
505 {
506 KPrintDialogPage *page = pages->take(0);
507 d->m_pages.append(page);
508 tabs->addTab(page, page->title());
509 }
510 tabs->show();
511 }
512 d->m_extbtn->setEnabled(d->m_pages.count() > 0);
513}
514
515KPrintDialog* KPrintDialog::printerDialog(KPrinter *printer, TQWidget *parent, const TQString& caption, bool forceExpand)
516{
517 if (printer)
518 {
519 KPrintDialog *dlg = new KPrintDialog(parent);
520 // needs to set the printer before setting up the
521 // print dialog as some additional pages may need it.
522 // Real initialization comes after.
523 dlg->d->m_printer = printer;
524 KMFactory::self()->uiManager()->setupPrintDialog(dlg);
525 dlg->init();
526 if (!caption.isEmpty())
527 dlg->setCaption(caption);
528 if (forceExpand)
529 {
530 // we force the dialog to be expanded:
531 // - expand the dialog
532 // - hide the show/hide button
533 dlg->expandDialog(true);
534 dlg->d->m_extbtn->hide();
535 }
536 return dlg;
537 }
538 return NULL;
539}
540
541void KPrintDialog::initialize(KPrinter *printer)
542{
543 d->m_printer = printer;
544
545 // first retrieve printer list and update combo box (get default or last used printer also)
546 TQPtrList<KMPrinter> *plist = KMFactory::self()->manager()->printerList();
547 if (!KMManager::self()->errorMsg().isEmpty())
548 {
549 KMessageBox::error(parentWidget(),
550 "<qt><nobr>"+
551 i18n("An error occurred while retrieving the printer list:")
552 +"</nobr><br><br>"+KMManager::self()->errorMsg()+"</qt>");
553 }
554
555 if (plist)
556 {
557 TQString oldP = d->m_printers->currentText();
558 d->m_printers->clear();
559 TQPtrListIterator<KMPrinter> it(*plist);
560 int defsoft(-1), defhard(-1), defsearch(-1);
561 bool sep(false);
562 for (;it.current();++it)
563 {
564 // skip invalid printers
565 if ( !it.current()->isValid() )
566 continue;
567
568 if (!sep && it.current()->isSpecial())
569 {
570 sep = true;
571 d->m_printers->insertItem(TQPixmap(), TQString::fromLatin1("--------"));
572 }
573 d->m_printers->insertItem(SmallIcon(it.current()->pixmap(),0,(it.current()->isValid() ? (int)TDEIcon::DefaultState : (int)TDEIcon::LockOverlay)),it.current()->name(),false/*sep*/);
574 if (it.current()->isSoftDefault())
575 defsoft = d->m_printers->count()-1;
576 if (it.current()->isHardDefault())
577 defhard = d->m_printers->count()-1;
578 if (!oldP.isEmpty() && oldP == it.current()->name())
579 defsearch = d->m_printers->count()-1;
580 else if (defsearch == -1 && it.current()->name() == printer->searchName())
581 defsearch = d->m_printers->count()-1;
582 }
583 int defindex = (defsearch != -1 ? defsearch : (defsoft != -1 ? defsoft : TQMAX(defhard,0)));
584 d->m_printers->setCurrentItem(defindex);
585 //slotPrinterSelected(defindex);
586 }
587
588 // Initialize output filename
589 if (!d->m_printer->outputFileName().isEmpty())
590 d->m_file->setURL( d->m_printer->outputFileName() );
591 else if (!d->m_printer->docFileName().isEmpty())
592 d->m_file->setURL( d->m_printer->docDirectory()+"/"+d->m_printer->docFileName()+".ps" );
593
594 if ( d->m_printers->count() > 0 )
595 slotPrinterSelected( d->m_printers->currentItem() );
596
597 // update with KPrinter options
598 if (d->m_printer->option("kde-preview") == "1" || d->m_printer->previewOnly())
599 d->m_preview->setChecked(true);
600 d->m_preview->setEnabled(!d->m_printer->previewOnly());
601 d->m_cmd->setText(d->m_printer->option("kde-printcommand"));
602 TQPtrListIterator<KPrintDialogPage> it(d->m_pages);
603 for (;it.current();++it)
604 it.current()->setOptions(d->m_printer->options());
605}
606
607void KPrintDialog::slotPrinterSelected(int index)
608{
609 bool ok(false);
610 d->m_location->setText(TQString::null);
611 d->m_state->setText(TQString::null);
612 d->m_comment->setText(TQString::null);
613 d->m_type->setText(TQString::null);
614 if (index >= 0 && index < d->m_printers->count())
615 {
616 KMManager *mgr = KMFactory::self()->manager();
617 KMPrinter *p = mgr->findPrinter(d->m_printers->text(index));
618 if (p)
619 {
620 if (!p->isSpecial()) mgr->completePrinterShort(p);
621 d->m_location->setText(p->location());
622 d->m_comment->setText(p->driverInfo());
623 d->m_type->setText(p->description());
624 d->m_state->setText(p->stateString());
625 ok = p->isValid();
626 enableSpecial(p->isSpecial());
627 enableOutputFile(p->option("kde-special-file") == "1");
628 setOutputFileExtension(p->option("kde-special-extension"));
629 }
630 else
631 enableOutputFile( ok );
632 }
633 d->m_properties->setEnabled(ok);
634 d->m_ok->setEnabled(ok);
635}
636
637void KPrintDialog::slotProperties()
638{
639 if (!d->m_printer) return;
640
641 KMPrinter *prt = KMFactory::self()->manager()->findPrinter(d->m_printers->currentText());
642 if (prt)
643 KPrinterPropertyDialog::setupPrinter(prt, this);
644}
645
646void KPrintDialog::slotSetDefault()
647{
648 KMPrinter *p = KMFactory::self()->manager()->findPrinter(d->m_printers->currentText());
649 if (p)
650 KMFactory::self()->virtualManager()->setDefault(p);
651}
652
653void KPrintDialog::done(int result)
654{
655 if (result == Accepted && d->m_printer)
656 {
657 TQMap<TQString,TQString> opts;
658 KMPrinter *prt(0);
659
660 // get options from global pages
661 TQString msg;
662 TQPtrListIterator<KPrintDialogPage> it(d->m_pages);
663 for (;it.current();++it)
664 if (it.current()->isEnabled())
665 {
666 if (it.current()->isValid(msg))
667 it.current()->getOptions(opts);
668 else
669 {
670 KMessageBox::error(this, msg.prepend("<qt>").append("</qt>"));
671 return;
672 }
673 }
674
675 // add options from the dialog itself
676 // TODO: ADD PRINTER CHECK MECHANISM !!!
677 prt = KMFactory::self()->manager()->findPrinter(d->m_printers->currentText());
678 if (prt->isSpecial() && prt->option("kde-special-file") == "1")
679 {
680 if (!checkOutputFile()) return;
681 d->m_printer->setOutputToFile(true);
682 /* be sure to decode the output filename */
683 d->m_printer->setOutputFileName( KURL::decode_string( d->m_file->url() ) );
684 }
685 else
686 d->m_printer->setOutputToFile(false);
687 d->m_printer->setPrinterName(prt->printerName());
688 d->m_printer->setSearchName(prt->name());
689 opts["kde-printcommand"] = d->m_cmd->text();
690 opts["kde-preview"] = (d->m_preview->isChecked() ? "1" : "0");
691 opts["kde-isspecial"] = (prt->isSpecial() ? "1" : "0");
692 opts["kde-special-command"] = prt->option("kde-special-command");
693
694 // merge options with KMPrinter object options
695 TQMap<TQString,TQString> popts = (prt->isEdited() ? prt->editedOptions() : prt->defaultOptions());
696 for (TQMap<TQString,TQString>::ConstIterator it=popts.begin(); it!=popts.end(); ++it)
697 opts[it.key()] = it.data();
698
699 // update KPrinter object
700 d->m_printer->setOptions(opts);
701
702 emit printRequested(d->m_printer);
703 // close dialog if not persistent
704 if (!d->m_persistent->isChecked() || !d->m_persistent->isVisible())
705 KDialog::done(result);
706 }
707 else
708 KDialog::done(result);
709}
710
711bool KPrintDialog::checkOutputFile()
712{
713 bool value(false);
714 if (d->m_file->url().isEmpty())
715 KMessageBox::error(this,i18n("The output filename is empty."));
716 else
717 {
718 KURL url( d->m_file->url() );
719 if ( !url.isLocalFile() )
720 return true;
721
722 bool anotherCheck;
723 do
724 {
725 anotherCheck = false;
726 TQFileInfo f(url.path());
727 if (f.exists())
728 {
729 if (f.isWritable())
730 {
731 //value = (KMessageBox::warningYesNo(this,i18n("File \"%1\" already exists. Overwrite?").arg(f.absFilePath())) == KMessageBox::Yes);
732 time_t mtimeDest = f.lastModified().toTime_t();
733 TDEIO::RenameDlg dlg( this, i18n( "Print" ), TQString::null, d->m_file->url(),
734 TDEIO::M_OVERWRITE, ( time_t ) -1, f.size(), ( time_t ) -1, f.created().toTime_t() , mtimeDest+1, mtimeDest, true );
735 int result = dlg.exec();
736 switch ( result )
737 {
738 case TDEIO::R_OVERWRITE:
739 value = true;
740 break;
741 default:
742 case TDEIO::R_CANCEL:
743 value = false;
744 break;
745 case TDEIO::R_RENAME:
746 url = dlg.newDestURL();
747 d->m_file->setURL( url.path() );
748 value = true;
749 anotherCheck = true;
750 break;
751 }
752 }
753 else
754 KMessageBox::error(this,i18n("You don't have write permissions to this file."));
755 }
756 else
757 {
758 TQFileInfo d( f.dirPath( true ) );
759 if ( !d.exists() )
760 KMessageBox::error( this, i18n( "The output directory does not exist." ) );
761 else if ( !d.isWritable() )
762 KMessageBox::error(this,i18n("You don't have write permissions in that directory."));
763 else
764 value = true;
765 }
766 } while( anotherCheck );
767 }
768 return value;
769}
770
771void KPrintDialog::slotOptions()
772{
773 if (KMManager::self()->invokeOptionsDialog(this))
774 init();
775}
776
777void KPrintDialog::enableOutputFile(bool on)
778{
779 d->m_filelabel->setEnabled(on);
780 d->m_file->setEnabled(on);
781}
782
783void KPrintDialog::enableSpecial(bool on)
784{
785 d->m_default->setDisabled(on);
786 d->m_cmdlabel->setDisabled(on);
787 d->m_cmd->setDisabled(on);
788 KPCopiesPage *copypage = (KPCopiesPage*)child("CopiesPage","KPCopiesPage");
789 if (copypage)
790 copypage->initialize(!on);
791 // disable/enable all other pages (if needed)
792 for (d->m_pages.first(); d->m_pages.current(); d->m_pages.next())
793 if (d->m_pages.current()->onlyRealPrinters())
794 d->m_pages.current()->setEnabled(!on);
795}
796
797void KPrintDialog::setOutputFileExtension(const TQString& ext)
798{
799 if (!ext.isEmpty())
800 {
801 KURL url( d->m_file->url() );
802 TQString f( url.fileName() );
803 int p = f.findRev( '.' );
804 // change "file.ext"; don't change "file", "file." or ".file" but do change ".file.ext"
805 if ( p > 0 && p != int (f.length () - 1) )
806 {
807 url.setFileName( f.left( p ) + "." + ext );
808 d->m_file->setURL( KURL::decode_string( url.url() ) );
809 }
810 }
811}
812
813void KPrintDialog::slotWizard()
814{
815 int result = KMFactory::self()->manager()->addPrinterWizard(this);
816 if (result == -1)
817 KMessageBox::error(this, KMFactory::self()->manager()->errorMsg().prepend("<qt>").append("</qt>"));
818 else if (result == 1)
819 initialize(d->m_printer);
820}
821
822void KPrintDialog::reload()
823{
824 // remove printer dependent pages (usually from plugin)
825 TQTabWidget *tabs = static_cast<TQTabWidget*>(d->m_dummy->child("TabWidget", "TQTabWidget"));
826 for (uint i=0; i<d->m_pages.count(); i++)
827 if (d->m_pages.at(i)->onlyRealPrinters())
828 {
829 KPrintDialogPage *page = d->m_pages.take(i--);
830 if (tabs)
831 tabs->removePage(page);
832 delete page;
833 }
834 // reload printer dependent pages from plugin
835 TQPtrList<KPrintDialogPage> pages;
836 pages.setAutoDelete(false);
837 KMFactory::self()->uiManager()->setupPrintDialogPages(&pages);
838 // add those pages to the dialog
839 setDialogPages(&pages);
840 if (!d->m_reduced)
841 d->m_dummy->show();
842 // other initializations
843 setFlags(KMFactory::self()->uiManager()->dialogFlags());
844 connect( KMFactory::self()->manager(), TQ_SIGNAL( updatePossible( bool ) ), TQ_SLOT( slotUpdatePossible( bool ) ) );
845 init();
846}
847
848void KPrintDialog::configChanged()
849{
850 // simply update the printer list: do it all the time
851 // as changing settings may influence the way printer
852 // are listed.
853 init();
854
855 // update the GUI
856 setFlags(KMFactory::self()->uiManager()->dialogFlags());
857}
858
859void KPrintDialog::expandDialog(bool on)
860{
861 TQSize sz(size());
862 bool needResize(isVisible());
863
864 if (on)
865 {
866 sz.setHeight(sz.height()+d->m_dummy->minimumSize().height()+d->m_plugin->minimumSize().height()+2*layout()->spacing());
867 if (isVisible() || !d->m_dummy->isVisible() || !d->m_plugin->isVisible())
868 {
869 d->m_dummy->show();
870 if (d->b_systemEnabled)
871 d->m_plugin->show();
872 }
873 d->m_extbtn->setIconSet(SmallIconSet("go-up"));
874 d->m_extbtn->setText(i18n("&Options <<"));
875 d->m_reduced = false;
876 }
877 else
878 {
879 sz.setHeight(sz.height()-d->m_dummy->height()-d->m_plugin->height()-2*layout()->spacing());
880 if (!isVisible() || d->m_dummy->isVisible() || d->m_plugin->isVisible())
881 {
882 d->m_dummy->hide();
883 if (d->b_systemEnabled)
884 d->m_plugin->hide();
885 }
886 d->m_extbtn->setIconSet(SmallIconSet("go-down"));
887 d->m_extbtn->setText(i18n("&Options >>"));
888 d->m_reduced = true;
889 }
890
891 if (needResize)
892 {
893 layout()->activate();
894 resize(sz);
895 }
896}
897
898void KPrintDialog::slotExtensionClicked()
899{
900 // As all pages are children of d->m_dummy, I simply have to hide/show it
901 expandDialog(!(d->m_dummy->isVisible()));
902}
903
904KPrinter* KPrintDialog::printer() const
905{
906 return d->m_printer;
907}
908
909void KPrintDialog::slotToggleFilter(bool on)
910{
911 KMManager::self()->enableFilter(on);
912 initialize(d->m_printer);
913}
914
915void KPrintDialog::slotHelp()
916{
917 tdeApp->invokeHelp(TQString::null, "tdeprint");
918}
919
920void KPrintDialog::slotOutputFileSelected(const TQString& txt)
921{
922 d->m_file->setURL( txt );
923}
924
925void KPrintDialog::init()
926{
927 d->m_ok->setEnabled( false );
928 MessageWindow::remove( this );
929 MessageWindow::add( this, i18n( "Initializing printing system..." ), 500 );
930 KMFactory::self()->manager()->checkUpdatePossible();
931}
932
933void KPrintDialog::slotUpdatePossible( bool flag )
934{
935 MessageWindow::remove( this );
936 if ( !flag )
937 KMessageBox::error(parentWidget(),
938 "<qt><nobr>"+
939 i18n("An error occurred while retrieving the printer list:")
940 +"</nobr><br><br>"+KMManager::self()->errorMsg()+"</qt>");
941 initialize( d->m_printer );
942}
943
944void KPrintDialog::enableDialogPage( int index, bool flag )
945{
946 if ( index < 0 || index >= ( int )d->m_pages.count() )
947 {
948 kdWarning() << "KPrintDialog: page index out of bound" << endl;
949 return;
950 }
951
952 if ( d->m_pages.count() > 1 )
953 {
954 TQTabWidget *tabs = static_cast<TQTabWidget*>(d->m_dummy->child("TabWidget", "TQTabWidget"));
955 tabs->setTabEnabled( d->m_pages.at( index ), flag );
956 }
957 else
958 d->m_pages.at( 0 )->setEnabled( flag );
959}
960
961void KPrintDialog::slotOpenFileDialog()
962{
963 KFileDialog *dialog = d->m_file->fileDialog();
964
965 dialog->setCaption(i18n("Print to File"));
966 dialog->setMode(d->m_file->fileDialog()->mode() & ~KFile::LocalOnly);
967 dialog->setOperationMode( KFileDialog::Saving );
968
969 KMPrinter *prt = KMFactory::self()->manager()->findPrinter(d->m_printers->currentText());
970 if (prt)
971 {
972 TQString mimetype(prt->option("kde-special-mimetype"));
973 TQString ext(prt->option("kde-special-extension"));
974
975 if (!mimetype.isEmpty())
976 {
977 TQStringList filter;
978 filter << mimetype;
979 filter << "all/allfiles";
980 dialog->setMimeFilter (filter, mimetype);
981 }
982 else if (!ext.isEmpty())
983 dialog->setFilter ("*." + ext + "\n*|" + i18n ("All Files"));
984 }
985}
986
987#include "kprintdialog.moc"
KPrintDialogPage
This class is intended to be used as base class for customized print dialog page.
Definition: kprintdialogpage.h:91
KPrintDialogPage::title
TQString title() const
Get the page title.
Definition: kprintdialogpage.h:147
KPrinter
This class is the main interface to access the TDE print framework.
Definition: kprinter.h:89
KPrinter::searchName
TQString searchName() const
Returns the search name of the printer selected by the user.
Definition: kprinter.cpp:906
TreeComboBox
Main class.
Definition: treecombobox.h:67

tdeprint

Skip menu "tdeprint"
  • Main Page
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Class Members
  • Related Pages

tdeprint

Skip menu "tdeprint"
  • arts
  • dcop
  • dnssd
  • interfaces
  •   kspeech
  •     interface
  •     library
  •   tdetexteditor
  • kate
  • kded
  • kdoctools
  • kimgio
  • kjs
  • libtdemid
  • libtdescreensaver
  • tdeabc
  • tdecmshell
  • tdecore
  • tdefx
  • tdehtml
  • tdeinit
  • tdeio
  •   bookmarks
  •   httpfilter
  •   kpasswdserver
  •   kssl
  •   tdefile
  •   tdeio
  •   tdeioexec
  • tdeioslave
  •   http
  • tdemdi
  •   tdemdi
  • tdenewstuff
  • tdeparts
  • tdeprint
  • tderandr
  • tderesources
  • tdespell2
  • tdesu
  • tdeui
  • tdeunittest
  • tdeutils
  • tdewallet
Generated for tdeprint by doxygen 1.9.4
This website is maintained by Timothy Pearson.