1
/***************************************************************************
2
* Copyright (C) 2001 by Matthias Hoelzer-Kluepfel <mhk@caldera.de> *
4
* This program is free software; you can redistribute it and/or modify *
5
* it under the terms of the GNU General Public License as published by *
6
* the Free Software Foundation; either version 2 of the License, or *
7
* (at your option) any later version. *
9
***************************************************************************/
18
#include <QTextStream>
21
#include <kstandarddirs.h>
29
QString db = "/usr/share/hwdata/usb.ids"; /* on Fedora */
30
if (!QFile::exists(db))
31
db = KStandardDirs::locate("data", "kcmusb/usb.ids");
35
_classes.setAutoDelete(true);
36
_ids.setAutoDelete(true);
40
if (f.open(QIODevice::ReadOnly))
46
int id=0, subid=0, protid=0;
47
QRegExp vendor("[0-9a-fA-F]+ ");
48
QRegExp product("\\s+[0-9a-fA-F]+ ");
49
QRegExp cls("C [0-9a-fA-F][0-9a-fA-F]");
50
QRegExp subclass("\\s+[0-9a-fA-F][0-9a-fA-F] ");
51
QRegExp prot("\\s+[0-9a-fA-F][0-9a-fA-F] ");
55
if (line.left(1) == "#" || line.trimmed().isEmpty())
59
if (line.left(2) == "AT")
62
if (cls.indexIn(line) == 0 && cls.matchedLength() == 4)
64
id = line.mid(2,2).toInt(0, 16);
65
name = line.mid(4).trimmed();
66
_classes.insert(QString("%1").arg(id), new QString(name));
68
else if (prot.indexIn(line) == 0 && prot.matchedLength() > 5)
70
line = line.trimmed();
71
protid = line.left(2).toInt(0, 16);
72
name = line.mid(4).trimmed();
73
_classes.insert(QString("%1-%2-%3").arg(id).arg(subid).arg(protid), new QString(name));
75
else if (subclass.indexIn(line) == 0 && subclass.matchedLength() > 4)
77
line = line.trimmed();
78
subid = line.left(2).toInt(0, 16);
79
name = line.mid(4).trimmed();
80
_classes.insert(QString("%1-%2").arg(id).arg(subid), new QString(name));
82
else if (vendor.indexIn(line) == 0 && vendor.matchedLength() == 5)
84
id = line.left(4).toInt(0,16);
86
_ids.insert(QString("%1").arg(id), new QString(name));
88
else if (product.indexIn(line) == 0 && product.matchedLength() > 5 )
90
line = line.trimmed();
91
subid = line.left(4).toInt(0,16);
93
_ids.insert(QString("%1-%2").arg(id).arg(subid), new QString(name));
103
QString USBDB::vendor(int id)
105
QString *s = _ids[QString("%1").arg(id)];
114
QString USBDB::device(int vendor, int id)
116
QString *s = _ids[QString("%1-%2").arg(vendor).arg(id)];
117
if ((id != 0) && (vendor != 0) && s)
123
QString USBDB::cls(int cls)
125
QString *s = _classes[QString("%1").arg(cls)];
132
QString USBDB::subclass(int cls, int sub)
134
QString *s = _classes[QString("%1-%2").arg(cls).arg(sub)];
141
QString USBDB::protocol(int cls, int sub, int prot)
143
QString *s = _classes[QString("%1-%2-%3").arg(cls).arg(sub).arg(prot)];