• Skip to content
  • Skip to link menu
Trinity API Reference
  • Trinity API Reference
  • kdeprint
 

kdeprint

kmdriverdbwidget.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., 51 Franklin Street, Fifth Floor,
00017  *  Boston, MA 02110-1301, USA.
00018  **/
00019 
00020 #include "kmdriverdbwidget.h"
00021 #include "kmdriverdb.h"
00022 #include "kmfactory.h"
00023 #include "kmmanager.h"
00024 #include "driver.h"
00025 
00026 #include <klistbox.h>
00027 #include <kpushbutton.h>
00028 #include <tqcheckbox.h>
00029 #include <kcursor.h>
00030 #include <tqapplication.h>
00031 #include <kmessagebox.h>
00032 #include <tqlayout.h>
00033 #include <tqlabel.h>
00034 #include <tqstrlist.h>
00035 
00036 #include <klocale.h>
00037 #include <kcursor.h>
00038 #include <kfiledialog.h>
00039 #include <kguiitem.h>
00040 #include <kio/netaccess.h>
00041 
00042 KMDriverDbWidget::KMDriverDbWidget(TQWidget *parent, const char *name)
00043 : TQWidget(parent,name)
00044 {
00045     m_external = TQString::null;
00046     m_valid = false;
00047 
00048     // build widget
00049     m_manu = new KListBox(this);
00050     m_model = new KListBox(this);
00051     m_postscript = new TQCheckBox(i18n("&PostScript printer"),this);
00052     m_raw = new TQCheckBox(i18n("&Raw printer (no driver needed)"),this);
00053     m_postscript->setCursor(KCursor::handCursor());
00054     m_raw->setCursor(KCursor::handCursor());
00055     m_other = new KPushButton(KGuiItem(i18n("&Other..."), "fileopen"), this);
00056     TQLabel *l1 = new TQLabel(i18n("&Manufacturer:"), this);
00057     TQLabel *l2 = new TQLabel(i18n("Mo&del:"), this);
00058     l1->setBuddy(m_manu);
00059     l2->setBuddy(m_model);
00060 
00061     // build layout
00062     TQVBoxLayout    *main_ = new TQVBoxLayout(this, 0, 10);
00063     TQGridLayout    *sub1_ = new TQGridLayout(0, 2, 3, 0, 0);
00064     TQHBoxLayout    *sub2_ = new TQHBoxLayout(0, 0, 10);
00065     main_->addLayout(TQT_TQLAYOUT(sub1_));
00066     main_->addLayout(sub2_);
00067     main_->addWidget(m_raw);
00068     sub1_->addWidget(l1,0,0);
00069     sub1_->addWidget(l2,0,2);
00070     sub1_->addWidget(m_manu,1,0);
00071     sub1_->addWidget(m_model,1,2);
00072     sub1_->addColSpacing(1,20);
00073     sub2_->addWidget(m_postscript,1);
00074     sub2_->addWidget(m_other,0);
00075 
00076     // build connections
00077     connect(KMDriverDB::self(),TQT_SIGNAL(dbLoaded(bool)),TQT_SLOT(slotDbLoaded(bool)));
00078     connect(KMDriverDB::self(), TQT_SIGNAL(error(const TQString&)), TQT_SLOT(slotError(const TQString&)));
00079     connect(m_manu,TQT_SIGNAL(highlighted(const TQString&)),TQT_SLOT(slotManufacturerSelected(const TQString&)));
00080     connect(m_raw,TQT_SIGNAL(toggled(bool)),m_manu,TQT_SLOT(setDisabled(bool)));
00081     connect(m_raw,TQT_SIGNAL(toggled(bool)),m_model,TQT_SLOT(setDisabled(bool)));
00082     connect(m_raw,TQT_SIGNAL(toggled(bool)),m_other,TQT_SLOT(setDisabled(bool)));
00083     connect(m_raw,TQT_SIGNAL(toggled(bool)),m_postscript,TQT_SLOT(setDisabled(bool)));
00084     connect(m_postscript,TQT_SIGNAL(toggled(bool)),m_manu,TQT_SLOT(setDisabled(bool)));
00085     connect(m_postscript,TQT_SIGNAL(toggled(bool)),m_model,TQT_SLOT(setDisabled(bool)));
00086     connect(m_postscript,TQT_SIGNAL(toggled(bool)),m_other,TQT_SLOT(setDisabled(bool)));
00087     connect(m_postscript,TQT_SIGNAL(toggled(bool)),m_raw,TQT_SLOT(setDisabled(bool)));
00088     connect(m_postscript,TQT_SIGNAL(toggled(bool)),TQT_SLOT(slotPostscriptToggled(bool)));
00089     connect(m_other,TQT_SIGNAL(clicked()),TQT_SLOT(slotOtherClicked()));
00090 }
00091 
00092 KMDriverDbWidget::~KMDriverDbWidget()
00093 {
00094 }
00095 
00096 void KMDriverDbWidget::setDriver(const TQString& manu, const TQString& model)
00097 {
00098     TQListBoxItem   *item = m_manu->findItem(manu);
00099     TQString        model_(model);
00100     if (item)
00101     {
00102         m_manu->setCurrentItem(item);
00103         item = m_model->findItem(model_);
00104         if (!item)
00105             // try by stripping the manufacturer name from
00106             // the beginning of the model string. This is
00107             // often the case with PPD files
00108             item = m_model->findItem(model_.replace(0,manu.length()+1,TQString::fromLatin1("")));
00109         if (item)
00110             m_model->setCurrentItem(item);
00111     }
00112 }
00113 
00114 void KMDriverDbWidget::setHaveRaw(bool on)
00115 {
00116     if (on)
00117         m_raw->show();
00118     else
00119         m_raw->hide();
00120 }
00121 
00122 void KMDriverDbWidget::setHaveOther(bool on)
00123 {
00124     if (on)
00125         m_other->show();
00126     else
00127         m_other->hide();
00128 }
00129 
00130 TQString KMDriverDbWidget::manufacturer()
00131 {
00132     return m_manu->currentText();
00133 }
00134 
00135 TQString KMDriverDbWidget::model()
00136 {
00137     return m_model->currentText();
00138 }
00139 
00140 KMDBEntryList* KMDriverDbWidget::drivers()
00141 {
00142     return KMDriverDB::self()->findEntry(manufacturer(),model());
00143 }
00144 
00145 bool KMDriverDbWidget::isRaw()
00146 {
00147     return m_raw->isChecked();
00148 }
00149 
00150 void KMDriverDbWidget::init()
00151 {
00152     if (!m_valid)
00153     {
00154         TQApplication::setOverrideCursor(KCursor::waitCursor());
00155         m_manu->clear();
00156         m_model->clear();
00157         m_manu->insertItem(i18n("Loading..."));
00158         KMDriverDB::self()->init(this);
00159     }
00160 }
00161 
00162 void KMDriverDbWidget::slotDbLoaded(bool reloaded)
00163 {
00164     TQApplication::restoreOverrideCursor();
00165     m_valid = true;
00166     if (reloaded || m_manu->count() == 0 || (m_manu->count() == 1 && m_manu->text(0) == i18n("Loading...")))
00167     { // do something only if DB reloaded
00168         m_manu->clear();
00169         m_model->clear();
00170         TQDictIterator< TQDict<KMDBEntryList> > it(KMDriverDB::self()->manufacturers());
00171         for (;it.current();++it)
00172             m_manu->insertItem(it.currentKey());
00173         m_manu->sort();
00174         m_manu->setCurrentItem(0);
00175     }
00176 }
00177 
00178 void KMDriverDbWidget::slotError(const TQString& msg)
00179 {
00180     TQApplication::restoreOverrideCursor();
00181     m_valid = false;
00182     m_manu->clear();
00183     KMessageBox::error(this, "<qt>"+msg+"</qt>");
00184 }
00185 
00186 void KMDriverDbWidget::slotManufacturerSelected(const TQString& name)
00187 {
00188     m_model->clear();
00189     TQDict<KMDBEntryList>   *models = KMDriverDB::self()->findModels(name);
00190     if (models)
00191     {
00192         TQStrIList  ilist(true);
00193         TQDictIterator<KMDBEntryList>   it(*models);
00194         for (;it.current();++it)
00195             ilist.append(it.currentKey().latin1());
00196         ilist.sort();
00197         m_model->insertStrList(&ilist);
00198         m_model->setCurrentItem(0);
00199     }
00200 }
00201 
00202 void KMDriverDbWidget::slotPostscriptToggled(bool on)
00203 {
00204     if (on)
00205     {
00206         TQListBoxItem   *item = m_manu->findItem("GENERIC");
00207         if (item)
00208         {
00209             m_manu->setCurrentItem(item);
00210             item = m_model->findItem( "POSTSCRIPT PRINTER" );
00211             if ( item )
00212             {
00213                 m_model->setCurrentItem( item );
00214                 return;
00215             }
00216         }
00217         KMessageBox::error(this,i18n("Unable to find the PostScript driver."));
00218         m_postscript->setChecked(false);
00219     }
00220 }
00221 
00222 void KMDriverDbWidget::slotOtherClicked()
00223 {
00224     if (m_external.isEmpty())
00225     {
00226         KFileDialog dlg( TQString::null, TQString::null, this, 0, true );
00227         KURL url;
00228 
00229         dlg.setMode( KFile::File );
00230         dlg.setCaption( i18n( "Select Driver" ) );
00231         if ( dlg.exec() )
00232             url = dlg.selectedURL();
00233 
00234         if ( !url.isEmpty() )
00235         {
00236             TQString filename;
00237             if ( KIO::NetAccess::download( url, filename, this ) )
00238             {
00239                 DrMain  *driver = KMFactory::self()->manager()->loadFileDriver(filename);
00240                 if (driver)
00241                 {
00242                     m_external = filename;
00243                     disconnect(m_manu,TQT_SIGNAL(highlighted(const TQString&)),this,TQT_SLOT(slotManufacturerSelected(const TQString&)));
00244                     m_manu->clear();
00245                     m_model->clear();
00246                     TQString    s = driver->get("manufacturer");
00247                     m_manu->insertItem((s.isEmpty() ? i18n("<Unknown>") : s));
00248                     s = driver->get("model");
00249                     m_model->insertItem((s.isEmpty() ? i18n("<Unknown>") : s));
00250                     m_manu->setCurrentItem(0);
00251                     m_model->setCurrentItem(0);
00252                     m_other->setText(i18n("Database"));
00253                     m_desc = driver->get("description");
00254                     delete driver;
00255                 }
00256                 else
00257                 {
00258                     KIO::NetAccess::removeTempFile( filename );
00259                     KMessageBox::error(this,"<qt>"+i18n("Wrong driver format.")+"<p>"+KMManager::self()->errorMsg()+"</p></qt>");
00260                 }
00261             }
00262         }
00263     }
00264     else
00265     {
00266         m_external = TQString::null;
00267         connect(m_manu,TQT_SIGNAL(highlighted(const TQString&)),this,TQT_SLOT(slotManufacturerSelected(const TQString&)));
00268         m_other->setText(i18n("Other"));
00269         m_desc = TQString::null;
00270         slotDbLoaded(true);
00271     }
00272 }
00273 #include "kmdriverdbwidget.moc"

kdeprint

Skip menu "kdeprint"
  • Main Page
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Class Members
  • Related Pages

kdeprint

Skip menu "kdeprint"
  • arts
  • dcop
  • dnssd
  • interfaces
  •     interface
  •     library
  •   kspeech
  •   ktexteditor
  • kabc
  • kate
  • kcmshell
  • kdecore
  • kded
  • kdefx
  • kdeprint
  • kdesu
  • kdeui
  • kdoctools
  • khtml
  • kimgio
  • kinit
  • kio
  •   bookmarks
  •   httpfilter
  •   kfile
  •   kio
  •   kioexec
  •   kpasswdserver
  •   kssl
  • kioslave
  •   http
  • kjs
  • kmdi
  •   kmdi
  • knewstuff
  • kparts
  • krandr
  • kresources
  • kspell2
  • kunittest
  • kutils
  • kwallet
  • libkmid
  • libkscreensaver
Generated for kdeprint by doxygen 1.7.6.1
This website is maintained by Timothy Pearson.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. |