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