View | Details | Raw Unified | Return to bug 179690
Collapse All | Expand All

(-)kcontrol/usbview/usbdevices.h (+2 lines)
Lines 30-35 public: Link Here
30
  USBDevice();
30
  USBDevice();
31
31
32
  void parseLine(QString line);
32
  void parseLine(QString line);
33
  void parseSysDir(int bus, int parent, int level, QString line);
33
34
34
  int level() { return _level; };
35
  int level() { return _level; };
35
  int device() { return _device; };
36
  int device() { return _device; };
Lines 42-47 public: Link Here
42
  static QPtrList<USBDevice> &devices() { return _devices; };
43
  static QPtrList<USBDevice> &devices() { return _devices; };
43
  static USBDevice *find(int bus, int device);
44
  static USBDevice *find(int bus, int device);
44
  static bool parse(QString fname);
45
  static bool parse(QString fname);
46
  static bool parseSys(QString fname);
45
47
46
48
47
private:
49
private:
(-)kcontrol/usbview/kcmusb.cpp (-1 / +1 lines)
Lines 117-123 void USBViewer::refresh() Link Here
117
  QIntDict<QListViewItem> new_items;
117
  QIntDict<QListViewItem> new_items;
118
118
119
  if (!USBDevice::parse("/proc/bus/usb/devices"))
119
  if (!USBDevice::parse("/proc/bus/usb/devices"))
120
    USBDevice::parse("/proc/bus/usb/devices_please-use-sysfs-instead");
120
    USBDevice::parseSys("/sys/bus/usb/devices");
121
121
122
  int level = 0;
122
  int level = 0;
123
  bool found = true;
123
  bool found = true;
(-)kcontrol/usbview/usbdevices.cpp (+85 lines)
Lines 16-21 Link Here
16
#include <stdio.h>
16
#include <stdio.h>
17
17
18
#include <qfile.h>
18
#include <qfile.h>
19
#include <qdir.h>
19
#include <qregexp.h>
20
#include <qregexp.h>
20
21
21
#include <klocale.h>
22
#include <klocale.h>
Lines 24-29 Link Here
24
#include "usbdb.h"
25
#include "usbdb.h"
25
#include "usbdevices.h"
26
#include "usbdevices.h"
26
27
28
#include <math.h>
29
27
#ifdef Q_OS_FREEBSD
30
#ifdef Q_OS_FREEBSD
28
#include <sys/ioctl.h>
31
#include <sys/ioctl.h>
29
#include <sys/param.h>
32
#include <sys/param.h>
Lines 47-52 USBDevice::USBDevice() Link Here
47
    _db = new USBDB;
50
    _db = new USBDB;
48
}
51
}
49
52
53
static QString catFile(QString fname)
54
{
55
  char buffer[256];
56
  QString result;
57
  int fd = ::open(QFile::encodeName(fname), O_RDONLY);
58
  if (fd<0)
59
	return QString::null;
60
61
  if (fd >= 0)
62
    {
63
      ssize_t count;
64
      while ((count = ::read(fd, buffer, 256)) > 0)
65
	result.append(QString(buffer).left(count));
66
67
      ::close(fd);
68
    }
69
  return result.stripWhiteSpace();
70
}
71
72
void USBDevice::parseSysDir(int bus, int parent, int level, QString dname)
73
{
74
  _level = level;
75
  _parent = parent;
76
  _manufacturer = catFile(dname + "/manufacturer");
77
  _product = catFile(dname + "/product");
78
79
  _bus = bus;
80
  _device = catFile(dname + "/devnum").toUInt();
81
82
  if (_device == 1)
83
    _product += QString(" (%1)").arg(_bus);
84
85
  _vendorID = catFile(dname + "/idVendor").toUInt(0, 16);
86
  _prodID = catFile(dname + "/idProduct").toUInt(0, 16);
87
88
  _class = catFile(dname + "/bDeviceClass").toUInt(0, 16);
89
  _sub = catFile(dname + "/bDeviceSubClass").toUInt(0, 16);
90
  _maxPacketSize = catFile(dname + "/bMaxPacketSize0").toUInt();
91
92
  _speed = catFile(dname + "/speed").toDouble();
93
  _serial = catFile(dname + "/serial");
94
  _channels = catFile(dname + "/maxchild").toUInt();
95
96
  double version = catFile(dname + "/version").toDouble();
97
  _verMajor = int(version);
98
  _verMinor = int(10*(version - floor(version)));
99
100
  QDir dir(dname);
101
  dir.setNameFilter(QString("%1-*").arg(bus));
102
  dir.setFilter(QDir::Dirs);
103
  QStringList list = dir.entryList();
104
105
  for(QStringList::Iterator it = list.begin(); it != list.end(); ++it) {
106
    if ((*it).contains(':'))
107
      continue;
108
109
    USBDevice* dev = new USBDevice();
110
    dev->parseSysDir(bus, ++level, _device, dname + "/" + *it);
111
  }
112
}
50
113
51
void USBDevice::parseLine(QString line)
114
void USBDevice::parseLine(QString line)
52
{
115
{
Lines 230-235 bool USBDevice::parse(QString fname) Link Here
230
  return true;
293
  return true;
231
}
294
}
232
295
296
bool USBDevice::parseSys(QString dname)
297
{
298
   QDir d(dname);
299
   d.setNameFilter("usb*");
300
   QStringList list = d.entryList();
301
302
   for(QStringList::Iterator it = list.begin(); it != list.end(); ++it) {
303
     USBDevice* device = new USBDevice();
304
305
     int bus = 0;
306
     QRegExp bus_reg("[a-z]*([0-9]+)");
307
     if (bus_reg.search(*it) != -1)
308
         bus = bus_reg.cap(1).toInt();
309
310
311
     device->parseSysDir(bus, 0, 0, d.absPath() + "/" + *it);
312
  }
313
314
  return d.count();
315
}
316
233
#else
317
#else
234
318
235
/*
319
/*
Lines 302-307 void USBDevice::collectData( int fd, int Link Here
302
}
386
}
303
387
304
388
389
305
bool USBDevice::parse(QString fname)
390
bool USBDevice::parse(QString fname)
306
{
391
{
307
	static bool showErrorMessage = true;
392
	static bool showErrorMessage = true;

Return to bug 179690