20 #include "kmwdrivertest.h"
21 #include "kmprinter.h"
24 #include "kmfactory.h"
25 #include "kmmanager.h"
26 #include "kmdriverdialog.h"
29 #include <kpushbutton.h>
31 #include <tdelocale.h>
32 #include <tdeapplication.h>
33 #include <tdemessagebox.h>
35 #include <tdeio/netaccess.h>
37 KMWDriverTest::KMWDriverTest(TQWidget *parent,
const char *name)
38 : KMWizardPage(parent,name)
40 m_ID = KMWizard::DriverTest;
41 m_title = i18n(
"Printer Test");
42 m_nextpage = KMWizard::Name;
43 m_needsinitonback =
true;
47 m_manufacturer =
new TQLabel(
this);
48 m_model =
new TQLabel(
this);
49 m_driverinfo =
new TQLabel(
this);
50 m_driverinfo->setTextFormat(TQt::RichText);
51 TQLabel *l1 =
new TQLabel(i18n(
"<b>Manufacturer:</b>"),
this);
52 TQLabel *l2 =
new TQLabel(i18n(
"<b>Model:</b>"),
this);
53 TQLabel *l3 =
new TQLabel(i18n(
"<b>Description:</b>"),
this);
55 m_test =
new KPushButton(KGuiItem(i18n(
"&Test"),
"tdeprint_testprinter"),
this);
56 m_settings =
new KPushButton(KGuiItem(i18n(
"&Settings"),
"configure"),
this);
58 TQLabel *l0 =
new TQLabel(
this);
59 l0->setText(i18n(
"<p>Now you can test the printer before finishing installation. "
60 "Use the <b>Settings</b> button to configure the printer driver and "
61 "the <b>Test</b> button to test your configuration. Use the <b>Back</b> "
62 "button to change the driver (your current configuration will be discarded).</p>"));
64 TQVBoxLayout *lay1 =
new TQVBoxLayout(
this, 0, 15);
65 TQGridLayout *lay2 =
new TQGridLayout(0, 3, 3, 0, 0);
66 TQHBoxLayout *lay3 =
new TQHBoxLayout(0, 0, 10);
67 lay1->addWidget(l0,0);
68 lay1->addLayout(lay2,0);
69 lay1->addLayout(lay3,0);
71 lay2->setColStretch(2,1);
72 lay2->addColSpacing(1,10);
73 lay2->addWidget(l1,0,0);
74 lay2->addWidget(l2,1,0);
75 lay2->addWidget(l3,2,0,TQt::AlignLeft|TQt::AlignTop);
76 lay2->addWidget(m_manufacturer,0,2);
77 lay2->addWidget(m_model,1,2);
78 lay2->addWidget(m_driverinfo,2,2);
79 lay3->addWidget(m_test,0);
80 lay3->addWidget(m_settings,0);
83 connect(m_test,TQ_SIGNAL(clicked()),TQ_SLOT(slotTest()));
84 connect(m_settings,TQ_SIGNAL(clicked()),TQ_SLOT(slotSettings()));
87 KMWDriverTest::~KMWDriverTest()
92 void KMWDriverTest::initPrinter(KMPrinter *p)
94 m_manufacturer->setText(p->manufacturer());
95 m_model->setText(p->model());
96 m_driverinfo->setText(p->driverInfo());
102 TQString drfile = p->option(
"kde-driver");
103 bool checkDriver(
true);
104 if (!drfile.isEmpty() && drfile !=
"raw")
106 m_driver = KMFactory::self()->manager()->loadFileDriver(drfile);
108 TDEIO::NetAccess::removeTempFile( drfile );
110 else if (p->dbEntry() != NULL)
111 m_driver = KMFactory::self()->manager()->loadDbDriver(p->dbEntry());
115 if (checkDriver && !m_driver)
117 KMessageBox::error(
this, i18n(
"<qt>Unable to load the requested driver:<p>%1</p></qt>").arg(KMManager::self()->errorMsg()));
118 KMManager::self()->setErrorMsg(TQString::null);
120 m_settings->setEnabled((m_driver != 0));
123 void KMWDriverTest::updatePrinter(KMPrinter *p)
128 p->setDriver(m_driver);
132 void KMWDriverTest::slotTest()
134 if (!m_printer)
return;
136 TQString name =
"tmpprinter_"+TDEApplication::randomString(8);
138 TQString oldname = m_printer->name();
140 m_printer->setName(name);
141 m_printer->setPrinterName(name);
142 m_printer->setDriver(m_driver);
143 if (KMFactory::self()->manager()->createPrinter(m_printer))
145 if (KMFactory::self()->manager()->testPrinter(m_printer))
146 KMessageBox::information(
this,
"<qt>"+i18n(
"Test page successfully sent to printer. Wait until printing is complete, then click the OK button."));
148 KMessageBox::error(
this,
"<qt>"+i18n(
"Unable to test printer: ")+KMFactory::self()->manager()->errorMsg()+
"</qt>");
149 if (!KMFactory::self()->manager()->removePrinter(m_printer))
150 KMessageBox::error(
this,i18n(
"Unable to remove temporary printer."));
153 KMessageBox::error(
this,i18n(
"Unable to create temporary printer."));
156 m_printer->setName(oldname);
157 m_printer->setPrinterName(oldname);
159 m_driver = m_printer->takeDriver();
162 void KMWDriverTest::slotSettings()
166 KMDriverDialog dlg(
this);
167 dlg.setDriver(m_driver);
168 dlg.showButtonCancel(
false);
172 #include "kmwdrivertest.moc"