kinfocenter: add more paths to USB IDs database

Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
This commit is contained in:
Ivailo Monev 2021-06-17 07:20:02 +03:00
parent f5db354473
commit 2d70a55db3
3 changed files with 49 additions and 21 deletions

View file

@ -60,6 +60,9 @@
/* KDE's static data directory */ /* KDE's static data directory */
#define KDE_DATADIR "${KDE4_DATA_INSTALL_DIR}" #define KDE_DATADIR "${KDE4_DATA_INSTALL_DIR}"
/* KDE's static shared data directory */
#define KDE_SHAREDIR "${KDE4_SHARE_INSTALL_PREFIX}"
/* X binaries directory */ /* X binaries directory */
#cmakedefine XBINDIR "${XBINDIR}" #cmakedefine XBINDIR "${XBINDIR}"

View file

@ -14,17 +14,40 @@
#include <QFile> #include <QFile>
#include <QRegExp> #include <QRegExp>
//Added by qt3to4: #include <QStringList>
#include <QTextStream> #include <QTextStream>
#include <kdebug.h>
#include <kstandarddirs.h> #include <kstandarddirs.h>
#include "config-workspace.h"
USBDB::USBDB() { USBDB::USBDB() {
QString db = "/usr/share/hwdata/usb.ids"; /* on Fedora */ static const QStringList s_dbpaths = QStringList()
if (!QFile::exists(db)) << QLatin1String("/share/hwdata/usb.ids")
db = KStandardDirs::locate("data", "kcmusb/usb.ids"); << QLatin1String("/local/share/hwdata/usb.ids")
if (db.isEmpty()) << QLatin1String("/usr/share/hwdata/usb.ids")
return; << QLatin1String("/usr/local/share/hwdata/usb.ids")
<< QLatin1String("/var/lib/usbutils/usb.ids") // Debian
<< QLatin1String(KDE_SHAREDIR "/hwdata/usb.ids");
QString db;
foreach (const QString &dbpath, s_dbpaths) {
if (QFile::exists(dbpath)) {
kDebug() << "Using" << dbpath << "USB database";
db = dbpath;
break;
}
}
if (db.isEmpty()) {
kDebug() << "Using bundled USB database";
db = KStandardDirs::locate("data", "kcmusb/usb.ids");
}
if (db.isEmpty()) {
kWarning() << "Could not find USB database";
return;
}
QFile f(db); QFile f(db);
@ -81,29 +104,30 @@ USBDB::USBDB() {
} }
QString USBDB::vendor(int id) { QString USBDB::vendor(int id) {
QString s = _ids[QString("%1").arg(id)]; QString s = _ids[QString("%1").arg(id)];
if (id != 0) { if (id != 0) {
return s; return s;
} }
return QString(); return QString();
} }
QString USBDB::device(int vendor, int id) { QString USBDB::device(int vendor, int id) {
QString s = _ids[QString("%1-%2").arg(vendor).arg(id)]; QString s = _ids[QString("%1-%2").arg(vendor).arg(id)];
if ((id != 0) && (vendor != 0)) if ((id != 0) && (vendor != 0)) {
return s; return s;
return QString(); }
return QString();
} }
QString USBDB::cls(int cls) { QString USBDB::cls(int cls) {
return _classes[QString("%1").arg(cls)]; return _classes[QString("%1").arg(cls)];
} }
QString USBDB::subclass(int cls, int sub) { QString USBDB::subclass(int cls, int sub) {
return _classes[QString("%1-%2").arg(cls).arg(sub)]; return _classes[QString("%1-%2").arg(cls).arg(sub)];
} }
QString USBDB::protocol(int cls, int sub, int prot) { QString USBDB::protocol(int cls, int sub, int prot) {
return _classes[QString("%1-%2-%3").arg(cls).arg(sub).arg(prot)]; return _classes[QString("%1-%2-%3").arg(cls).arg(sub).arg(prot)];
} }

View file

@ -36,8 +36,10 @@ QList<USBDevice*> USBDevice::_devices;
USBDB *USBDevice::_db; USBDB *USBDevice::_db;
USBDevice::USBDevice() : USBDevice::USBDevice() :
_bus(0), _level(0), _parent(0), _port(0), _count(0), _device(0), _channels(0), _power(0), _speed(0.0), _bwTotal(0), _bwUsed(0), _bwPercent(0), _bwIntr(0), _bwIso(0), _hasBW(false), _verMajor(0), _verMinor(0), _class(0), _sub(0), _prot(0), _maxPacketSize(0), _configs(0), _vendorID(0), _bus(0), _level(0), _parent(0), _port(0), _count(0), _device(0), _channels(0), _power(0),
_prodID(0), _revMajor(0), _revMinor(0) { _speed(0.0), _bwTotal(0), _bwUsed(0), _bwPercent(0), _bwIntr(0), _bwIso(0), _hasBW(false),
_verMajor(0), _verMinor(0), _class(0), _sub(0), _prot(0), _maxPacketSize(0), _configs(0),
_vendorID(0), _prodID(0), _revMajor(0), _revMinor(0) {
_devices.append(this); _devices.append(this);
if (!_db) { if (!_db) {
@ -46,7 +48,6 @@ USBDevice::USBDevice() :
} }
USBDevice::~USBDevice() { USBDevice::~USBDevice() {
} }
static QString catFile(QString fname) { static QString catFile(QString fname) {