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>
20 #include <kstandarddirs.h>
23 QString db
= "/usr/share/hwdata/usb.ids"; /* on Fedora */
24 if (!QFile::exists(db
))
25 db
= KStandardDirs::locate("data", "kcmusb/usb.ids");
31 if (f
.open(QIODevice::ReadOnly
)) {
36 int id
=0, subid
=0, protid
=0;
37 QRegExp
vendor("[0-9a-fA-F]+ ");
38 QRegExp
product("\\s+[0-9a-fA-F]+ ");
39 QRegExp
cls("C [0-9a-fA-F][0-9a-fA-F]");
40 QRegExp
subclass("\\s+[0-9a-fA-F][0-9a-fA-F] ");
41 QRegExp
prot("\\s+[0-9a-fA-F][0-9a-fA-F] ");
44 if (line
.left(1) == "#" || line
.trimmed().isEmpty())
48 if (line
.left(2) == "AT")
51 if (cls
.indexIn(line
) == 0 && cls
.matchedLength() == 4) {
52 id
= line
.mid(2,2).toInt(0, 16);
53 name
= line
.mid(4).trimmed();
54 _classes
.insert(QString("%1").arg(id
), name
);
55 } else if (prot
.indexIn(line
) == 0 && prot
.matchedLength() > 5) {
56 line
= line
.trimmed();
57 protid
= line
.left(2).toInt(0, 16);
58 name
= line
.mid(4).trimmed();
59 _classes
.insert(QString("%1-%2-%3").arg(id
).arg(subid
).arg(protid
), name
);
60 } else if (subclass
.indexIn(line
) == 0 && subclass
.matchedLength() > 4) {
61 line
= line
.trimmed();
62 subid
= line
.left(2).toInt(0, 16);
63 name
= line
.mid(4).trimmed();
64 _classes
.insert(QString("%1-%2").arg(id
).arg(subid
), name
);
65 } else if (vendor
.indexIn(line
) == 0 && vendor
.matchedLength() == 5) {
66 id
= line
.left(4).toInt(0, 16);
68 _ids
.insert(QString("%1").arg(id
), name
);
69 } else if (product
.indexIn(line
) == 0 && product
.matchedLength() > 5) {
70 line
= line
.trimmed();
71 subid
= line
.left(4).toInt(0, 16);
73 _ids
.insert(QString("%1-%2").arg(id
).arg(subid
), name
);
82 QString
USBDB::vendor(int id
) {
83 QString s
= _ids
[QString("%1").arg(id
)];
90 QString
USBDB::device(int vendor
, int id
) {
91 QString s
= _ids
[QString("%1-%2").arg(vendor
).arg(id
)];
92 if ((id
!= 0) && (vendor
!= 0))
97 QString
USBDB::cls(int cls
) {
98 return _classes
[QString("%1").arg(cls
)];
101 QString
USBDB::subclass(int cls
, int sub
) {
102 return _classes
[QString("%1-%2").arg(cls
).arg(sub
)];
105 QString
USBDB::protocol(int cls
, int sub
, int prot
) {
106 return _classes
[QString("%1-%2-%3").arg(cls
).arg(sub
).arg(prot
)];