20 #include "kmdriverdb.h"
21 #include "kmdbentry.h"
22 #include "kmdbcreator.h"
23 #include "kmmanager.h"
24 #include "kmfactory.h"
28 #include <tqtextstream.h>
29 #include <tqfileinfo.h>
30 #include <kstandarddirs.h>
31 #include <tdeapplication.h>
32 #include <tdemessagebox.h>
34 KMDriverDB* KMDriverDB::m_self = 0;
36 KMDriverDB* KMDriverDB::self()
40 m_self =
new KMDriverDB();
46 KMDriverDB::KMDriverDB(TQObject *parent,
const char *name)
47 : TQObject(parent,name)
49 m_creator =
new KMDBCreator(
this,
"db-creator");
50 connect(m_creator,TQ_SIGNAL(dbCreated()),TQ_SLOT(slotDbCreated()));
52 m_entries.setAutoDelete(
true);
53 m_pnpentries.setAutoDelete(
true);
56 KMDriverDB::~KMDriverDB()
60 TQString KMDriverDB::dbFile()
63 TQString filename = locateLocal(
"data",TQString::fromLatin1(
"tdeprint/printerdb_%1.txt").arg(KMFactory::self()->printSystem()));
67 void KMDriverDB::init(TQWidget *parent)
69 TQFileInfo dbfi(dbFile());
70 TQString dirname = KMFactory::self()->manager()->driverDirectory();
71 TQStringList dbDirs = TQStringList::split(
':', dirname,
false);
72 bool createflag(
false);
74 for (TQStringList::ConstIterator it=dbDirs.begin(); it!=dbDirs.end() && !createflag; ++it)
75 if (!(*it).startsWith(
"module:") && !m_creator->checkDriverDB(*it, dbfi.lastModified()))
81 if (!m_creator->createDriverDB(dirname,dbfi.absFilePath(),parent))
82 KMessageBox::error(parent, KMFactory::self()->manager()->errorMsg().prepend(
"<qt>").append(
"</qt>"));
84 else if (m_entries.count() == 0)
95 void KMDriverDB::slotDbCreated()
98 if (m_creator->status())
106 emit error(KMManager::self()->errorMsg());
111 KMDBEntryList* KMDriverDB::findEntry(
const TQString& manu,
const TQString& model)
113 TQDict<KMDBEntryList> *models = m_entries.find(manu);
115 return models->find(model);
119 KMDBEntryList* KMDriverDB::findPnpEntry(
const TQString& manu,
const TQString& model)
121 TQDict<KMDBEntryList> *models = m_pnpentries.find(manu);
123 return models->find(model);
127 TQDict<KMDBEntryList>* KMDriverDB::findModels(
const TQString& manu)
129 return m_entries.find(manu);
132 void KMDriverDB::insertEntry(KMDBEntry *entry)
135 if (!entry->validate())
137 kdDebug() <<
"Incorrect entry, skipping...(" << entry->file <<
")" << endl;
143 TQDict<KMDBEntryList> *models = m_entries.find(entry->manufacturer);
146 models =
new TQDict<KMDBEntryList>(17,
false);
147 models->setAutoDelete(
true);
148 m_entries.insert(entry->manufacturer,models);
150 KMDBEntryList *list = models->find(entry->model);
153 list =
new KMDBEntryList;
154 list->setAutoDelete(
true);
155 models->insert(entry->model,list);
159 if (!entry->pnpmanufacturer.isEmpty() && !entry->pnpmodel.isEmpty())
162 models = m_pnpentries.find(entry->manufacturer);
165 models =
new TQDict<KMDBEntryList>(17,
false);
166 models->setAutoDelete(
true);
167 m_pnpentries.insert(entry->manufacturer,models);
169 list = models->find(entry->model);
172 list =
new KMDBEntryList;
173 list->setAutoDelete(
true);
174 models->insert(entry->model,list);
180 kapp->processEvents();
193 void KMDriverDB::loadDbFile()
197 m_pnpentries.clear();
200 if (f.exists() && f.open(IO_ReadOnly))
209 line = t.readLine().stripWhiteSpace();
212 int p = line.find(
'=');
216 words << line.left(p) << line.mid(p+1);
217 if (words[0] ==
"FILE")
219 if (entry) insertEntry(entry);
220 entry =
new KMDBEntry;
221 entry->file = words[1];
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(
"<",
"<").replace(
">",
">")+
"</qt>");
244 #include "kmdriverdb.moc"