author | mickeyl <mickeyl> | 2005-05-06 10:27:14 (UTC) |
---|---|---|
committer | mickeyl <mickeyl> | 2005-05-06 10:27:14 (UTC) |
commit | e73cc9ec4596e1b5e9eed13af710606f358860ba (patch) (unidiff) | |
tree | e83705b0bd60adcee980c30c3b8b83ad0376cd9c | |
parent | 543d9d7c58c9601dba6f47b3a4011313d1d75499 (diff) | |
download | opie-e73cc9ec4596e1b5e9eed13af710606f358860ba.zip opie-e73cc9ec4596e1b5e9eed13af710606f358860ba.tar.gz opie-e73cc9ec4596e1b5e9eed13af710606f358860ba.tar.bz2 |
quick'n'dirty parsing of USB tree
-rw-r--r-- | noncore/settings/sysinfo/devicesinfo.cpp | 34 | ||||
-rw-r--r-- | noncore/settings/sysinfo/devicesinfo.h | 2 |
2 files changed, 35 insertions, 1 deletions
diff --git a/noncore/settings/sysinfo/devicesinfo.cpp b/noncore/settings/sysinfo/devicesinfo.cpp index 6508d3c..b463e43 100644 --- a/noncore/settings/sysinfo/devicesinfo.cpp +++ b/noncore/settings/sysinfo/devicesinfo.cpp | |||
@@ -227,89 +227,113 @@ void CardsCategory::populate() | |||
227 | { | 227 | { |
228 | continue; | 228 | continue; |
229 | } | 229 | } |
230 | } | 230 | } |
231 | } | 231 | } |
232 | 232 | ||
233 | //================================================================================================= | 233 | //================================================================================================= |
234 | UsbCategory::UsbCategory( DevicesView* parent ) | 234 | UsbCategory::UsbCategory( DevicesView* parent ) |
235 | :Category( parent, "4. Universal Serial Bus" ) | 235 | :Category( parent, "4. Universal Serial Bus" ) |
236 | { | 236 | { |
237 | } | 237 | } |
238 | 238 | ||
239 | UsbCategory::~UsbCategory() | 239 | UsbCategory::~UsbCategory() |
240 | { | 240 | { |
241 | } | 241 | } |
242 | 242 | ||
243 | void UsbCategory::populate() | 243 | void UsbCategory::populate() |
244 | { | 244 | { |
245 | odebug << "UsbCategory::populate()" << oendl; | 245 | odebug << "UsbCategory::populate()" << oendl; |
246 | QFile usbinfofile( "/proc/bus/usb/devices" ); | 246 | QFile usbinfofile( "/proc/bus/usb/devices" ); |
247 | if ( !usbinfofile.exists() || !usbinfofile.open( IO_ReadOnly ) ) | 247 | if ( !usbinfofile.exists() || !usbinfofile.open( IO_ReadOnly ) ) |
248 | { | 248 | { |
249 | new UsbDevice( this, "ERROR: /proc/bus/usb/devices not found or unaccessible" ); | 249 | new UsbDevice( this, "ERROR: /proc/bus/usb/devices not found or unaccessible" ); |
250 | return; | 250 | return; |
251 | } | 251 | } |
252 | QTextStream usbinfo( &usbinfofile ); | 252 | QTextStream usbinfo( &usbinfofile ); |
253 | 253 | ||
254 | int _bus, _level, _parent, _port, _count, _device, _channels, _power; | 254 | int _bus, _level, _parent, _port, _count, _device, _channels, _power; |
255 | float _speed; | 255 | float _speed; |
256 | QString _manufacturer, _product, _serial; | 256 | QString _manufacturer, _product, _serial; |
257 | 257 | ||
258 | int usbcount = 0; | 258 | int usbcount = 0; |
259 | UsbDevice* lastDev = 0; | ||
260 | UsbDevice* dev = 0; | ||
259 | while ( !usbinfo.atEnd() ) | 261 | while ( !usbinfo.atEnd() ) |
260 | { | 262 | { |
261 | QString line = usbinfo.readLine(); | 263 | QString line = usbinfo.readLine(); |
262 | odebug << "got line '" << line << "'" << oendl; | 264 | odebug << "got line '" << line << "'" << oendl; |
263 | if ( line.startsWith( "T:" ) ) | 265 | if ( line.startsWith( "T:" ) ) |
264 | { | 266 | { |
265 | sscanf(line.local8Bit().data(), "T: Bus=%2d Lev=%2d Prnt=%2d Port=%d Cnt=%2d Dev#=%3d Spd=%3f MxCh=%2d", &_bus, &_level, &_parent, &_port, &_count, &_device, &_speed, &_channels); | 267 | sscanf(line.local8Bit().data(), "T: Bus=%2d Lev=%2d Prnt=%2d Port=%d Cnt=%2d Dev#=%3d Spd=%3f MxCh=%2d", &_bus, &_level, &_parent, &_port, &_count, &_device, &_speed, &_channels); |
266 | 268 | ||
267 | new UsbDevice( this, QString( "USB Device #%1" ).arg( usbcount++ ) ); | 269 | if ( !_level ) |
270 | { | ||
271 | odebug << "adding new bus" << oendl; | ||
272 | dev = new UsbDevice( this, QString( "Generic USB Hub Device" ) ); | ||
273 | lastDev = dev; | ||
274 | } | ||
275 | else | ||
276 | { | ||
277 | odebug << "adding new dev" << oendl; | ||
278 | dev = new UsbDevice( lastDev, QString( "Generic USB Hub Device" ) ); | ||
279 | lastDev = dev; | ||
280 | } | ||
281 | } | ||
282 | else if ( line.startsWith( "S: Product" ) ) | ||
283 | { | ||
284 | int dp = line.find( '=' ); | ||
285 | dev->setText( 0, dp != -1 ? line.right( line.length()-1-dp ) : "<unknown>" ); | ||
268 | } | 286 | } |
269 | else | 287 | else |
270 | { | 288 | { |
271 | continue; | 289 | continue; |
272 | } | 290 | } |
273 | } | 291 | } |
274 | } | 292 | } |
275 | 293 | ||
276 | 294 | ||
277 | //================================================================================================= | 295 | //================================================================================================= |
278 | Device::Device( Category* parent, const QString& name ) | 296 | Device::Device( Category* parent, const QString& name ) |
279 | :OListViewItem( parent, name ) | 297 | :OListViewItem( parent, name ) |
280 | { | 298 | { |
281 | devinfo = static_cast<QWidget*>( listView()->parent() ); | 299 | devinfo = static_cast<QWidget*>( listView()->parent() ); |
282 | } | 300 | } |
283 | 301 | ||
302 | Device::Device( Device* parent, const QString& name ) | ||
303 | :OListViewItem( parent, name ) | ||
304 | { | ||
305 | devinfo = static_cast<QWidget*>( listView()->parent() ); | ||
306 | } | ||
307 | |||
284 | Device::~Device() | 308 | Device::~Device() |
285 | { | 309 | { |
286 | } | 310 | } |
287 | 311 | ||
288 | 312 | ||
289 | QWidget* Device::detailsWidget() | 313 | QWidget* Device::detailsWidget() |
290 | { | 314 | { |
291 | return details; | 315 | return details; |
292 | } | 316 | } |
293 | 317 | ||
294 | //================================================================================================= | 318 | //================================================================================================= |
295 | CpuDevice::CpuDevice( Category* parent, const QString& name ) | 319 | CpuDevice::CpuDevice( Category* parent, const QString& name ) |
296 | :Device( parent, name ) | 320 | :Device( parent, name ) |
297 | { | 321 | { |
298 | OListView* w = new OListView( devinfo ); | 322 | OListView* w = new OListView( devinfo ); |
299 | details = w; | 323 | details = w; |
300 | w->addColumn( "Info" ); | 324 | w->addColumn( "Info" ); |
301 | w->addColumn( "Value" ); | 325 | w->addColumn( "Value" ); |
302 | w->hide(); | 326 | w->hide(); |
303 | } | 327 | } |
304 | 328 | ||
305 | CpuDevice::~CpuDevice() | 329 | CpuDevice::~CpuDevice() |
306 | { | 330 | { |
307 | } | 331 | } |
308 | 332 | ||
309 | void CpuDevice::addInfo( const QString& info ) | 333 | void CpuDevice::addInfo( const QString& info ) |
310 | { | 334 | { |
311 | int dp = info.find( ':' ); | 335 | int dp = info.find( ':' ); |
312 | if ( dp != -1 ) | 336 | if ( dp != -1 ) |
313 | { | 337 | { |
314 | new OListViewItem( (OListView*) details, info.left( dp ), info.right( info.length()-dp ) ); | 338 | new OListViewItem( (OListView*) details, info.left( dp ), info.right( info.length()-dp ) ); |
315 | } | 339 | } |
@@ -318,35 +342,43 @@ void CpuDevice::addInfo( const QString& info ) | |||
318 | //================================================================================================= | 342 | //================================================================================================= |
319 | CardDevice::CardDevice( Category* parent, const QString& name ) | 343 | CardDevice::CardDevice( Category* parent, const QString& name ) |
320 | :Device( parent, name ) | 344 | :Device( parent, name ) |
321 | { | 345 | { |
322 | details = new QPushButton( name, devinfo ); | 346 | details = new QPushButton( name, devinfo ); |
323 | details->hide(); | 347 | details->hide(); |
324 | } | 348 | } |
325 | 349 | ||
326 | CardDevice::~CardDevice() | 350 | CardDevice::~CardDevice() |
327 | { | 351 | { |
328 | } | 352 | } |
329 | 353 | ||
330 | //================================================================================================= | 354 | //================================================================================================= |
331 | InputDevice::InputDevice( Category* parent, const QString& name ) | 355 | InputDevice::InputDevice( Category* parent, const QString& name ) |
332 | :Device( parent, name ) | 356 | :Device( parent, name ) |
333 | { | 357 | { |
334 | details = new QPushButton( name, devinfo ); | 358 | details = new QPushButton( name, devinfo ); |
335 | details->hide(); | 359 | details->hide(); |
336 | } | 360 | } |
337 | 361 | ||
338 | InputDevice::~InputDevice() | 362 | InputDevice::~InputDevice() |
339 | { | 363 | { |
340 | } | 364 | } |
341 | 365 | ||
342 | //================================================================================================= | 366 | //================================================================================================= |
343 | UsbDevice::UsbDevice( Category* parent, const QString& name ) | 367 | UsbDevice::UsbDevice( Category* parent, const QString& name ) |
344 | :Device( parent, name ) | 368 | :Device( parent, name ) |
345 | { | 369 | { |
346 | details = new QPushButton( name, devinfo ); | 370 | details = new QPushButton( name, devinfo ); |
347 | details->hide(); | 371 | details->hide(); |
348 | } | 372 | } |
349 | 373 | ||
374 | //================================================================================================= | ||
375 | UsbDevice::UsbDevice( UsbDevice* parent, const QString& name ) | ||
376 | :Device( parent, name ) | ||
377 | { | ||
378 | details = new QPushButton( name, devinfo ); | ||
379 | details->hide(); | ||
380 | } | ||
381 | |||
350 | UsbDevice::~UsbDevice() | 382 | UsbDevice::~UsbDevice() |
351 | { | 383 | { |
352 | } | 384 | } |
diff --git a/noncore/settings/sysinfo/devicesinfo.h b/noncore/settings/sysinfo/devicesinfo.h index 586d204..c601a96 100644 --- a/noncore/settings/sysinfo/devicesinfo.h +++ b/noncore/settings/sysinfo/devicesinfo.h | |||
@@ -92,83 +92,85 @@ class InputCategory : public Category | |||
92 | public: | 92 | public: |
93 | InputCategory( DevicesView* parent ); | 93 | InputCategory( DevicesView* parent ); |
94 | virtual ~InputCategory(); | 94 | virtual ~InputCategory(); |
95 | 95 | ||
96 | virtual void populate(); | 96 | virtual void populate(); |
97 | }; | 97 | }; |
98 | 98 | ||
99 | //================================================================================================= | 99 | //================================================================================================= |
100 | class CardsCategory : public Category | 100 | class CardsCategory : public Category |
101 | { | 101 | { |
102 | public: | 102 | public: |
103 | CardsCategory( DevicesView* parent ); | 103 | CardsCategory( DevicesView* parent ); |
104 | virtual ~CardsCategory(); | 104 | virtual ~CardsCategory(); |
105 | 105 | ||
106 | virtual void populate(); | 106 | virtual void populate(); |
107 | }; | 107 | }; |
108 | 108 | ||
109 | //================================================================================================= | 109 | //================================================================================================= |
110 | class UsbCategory : public Category | 110 | class UsbCategory : public Category |
111 | { | 111 | { |
112 | public: | 112 | public: |
113 | UsbCategory( DevicesView* parent ); | 113 | UsbCategory( DevicesView* parent ); |
114 | virtual ~UsbCategory(); | 114 | virtual ~UsbCategory(); |
115 | 115 | ||
116 | virtual void populate(); | 116 | virtual void populate(); |
117 | }; | 117 | }; |
118 | 118 | ||
119 | //================================================================================================= | 119 | //================================================================================================= |
120 | class Device : public Opie::Ui::OListViewItem | 120 | class Device : public Opie::Ui::OListViewItem |
121 | { | 121 | { |
122 | public: | 122 | public: |
123 | Device( Category* parent, const QString& name ); | 123 | Device( Category* parent, const QString& name ); |
124 | Device( Device* parent, const QString& name ); | ||
124 | ~Device(); | 125 | ~Device(); |
125 | 126 | ||
126 | QWidget* devinfo; | 127 | QWidget* devinfo; |
127 | QWidget* details; | 128 | QWidget* details; |
128 | 129 | ||
129 | virtual QWidget* detailsWidget(); | 130 | virtual QWidget* detailsWidget(); |
130 | }; | 131 | }; |
131 | 132 | ||
132 | //================================================================================================= | 133 | //================================================================================================= |
133 | class CpuDevice : public Device | 134 | class CpuDevice : public Device |
134 | { | 135 | { |
135 | public: | 136 | public: |
136 | CpuDevice( Category* parent, const QString& name ); | 137 | CpuDevice( Category* parent, const QString& name ); |
137 | ~CpuDevice(); | 138 | ~CpuDevice(); |
138 | 139 | ||
139 | void addInfo( const QString& line ); | 140 | void addInfo( const QString& line ); |
140 | 141 | ||
141 | // virtual QWidget* detailsWidget(); | 142 | // virtual QWidget* detailsWidget(); |
142 | }; | 143 | }; |
143 | 144 | ||
144 | //================================================================================================= | 145 | //================================================================================================= |
145 | class InputDevice : public Device | 146 | class InputDevice : public Device |
146 | { | 147 | { |
147 | public: | 148 | public: |
148 | InputDevice( Category* parent, const QString& name ); | 149 | InputDevice( Category* parent, const QString& name ); |
149 | ~InputDevice(); | 150 | ~InputDevice(); |
150 | 151 | ||
151 | // virtual QWidget* detailsWidget(); | 152 | // virtual QWidget* detailsWidget(); |
152 | }; | 153 | }; |
153 | 154 | ||
154 | //================================================================================================= | 155 | //================================================================================================= |
155 | class CardDevice : public Device | 156 | class CardDevice : public Device |
156 | { | 157 | { |
157 | public: | 158 | public: |
158 | CardDevice( Category* parent, const QString& name ); | 159 | CardDevice( Category* parent, const QString& name ); |
159 | ~CardDevice(); | 160 | ~CardDevice(); |
160 | 161 | ||
161 | // virtual QWidget* detailsWidget(); | 162 | // virtual QWidget* detailsWidget(); |
162 | }; | 163 | }; |
163 | 164 | ||
164 | //================================================================================================= | 165 | //================================================================================================= |
165 | class UsbDevice : public Device | 166 | class UsbDevice : public Device |
166 | { | 167 | { |
167 | public: | 168 | public: |
168 | UsbDevice( Category* parent, const QString& name ); | 169 | UsbDevice( Category* parent, const QString& name ); |
170 | UsbDevice( UsbDevice* parent, const QString& name ); | ||
169 | ~UsbDevice(); | 171 | ~UsbDevice(); |
170 | 172 | ||
171 | // virtual QWidget* detailsWidget(); | 173 | // virtual QWidget* detailsWidget(); |
172 | }; | 174 | }; |
173 | 175 | ||
174 | #endif | 176 | #endif |