00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029 #include "devicesinfo.h"
00030
00031 #include <opie2/odebug.h>
00032 #include <opie2/oinputsystem.h>
00033 #include <opie2/opcmciasystem.h>
00034 #include <opie2/olayout.h>
00035 #include <opie2/olistview.h>
00036 #include <qpe/qpeapplication.h>
00037 using namespace Opie::Core;
00038 using namespace Opie::Ui;
00039
00040
00041 #include <qobjectlist.h>
00042 #include <qlistview.h>
00043 #include <qcombobox.h>
00044 #include <qfile.h>
00045 #include <qpushbutton.h>
00046 #include <qstringlist.h>
00047 #include <qtextstream.h>
00048 #include <qtextview.h>
00049 #include <qtimer.h>
00050 #include <qwhatsthis.h>
00051
00052
00053 DevicesView::DevicesView( QWidget* parent, const char* name, WFlags fl )
00054 :Opie::Ui::OListView( parent, name, fl )
00055 {
00056 addColumn( tr( "My Computer" ) );
00057 setAllColumnsShowFocus( true );
00058 setRootIsDecorated( true );
00059 QWhatsThis::add( this, tr( "This is a list of all the devices currently recognized on this device." ) );
00060
00061 DevicesView* root = this;
00062 ( new CpuCategory( root ) )->populate();
00063 ( new InputCategory( root ) )->populate();
00064 ( new CardsCategory( root ) )->populate();
00065 ( new UsbCategory( root ) )->populate();
00066
00067 connect( this, SIGNAL(selectionChanged(QListViewItem*)), this, SLOT(selectionChanged(QListViewItem*)) );
00068 }
00069
00070 DevicesView::~DevicesView()
00071 {
00072 }
00073
00074
00075 void DevicesView::selectionChanged( QListViewItem* item )
00076 {
00077 odebug << "DevicesView::selectionChanged to '" << item->text( 0 ) << "'" << oendl;
00078 if ( item->parent() )
00079 {
00080 QWidget* details = ( static_cast<Device*>( item ) )->detailsWidget();
00081 ( static_cast<DevicesInfo*>( parent() ) )->setDetailsWidget( details );
00082 }
00083 else
00084 {
00085 odebug << "DevicesView::not a device node." << oendl;
00086 }
00087 }
00088
00089
00090
00091 DevicesInfo::DevicesInfo( QWidget* parent, const char* name, WFlags fl )
00092 :QWidget( parent, name, fl ), details( 0 )
00093 {
00094 layout = new OAutoBoxLayout( this );
00095 layout->setSpacing( 2 );
00096 layout->setMargin( 2 );
00097 view = new DevicesView( this );
00098 layout->addWidget( view, 100 );
00099 stack = new QWidgetStack( this );
00100 layout->addWidget( stack, 80 );
00101 }
00102
00103
00104 DevicesInfo::~DevicesInfo()
00105 {
00106 }
00107
00108
00109 void DevicesInfo::setDetailsWidget( QWidget* w )
00110 {
00111 if ( details )
00112 {
00113 qDebug( "hiding widget '%s' ('%s')", details->name(), details->className() );
00114 stack->removeWidget( w );
00115 }
00116
00117 stack->addWidget( details = w, 40 );
00118 stack->raiseWidget( details );
00119 }
00120
00121
00122
00123 Category::Category( DevicesView* parent, const QString& name )
00124 :OListViewItem( parent, name )
00125 {
00126 odebug << "Category '" << name << "' inserted. Scanning for devices..." << oendl;
00127 }
00128
00129 Category::~Category()
00130 {
00131 }
00132
00133
00134 CpuCategory::CpuCategory( DevicesView* parent )
00135 :Category( parent, "1. Central Processing Unit" )
00136 {
00137 }
00138
00139 CpuCategory::~CpuCategory()
00140 {
00141 }
00142
00143 void CpuCategory::populate()
00144 {
00145 odebug << "CpuCategory::populate()" << oendl;
00146 QFile cpuinfofile( "/proc/cpuinfo" );
00147 if ( !cpuinfofile.exists() || !cpuinfofile.open( IO_ReadOnly ) )
00148 {
00149 new CpuDevice( this, "(no cpu found)" );
00150 return;
00151 }
00152 QTextStream cpuinfo( &cpuinfofile );
00153
00154 int cpucount = 0;
00155 CpuDevice* dev = 0;
00156
00157 while ( !cpuinfo.atEnd() )
00158 {
00159 QString line = cpuinfo.readLine();
00160 odebug << "got line '" << line << "'" << oendl;
00161 if ( line.lower().startsWith( "processor" ) )
00162 {
00163 dev = new CpuDevice( this, QString( "CPU #%1" ).arg( cpucount++ ) );
00164 dev->addInfo( line );
00165 }
00166 else
00167 {
00168 if ( dev ) dev->addInfo( line );
00169 }
00170 }
00171 }
00172
00173
00174 InputCategory::InputCategory( DevicesView* parent )
00175 :Category( parent, "2. Input Subsystem" )
00176 {
00177 }
00178
00179 InputCategory::~InputCategory()
00180 {
00181 }
00182
00183 void InputCategory::populate()
00184 {
00185 odebug << "InputCategory::populate()" << oendl;
00186 OInputSystem* sys = OInputSystem::instance();
00187 OInputSystem::DeviceIterator it = sys->iterator();
00188 while ( it.current() )
00189 {
00190 InputDevice* dev = new InputDevice( this, it.current()->identity() );
00191 dev->setInfo( it.current() );
00192 ++it;
00193 }
00194 }
00195
00196
00197 CardsCategory::CardsCategory( DevicesView* parent )
00198 :Category( parent, "3. Removable Cards" )
00199 {
00200 }
00201
00202 CardsCategory::~CardsCategory()
00203 {
00204 }
00205
00206 void CardsCategory::populate()
00207 {
00208 odebug << "CardsCategory::populate()" << oendl;
00209 OPcmciaSystem* sys = OPcmciaSystem::instance();
00210 OPcmciaSystem::CardIterator it = sys->iterator();
00211 while ( it.current() )
00212 {
00213 CardDevice *dev = new CardDevice( this, it.current()->identity() );
00214 dev->setInfo( it.current() );
00215 ++it;
00216 }
00217 }
00218
00219
00220 UsbCategory::UsbCategory( DevicesView* parent )
00221 :Category( parent, "4. Universal Serial Bus" )
00222 {
00223 }
00224
00225 UsbCategory::~UsbCategory()
00226 {
00227 }
00228
00229 void UsbCategory::populate()
00230 {
00231 odebug << "UsbCategory::populate()" << oendl;
00232 QFile usbinfofile( "/proc/bus/usb/devices" );
00233 if ( !usbinfofile.exists() || !usbinfofile.open( IO_ReadOnly ) )
00234 {
00235 new UsbDevice( this, "(no USB found)" );
00236 return;
00237 }
00238 QTextStream usbinfo( &usbinfofile );
00239
00240 int _bus, _level, _parent, _port, _count, _device, _channels, _power;
00241 float _speed;
00242 QString _manufacturer, _product, _serial;
00243
00244 int usbcount = 0;
00245 UsbDevice* lastDev = 0;
00246 UsbDevice* dev = 0;
00247 while ( !usbinfo.atEnd() )
00248 {
00249 QString line = usbinfo.readLine();
00250 odebug << "got line '" << line << "'" << oendl;
00251 if ( line.startsWith( "T:" ) )
00252 {
00253 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);
00254
00255 if ( !_level )
00256 {
00257 odebug << "adding new bus" << oendl;
00258 dev = new UsbDevice( this, QString( "Generic USB Hub Device" ) );
00259 lastDev = dev;
00260 }
00261 else
00262 {
00263 odebug << "adding new dev" << oendl;
00264 dev = new UsbDevice( lastDev, QString( "Generic USB Hub Device" ) );
00265 lastDev = dev;
00266 }
00267 }
00268 else if ( line.startsWith( "S: Product" ) )
00269 {
00270 int dp = line.find( '=' );
00271 dev->setText( 0, dp != -1 ? line.right( line.length()-1-dp ) : "<unknown>" );
00272 }
00273 else
00274 {
00275 continue;
00276 }
00277 }
00278 }
00279
00280
00281
00282 Device::Device( Category* parent, const QString& name )
00283 :OListViewItem( parent, name )
00284 {
00285 devinfo = static_cast<QWidget*>( listView()->parent() );
00286 }
00287
00288 Device::Device( Device* parent, const QString& name )
00289 :OListViewItem( parent, name )
00290 {
00291 devinfo = static_cast<QWidget*>( listView()->parent() );
00292 }
00293
00294 Device::~Device()
00295 {
00296 }
00297
00298
00299 QWidget* Device::detailsWidget()
00300 {
00301 return details;
00302 }
00303
00304
00305 CpuDevice::CpuDevice( Category* parent, const QString& name )
00306 :Device( parent, name )
00307 {
00308 OListView* w = new OListView( devinfo );
00309 details = w;
00310 w->addColumn( "Info" );
00311 w->addColumn( "Value" );
00312 w->hide();
00313 }
00314
00315 CpuDevice::~CpuDevice()
00316 {
00317 }
00318
00319 void CpuDevice::addInfo( const QString& info )
00320 {
00321 int dp = info.find( ':' );
00322 if ( dp != -1 )
00323 {
00324 new OListViewItem( (OListView*) details, info.left( dp ), info.right( info.length()-dp ) );
00325 }
00326 }
00327
00328
00329 CardDevice::CardDevice( Category* parent, const QString& name )
00330 :Device( parent, name )
00331 {
00332 OListView* w = new OListView( devinfo );
00333 details = w;
00334 w->addColumn( "Info" );
00335 w->addColumn( "Value" );
00336 w->hide();
00337 }
00338
00339 void CardDevice::setInfo( const OPcmciaSocket* card )
00340 {
00341 QStringList vendorlst = card->productIdentityVector();
00342 for( QStringList::Iterator it = vendorlst.begin(); it != vendorlst.end(); ++it )
00343 {
00344 new OListViewItem( (OListView*) details, "VendorID", *it );
00345 }
00346 new OListViewItem( (OListView*) details, "Manufacturer", card->manufacturerIdentity() );
00347 new OListViewItem( (OListView*) details, "Function", card->function() );
00348
00349 QStringList text;
00350 OPcmciaSocket::OPcmciaSocketCardStatus status = card->status();
00351 if ( status )
00352 {
00353 if ( status & OPcmciaSocket::Occupied ) text += "Occupied";
00354 if ( status & OPcmciaSocket::OccupiedCardBus ) text += "CardBus";
00355 if ( status & OPcmciaSocket::WriteProtected ) text += "WriteProtected";
00356 if ( status & OPcmciaSocket::BatteryLow ) text += "BatteryLow";
00357 if ( status & OPcmciaSocket::BatteryDead ) text += "BatteryDead";
00358 if ( status & OPcmciaSocket::Ready ) text += "Ready";
00359 if ( status & OPcmciaSocket::Suspended ) text += "Suspended";
00360 if ( status & OPcmciaSocket::Attention ) text += "Attention";
00361 if ( status & OPcmciaSocket::InsertionInProgress ) text += "InsertionInProgress";
00362 if ( status & OPcmciaSocket::RemovalInProgress ) text += "RemovalInProgress";
00363 if ( status & OPcmciaSocket::ThreeVolts ) text += "3V";
00364 if ( status & OPcmciaSocket::SupportsVoltage ) text += "SupportsVoltage";
00365 }
00366 else
00367 {
00368 text += "<unknown>";
00369 }
00370 new OListViewItem( (OListView*) details, "Status", text.join( ", " ) );
00371 }
00372
00373 CardDevice::~CardDevice()
00374 {
00375 }
00376
00377
00378 InputDevice::InputDevice( Category* parent, const QString& name )
00379 :Device( parent, name )
00380 {
00381 OListView* w = new OListView( devinfo );
00382 details = w;
00383 w->addColumn( "Info" );
00384 w->addColumn( "Value" );
00385 w->hide();
00386 }
00387
00388 void InputDevice::setInfo( const OInputDevice* dev )
00389 {
00390 new OListViewItem( (OListView*) details, "Identity", dev->identity() );
00391 new OListViewItem( (OListView*) details, "Path", dev->path() );
00392 new OListViewItem( (OListView*) details, "Unique", dev->uniq() );
00393
00394 QStringList text;
00395 if ( dev->hasFeature( OInputDevice::Synchronous ) ) text += "Synchronous";
00396 if ( dev->hasFeature( OInputDevice::Keys ) ) text += "Keys";
00397 if ( dev->hasFeature( OInputDevice::Relative ) ) text += "Relative";
00398 if ( dev->hasFeature( OInputDevice::Absolute ) ) text += "Absolute";
00399 if ( dev->hasFeature( OInputDevice::Miscellaneous ) ) text += "Miscellaneous";
00400 if ( dev->hasFeature( OInputDevice::Switches ) ) text += "Switches";
00401 if ( dev->hasFeature( OInputDevice::Leds ) ) text += "Leds";
00402 if ( dev->hasFeature( OInputDevice::Sound ) ) text += "Sound";
00403 if ( dev->hasFeature( OInputDevice::AutoRepeat ) ) text += "AutoRepeat";
00404 if ( dev->hasFeature( OInputDevice::ForceFeedback ) ) text += "ForceFeedback";
00405 if ( dev->hasFeature( OInputDevice::PowerManagement ) ) text += "PowerManagement";
00406 if ( dev->hasFeature( OInputDevice::ForceFeedbackStatus ) ) text += "ForceFeedbackStatus";
00407 new OListViewItem( (OListView*) details, "Features", text.join( ", " ) );
00408
00409 }
00410
00411 InputDevice::~InputDevice()
00412 {
00413 }
00414
00415
00416 UsbDevice::UsbDevice( Category* parent, const QString& name )
00417 :Device( parent, name )
00418 {
00419 details = new QPushButton( name, devinfo );
00420 details->hide();
00421 }
00422
00423
00424 UsbDevice::UsbDevice( UsbDevice* parent, const QString& name )
00425 :Device( parent, name )
00426 {
00427 details = new QPushButton( name, devinfo );
00428 details->hide();
00429 }
00430
00431 UsbDevice::~UsbDevice()
00432 {
00433 }