20 #include "kmdriverdbwidget.h"
21 #include "kmdriverdb.h"
22 #include "kmfactory.h"
23 #include "kmmanager.h"
26 #include <tdelistbox.h>
27 #include <kpushbutton.h>
28 #include <tqcheckbox.h>
30 #include <tqapplication.h>
31 #include <tdemessagebox.h>
34 #include <tqstrlist.h>
36 #include <tdelocale.h>
38 #include <tdefiledialog.h>
40 #include <tdeio/netaccess.h>
42 KMDriverDbWidget::KMDriverDbWidget(TQWidget *parent,
const char *name)
43 : TQWidget(parent,name)
45 m_external = TQString::null;
49 m_manu =
new TDEListBox(
this);
50 m_model =
new TDEListBox(
this);
51 m_postscript =
new TQCheckBox(i18n(
"&PostScript printer"),
this);
52 m_raw =
new TQCheckBox(i18n(
"&Raw printer (no driver needed)"),
this);
53 m_postscript->setCursor(KCursor::handCursor());
54 m_raw->setCursor(KCursor::handCursor());
55 m_other =
new KPushButton(KGuiItem(i18n(
"&Other..."),
"document-open"),
this);
56 TQLabel *l1 =
new TQLabel(i18n(
"&Manufacturer:"),
this);
57 TQLabel *l2 =
new TQLabel(i18n(
"Mo&del:"),
this);
59 l2->setBuddy(m_model);
62 TQVBoxLayout *main_ =
new TQVBoxLayout(
this, 0, 10);
63 TQGridLayout *sub1_ =
new TQGridLayout(0, 2, 3, 0, 0);
64 TQHBoxLayout *sub2_ =
new TQHBoxLayout(0, 0, 10);
65 main_->addLayout(sub1_);
66 main_->addLayout(sub2_);
67 main_->addWidget(m_raw);
68 sub1_->addWidget(l1,0,0);
69 sub1_->addWidget(l2,0,2);
70 sub1_->addWidget(m_manu,1,0);
71 sub1_->addWidget(m_model,1,2);
72 sub1_->addColSpacing(1,20);
73 sub2_->addWidget(m_postscript,1);
74 sub2_->addWidget(m_other,0);
77 connect(KMDriverDB::self(),TQ_SIGNAL(dbLoaded(
bool)),TQ_SLOT(slotDbLoaded(
bool)));
78 connect(KMDriverDB::self(), TQ_SIGNAL(error(
const TQString&)), TQ_SLOT(slotError(
const TQString&)));
79 connect(m_manu,TQ_SIGNAL(highlighted(
const TQString&)),TQ_SLOT(slotManufacturerSelected(
const TQString&)));
80 connect(m_raw,TQ_SIGNAL(toggled(
bool)),m_manu,TQ_SLOT(setDisabled(
bool)));
81 connect(m_raw,TQ_SIGNAL(toggled(
bool)),m_model,TQ_SLOT(setDisabled(
bool)));
82 connect(m_raw,TQ_SIGNAL(toggled(
bool)),m_other,TQ_SLOT(setDisabled(
bool)));
83 connect(m_raw,TQ_SIGNAL(toggled(
bool)),m_postscript,TQ_SLOT(setDisabled(
bool)));
84 connect(m_postscript,TQ_SIGNAL(toggled(
bool)),m_manu,TQ_SLOT(setDisabled(
bool)));
85 connect(m_postscript,TQ_SIGNAL(toggled(
bool)),m_model,TQ_SLOT(setDisabled(
bool)));
86 connect(m_postscript,TQ_SIGNAL(toggled(
bool)),m_other,TQ_SLOT(setDisabled(
bool)));
87 connect(m_postscript,TQ_SIGNAL(toggled(
bool)),m_raw,TQ_SLOT(setDisabled(
bool)));
88 connect(m_postscript,TQ_SIGNAL(toggled(
bool)),TQ_SLOT(slotPostscriptToggled(
bool)));
89 connect(m_other,TQ_SIGNAL(clicked()),TQ_SLOT(slotOtherClicked()));
92 KMDriverDbWidget::~KMDriverDbWidget()
96 void KMDriverDbWidget::setDriver(
const TQString& manu,
const TQString& model)
98 TQListBoxItem *item = m_manu->findItem(manu);
99 TQString model_(model);
102 m_manu->setCurrentItem(item);
103 item = m_model->findItem(model_);
108 item = m_model->findItem(model_.replace(0,manu.length()+1,TQString::fromLatin1(
"")));
110 m_model->setCurrentItem(item);
114 void KMDriverDbWidget::setHaveRaw(
bool on)
122 void KMDriverDbWidget::setHaveOther(
bool on)
130 TQString KMDriverDbWidget::manufacturer()
132 return m_manu->currentText();
135 TQString KMDriverDbWidget::model()
137 return m_model->currentText();
140 KMDBEntryList* KMDriverDbWidget::drivers()
142 return KMDriverDB::self()->findEntry(manufacturer(),model());
145 bool KMDriverDbWidget::isRaw()
147 return m_raw->isChecked();
150 void KMDriverDbWidget::init()
154 TQApplication::setOverrideCursor(KCursor::waitCursor());
157 m_manu->insertItem(i18n(
"Loading..."));
158 KMDriverDB::self()->init(
this);
162 void KMDriverDbWidget::slotDbLoaded(
bool reloaded)
164 TQApplication::restoreOverrideCursor();
166 if (reloaded || m_manu->count() == 0 || (m_manu->count() == 1 && m_manu->text(0) == i18n(
"Loading...")))
170 TQDictIterator< TQDict<KMDBEntryList> > it(KMDriverDB::self()->manufacturers());
171 for (;it.current();++it)
172 m_manu->insertItem(it.currentKey());
174 m_manu->setCurrentItem(0);
178 void KMDriverDbWidget::slotError(
const TQString& msg)
180 TQApplication::restoreOverrideCursor();
183 KMessageBox::error(
this,
"<qt>"+msg+
"</qt>");
186 void KMDriverDbWidget::slotManufacturerSelected(
const TQString& name)
189 TQDict<KMDBEntryList> *models = KMDriverDB::self()->findModels(name);
192 TQStrIList ilist(
true);
193 TQDictIterator<KMDBEntryList> it(*models);
194 for (;it.current();++it)
195 ilist.append(it.currentKey().latin1());
197 m_model->insertStrList(&ilist);
198 m_model->setCurrentItem(0);
202 void KMDriverDbWidget::slotPostscriptToggled(
bool on)
206 TQListBoxItem *item = m_manu->findItem(
"GENERIC");
209 m_manu->setCurrentItem(item);
210 item = m_model->findItem(
"POSTSCRIPT PRINTER" );
213 m_model->setCurrentItem( item );
217 KMessageBox::error(
this,i18n(
"Unable to find the PostScript driver."));
218 m_postscript->setChecked(
false);
222 void KMDriverDbWidget::slotOtherClicked()
224 if (m_external.isEmpty())
226 KFileDialog dlg( TQString::null, TQString::null,
this, 0,
true );
229 dlg.setMode( KFile::File );
230 dlg.setCaption( i18n(
"Select Driver" ) );
232 url = dlg.selectedURL();
234 if ( !url.isEmpty() )
237 if ( TDEIO::NetAccess::download( url, filename,
this ) )
239 DrMain *driver = KMFactory::self()->manager()->loadFileDriver(filename);
242 m_external = filename;
243 disconnect(m_manu,TQ_SIGNAL(highlighted(
const TQString&)),
this,TQ_SLOT(slotManufacturerSelected(
const TQString&)));
246 TQString s = driver->get(
"manufacturer");
247 m_manu->insertItem((s.isEmpty() ? i18n(
"<Unknown>") : s));
248 s = driver->get(
"model");
249 m_model->insertItem((s.isEmpty() ? i18n(
"<Unknown>") : s));
250 m_manu->setCurrentItem(0);
251 m_model->setCurrentItem(0);
252 m_other->setText(i18n(
"Database"));
253 m_desc = driver->get(
"description");
258 TDEIO::NetAccess::removeTempFile( filename );
259 KMessageBox::error(
this,
"<qt>"+i18n(
"Wrong driver format.")+
"<p>"+KMManager::self()->errorMsg()+
"</p></qt>");
266 m_external = TQString::null;
267 connect(m_manu,TQ_SIGNAL(highlighted(
const TQString&)),
this,TQ_SLOT(slotManufacturerSelected(
const TQString&)));
268 m_other->setText(i18n(
"Other"));
269 m_desc = TQString::null;
273 #include "kmdriverdbwidget.moc"