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

tdeprint

  • tdeprint
  • management
kmdriverdb.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 "kmdriverdb.h"
21 #include "kmdbentry.h"
22 #include "kmdbcreator.h"
23 #include "kmmanager.h"
24 #include "kmfactory.h"
25 #include <kdebug.h>
26 
27 #include <tqfile.h>
28 #include <tqtextstream.h>
29 #include <tqfileinfo.h>
30 #include <kstandarddirs.h>
31 #include <tdeapplication.h>
32 #include <tdemessagebox.h>
33 
34 KMDriverDB* KMDriverDB::m_self = 0;
35 
36 KMDriverDB* KMDriverDB::self()
37 {
38  if (!m_self)
39  {
40  m_self = new KMDriverDB();
41  TQ_CHECK_PTR(m_self);
42  }
43  return m_self;
44 }
45 
46 KMDriverDB::KMDriverDB(TQObject *parent, const char *name)
47 : TQObject(parent,name)
48 {
49  m_creator = new KMDBCreator(this,"db-creator");
50  connect(m_creator,TQT_SIGNAL(dbCreated()),TQT_SLOT(slotDbCreated()));
51 
52  m_entries.setAutoDelete(true);
53  m_pnpentries.setAutoDelete(true);
54 }
55 
56 KMDriverDB::~KMDriverDB()
57 {
58 }
59 
60 TQString KMDriverDB::dbFile()
61 {
62  // this calls insure missing directories creation
63  TQString filename = locateLocal("data",TQString::fromLatin1("tdeprint/printerdb_%1.txt").arg(KMFactory::self()->printSystem()));
64  return filename;
65 }
66 
67 void KMDriverDB::init(TQWidget *parent)
68 {
69  TQFileInfo dbfi(dbFile());
70  TQString dirname = KMFactory::self()->manager()->driverDirectory();
71  TQStringList dbDirs = TQStringList::split(':', dirname, false);
72  bool createflag(false);
73 
74  for (TQStringList::ConstIterator it=dbDirs.begin(); it!=dbDirs.end() && !createflag; ++it)
75  if (!(*it).startsWith("module:") && !m_creator->checkDriverDB(*it, dbfi.lastModified()))
76  createflag = true;
77 
78  if (createflag)
79  {
80  // starts DB creation and wait for creator signal
81  if (!m_creator->createDriverDB(dirname,dbfi.absFilePath(),parent))
82  KMessageBox::error(parent, KMFactory::self()->manager()->errorMsg().prepend("<qt>").append("</qt>"));
83  }
84  else if (m_entries.count() == 0)
85  {
86  // call directly the slot as the DB won't be re-created
87  // this will (re)load the driver DB
88  slotDbCreated();
89  }
90  else
91  // no need to refresh, and already loaded, just emit signal
92  emit dbLoaded(false);
93 }
94 
95 void KMDriverDB::slotDbCreated()
96 {
97  // DB should be created, check creator status
98  if (m_creator->status())
99  {
100  // OK, load DB and emit signal
101  loadDbFile();
102  emit dbLoaded(true);
103  }
104  else
105  // error while creating DB, notify the DB widget
106  emit error(KMManager::self()->errorMsg());
107  // be sure to emit this signal to notify the DB widget
108  //emit dbLoaded(true);
109 }
110 
111 KMDBEntryList* KMDriverDB::findEntry(const TQString& manu, const TQString& model)
112 {
113  TQDict<KMDBEntryList> *models = m_entries.find(manu);
114  if (models)
115  return models->find(model);
116  return 0;
117 }
118 
119 KMDBEntryList* KMDriverDB::findPnpEntry(const TQString& manu, const TQString& model)
120 {
121  TQDict<KMDBEntryList> *models = m_pnpentries.find(manu);
122  if (models)
123  return models->find(model);
124  return 0;
125 }
126 
127 TQDict<KMDBEntryList>* KMDriverDB::findModels(const TQString& manu)
128 {
129  return m_entries.find(manu);
130 }
131 
132 void KMDriverDB::insertEntry(KMDBEntry *entry)
133 {
134  // first check entry
135  if (!entry->validate())
136  {
137  kdDebug() << "Incorrect entry, skipping...(" << entry->file << ")" << endl;
138  delete entry;
139  return;
140  }
141 
142  // insert it in normal entries
143  TQDict<KMDBEntryList> *models = m_entries.find(entry->manufacturer);
144  if (!models)
145  {
146  models = new TQDict<KMDBEntryList>(17,false);
147  models->setAutoDelete(true);
148  m_entries.insert(entry->manufacturer,models);
149  }
150  KMDBEntryList *list = models->find(entry->model);
151  if (!list)
152  {
153  list = new KMDBEntryList;
154  list->setAutoDelete(true);
155  models->insert(entry->model,list);
156  }
157  list->append(entry);
158 
159  if (!entry->pnpmanufacturer.isEmpty() && !entry->pnpmodel.isEmpty())
160  {
161  // insert it in PNP entries
162  models = m_pnpentries.find(entry->manufacturer);
163  if (!models)
164  {
165  models = new TQDict<KMDBEntryList>(17,false);
166  models->setAutoDelete(true);
167  m_pnpentries.insert(entry->manufacturer,models);
168  }
169  list = models->find(entry->model);
170  if (!list)
171  {
172  list = new KMDBEntryList;
173  list->setAutoDelete(true);
174  models->insert(entry->model,list);
175  }
176  list->append(entry);
177  }
178 
179  // don't block GUI
180  kapp->processEvents();
181 }
182 
183 /*
184  Driver DB file format:
185  FILE=<path>
186  MANUFACTURER=<string>
187  MODEL=<string>
188  PNPMANUFACTURER=<string>
189  PNPMODEL=<string>
190  DESCRIPTION=<string>
191 */
192 
193 void KMDriverDB::loadDbFile()
194 {
195  // first clear everything
196  m_entries.clear();
197  m_pnpentries.clear();
198 
199  TQFile f(dbFile());
200  if (f.exists() && f.open(IO_ReadOnly))
201  {
202  TQTextStream t(&f);
203  TQString line;
204  TQStringList words;
205  KMDBEntry *entry(0);
206 
207  while (!t.eof())
208  {
209  line = t.readLine().stripWhiteSpace();
210  if (line.isEmpty())
211  continue;
212  int p = line.find('=');
213  if (p == -1)
214  continue;
215  words.clear();
216  words << line.left(p) << line.mid(p+1);
217  if (words[0] == "FILE")
218  {
219  if (entry) insertEntry(entry);
220  entry = new KMDBEntry;
221  entry->file = words[1];
222  }
223  else if (words[0] == "MANUFACTURER" && entry)
224  entry->manufacturer = words[1].upper();
225  else if (words[0] == "MODEL" && entry)
226  entry->model = words[1];
227  else if (words[0] == "MODELNAME" && entry)
228  entry->modelname = words[1];
229  else if (words[0] == "PNPMANUFACTURER" && entry)
230  entry->pnpmanufacturer = words[1].upper();
231  else if (words[0] == "PNPMODEL" && entry)
232  entry->pnpmodel = words[1];
233  else if (words[0] == "DESCRIPTION" && entry)
234  entry->description = words[1];
235  else if (words[0] == "RECOMMANDED" && entry && words[1].lower() == "yes")
236  entry->recommended = true;
237  else if (words[0] == "DRIVERCOMMENT" && entry)
238  entry->drivercomment = ("<qt>"+words[1].replace("&lt;", "<").replace("&gt;", ">")+"</qt>");
239  }
240  if (entry)
241  insertEntry(entry);
242  }
243 }
244 #include "kmdriverdb.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.