00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #include "kprintdialog.h"
00026 #include "kprinter.h"
00027 #include "kprinterimpl.h"
00028 #include "kmfactory.h"
00029 #include "kmuimanager.h"
00030 #include "kmmanager.h"
00031 #include "kmprinter.h"
00032 #include "kmvirtualmanager.h"
00033 #include "kprintdialogpage.h"
00034 #include "kprinterpropertydialog.h"
00035 #include "plugincombobox.h"
00036 #include "kpcopiespage.h"
00037 #include "treecombobox.h"
00038 #include "messagewindow.h"
00039
00040 #include <tqgroupbox.h>
00041 #include <tqcheckbox.h>
00042 #include <kpushbutton.h>
00043 #include <tqlabel.h>
00044 #include <tqcombobox.h>
00045 #include <tqtabwidget.h>
00046 #include <tqvbox.h>
00047 #include <tqlayout.h>
00048 #include <tqregexp.h>
00049 #include <tdemessagebox.h>
00050 #include <tqdir.h>
00051 #include <tqtooltip.h>
00052 #include <tqwhatsthis.h>
00053
00054 #include <tdelocale.h>
00055 #include <kiconloader.h>
00056 #include <tdefiledialog.h>
00057 #include <kurlrequester.h>
00058 #include <klineedit.h>
00059 #include <kdebug.h>
00060 #include <tdeglobal.h>
00061 #include <tdeconfig.h>
00062 #include <kguiitem.h>
00063 #include <kstdguiitem.h>
00064 #include <tdeapplication.h>
00065 #include <tdeio/renamedlg.h>
00066
00067 #include <time.h>
00068
00069 #define SHOWHIDE(widget,on) if (on) widget->show(); else widget->hide();
00070
00071 class KPrintDialog::KPrintDialogPrivate
00072 {
00073 public:
00074 TQLabel *m_type, *m_state, *m_comment, *m_location, *m_cmdlabel, *m_filelabel;
00075 KPushButton *m_properties, *m_default, *m_options, *m_ok, *m_extbtn;
00076 TQPushButton *m_wizard, *m_filter;
00077 TQCheckBox *m_preview;
00078 TQLineEdit *m_cmd;
00079 TreeComboBox *m_printers;
00080 TQVBox *m_dummy;
00081 PluginComboBox *m_plugin;
00082 KURLRequester *m_file;
00083 TQCheckBox *m_persistent;
00084 bool m_reduced;
00085
00086 TQPtrList<KPrintDialogPage> m_pages;
00087 KPrinter *m_printer;
00088 bool b_optionsEnabled;
00089 bool b_propertiesEnabled;
00090 bool b_systemEnabled;
00091 };
00092
00093 KPrintDialog::KPrintDialog(TQWidget *parent, const char *name)
00094 : KDialog(parent,name,true)
00095 {
00096
00097 TQString whatsThisLocationLabel = i18n( " <qt><b>Printer Location:</b> The <em>Location</em> may describe where the"
00098 " selected printer is located. The Location description is created"
00099 " by the administrator of the print system (or may be"
00100 " left empty)."
00101 " </qt>" );
00102 TQString whatsThisPrinterType = i18n( " <qt><b>Printer Type:</b> The <em>Type</em> indicates your printer type."
00103 " </qt>" );
00104 TQString whatsThisPrinterState = i18n( " <qt><b>Printer State:</b> The <em>State</em> indicates the state of the"
00105 " print queue on the print server (which could be your localhost). The"
00106 " state may be 'Idle', 'Processing', 'Stopped', 'Paused' or similar."
00107 " </qt>" );
00108 TQString whatsThisPrinterComment = i18n( " <qt><b>Printer Comment:</b> The <em>Comment</em> may describe the selected"
00109 " printer. This comment is created by the administrator"
00110 " of the print system (or may be left empty)."
00111 " </qt>" );
00112 TQString whatsThisPrinterSelect = i18n( " <qt><b>Printer Selection Menu:</b> "
00113 " <p>Use this combo box to select the printer to which you want to print."
00114 " Initially (if you run TDEPrint for the first time), you may only find the "
00115 " <em>TDE special printers</em> (which save"
00116 " jobs to disk [as PostScript- or PDF-files], or deliver jobs via"
00117 " email (as a PDF"
00118 " attachment). If you are missing a real printer, you need to..."
00119 " <ul>"
00120 " <li>...either create a local printer with the help of the <em>TDE Add"
00121 " Printer Wizard</em>. The Wizard is available for the CUPS and RLPR printing"
00122 " systems (click button to the left of the <em>'Properties'</em> button),</li>"
00123 " <li>...or try to connect to an existing remote"
00124 " CUPS print server. You can connect by clicking the <em>'System Options'</em> button"
00125 " below. A new dialog opens: click on the <em>'CUPS server'</em>"
00126 " icon: Fill in the information required to use the remote"
00127 " server. </li> "
00128 " </ul>"
00129 " <p><b>Note:</b> It may happen that you successfully connected to a remote CUPS "
00130 " server and still do not get a printer list. If this happens: force TDEPrint to "
00131 " re-load its configuration files."
00132 " To reload the configuration files, either start kprinter again, or use the "
00133 " switch the print system away from CUPS and back again once. The print system switch "
00134 " can be made through a selection in the drop-down menu at bottom of this dialog when "
00135 " fully expanded). </p> "
00136 " </qt>" );
00137 TQString whatsThisPrintJobProperties = i18n( " <qt><b>Print Job Properties:</b> "
00138 " <p>This button opens a dialog where you can make decisions"
00139 " regarding all supported print job options."
00140 " </qt>" );
00141 TQString whatsThisPrinterFilter = i18n( " <qt><b>Selective View on List of Printers:</b>"
00142 " <p> This button reduces the list of visible printers"
00143 " to a shorter, more convenient, pre-defined list.</p>"
00144 " <p>This is particularly useful in enterprise environments"
00145 " with lots of printers. The default is to show <b>all</b> printers.</p>"
00146 " <p>To create a personal <em>'selective view list'</em>, click on the"
00147 " <em>'System Options'</em> button at the bottom of this dialog."
00148 " Then, in the new dialog, select <em>'Filter'</em> (left column in the"
00149 " <em>TDE Print Configuration</em> dialog) and setup your selection..</p>"
00150 " <p><b>Warning:</b> Clicking this button without prior creation of a personal "
00151 " <em>'selective view list'</em> will make all printers dissappear from the "
00152 " view. (To re-enable all printers, just click this button again.) </p> "
00153 " </qt>" );
00154 TQString whatsThisAddPrinterWizard = i18n( "<qt><b>TDE Add Printer Wizard</b>"
00155 " <p>This button starts the <em>TDE Add Printer Wizard</em>.</p>"
00156 " <p>Use the Wizard (with <em>\"CUPS\"</em> or <em>\"RLPR\"</em>) to add locally"
00157 " defined printers to your system. </p>"
00158 " <p><b>Note:</b> The <em>TDE Add Printer Wizard</em> does <b>not</b> work, "
00159 " and this button is disabled if you use "
00160 " <em>\"Generic LPD</em>\", <em>\"LPRng\"</em>, or <em>\"Print Through "
00161 " an External Program</em>\".) </p> "
00162 " </qt>" );
00163 TQString whatsThisExternalPrintCommand = i18n( " <qt><b>External Print Command</b>"
00164 " <p>Here you can enter any command that would also print for you in "
00165 " a <em>konsole</em> window. </p>"
00166 " <b>Example:</b> <pre>a2ps -P <printername> --medium=A3</pre>."
00167 " </qt>" );
00168 TQString whatsThisOptions = i18n( " <qt><b>Additional Print Job Options</b>"
00169 " <p>This button shows or hides additional printing options.</qt>" );
00170 TQString whatsThisSystemOptions = i18n( " <qt><b>System Options:</b> "
00171 " <p>This button starts a new dialog where you can adjust various"
00172 " settings of your printing system. Amongst them:"
00173 " <ul><li> Should \tDE"
00174 " applications embed all fonts into the PostScript they"
00175 " generate for printing?"
00176 " <li> Should TDE use an external PostScript viewer"
00177 " like <em>gv</em> for print page previews?"
00178 " <li> Should TDEPrint use a local or a remote CUPS server?,"
00179 " </ul> and many more.... "
00180 " </qt>" );
00181
00182 TQString whatsThisHelpButton = i18n( " <qt><b>Help:</b> This button takes you to the complete <em>TDEPrint"
00183 " Manual</em>."
00184 " </qt>" );
00185
00186 TQString whatsThisCancelButton = i18n( " <qt><b>Cancel:</b> This button cancels your print job and quits the"
00187 " kprinter dialog."
00188 " </qt>" );
00189
00190 TQString whatsThisPrintButton = i18n( " <qt><b>Print:</b> This button sends the job to the printing process."
00191 " If you are sending non-PostScript files, you may be"
00192 " asked if you want TDE to convert the files into PostScript,"
00193 " or if you want your print subsystem (like CUPS) to do this."
00194 " </qt>" );
00195
00196 TQString whatsThisKeepDialogOpenCheckbox = i18n( " <qt><b>Keep Printing Dialog Open</b>"
00197 "<p>If you enable this checkbox, the printing dialog"
00198 " stays open after you hit the <em>Print</em> button.</p>"
00199 " <p> This is"
00200 " especially useful, if you need to test various"
00201 " print settings (like color matching for an inkjet printer)"
00202 " or if you want to send your job to multiple printers (one after"
00203 " the other) to have it finished more quickly.</p>"
00204 " </qt>" );
00205
00206 TQString whatsThisOutputFileLabel = i18n(" <qt><b>Output File Name and Path:</b> The \"Output file:\" shows "
00207 " you where your file will be"
00208 " saved if you decide to \"Print to File\" your job, using one of the"
00209 " TDE <em>Special Printers</em> named \"Print to File (PostScript)\""
00210 " or \"Print to File (PDF)\". Choose a name and location that suits"
00211 " your need by using the button and/or editing the line on the right."
00212 " </qt>" );
00213
00214 TQString whatsThisOutputFileLineedit = i18n(" <qt><b>Output File Name and Path:</b> Edit this line to create a "
00215 " path and filename that suits your needs."
00216 " (Button and Lineedit field are only available if you \"Print to File\")"
00217 " </qt>" );
00218
00219 TQString whatsThisOutputFileButton = i18n(" <qt><b>Browse Directories button:<b> This button calls "
00220 " the \"File Open / Browsed Directories\" dialog to let you"
00221 " choose a directory and file name where your \"Print-to-File\""
00222 " job should be saved."
00223 " </qt>" );
00224
00225 TQString whatsThisAddFileButton = i18n( " <qt><b>Add File to Job</b>"
00226 " <p>This button calls the \"File Open / Browse Directories\" dialog to allow you"
00227 " to select a file for printing. Note, that "
00228 " <ul><li>you can select ASCII or International Text, PDF,"
00229 " PostScript, JPEG, TIFF, PNG, GIF and many other graphical"
00230 " formats."
00231 " <li>you can select various files from different paths"
00232 " and send them as one \"multi-file job\" to the printing"
00233 " system."
00234 " </ul>"
00235 " </qt>" );
00236
00237 TQString whatsThisPreviewCheckBox = i18n(" <qt><b>Print Preview</b>"
00238 " Enable this checkbox if you want to see a preview of"
00239 " your printout. A preview lets you check if, for instance,"
00240 " your intended \"poster\" or \"pamphlet\" layout"
00241 " looks like you expected, without wasting paper first. It"
00242 " also lets you cancel the job if something looks wrong. "
00243 " <p><b>Note:</b> The preview feature (and therefore this checkbox) "
00244 " is only visible for printjobs created from inside TDE applications. "
00245 " If you start kprinter from the commandline, or if you use kprinter "
00246 " as a print command for non-TDE applications (like Acrobat Reader, "
00247 " Firefox or OpenOffice), print preview is not available here. "
00248 " </qt>" );
00249
00250 TQString whatsThisSetDefaultPrinter = i18n(" <qt><b>Set as Default Printer</b>"
00251 " This button sets the current printer as the user's"
00252 " default. "
00253 " <p><b>Note:</b> (Button is only visible if the checkbox for "
00254 " <em>System Options</em>"
00255 " --> <em>General</em> --> <em>Miscellaneous</em>: <em>\"Defaults"
00256 " to the last printer used in the application\"</em> is disabled.)"
00257 " </qt>" );
00258 d = new KPrintDialogPrivate;
00259
00260 d->m_pages.setAutoDelete(false);
00261 d->m_printer = 0;
00262 setCaption(i18n("Print"));
00263
00264
00265 TQGroupBox *m_pbox = new TQGroupBox(0,Qt::Vertical,i18n("Printer"), this);
00266 d->m_type = new TQLabel(m_pbox);
00267 TQWhatsThis::add(d->m_type, whatsThisPrinterType);
00268 d->m_state = new TQLabel(m_pbox);
00269 TQWhatsThis::add(d->m_state, whatsThisPrinterState);
00270 d->m_comment = new TQLabel(m_pbox);
00271 TQWhatsThis::add(d->m_comment, whatsThisPrinterComment);
00272 d->m_location = new TQLabel(m_pbox);
00273 TQWhatsThis::add(d->m_location, whatsThisLocationLabel);
00274
00275 d->m_printers = new TreeComboBox(m_pbox);
00276 TQWhatsThis::add(d->m_printers, whatsThisPrinterSelect);
00277 d->m_printers->setMinimumHeight(25);
00278 TQLabel *m_printerlabel = new TQLabel(i18n("&Name:"), m_pbox);
00279 TQWhatsThis::add(m_printerlabel, whatsThisPrinterSelect);
00280 TQLabel *m_statelabel = new TQLabel(i18n("Status", "State:"), m_pbox);
00281 TQWhatsThis::add(m_statelabel, whatsThisPrinterState);
00282 TQLabel *m_typelabel = new TQLabel(i18n("Type:"), m_pbox);
00283 TQWhatsThis::add(m_typelabel, whatsThisPrinterType);
00284 TQLabel *m_locationlabel = new TQLabel(i18n("Location:"), m_pbox);
00285 TQWhatsThis::add(m_locationlabel, whatsThisLocationLabel);
00286 TQLabel *m_commentlabel = new TQLabel(i18n("Comment:"), m_pbox);
00287 TQWhatsThis::add(m_commentlabel, whatsThisPrinterComment);
00288 m_printerlabel->setBuddy(d->m_printers);
00289 d->m_properties = new KPushButton(KGuiItem(i18n("P&roperties"), "edit"), m_pbox);
00290 TQWhatsThis::add( d->m_properties, whatsThisPrintJobProperties);
00291 d->m_options = new KPushButton(KGuiItem(i18n("System Op&tions"), "tdeprint_configmgr"), this);
00292 TQWhatsThis::add(d->m_options,whatsThisSystemOptions);
00293 d->m_default = new KPushButton(KGuiItem(i18n("Set as &Default"), "tdeprint_defaultsoft"), m_pbox);
00294 TQWhatsThis::add(d->m_default,whatsThisSetDefaultPrinter);
00295 d->m_filter = new TQPushButton(m_pbox);
00296 d->m_filter->setPixmap(SmallIcon("filter"));
00297 d->m_filter->setMinimumSize(TQSize(d->m_printers->minimumHeight(),d->m_printers->minimumHeight()));
00298 d->m_filter->setToggleButton(true);
00299 d->m_filter->setOn(KMManager::self()->isFilterEnabled());
00300 TQToolTip::add(d->m_filter, i18n("Toggle selective view on printer list"));
00301 TQWhatsThis::add(d->m_filter, whatsThisPrinterFilter);
00302 d->m_wizard = new TQPushButton(m_pbox);
00303 d->m_wizard->setPixmap(SmallIcon("wizard"));
00304 d->m_wizard->setMinimumSize(TQSize(d->m_printers->minimumHeight(),d->m_printers->minimumHeight()));
00305 TQToolTip::add(d->m_wizard, i18n("Add printer..."));
00306 TQWhatsThis::add(d->m_wizard, whatsThisAddPrinterWizard);
00307 d->m_ok = new KPushButton(KGuiItem(i18n("&Print"), "document-print"), this);
00308 TQWhatsThis::add( d->m_ok, whatsThisPrintButton);
00309 d->m_ok->setDefault(true);
00310 d->m_ok->setEnabled( false );
00311 TQPushButton *m_cancel = new KPushButton(KStdGuiItem::cancel(), this);
00312 TQWhatsThis::add(m_cancel, whatsThisCancelButton);
00313 d->m_preview = new TQCheckBox(i18n("Previe&w"), m_pbox);
00314 TQWhatsThis::add(d->m_preview, whatsThisPreviewCheckBox);
00315 d->m_filelabel = new TQLabel(i18n("O&utput file:"), m_pbox);
00316 TQWhatsThis::add(d->m_filelabel,whatsThisOutputFileLabel);
00317 d->m_file = new KURLRequester(TQDir::homeDirPath()+"/print.ps", m_pbox);
00318 TQWhatsThis::add(d->m_file,whatsThisOutputFileLineedit);
00319 d->m_file->setEnabled(false);
00320 d->m_filelabel->setBuddy(d->m_file);
00321 d->m_cmdlabel = new TQLabel(i18n("Print co&mmand:"), m_pbox);
00322 TQWhatsThis::add( d->m_cmdlabel, whatsThisExternalPrintCommand);
00323
00324 d->m_cmd = new TQLineEdit(m_pbox);
00325 TQWhatsThis::add( d->m_cmd, whatsThisExternalPrintCommand);
00326 d->m_cmdlabel->setBuddy(d->m_cmd);
00327 d->m_dummy = new TQVBox(this);
00328 d->m_plugin = new PluginComboBox(this);
00329 d->m_extbtn = new KPushButton(this);
00330 TQToolTip::add(d->m_extbtn, i18n("Show/hide advanced options"));
00331 TQWhatsThis::add(d->m_extbtn, whatsThisOptions);
00332 d->m_persistent = new TQCheckBox(i18n("&Keep this dialog open after printing"), this);
00333 TQWhatsThis::add( d->m_persistent, whatsThisKeepDialogOpenCheckbox);
00334 TQPushButton *m_help = new KPushButton(KStdGuiItem::help(), this);
00335 TQWhatsThis::add( m_help, whatsThisHelpButton);
00336
00337 TQWidget::setTabOrder( d->m_printers, d->m_filter );
00338 TQWidget::setTabOrder( d->m_filter, d->m_wizard );
00339 TQWidget::setTabOrder( d->m_wizard, d->m_properties );
00340 TQWidget::setTabOrder( d->m_properties, d->m_preview );
00341 TQWidget::setTabOrder( d->m_preview, d->m_file );
00342 TQWidget::setTabOrder( d->m_file, d->m_cmd );
00343 TQWidget::setTabOrder( d->m_plugin, d->m_persistent );
00344 TQWidget::setTabOrder( d->m_persistent, d->m_extbtn );
00345 TQWidget::setTabOrder( d->m_extbtn, d->m_options );
00346 TQWidget::setTabOrder( d->m_options, m_help );
00347 TQWidget::setTabOrder( m_help, d->m_ok );
00348 TQWidget::setTabOrder( d->m_ok, m_cancel );
00349
00350
00351 TQVBoxLayout *l1 = new TQVBoxLayout(this, 10, 10);
00352 l1->addWidget(m_pbox,0);
00353 l1->addWidget(d->m_dummy,1);
00354 l1->addWidget(d->m_plugin,0);
00355 l1->addWidget(d->m_persistent);
00356 TQHBoxLayout *l2 = new TQHBoxLayout(0, 0, 10);
00357 l1->addLayout(l2);
00358 l2->addWidget(d->m_extbtn,0);
00359 l2->addWidget(d->m_options,0);
00360 l2->addWidget(m_help,0);
00361 l2->addStretch(1);
00362 l2->addWidget(d->m_ok,0);
00363 l2->addWidget(m_cancel,0);
00364 TQGridLayout *l3 = new TQGridLayout(m_pbox->layout(),3,3,7);
00365 l3->setColStretch(1,1);
00366 l3->setRowStretch(0,1);
00367 TQGridLayout *l4 = new TQGridLayout(0, 5, 2, 0, 5);
00368 l3->addMultiCellLayout(l4,0,0,0,1);
00369 l4->addWidget(m_printerlabel,0,0);
00370 l4->addWidget(m_statelabel,1,0);
00371 l4->addWidget(m_typelabel,2,0);
00372 l4->addWidget(m_locationlabel,3,0);
00373 l4->addWidget(m_commentlabel,4,0);
00374 TQHBoxLayout *ll4 = new TQHBoxLayout(0, 0, 3);
00375 l4->addLayout(ll4,0,1);
00376 ll4->addWidget(d->m_printers,1);
00377 ll4->addWidget(d->m_filter,0);
00378 ll4->addWidget(d->m_wizard,0);
00379
00380 l4->addWidget(d->m_state,1,1);
00381 l4->addWidget(d->m_type,2,1);
00382 l4->addWidget(d->m_location,3,1);
00383 l4->addWidget(d->m_comment,4,1);
00384 l4->setColStretch(1,1);
00385 TQVBoxLayout *l5 = new TQVBoxLayout(0, 0, 10);
00386 l3->addLayout(l5,0,2);
00387 l5->addWidget(d->m_properties,0);
00388 l5->addWidget(d->m_default,0);
00389 l5->addWidget(d->m_preview,0);
00390 l5->addStretch(1);
00391
00392 l3->addWidget(d->m_filelabel,1,0);
00393 l3->addWidget(d->m_file,1,1);
00394
00395 l3->addWidget(d->m_cmdlabel,2,0);
00396 l3->addMultiCellWidget(d->m_cmd,2,2,1,2);
00397
00398
00399 connect(d->m_ok,TQT_SIGNAL(clicked()),TQT_SLOT(accept()));
00400 connect(m_cancel,TQT_SIGNAL(clicked()),TQT_SLOT(reject()));
00401 connect(d->m_properties,TQT_SIGNAL(clicked()),TQT_SLOT(slotProperties()));
00402 connect(d->m_default,TQT_SIGNAL(clicked()),TQT_SLOT(slotSetDefault()));
00403 connect(d->m_printers,TQT_SIGNAL(activated(int)),TQT_SLOT(slotPrinterSelected(int)));
00404 connect(d->m_options,TQT_SIGNAL(clicked()),TQT_SLOT(slotOptions()));
00405 connect(d->m_wizard,TQT_SIGNAL(clicked()),TQT_SLOT(slotWizard()));
00406 connect(d->m_extbtn, TQT_SIGNAL(clicked()), TQT_SLOT(slotExtensionClicked()));
00407 connect(d->m_filter, TQT_SIGNAL(toggled(bool)), TQT_SLOT(slotToggleFilter(bool)));
00408 connect(m_help, TQT_SIGNAL(clicked()), TQT_SLOT(slotHelp()));
00409 connect(d->m_file, TQT_SIGNAL(urlSelected(const TQString&)), TQT_SLOT(slotOutputFileSelected(const TQString&)));
00410 connect( d->m_file, TQT_SIGNAL( openFileDialog( KURLRequester* ) ), TQT_SLOT( slotOpenFileDialog() ) );
00411 connect( KMFactory::self()->manager(), TQT_SIGNAL( updatePossible( bool ) ), TQT_SLOT( slotUpdatePossible( bool ) ) );
00412
00413 d->b_optionsEnabled = kapp->authorize("print/options") && kapp->authorize("print/selection");
00414 d->b_propertiesEnabled = kapp->authorize("print/properties") && kapp->authorize("print/selection");
00415 d->b_systemEnabled = kapp->authorize("print/system") && kapp->authorize("print/selection");
00416
00417 if (!d->b_systemEnabled)
00418 {
00419 d->m_plugin->hide();
00420 }
00421
00422 if (!d->b_optionsEnabled)
00423 {
00424 d->m_options->hide();
00425 }
00426
00427 if (!d->b_propertiesEnabled)
00428 {
00429 d->m_properties->hide();
00430 d->m_wizard->hide();
00431 }
00432
00433 if (!kapp->authorize("print/selection"))
00434 {
00435 d->m_extbtn->hide();
00436 m_pbox->hide();
00437
00438 expandDialog(true);
00439 }
00440 else
00441 {
00442 TDEConfig *config = TDEGlobal::config();
00443 config->setGroup("KPrinter Settings");
00444 expandDialog(!config->readBoolEntry("DialogReduced", (KMFactory::self()->settings()->application != KPrinter::StandAlone)));
00445 }
00446 }
00447
00448 KPrintDialog::~KPrintDialog()
00449 {
00450 TDEConfig *config = TDEGlobal::config();
00451 config->setGroup("KPrinter Settings");
00452 config->writeEntry("DialogReduced", d->m_reduced);
00453
00454 delete d;
00455 }
00456
00457 void KPrintDialog::setFlags(int f)
00458 {
00459 SHOWHIDE(d->m_properties, (f & KMUiManager::Properties) && d->b_propertiesEnabled)
00460 d->m_default->hide();
00461 SHOWHIDE(d->m_default, ((f & KMUiManager::Default) && !KMFactory::self()->printConfig("General")->readBoolEntry("UseLast", true)))
00462 SHOWHIDE(d->m_preview, (f & KMUiManager::Preview))
00463 bool on = (f & KMUiManager::OutputToFile);
00464 SHOWHIDE(d->m_filelabel, on)
00465 SHOWHIDE(d->m_file, on)
00466 on = (f & KMUiManager::PrintCommand);
00467 SHOWHIDE(d->m_cmdlabel, on)
00468 SHOWHIDE(d->m_cmd, on)
00469 SHOWHIDE(d->m_persistent, (f & KMUiManager::Persistent))
00470
00471
00472 KMManager *mgr = KMFactory::self()->manager();
00473 d->m_wizard->setEnabled((mgr->hasManagement() && (mgr->printerOperationMask() & KMManager::PrinterCreation)));
00474 }
00475
00476 void KPrintDialog::setDialogPages(TQPtrList<KPrintDialogPage> *pages)
00477 {
00478 if (!pages) return;
00479 if (pages->count() + d->m_pages.count() == 1)
00480 {
00481
00482
00483 if (pages->count() > 0)
00484 d->m_pages.append(pages->take(0));
00485 d->m_pages.first()->reparent(d->m_dummy, TQPoint(0,0));
00486 d->m_pages.first()->show();
00487 delete d->m_dummy->child("TabWidget", TQTABWIDGET_OBJECT_NAME_STRING);
00488 }
00489 else
00490 {
00491
00492 TQTabWidget *tabs = static_cast<TQTabWidget*>(TQT_TQWIDGET(d->m_dummy->child("TabWidget", TQTABWIDGET_OBJECT_NAME_STRING)));
00493 if (!tabs)
00494 {
00495
00496
00497 tabs = new TQTabWidget(d->m_dummy, "TabWidget");
00498 tabs->setMargin(10);
00499 for (d->m_pages.first(); d->m_pages.current(); d->m_pages.next())
00500 {
00501 tabs->addTab(d->m_pages.current(), d->m_pages.current()->title());
00502 }
00503 }
00504 while (pages->count() > 0)
00505 {
00506 KPrintDialogPage *page = pages->take(0);
00507 d->m_pages.append(page);
00508 tabs->addTab(page, page->title());
00509 }
00510 tabs->show();
00511 }
00512 d->m_extbtn->setEnabled(d->m_pages.count() > 0);
00513 }
00514
00515 KPrintDialog* KPrintDialog::printerDialog(KPrinter *printer, TQWidget *parent, const TQString& caption, bool forceExpand)
00516 {
00517 if (printer)
00518 {
00519 KPrintDialog *dlg = new KPrintDialog(parent);
00520
00521
00522
00523 dlg->d->m_printer = printer;
00524 KMFactory::self()->uiManager()->setupPrintDialog(dlg);
00525 dlg->init();
00526 if (!caption.isEmpty())
00527 dlg->setCaption(caption);
00528 if (forceExpand)
00529 {
00530
00531
00532
00533 dlg->expandDialog(true);
00534 dlg->d->m_extbtn->hide();
00535 }
00536 return dlg;
00537 }
00538 return NULL;
00539 }
00540
00541 void KPrintDialog::initialize(KPrinter *printer)
00542 {
00543 d->m_printer = printer;
00544
00545
00546 TQPtrList<KMPrinter> *plist = KMFactory::self()->manager()->printerList();
00547 if (!KMManager::self()->errorMsg().isEmpty())
00548 {
00549 KMessageBox::error(parentWidget(),
00550 "<qt><nobr>"+
00551 i18n("An error occurred while retrieving the printer list:")
00552 +"</nobr><br><br>"+KMManager::self()->errorMsg()+"</qt>");
00553 }
00554
00555 if (plist)
00556 {
00557 QString oldP = d->m_printers->currentText();
00558 d->m_printers->clear();
00559 TQPtrListIterator<KMPrinter> it(*plist);
00560 int defsoft(-1), defhard(-1), defsearch(-1);
00561 bool sep(false);
00562 for (;it.current();++it)
00563 {
00564
00565 if ( !it.current()->isValid() )
00566 continue;
00567
00568 if (!sep && it.current()->isSpecial())
00569 {
00570 sep = true;
00571 d->m_printers->insertItem(TQPixmap(), TQString::fromLatin1("--------"));
00572 }
00573 d->m_printers->insertItem(SmallIcon(it.current()->pixmap(),0,(it.current()->isValid() ? (int)TDEIcon::DefaultState : (int)TDEIcon::LockOverlay)),it.current()->name(),false);
00574 if (it.current()->isSoftDefault())
00575 defsoft = d->m_printers->count()-1;
00576 if (it.current()->isHardDefault())
00577 defhard = d->m_printers->count()-1;
00578 if (!oldP.isEmpty() && oldP == it.current()->name())
00579 defsearch = d->m_printers->count()-1;
00580 else if (defsearch == -1 && it.current()->name() == printer->searchName())
00581 defsearch = d->m_printers->count()-1;
00582 }
00583 int defindex = (defsearch != -1 ? defsearch : (defsoft != -1 ? defsoft : TQMAX(defhard,0)));
00584 d->m_printers->setCurrentItem(defindex);
00585
00586 }
00587
00588
00589 if (!d->m_printer->outputFileName().isEmpty())
00590 d->m_file->setURL( d->m_printer->outputFileName() );
00591 else if (!d->m_printer->docFileName().isEmpty())
00592 d->m_file->setURL( d->m_printer->docDirectory()+"/"+d->m_printer->docFileName()+".ps" );
00593
00594 if ( d->m_printers->count() > 0 )
00595 slotPrinterSelected( d->m_printers->currentItem() );
00596
00597
00598 if (d->m_printer->option("kde-preview") == "1" || d->m_printer->previewOnly())
00599 d->m_preview->setChecked(true);
00600 d->m_preview->setEnabled(!d->m_printer->previewOnly());
00601 d->m_cmd->setText(d->m_printer->option("kde-printcommand"));
00602 TQPtrListIterator<KPrintDialogPage> it(d->m_pages);
00603 for (;it.current();++it)
00604 it.current()->setOptions(d->m_printer->options());
00605 }
00606
00607 void KPrintDialog::slotPrinterSelected(int index)
00608 {
00609 bool ok(false);
00610 d->m_location->setText(TQString::null);
00611 d->m_state->setText(TQString::null);
00612 d->m_comment->setText(TQString::null);
00613 d->m_type->setText(TQString::null);
00614 if (index >= 0 && index < d->m_printers->count())
00615 {
00616 KMManager *mgr = KMFactory::self()->manager();
00617 KMPrinter *p = mgr->findPrinter(d->m_printers->text(index));
00618 if (p)
00619 {
00620 if (!p->isSpecial()) mgr->completePrinterShort(p);
00621 d->m_location->setText(p->location());
00622 d->m_comment->setText(p->driverInfo());
00623 d->m_type->setText(p->description());
00624 d->m_state->setText(p->stateString());
00625 ok = p->isValid();
00626 enableSpecial(p->isSpecial());
00627 enableOutputFile(p->option("kde-special-file") == "1");
00628 setOutputFileExtension(p->option("kde-special-extension"));
00629 }
00630 else
00631 enableOutputFile( ok );
00632 }
00633 d->m_properties->setEnabled(ok);
00634 d->m_ok->setEnabled(ok);
00635 }
00636
00637 void KPrintDialog::slotProperties()
00638 {
00639 if (!d->m_printer) return;
00640
00641 KMPrinter *prt = KMFactory::self()->manager()->findPrinter(d->m_printers->currentText());
00642 if (prt)
00643 KPrinterPropertyDialog::setupPrinter(prt, this);
00644 }
00645
00646 void KPrintDialog::slotSetDefault()
00647 {
00648 KMPrinter *p = KMFactory::self()->manager()->findPrinter(d->m_printers->currentText());
00649 if (p)
00650 KMFactory::self()->virtualManager()->setDefault(p);
00651 }
00652
00653 void KPrintDialog::done(int result)
00654 {
00655 if (result == Accepted && d->m_printer)
00656 {
00657 TQMap<TQString,TQString> opts;
00658 KMPrinter *prt(0);
00659
00660
00661 TQString msg;
00662 TQPtrListIterator<KPrintDialogPage> it(d->m_pages);
00663 for (;it.current();++it)
00664 if (it.current()->isEnabled())
00665 {
00666 if (it.current()->isValid(msg))
00667 it.current()->getOptions(opts);
00668 else
00669 {
00670 KMessageBox::error(this, msg.prepend("<qt>").append("</qt>"));
00671 return;
00672 }
00673 }
00674
00675
00676
00677 prt = KMFactory::self()->manager()->findPrinter(d->m_printers->currentText());
00678 if (prt->isSpecial() && prt->option("kde-special-file") == "1")
00679 {
00680 if (!checkOutputFile()) return;
00681 d->m_printer->setOutputToFile(true);
00682
00683 d->m_printer->setOutputFileName( KURL::decode_string( d->m_file->url() ) );
00684 }
00685 else
00686 d->m_printer->setOutputToFile(false);
00687 d->m_printer->setPrinterName(prt->printerName());
00688 d->m_printer->setSearchName(prt->name());
00689 opts["kde-printcommand"] = d->m_cmd->text();
00690 opts["kde-preview"] = (d->m_preview->isChecked() ? "1" : "0");
00691 opts["kde-isspecial"] = (prt->isSpecial() ? "1" : "0");
00692 opts["kde-special-command"] = prt->option("kde-special-command");
00693
00694
00695 TQMap<TQString,TQString> popts = (prt->isEdited() ? prt->editedOptions() : prt->defaultOptions());
00696 for (TQMap<TQString,TQString>::ConstIterator it=popts.begin(); it!=popts.end(); ++it)
00697 opts[it.key()] = it.data();
00698
00699
00700 d->m_printer->setOptions(opts);
00701
00702 emit printRequested(d->m_printer);
00703
00704 if (!d->m_persistent->isChecked() || !d->m_persistent->isVisible())
00705 KDialog::done(result);
00706 }
00707 else
00708 KDialog::done(result);
00709 }
00710
00711 bool KPrintDialog::checkOutputFile()
00712 {
00713 bool value(false);
00714 if (d->m_file->url().isEmpty())
00715 KMessageBox::error(this,i18n("The output filename is empty."));
00716 else
00717 {
00718 KURL url( d->m_file->url() );
00719 if ( !url.isLocalFile() )
00720 return true;
00721
00722 bool anotherCheck;
00723 do
00724 {
00725 anotherCheck = false;
00726 TQFileInfo f(url.path());
00727 if (f.exists())
00728 {
00729 if (f.isWritable())
00730 {
00731
00732 time_t mtimeDest = f.lastModified().toTime_t();
00733 TDEIO::RenameDlg dlg( this, i18n( "Print" ), TQString::null, d->m_file->url(),
00734 TDEIO::M_OVERWRITE, ( time_t ) -1, f.size(), ( time_t ) -1, f.created().toTime_t() , mtimeDest+1, mtimeDest, true );
00735 int result = dlg.exec();
00736 switch ( result )
00737 {
00738 case TDEIO::R_OVERWRITE:
00739 value = true;
00740 break;
00741 default:
00742 case TDEIO::R_CANCEL:
00743 value = false;
00744 break;
00745 case TDEIO::R_RENAME:
00746 url = dlg.newDestURL();
00747 d->m_file->setURL( url.path() );
00748 value = true;
00749 anotherCheck = true;
00750 break;
00751 }
00752 }
00753 else
00754 KMessageBox::error(this,i18n("You don't have write permissions to this file."));
00755 }
00756 else
00757 {
00758 TQFileInfo d( f.dirPath( true ) );
00759 if ( !d.exists() )
00760 KMessageBox::error( this, i18n( "The output directory does not exist." ) );
00761 else if ( !d.isWritable() )
00762 KMessageBox::error(this,i18n("You don't have write permissions in that directory."));
00763 else
00764 value = true;
00765 }
00766 } while( anotherCheck );
00767 }
00768 return value;
00769 }
00770
00771 void KPrintDialog::slotOptions()
00772 {
00773 if (KMManager::self()->invokeOptionsDialog(this))
00774 init();
00775 }
00776
00777 void KPrintDialog::enableOutputFile(bool on)
00778 {
00779 d->m_filelabel->setEnabled(on);
00780 d->m_file->setEnabled(on);
00781 }
00782
00783 void KPrintDialog::enableSpecial(bool on)
00784 {
00785 d->m_default->setDisabled(on);
00786 d->m_cmdlabel->setDisabled(on);
00787 d->m_cmd->setDisabled(on);
00788 KPCopiesPage *copypage = (KPCopiesPage*)child("CopiesPage","KPCopiesPage");
00789 if (copypage)
00790 copypage->initialize(!on);
00791
00792 for (d->m_pages.first(); d->m_pages.current(); d->m_pages.next())
00793 if (d->m_pages.current()->onlyRealPrinters())
00794 d->m_pages.current()->setEnabled(!on);
00795 }
00796
00797 void KPrintDialog::setOutputFileExtension(const TQString& ext)
00798 {
00799 if (!ext.isEmpty())
00800 {
00801 KURL url( d->m_file->url() );
00802 TQString f( url.fileName() );
00803 int p = f.findRev( '.' );
00804
00805 if ( p > 0 && p != int (f.length () - 1) )
00806 {
00807 url.setFileName( f.left( p ) + "." + ext );
00808 d->m_file->setURL( KURL::decode_string( url.url() ) );
00809 }
00810 }
00811 }
00812
00813 void KPrintDialog::slotWizard()
00814 {
00815 int result = KMFactory::self()->manager()->addPrinterWizard(this);
00816 if (result == -1)
00817 KMessageBox::error(this, KMFactory::self()->manager()->errorMsg().prepend("<qt>").append("</qt>"));
00818 else if (result == 1)
00819 initialize(d->m_printer);
00820 }
00821
00822 void KPrintDialog::reload()
00823 {
00824
00825 TQTabWidget *tabs = static_cast<TQTabWidget*>(TQT_TQWIDGET(d->m_dummy->child("TabWidget", TQTABWIDGET_OBJECT_NAME_STRING)));
00826 for (uint i=0; i<d->m_pages.count(); i++)
00827 if (d->m_pages.at(i)->onlyRealPrinters())
00828 {
00829 KPrintDialogPage *page = d->m_pages.take(i--);
00830 if (tabs)
00831 tabs->removePage(page);
00832 delete page;
00833 }
00834
00835 TQPtrList<KPrintDialogPage> pages;
00836 pages.setAutoDelete(false);
00837 KMFactory::self()->uiManager()->setupPrintDialogPages(&pages);
00838
00839 setDialogPages(&pages);
00840 if (!d->m_reduced)
00841 d->m_dummy->show();
00842
00843 setFlags(KMFactory::self()->uiManager()->dialogFlags());
00844 connect( KMFactory::self()->manager(), TQT_SIGNAL( updatePossible( bool ) ), TQT_SLOT( slotUpdatePossible( bool ) ) );
00845 init();
00846 }
00847
00848 void KPrintDialog::configChanged()
00849 {
00850
00851
00852
00853 init();
00854
00855
00856 setFlags(KMFactory::self()->uiManager()->dialogFlags());
00857 }
00858
00859 void KPrintDialog::expandDialog(bool on)
00860 {
00861 TQSize sz(size());
00862 bool needResize(isVisible());
00863
00864 if (on)
00865 {
00866 sz.setHeight(sz.height()+d->m_dummy->minimumSize().height()+d->m_plugin->minimumSize().height()+2*layout()->spacing());
00867 if (isVisible() || !d->m_dummy->isVisible() || !d->m_plugin->isVisible())
00868 {
00869 d->m_dummy->show();
00870 if (d->b_systemEnabled)
00871 d->m_plugin->show();
00872 }
00873 d->m_extbtn->setIconSet(SmallIconSet("go-up"));
00874 d->m_extbtn->setText(i18n("&Options <<"));
00875 d->m_reduced = false;
00876 }
00877 else
00878 {
00879 sz.setHeight(sz.height()-d->m_dummy->height()-d->m_plugin->height()-2*layout()->spacing());
00880 if (!isVisible() || d->m_dummy->isVisible() || d->m_plugin->isVisible())
00881 {
00882 d->m_dummy->hide();
00883 if (d->b_systemEnabled)
00884 d->m_plugin->hide();
00885 }
00886 d->m_extbtn->setIconSet(SmallIconSet("go-down"));
00887 d->m_extbtn->setText(i18n("&Options >>"));
00888 d->m_reduced = true;
00889 }
00890
00891 if (needResize)
00892 {
00893 layout()->activate();
00894 resize(sz);
00895 }
00896 }
00897
00898 void KPrintDialog::slotExtensionClicked()
00899 {
00900
00901 expandDialog(!(d->m_dummy->isVisible()));
00902 }
00903
00904 KPrinter* KPrintDialog::printer() const
00905 {
00906 return d->m_printer;
00907 }
00908
00909 void KPrintDialog::slotToggleFilter(bool on)
00910 {
00911 KMManager::self()->enableFilter(on);
00912 initialize(d->m_printer);
00913 }
00914
00915 void KPrintDialog::slotHelp()
00916 {
00917 kapp->invokeHelp(TQString::null, "tdeprint");
00918 }
00919
00920 void KPrintDialog::slotOutputFileSelected(const TQString& txt)
00921 {
00922 d->m_file->setURL( txt );
00923 }
00924
00925 void KPrintDialog::init()
00926 {
00927 d->m_ok->setEnabled( false );
00928 MessageWindow::remove( this );
00929 MessageWindow::add( this, i18n( "Initializing printing system..." ), 500 );
00930 KMFactory::self()->manager()->checkUpdatePossible();
00931 }
00932
00933 void KPrintDialog::slotUpdatePossible( bool flag )
00934 {
00935 MessageWindow::remove( this );
00936 if ( !flag )
00937 KMessageBox::error(parentWidget(),
00938 "<qt><nobr>"+
00939 i18n("An error occurred while retrieving the printer list:")
00940 +"</nobr><br><br>"+KMManager::self()->errorMsg()+"</qt>");
00941 initialize( d->m_printer );
00942 }
00943
00944 void KPrintDialog::enableDialogPage( int index, bool flag )
00945 {
00946 if ( index < 0 || index >= ( int )d->m_pages.count() )
00947 {
00948 kdWarning() << "KPrintDialog: page index out of bound" << endl;
00949 return;
00950 }
00951
00952 if ( d->m_pages.count() > 1 )
00953 {
00954 TQTabWidget *tabs = static_cast<TQTabWidget*>(TQT_TQWIDGET(d->m_dummy->child("TabWidget", TQTABWIDGET_OBJECT_NAME_STRING)));
00955 tabs->setTabEnabled( d->m_pages.at( index ), flag );
00956 }
00957 else
00958 d->m_pages.at( 0 )->setEnabled( flag );
00959 }
00960
00961 void KPrintDialog::slotOpenFileDialog()
00962 {
00963 KFileDialog *dialog = d->m_file->fileDialog();
00964
00965 dialog->setCaption(i18n("Print to File"));
00966 dialog->setMode(d->m_file->fileDialog()->mode() & ~KFile::LocalOnly);
00967 dialog->setOperationMode( KFileDialog::Saving );
00968
00969 KMPrinter *prt = KMFactory::self()->manager()->findPrinter(d->m_printers->currentText());
00970 if (prt)
00971 {
00972 QString mimetype(prt->option("kde-special-mimetype"));
00973 QString ext(prt->option("kde-special-extension"));
00974
00975 if (!mimetype.isEmpty())
00976 {
00977 TQStringList filter;
00978 filter << mimetype;
00979 filter << "all/allfiles";
00980 dialog->setMimeFilter (filter, mimetype);
00981 }
00982 else if (!ext.isEmpty())
00983 dialog->setFilter ("*." + ext + "\n*|" + i18n ("All Files"));
00984 }
00985 }
00986
00987 #include "kprintdialog.moc"