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

tdeprint

  • tdeprint
  • management
kmdriverdbwidget.cpp
1 /*
2  * This file is part of the KDE libraries
3  * Copyright (c) 2001 Michael Goffioul <tdeprint@swing.be>
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Library General Public
7  * License version 2 as published by the Free Software Foundation.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Library General Public License for more details.
13  *
14  * You should have received a copy of the GNU Library General Public License
15  * along with this library; see the file COPYING.LIB. If not, write to
16  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17  * Boston, MA 02110-1301, USA.
18  **/
19 
20 #include "kmdriverdbwidget.h"
21 #include "kmdriverdb.h"
22 #include "kmfactory.h"
23 #include "kmmanager.h"
24 #include "driver.h"
25 
26 #include <tdelistbox.h>
27 #include <kpushbutton.h>
28 #include <tqcheckbox.h>
29 #include <kcursor.h>
30 #include <tqapplication.h>
31 #include <tdemessagebox.h>
32 #include <tqlayout.h>
33 #include <tqlabel.h>
34 #include <tqstrlist.h>
35 
36 #include <tdelocale.h>
37 #include <kcursor.h>
38 #include <tdefiledialog.h>
39 #include <kguiitem.h>
40 #include <tdeio/netaccess.h>
41 
42 KMDriverDbWidget::KMDriverDbWidget(TQWidget *parent, const char *name)
43 : TQWidget(parent,name)
44 {
45  m_external = TQString::null;
46  m_valid = false;
47 
48  // build widget
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);
58  l1->setBuddy(m_manu);
59  l2->setBuddy(m_model);
60 
61  // build layout
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(TQT_TQLAYOUT(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);
75 
76  // build connections
77  connect(KMDriverDB::self(),TQT_SIGNAL(dbLoaded(bool)),TQT_SLOT(slotDbLoaded(bool)));
78  connect(KMDriverDB::self(), TQT_SIGNAL(error(const TQString&)), TQT_SLOT(slotError(const TQString&)));
79  connect(m_manu,TQT_SIGNAL(highlighted(const TQString&)),TQT_SLOT(slotManufacturerSelected(const TQString&)));
80  connect(m_raw,TQT_SIGNAL(toggled(bool)),m_manu,TQT_SLOT(setDisabled(bool)));
81  connect(m_raw,TQT_SIGNAL(toggled(bool)),m_model,TQT_SLOT(setDisabled(bool)));
82  connect(m_raw,TQT_SIGNAL(toggled(bool)),m_other,TQT_SLOT(setDisabled(bool)));
83  connect(m_raw,TQT_SIGNAL(toggled(bool)),m_postscript,TQT_SLOT(setDisabled(bool)));
84  connect(m_postscript,TQT_SIGNAL(toggled(bool)),m_manu,TQT_SLOT(setDisabled(bool)));
85  connect(m_postscript,TQT_SIGNAL(toggled(bool)),m_model,TQT_SLOT(setDisabled(bool)));
86  connect(m_postscript,TQT_SIGNAL(toggled(bool)),m_other,TQT_SLOT(setDisabled(bool)));
87  connect(m_postscript,TQT_SIGNAL(toggled(bool)),m_raw,TQT_SLOT(setDisabled(bool)));
88  connect(m_postscript,TQT_SIGNAL(toggled(bool)),TQT_SLOT(slotPostscriptToggled(bool)));
89  connect(m_other,TQT_SIGNAL(clicked()),TQT_SLOT(slotOtherClicked()));
90 }
91 
92 KMDriverDbWidget::~KMDriverDbWidget()
93 {
94 }
95 
96 void KMDriverDbWidget::setDriver(const TQString& manu, const TQString& model)
97 {
98  TQListBoxItem *item = m_manu->findItem(manu);
99  TQString model_(model);
100  if (item)
101  {
102  m_manu->setCurrentItem(item);
103  item = m_model->findItem(model_);
104  if (!item)
105  // try by stripping the manufacturer name from
106  // the beginning of the model string. This is
107  // often the case with PPD files
108  item = m_model->findItem(model_.replace(0,manu.length()+1,TQString::fromLatin1("")));
109  if (item)
110  m_model->setCurrentItem(item);
111  }
112 }
113 
114 void KMDriverDbWidget::setHaveRaw(bool on)
115 {
116  if (on)
117  m_raw->show();
118  else
119  m_raw->hide();
120 }
121 
122 void KMDriverDbWidget::setHaveOther(bool on)
123 {
124  if (on)
125  m_other->show();
126  else
127  m_other->hide();
128 }
129 
130 TQString KMDriverDbWidget::manufacturer()
131 {
132  return m_manu->currentText();
133 }
134 
135 TQString KMDriverDbWidget::model()
136 {
137  return m_model->currentText();
138 }
139 
140 KMDBEntryList* KMDriverDbWidget::drivers()
141 {
142  return KMDriverDB::self()->findEntry(manufacturer(),model());
143 }
144 
145 bool KMDriverDbWidget::isRaw()
146 {
147  return m_raw->isChecked();
148 }
149 
150 void KMDriverDbWidget::init()
151 {
152  if (!m_valid)
153  {
154  TQApplication::setOverrideCursor(KCursor::waitCursor());
155  m_manu->clear();
156  m_model->clear();
157  m_manu->insertItem(i18n("Loading..."));
158  KMDriverDB::self()->init(this);
159  }
160 }
161 
162 void KMDriverDbWidget::slotDbLoaded(bool reloaded)
163 {
164  TQApplication::restoreOverrideCursor();
165  m_valid = true;
166  if (reloaded || m_manu->count() == 0 || (m_manu->count() == 1 && m_manu->text(0) == i18n("Loading...")))
167  { // do something only if DB reloaded
168  m_manu->clear();
169  m_model->clear();
170  TQDictIterator< TQDict<KMDBEntryList> > it(KMDriverDB::self()->manufacturers());
171  for (;it.current();++it)
172  m_manu->insertItem(it.currentKey());
173  m_manu->sort();
174  m_manu->setCurrentItem(0);
175  }
176 }
177 
178 void KMDriverDbWidget::slotError(const TQString& msg)
179 {
180  TQApplication::restoreOverrideCursor();
181  m_valid = false;
182  m_manu->clear();
183  KMessageBox::error(this, "<qt>"+msg+"</qt>");
184 }
185 
186 void KMDriverDbWidget::slotManufacturerSelected(const TQString& name)
187 {
188  m_model->clear();
189  TQDict<KMDBEntryList> *models = KMDriverDB::self()->findModels(name);
190  if (models)
191  {
192  TQStrIList ilist(true);
193  TQDictIterator<KMDBEntryList> it(*models);
194  for (;it.current();++it)
195  ilist.append(it.currentKey().latin1());
196  ilist.sort();
197  m_model->insertStrList(&ilist);
198  m_model->setCurrentItem(0);
199  }
200 }
201 
202 void KMDriverDbWidget::slotPostscriptToggled(bool on)
203 {
204  if (on)
205  {
206  TQListBoxItem *item = m_manu->findItem("GENERIC");
207  if (item)
208  {
209  m_manu->setCurrentItem(item);
210  item = m_model->findItem( "POSTSCRIPT PRINTER" );
211  if ( item )
212  {
213  m_model->setCurrentItem( item );
214  return;
215  }
216  }
217  KMessageBox::error(this,i18n("Unable to find the PostScript driver."));
218  m_postscript->setChecked(false);
219  }
220 }
221 
222 void KMDriverDbWidget::slotOtherClicked()
223 {
224  if (m_external.isEmpty())
225  {
226  KFileDialog dlg( TQString::null, TQString::null, this, 0, true );
227  KURL url;
228 
229  dlg.setMode( KFile::File );
230  dlg.setCaption( i18n( "Select Driver" ) );
231  if ( dlg.exec() )
232  url = dlg.selectedURL();
233 
234  if ( !url.isEmpty() )
235  {
236  TQString filename;
237  if ( TDEIO::NetAccess::download( url, filename, this ) )
238  {
239  DrMain *driver = KMFactory::self()->manager()->loadFileDriver(filename);
240  if (driver)
241  {
242  m_external = filename;
243  disconnect(m_manu,TQT_SIGNAL(highlighted(const TQString&)),this,TQT_SLOT(slotManufacturerSelected(const TQString&)));
244  m_manu->clear();
245  m_model->clear();
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");
254  delete driver;
255  }
256  else
257  {
258  TDEIO::NetAccess::removeTempFile( filename );
259  KMessageBox::error(this,"<qt>"+i18n("Wrong driver format.")+"<p>"+KMManager::self()->errorMsg()+"</p></qt>");
260  }
261  }
262  }
263  }
264  else
265  {
266  m_external = TQString::null;
267  connect(m_manu,TQT_SIGNAL(highlighted(const TQString&)),this,TQT_SLOT(slotManufacturerSelected(const TQString&)));
268  m_other->setText(i18n("Other"));
269  m_desc = TQString::null;
270  slotDbLoaded(true);
271  }
272 }
273 #include "kmdriverdbwidget.moc"

tdeprint

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

tdeprint

Skip menu "tdeprint"
  • arts
  • dcop
  • dnssd
  • interfaces
  •   kspeech
  •     interface
  •     library
  •   tdetexteditor
  • kate
  • kded
  • kdoctools
  • kimgio
  • kjs
  • libtdemid
  • libtdescreensaver
  •     tdecore
  • tdeabc
  • tdecmshell
  • tdecore
  • tdefx
  • tdehtml
  • tdeinit
  • tdeio
  •   bookmarks
  •   httpfilter
  •   kpasswdserver
  •   kssl
  • tdeioslave
  •   http
  •   tdefile
  •   tdeio
  •   tdeioexec
  • tdemdi
  •   tdemdi
  • tdenewstuff
  • tdeparts
  • tdeprint
  • tderandr
  • tderesources
  • tdespell2
  • tdesu
  • tdeui
  • tdeunittest
  • tdeutils
  • tdewallet
Generated for tdeprint by doxygen 1.8.8
This website is maintained by Timothy Pearson.