kmwdriverselect.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 "kmwdriverselect.h"
00021 #include "kmwizard.h"
00022 #include "kmprinter.h"
00023 #include "kmdbentry.h"
00024 #include "kmdriverdb.h"
00025 
00026 #include <qlabel.h>
00027 #include <qlayout.h>
00028 #include <kpushbutton.h>
00029 #include <klistbox.h>
00030 #include <klocale.h>
00031 #include <kmessagebox.h>
00032 
00033 KMWDriverSelect::KMWDriverSelect(QWidget *parent, const char *name)
00034 : KMWizardPage(parent,name)
00035 {
00036     m_ID = KMWizard::DriverSelect;
00037     m_title = i18n("Driver Selection");
00038     m_nextpage = KMWizard::DriverTest;
00039     m_entries = NULL;
00040 
00041     m_list = new KListBox(this);
00042     QLabel  *l1 = new QLabel(this);
00043     l1->setText(i18n("<p>Several drivers have been detected for this model. Select the driver "
00044              "you want to use. You will have the opportunity to test it as well as to "
00045              "change it if necessary.</p>"));
00046     m_drivercomment = new KPushButton(i18n("Driver Information"), this);
00047     connect(m_drivercomment, SIGNAL(clicked()), SLOT(slotDriverComment()));
00048 
00049     QVBoxLayout *main_ = new QVBoxLayout(this, 0, 10);
00050     main_->addWidget(l1,0);
00051     main_->addWidget(m_list,1);
00052     QHBoxLayout *lay0 = new QHBoxLayout(0, 0, 0);
00053     main_->addLayout(lay0,0);
00054     lay0->addStretch(1);
00055     lay0->addWidget(m_drivercomment);
00056 }
00057 
00058 bool KMWDriverSelect::isValid(QString& msg)
00059 {
00060     if (m_list->currentItem() == -1)
00061     {
00062         msg = i18n("You must select a driver.");
00063         return false;
00064     }
00065     return true;
00066 }
00067 
00068 void KMWDriverSelect::initPrinter(KMPrinter *p)
00069 {
00070     m_entries = KMDriverDB::self()->findEntry(p->manufacturer(),p->model());
00071     m_list->clear();
00072     if (m_entries)
00073     {
00074         KMDBEntryListIterator   it(*m_entries);
00075         int recomm(0);
00076         for (;it.current();++it)
00077         {
00078             QString s(it.current()->description);
00079             if (it.current()->recommended)
00080             {
00081                 recomm = m_list->count();
00082                 s.append(i18n(" [recommended]"));
00083             }
00084             m_list->insertItem(s);
00085         }
00086         if (m_entries->count() > 0)
00087             m_list->setSelected(recomm, true);
00088     }
00089 }
00090 
00091 void KMWDriverSelect::updatePrinter(KMPrinter *p)
00092 {
00093     int index = m_list->currentItem();
00094     if (m_entries && index >= 0 && index < (int)(m_entries->count()))
00095     {
00096         KMDBEntry   *entry = m_entries->at(index);
00097         p->setDbEntry(entry);
00098         p->setDriverInfo(entry->description);
00099     }
00100     else
00101     {
00102         p->setDbEntry(0);
00103         p->setDriverInfo(QString::null);
00104     }
00105 }
00106 
00107 void KMWDriverSelect::slotDriverComment()
00108 {
00109     int index = m_list->currentItem();
00110     if (m_entries && index >=0 && index < (int)(m_entries->count()) && !m_entries->at(index)->drivercomment.isEmpty())
00111         KMessageBox::information(this, m_entries->at(index)->drivercomment, QString::null, QString::null, KMessageBox::AllowLink);
00112     else
00113         KMessageBox::error(this, i18n("No information about the selected driver."));
00114 }
00115 
00116 #include "kmwdriverselect.moc"
KDE Home | KDE Accessibility Home | Description of Access Keys