25 #include "kprintdialog.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"
40 #include <tqgroupbox.h>
41 #include <tqcheckbox.h>
42 #include <kpushbutton.h>
44 #include <tqcombobox.h>
45 #include <tqtabwidget.h>
49 #include <tdemessagebox.h>
51 #include <tqtooltip.h>
52 #include <tqwhatsthis.h>
54 #include <tdelocale.h>
55 #include <kiconloader.h>
56 #include <tdefiledialog.h>
57 #include <kurlrequester.h>
58 #include <klineedit.h>
60 #include <tdeglobal.h>
61 #include <tdeconfig.h>
63 #include <kstdguiitem.h>
64 #include <tdeapplication.h>
65 #include <tdeio/renamedlg.h>
69 #define SHOWHIDE(widget,on) if (on) widget->show(); else widget->hide();
71 class KPrintDialog::KPrintDialogPrivate
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;
81 PluginComboBox *m_plugin;
82 KURLRequester *m_file;
83 TQCheckBox *m_persistent;
86 TQPtrList<KPrintDialogPage> m_pages;
88 bool b_optionsEnabled;
89 bool b_propertiesEnabled;
93 KPrintDialog::KPrintDialog(TQWidget *parent,
const char *name)
94 : KDialog(parent,name,true)
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"
102 TQString whatsThisPrinterType = i18n(
" <qt><b>Printer Type:</b> The <em>Type</em> indicates your printer type."
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."
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)."
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"
118 " attachment). If you are missing a real printer, you need to..."
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"
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> "
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."
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> "
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> "
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 <printername> --medium=A3</pre>."
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.... "
182 TQString whatsThisHelpButton = i18n(
" <qt><b>Help:</b> This button takes you to the complete <em>TDEPrint"
186 TQString whatsThisCancelButton = i18n(
" <qt><b>Cancel:</b> This button cancels your print job and quits the"
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."
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>"
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>"
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."
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\")"
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."
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"
231 " <li>you can select various files from different paths"
232 " and send them as one \"multi-file job\" to the printing"
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. "
250 TQString whatsThisSetDefaultPrinter = i18n(
" <qt><b>Set as Default Printer</b>"
251 " This button sets the current printer as the user's"
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.)"
258 d =
new KPrintDialogPrivate;
260 d->m_pages.setAutoDelete(
false);
262 setCaption(i18n(
"Print"));
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);
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);
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);
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 );
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);
358 l2->addWidget(d->m_extbtn,0);
359 l2->addWidget(d->m_options,0);
360 l2->addWidget(m_help,0);
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);
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);
392 l3->addWidget(d->m_filelabel,1,0);
393 l3->addWidget(d->m_file,1,1);
395 l3->addWidget(d->m_cmdlabel,2,0);
396 l3->addMultiCellWidget(d->m_cmd,2,2,1,2);
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 ) ) );
413 d->b_optionsEnabled = kapp->authorize(
"print/options") && kapp->authorize(
"print/selection");
414 d->b_propertiesEnabled = kapp->authorize(
"print/properties") && kapp->authorize(
"print/selection");
415 d->b_systemEnabled = kapp->authorize(
"print/system") && kapp->authorize(
"print/selection");
417 if (!d->b_systemEnabled)
422 if (!d->b_optionsEnabled)
424 d->m_options->hide();
427 if (!d->b_propertiesEnabled)
429 d->m_properties->hide();
433 if (!kapp->authorize(
"print/selection"))
442 TDEConfig *config = TDEGlobal::config();
443 config->setGroup(
"KPrinter Settings");
444 expandDialog(!config->readBoolEntry(
"DialogReduced", (KMFactory::self()->settings()->application != KPrinter::StandAlone)));
448 KPrintDialog::~KPrintDialog()
450 TDEConfig *config = TDEGlobal::config();
451 config->setGroup(
"KPrinter Settings");
452 config->writeEntry(
"DialogReduced", d->m_reduced);
457 void KPrintDialog::setFlags(
int f)
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))
472 KMManager *mgr = KMFactory::self()->manager();
473 d->m_wizard->setEnabled((mgr->hasManagement() && (mgr->printerOperationMask() & KMManager::PrinterCreation)));
479 if (pages->count() + d->m_pages.count() == 1)
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");
492 TQTabWidget *tabs =
static_cast<TQTabWidget*
>(d->m_dummy->child(
"TabWidget",
"TQTabWidget"));
497 tabs =
new TQTabWidget(d->m_dummy,
"TabWidget");
499 for (d->m_pages.first(); d->m_pages.current(); d->m_pages.next())
501 tabs->addTab(d->m_pages.current(), d->m_pages.current()->title());
504 while (pages->count() > 0)
507 d->m_pages.append(page);
508 tabs->addTab(page, page->
title());
512 d->m_extbtn->setEnabled(d->m_pages.count() > 0);
515 KPrintDialog* KPrintDialog::printerDialog(
KPrinter *printer, TQWidget *parent,
const TQString& caption,
bool forceExpand)
519 KPrintDialog *dlg =
new KPrintDialog(parent);
523 dlg->d->m_printer = printer;
524 KMFactory::self()->uiManager()->setupPrintDialog(dlg);
526 if (!caption.isEmpty())
527 dlg->setCaption(caption);
533 dlg->expandDialog(
true);
534 dlg->d->m_extbtn->hide();
541 void KPrintDialog::initialize(
KPrinter *printer)
543 d->m_printer = printer;
546 TQPtrList<KMPrinter> *plist = KMFactory::self()->manager()->printerList();
547 if (!KMManager::self()->errorMsg().isEmpty())
549 KMessageBox::error(parentWidget(),
551 i18n(
"An error occurred while retrieving the printer list:")
552 +
"</nobr><br><br>"+KMManager::self()->errorMsg()+
"</qt>");
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);
562 for (;it.current();++it)
565 if ( !it.current()->isValid() )
568 if (!sep && it.current()->isSpecial())
571 d->m_printers->insertItem(TQPixmap(), TQString::fromLatin1(
"--------"));
573 d->m_printers->insertItem(SmallIcon(it.current()->pixmap(),0,(it.current()->isValid() ? (
int)TDEIcon::DefaultState : (
int)TDEIcon::LockOverlay)),it.current()->name(),
false);
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;
583 int defindex = (defsearch != -1 ? defsearch : (defsoft != -1 ? defsoft : TQMAX(defhard,0)));
584 d->m_printers->setCurrentItem(defindex);
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" );
594 if ( d->m_printers->count() > 0 )
595 slotPrinterSelected( d->m_printers->currentItem() );
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());
607 void KPrintDialog::slotPrinterSelected(
int index)
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())
616 KMManager *mgr = KMFactory::self()->manager();
617 KMPrinter *p = mgr->findPrinter(d->m_printers->text(index));
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());
626 enableSpecial(p->isSpecial());
627 enableOutputFile(p->option(
"kde-special-file") ==
"1");
628 setOutputFileExtension(p->option(
"kde-special-extension"));
631 enableOutputFile( ok );
633 d->m_properties->setEnabled(ok);
634 d->m_ok->setEnabled(ok);
637 void KPrintDialog::slotProperties()
639 if (!d->m_printer)
return;
641 KMPrinter *prt = KMFactory::self()->manager()->findPrinter(d->m_printers->currentText());
643 KPrinterPropertyDialog::setupPrinter(prt,
this);
646 void KPrintDialog::slotSetDefault()
648 KMPrinter *p = KMFactory::self()->manager()->findPrinter(d->m_printers->currentText());
650 KMFactory::self()->virtualManager()->setDefault(p);
653 void KPrintDialog::done(
int result)
655 if (result == Accepted && d->m_printer)
657 TQMap<TQString,TQString> opts;
662 TQPtrListIterator<KPrintDialogPage> it(d->m_pages);
663 for (;it.current();++it)
664 if (it.current()->isEnabled())
666 if (it.current()->isValid(msg))
667 it.current()->getOptions(opts);
670 KMessageBox::error(
this, msg.prepend(
"<qt>").append(
"</qt>"));
677 prt = KMFactory::self()->manager()->findPrinter(d->m_printers->currentText());
678 if (prt->isSpecial() && prt->option(
"kde-special-file") ==
"1")
680 if (!checkOutputFile())
return;
681 d->m_printer->setOutputToFile(
true);
683 d->m_printer->setOutputFileName( KURL::decode_string( d->m_file->url() ) );
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");
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();
700 d->m_printer->setOptions(opts);
702 emit printRequested(d->m_printer);
704 if (!d->m_persistent->isChecked() || !d->m_persistent->isVisible())
705 KDialog::done(result);
708 KDialog::done(result);
711 bool KPrintDialog::checkOutputFile()
714 if (d->m_file->url().isEmpty())
715 KMessageBox::error(
this,i18n(
"The output filename is empty."));
718 KURL url( d->m_file->url() );
719 if ( !url.isLocalFile() )
725 anotherCheck =
false;
726 TQFileInfo f(url.path());
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();
738 case TDEIO::R_OVERWRITE:
742 case TDEIO::R_CANCEL:
745 case TDEIO::R_RENAME:
746 url = dlg.newDestURL();
747 d->m_file->setURL( url.path() );
754 KMessageBox::error(
this,i18n(
"You don't have write permissions to this file."));
758 TQFileInfo d( f.dirPath(
true ) );
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."));
766 }
while( anotherCheck );
771 void KPrintDialog::slotOptions()
773 if (KMManager::self()->invokeOptionsDialog(
this))
777 void KPrintDialog::enableOutputFile(
bool on)
779 d->m_filelabel->setEnabled(on);
780 d->m_file->setEnabled(on);
783 void KPrintDialog::enableSpecial(
bool on)
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");
790 copypage->initialize(!on);
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);
797 void KPrintDialog::setOutputFileExtension(
const TQString& ext)
801 KURL url( d->m_file->url() );
802 TQString f( url.fileName() );
803 int p = f.findRev(
'.' );
805 if ( p > 0 && p !=
int (f.length () - 1) )
807 url.setFileName( f.left( p ) +
"." + ext );
808 d->m_file->setURL( KURL::decode_string( url.url() ) );
813 void KPrintDialog::slotWizard()
815 int result = KMFactory::self()->manager()->addPrinterWizard(
this);
817 KMessageBox::error(
this, KMFactory::self()->manager()->errorMsg().prepend(
"<qt>").append(
"</qt>"));
818 else if (result == 1)
819 initialize(d->m_printer);
822 void KPrintDialog::reload()
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())
831 tabs->removePage(page);
835 TQPtrList<KPrintDialogPage> pages;
836 pages.setAutoDelete(
false);
837 KMFactory::self()->uiManager()->setupPrintDialogPages(&pages);
839 setDialogPages(&pages);
843 setFlags(KMFactory::self()->uiManager()->dialogFlags());
844 connect( KMFactory::self()->manager(), TQ_SIGNAL( updatePossible(
bool ) ), TQ_SLOT( slotUpdatePossible(
bool ) ) );
848 void KPrintDialog::configChanged()
856 setFlags(KMFactory::self()->uiManager()->dialogFlags());
859 void KPrintDialog::expandDialog(
bool on)
862 bool needResize(isVisible());
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())
870 if (d->b_systemEnabled)
873 d->m_extbtn->setIconSet(SmallIconSet(
"go-up"));
874 d->m_extbtn->setText(i18n(
"&Options <<"));
875 d->m_reduced =
false;
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())
883 if (d->b_systemEnabled)
886 d->m_extbtn->setIconSet(SmallIconSet(
"go-down"));
887 d->m_extbtn->setText(i18n(
"&Options >>"));
893 layout()->activate();
898 void KPrintDialog::slotExtensionClicked()
901 expandDialog(!(d->m_dummy->isVisible()));
904 KPrinter* KPrintDialog::printer()
const
909 void KPrintDialog::slotToggleFilter(
bool on)
911 KMManager::self()->enableFilter(on);
912 initialize(d->m_printer);
915 void KPrintDialog::slotHelp()
917 kapp->invokeHelp(TQString::null,
"tdeprint");
920 void KPrintDialog::slotOutputFileSelected(
const TQString& txt)
922 d->m_file->setURL( txt );
925 void KPrintDialog::init()
927 d->m_ok->setEnabled(
false );
928 MessageWindow::remove(
this );
929 MessageWindow::add(
this, i18n(
"Initializing printing system..." ), 500 );
930 KMFactory::self()->manager()->checkUpdatePossible();
933 void KPrintDialog::slotUpdatePossible(
bool flag )
935 MessageWindow::remove(
this );
937 KMessageBox::error(parentWidget(),
939 i18n(
"An error occurred while retrieving the printer list:")
940 +
"</nobr><br><br>"+KMManager::self()->errorMsg()+
"</qt>");
941 initialize( d->m_printer );
944 void KPrintDialog::enableDialogPage(
int index,
bool flag )
946 if ( index < 0 || index >= (
int )d->m_pages.count() )
948 kdWarning() <<
"KPrintDialog: page index out of bound" << endl;
952 if ( d->m_pages.count() > 1 )
954 TQTabWidget *tabs =
static_cast<TQTabWidget*
>(d->m_dummy->child(
"TabWidget",
"TQTabWidget"));
955 tabs->setTabEnabled( d->m_pages.at( index ), flag );
958 d->m_pages.at( 0 )->setEnabled( flag );
961 void KPrintDialog::slotOpenFileDialog()
963 KFileDialog *dialog = d->m_file->fileDialog();
965 dialog->setCaption(i18n(
"Print to File"));
966 dialog->setMode(d->m_file->fileDialog()->mode() & ~KFile::LocalOnly);
967 dialog->setOperationMode( KFileDialog::Saving );
969 KMPrinter *prt = KMFactory::self()->manager()->findPrinter(d->m_printers->currentText());
972 TQString mimetype(prt->option(
"kde-special-mimetype"));
973 TQString ext(prt->option(
"kde-special-extension"));
975 if (!mimetype.isEmpty())
979 filter <<
"all/allfiles";
980 dialog->setMimeFilter (filter, mimetype);
982 else if (!ext.isEmpty())
983 dialog->setFilter (
"*." + ext +
"\n*|" + i18n (
"All Files"));
987 #include "kprintdialog.moc"