| # kdeprint Library API Documentation
Overview | Class Hierarchy | Classes | Classes (annotated) | Members | Namespaces | Source Files

# kmwdrivertest.cpp

    00001 /*
    00002  *  This file is part of the KDE libraries
    00003  *  Copyright (c) 2001 Michael Goffioul <kdeprint@swing.be>
    00004  *
    00005  *  This library is free software; you can redistribute it and/or
    00006  *  modify it under the terms of the GNU Library General Public
    00007  *  License version 2 as published by the Free Software Foundation.
    00008  *
    00009  *  This library is distributed in the hope that it will be useful,
    00010  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
    00011  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    00012  *  Library General Public License for more details.
    00013  *
    00014  *  You should have received a copy of the GNU Library General Public License
    00015  *  along with this library; see the file COPYING.LIB.  If not, write to
    00016  *  the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
    00017  *  Boston, MA 02111-1307, USA.
    00018  **/
    00019
    00020 #include "kmwdrivertest.h"
    00021 #include "kmprinter.h"
    00022 #include "kmwizard.h"
    00023 #include "driver.h"
    00024 #include "kmfactory.h"
    00025 #include "kmmanager.h"
    00026 #include "kmdriverdialog.h"
    00027
    00028 #include <qlabel.h>
    00029 #include <kpushbutton.h>
    00030 #include <qlayout.h>
    00031 #include <klocale.h>
    00032 #include <kapplication.h>
    00033 #include <kmessagebox.h>
    00034 #include <kguiitem.h>
    00035 #include <kio/netaccess.h>
    00036
    00037 KMWDriverTest::KMWDriverTest(QWidget *parent, const char *name)
    00038 : KMWizardPage(parent,name)
    00039 {
    00040     m_ID = KMWizard::DriverTest;
    00041     m_title = i18n("Printer Test");
    00042     m_nextpage = KMWizard::Name;
    00043     m_driver = 0;
    00044     m_printer = 0;
    00045
    00046     m_manufacturer = new QLabel(this);
    00047     m_model = new QLabel(this);
    00048     m_driverinfo = new QLabel(this);
    00049     m_driverinfo->setTextFormat(Qt::RichText);
    00050     QLabel  *l1 = new QLabel(i18n("<b>Manufacturer:</b>"), this);
    00051     QLabel  *l2 = new QLabel(i18n("<b>Model:</b>"), this);
    00052     QLabel  *l3 = new QLabel(i18n("<b>Description:</b>"), this);
    00053
    00054     m_test = new KPushButton(KGuiItem(i18n("&Test"), "kdeprint_testprinter"), this);
    00055     m_settings = new KPushButton(KGuiItem(i18n("&Settings"), "configure"), this);
    00056
    00057     QLabel  *l0 = new QLabel(this);
    00058     l0->setText(i18n("<p>Now you can test the printer before finishing installation. "
    00059              "Use the <b>Settings</b> button to configure the printer driver and "
    00060              "the <b>Test</b> button to test your configuration. Use the <b>Back</b> "
    00061              "button to change the driver (your current configuration will be discarded).</p>"));
    00062
    00063     QVBoxLayout *lay1 = new QVBoxLayout(this, 0, 15);
    00064     QGridLayout *lay2 = new QGridLayout(0, 3, 3, 0, 0);
    00065     QHBoxLayout *lay3 = new QHBoxLayout(0, 0, 10);
    00066     lay1->addWidget(l0,0);
    00067     lay1->addLayout(lay2,0);
    00068     lay1->addLayout(lay3,0);
    00069     lay1->addStretch(1);
    00070     lay2->setColStretch(2,1);
    00071     lay2->addColSpacing(1,10);
    00072     lay2->addWidget(l1,0,0);
    00073     lay2->addWidget(l2,1,0);
    00074     lay2->addWidget(l3,2,0,Qt::AlignLeft|Qt::AlignTop);
    00075     lay2->addWidget(m_manufacturer,0,2);
    00076     lay2->addWidget(m_model,1,2);
    00077     lay2->addWidget(m_driverinfo,2,2);
    00078     lay3->addWidget(m_test,0);
    00079     lay3->addWidget(m_settings,0);
    00080     lay3->addStretch(1);
    00081
    00082     connect(m_test,SIGNAL(clicked()),SLOT(slotTest()));
    00083     connect(m_settings,SIGNAL(clicked()),SLOT(slotSettings()));
    00084 }
    00085
    00086 KMWDriverTest::~KMWDriverTest()
    00087 {
    00088     delete m_driver;
    00089 }
    00090
    00091 void KMWDriverTest::initPrinter(KMPrinter *p)
    00092 {
    00093     m_manufacturer->setText(p->manufacturer());
    00094     m_model->setText(p->model());
    00095     m_driverinfo->setText(p->driverInfo());
    00096     m_printer = p;
    00097
    00098     delete m_driver;
    00099     m_driver = 0;
    00100
    00101     QString drfile = p->option("kde-driver");
    00102     bool    checkDriver(true);
    00103     if (!drfile.isEmpty() && drfile != "raw")
    00104     {
    00105         m_driver = KMFactory::self()->manager()->loadFileDriver(drfile);
    00106         /* remove the temp file if it has been downloaded */
    00107         KIO::NetAccess::removeTempFile( drfile );
    00108     }
    00109     else if (p->dbEntry() != NULL)
    00110         m_driver = KMFactory::self()->manager()->loadDbDriver(p->dbEntry());
    00111     else
    00112         checkDriver = false;
    00113
    00114     if (checkDriver && !m_driver)
    00115     {
    00116         KMessageBox::error(this, i18n("<qt>Unable to load the requested driver:<p>%1</p></qt>").arg(KMManager::self()->errorMsg()));
    00117         KMManager::self()->setErrorMsg(QString::null);
    00118     }
    00119     m_settings->setEnabled((m_driver != 0));
    00120 }
    00121
    00122 void KMWDriverTest::updatePrinter(KMPrinter *p)
    00123 {
    00124     // Give the DrMain structure to the driver and don't care about it anymore.
    00125     // It will be destroyed either when giving another structure, or when the
    00126     // printer object will be destroyed.
    00127     p->setDriver(m_driver);
    00128     m_driver = 0;
    00129 }
    00130
    00131 void KMWDriverTest::slotTest()
    00132 {
    00133     if (!m_printer) return;
    00134
    00135     QString name = "tmpprinter_"+KApplication::randomString(8);
    00136     // save printer name (can be non empty when modifying a printer)
    00137     QString oldname = m_printer->name();
    00138
    00139     m_printer->setName(name);
    00140     m_printer->setPrinterName(name);
    00141     m_printer->setDriver(m_driver);
    00142     if (KMFactory::self()->manager()->createPrinter(m_printer))
    00143     {
    00144         if (KMFactory::self()->manager()->testPrinter(m_printer))
    00145             KMessageBox::information(this,"<qt>"+i18n("Test page successfully sent to printer. Wait until printing is complete, then click the OK button."));
    00146         else
    00147             KMessageBox::error(this,"<qt>"+i18n("Unable to test printer: ")+KMFactory::self()->manager()->errorMsg()+"</qt>");
    00148         if (!KMFactory::self()->manager()->removePrinter(m_printer))
    00149             KMessageBox::error(this,i18n("Unable to remove temporary printer."));
    00150     }
    00151     else
    00152         KMessageBox::error(this,i18n("Unable to create temporary printer."));
    00153
    00154     // restoring old name
    00155     m_printer->setName(oldname);
    00156     m_printer->setPrinterName(oldname);
    00157
    00158     m_driver = m_printer->takeDriver();
    00159 }
    00160
    00161 void KMWDriverTest::slotSettings()
    00162 {
    00163     if (m_driver)
    00164     {
    00165         KMDriverDialog  dlg(this);
    00166         dlg.setDriver(m_driver);
    00167         dlg.showButtonCancel(false);    // only OK button
    00168         dlg.exec();
    00169     }
    00170 }
    00171 #include "kmwdrivertest.moc"

This file is part of the documentation for kdeprint Library Version 3.4.1.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Sat Jun 11 20:31:03 2005 by doxygen 1.4.1 written by Dimitri van Heesch, © 1997-2003