summaryrefslogtreecommitdiff
authormickeyl <mickeyl>2005-05-02 17:32:08 (UTC)
committer mickeyl <mickeyl>2005-05-02 17:32:08 (UTC)
commit8bd13e6ac069f9d58ec10e61a4dc174837c6b5ee (patch) (unidiff)
tree81d80182a1aee3e71ccf21a2bcb1a1e107d8d72d
parentc3d0da09d6c49061efc43ce9707c5952ebefdae3 (diff)
downloadopie-8bd13e6ac069f9d58ec10e61a4dc174837c6b5ee.zip
opie-8bd13e6ac069f9d58ec10e61a4dc174837c6b5ee.tar.gz
opie-8bd13e6ac069f9d58ec10e61a4dc174837c6b5ee.tar.bz2
first stab at populating device nodes
Diffstat (more/less context) (show whitespace changes)
-rw-r--r--noncore/settings/sysinfo/devicesinfo.cpp188
-rw-r--r--noncore/settings/sysinfo/devicesinfo.h62
2 files changed, 242 insertions, 8 deletions
diff --git a/noncore/settings/sysinfo/devicesinfo.cpp b/noncore/settings/sysinfo/devicesinfo.cpp
index 38afd54..a1c9e0b 100644
--- a/noncore/settings/sysinfo/devicesinfo.cpp
+++ b/noncore/settings/sysinfo/devicesinfo.cpp
@@ -29,46 +29,218 @@ _;:,     .>    :=|. This program is free software; you can
29#include "devicesinfo.h" 29#include "devicesinfo.h"
30 30
31/* OPIE */ 31/* OPIE */
32#include <opie2/odebug.h>
33#include <opie2/oinputsystem.h>
32#include <opie2/olistview.h> 34#include <opie2/olistview.h>
33#include <qpe/qpeapplication.h> 35#include <qpe/qpeapplication.h>
36using namespace Opie::Core;
37using namespace Opie::Ui;
34 38
35/* QT */ 39/* QT */
36#include <qcombobox.h> 40#include <qcombobox.h>
37#include <qfile.h> 41#include <qfile.h>
38#include <qlayout.h> 42#include <qlayout.h>
39#include <qmessagebox.h>
40#include <qpushbutton.h> 43#include <qpushbutton.h>
44#include <qtextstream.h>
41#include <qtextview.h> 45#include <qtextview.h>
42#include <qtimer.h> 46#include <qtimer.h>
43#include <qwhatsthis.h> 47#include <qwhatsthis.h>
44 48
45using namespace Opie::Ui; 49//=================================================================================================
46
47DevicesView::DevicesView( QWidget* parent, const char* name, WFlags fl ) 50DevicesView::DevicesView( QWidget* parent, const char* name, WFlags fl )
48 : OListView( parent, name, fl ) 51 : OListView( parent, name, fl )
49{ 52{
50 addColumn( tr( "Module" ) ); 53 addColumn( tr( "My Computer" ) );
51 setAllColumnsShowFocus( true ); 54 setAllColumnsShowFocus( true );
52 setRootIsDecorated( true ); 55 setRootIsDecorated( true );
53 QWhatsThis::add( this, tr( "This is a list of all the devices currently recognized on this device." ) ); 56 QWhatsThis::add( this, tr( "This is a list of all the devices currently recognized on this device." ) );
57
58 DevicesView* root = this;
59 ( new CpuCategory( root ) )->populate();
60 ( new InputCategory( root ) )->populate();
61 ( new CardsCategory( root ) )->populate();
62 ( new UsbCategory( root ) )->populate();
54} 63}
55 64
56DevicesView::~DevicesView() 65DevicesView::~DevicesView()
57{ 66{
58} 67}
59 68
69//=================================================================================================
60DevicesInfo::DevicesInfo( QWidget* parent, const char* name, WFlags fl ) 70DevicesInfo::DevicesInfo( QWidget* parent, const char* name, WFlags fl )
61 : QWidget( parent, name, fl ) 71 : QWidget( parent, name, fl )
62{ 72{
63 QGridLayout *layout = new QGridLayout( this ); 73 QVBoxLayout *layout = new QVBoxLayout( this );
64 layout->setSpacing( 4 ); 74 layout->setSpacing( 4 );
65 layout->setMargin( 4 ); 75 layout->setMargin( 4 );
66
67 view = new DevicesView( this ); 76 view = new DevicesView( this );
68 77 layout->addWidget( view );
69 layout->addMultiCellWidget( view, 0, 0, 0, 1 );
70} 78}
71 79
72DevicesInfo::~DevicesInfo() 80DevicesInfo::~DevicesInfo()
73{ 81{
74} 82}
83
84
85Category::Category( DevicesView* parent, const QString& name )
86 :OListViewItem( parent, name )
87{
88 odebug << "Category '" << name << "' inserted. Scanning for devices..." << oendl;
89}
90
91Category::~Category()
92{
93}
94
95//=================================================================================================
96Device::Device( Category* parent, const QString& name )
97 :OListViewItem( parent, name )
98{
99}
100
101Device::~Device()
102{
103}
104
105//=================================================================================================
106CpuCategory::CpuCategory( DevicesView* parent )
107 :Category( parent, "1. Central Processing Unit" )
108{
109}
110
111CpuCategory::~CpuCategory()
112{
113}
114
115void CpuCategory::populate()
116{
117 odebug << "CpuCategory::populate()" << oendl;
118 QFile cpuinfofile( "/proc/cpuinfo" );
119 if ( !cpuinfofile.exists() || !cpuinfofile.open( IO_ReadOnly ) )
120 {
121 new OListViewItem( this, "ERROR: /proc/cpuinfo not found or unaccessible" );
122 return;
123 }
124 QTextStream cpuinfo( &cpuinfofile );
125
126 int cpucount = 0;
127 while ( !cpuinfo.atEnd() )
128 {
129 QString line = cpuinfo.readLine();
130 odebug << "got line '" << line << "'" << oendl;
131 if ( line.startsWith( "processor" ) )
132 {
133 new OListViewItem( this, QString( "CPU #%1" ).arg( cpucount++ ) );
134 }
135 else
136 {
137 continue;
138 }
139 }
140}
141
142//=================================================================================================
143InputCategory::InputCategory( DevicesView* parent )
144 :Category( parent, "2. Input Subsystem" )
145{
146}
147
148InputCategory::~InputCategory()
149{
150}
151
152void InputCategory::populate()
153{
154 odebug << "InputCategory::populate()" << oendl;
155 OInputSystem* sys = OInputSystem::instance();
156 OInputSystem::DeviceIterator it = sys->iterator();
157 while ( it.current() )
158 {
159 OInputDevice* dev = it.current();
160 new OListViewItem( this, dev->identity() );
161 ++it;
162 }
163}
164
165//=================================================================================================
166CardsCategory::CardsCategory( DevicesView* parent )
167 :Category( parent, "3. Removable Cards" )
168{
169}
170
171CardsCategory::~CardsCategory()
172{
173}
174
175void CardsCategory::populate()
176{
177 odebug << "CardsCategory::populate()" << oendl;
178 QString fileName;
179 if ( QFile::exists( "/var/run/stab" ) ) { fileName = "/var/run/stab"; }
180 else if ( QFile::exists( "/var/state/pcmcia/stab" ) ) { fileName = "/var/state/pcmcia/stab"; }
181 else { fileName = "/var/lib/pcmcia/stab"; }
182 QFile cardinfofile( fileName );
183 if ( !cardinfofile.exists() || !cardinfofile.open( IO_ReadOnly ) )
184 {
185 new OListViewItem( this, "ERROR: pcmcia info file not found or unaccessible" );
186 return;
187 }
188 QTextStream cardinfo( &cardinfofile );
189 while ( !cardinfo.atEnd() )
190 {
191 QString line = cardinfo.readLine();
192 odebug << "got line '" << line << "'" << oendl;
193 if ( line.startsWith("Socket") )
194 {
195 new OListViewItem( this, line );
196 }
197 else
198 {
199 continue;
200 }
201 }
202}
203
204//=================================================================================================
205UsbCategory::UsbCategory( DevicesView* parent )
206 :Category( parent, "4. Universal Serial Bus" )
207{
208}
209
210UsbCategory::~UsbCategory()
211{
212}
213
214void UsbCategory::populate()
215{
216 odebug << "UsbCategory::populate()" << oendl;
217 QFile usbinfofile( "/proc/bus/usb/devices" );
218 if ( !usbinfofile.exists() || !usbinfofile.open( IO_ReadOnly ) )
219 {
220 new OListViewItem( this, "ERROR: /proc/bus/usb/devices not found or unaccessible" );
221 return;
222 }
223 QTextStream usbinfo( &usbinfofile );
224
225 int _bus, _level, _parent, _port, _count, _device, _channels, _power;
226 float _speed;
227 QString _manufacturer, _product, _serial;
228
229 int usbcount = 0;
230 while ( !usbinfo.atEnd() )
231 {
232 QString line = usbinfo.readLine();
233 odebug << "got line '" << line << "'" << oendl;
234 if ( line.startsWith("T:") )
235 {
236 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);
237
238 new OListViewItem( this, QString( "USB Device #%1" ).arg( usbcount++ ) );
239 }
240 else
241 {
242 continue;
243 }
244 }
245}
246
diff --git a/noncore/settings/sysinfo/devicesinfo.h b/noncore/settings/sysinfo/devicesinfo.h
index 082586b..60ec999 100644
--- a/noncore/settings/sysinfo/devicesinfo.h
+++ b/noncore/settings/sysinfo/devicesinfo.h
@@ -33,6 +33,7 @@ _;:,     .>    :=|. This program is free software; you can
33#include <opie2/olistview.h> 33#include <opie2/olistview.h>
34using namespace Opie::Ui; 34using namespace Opie::Ui;
35 35
36//=================================================================================================
36class DevicesView : public OListView 37class DevicesView : public OListView
37{ 38{
38 Q_OBJECT 39 Q_OBJECT
@@ -41,6 +42,7 @@ public:
41 ~DevicesView(); 42 ~DevicesView();
42}; 43};
43 44
45//=================================================================================================
44class DevicesInfo : public QWidget 46class DevicesInfo : public QWidget
45{ 47{
46 Q_OBJECT 48 Q_OBJECT
@@ -53,4 +55,64 @@ private:
53 55
54private slots: 56private slots:
55}; 57};
58
59//=================================================================================================
60class Category : public OListViewItem
61{
62public:
63 Category( DevicesView* parent, const QString& name );
64 virtual ~Category();
65
66 virtual void populate() = 0;
67};
68
69//=================================================================================================
70class Device : public OListViewItem
71{
72public:
73 Device( Category* parent, const QString& name );
74 ~Device();
75};
76
77//=================================================================================================
78class CpuCategory : public Category
79{
80public:
81 CpuCategory( DevicesView* parent );
82 virtual ~CpuCategory();
83
84 virtual void populate();
85};
86
87//=================================================================================================
88class InputCategory : public Category
89{
90public:
91 InputCategory( DevicesView* parent );
92 virtual ~InputCategory();
93
94 virtual void populate();
95};
96
97//=================================================================================================
98class CardsCategory : public Category
99{
100public:
101 CardsCategory( DevicesView* parent );
102 virtual ~CardsCategory();
103
104 virtual void populate();
105};
106
107//=================================================================================================
108class UsbCategory : public Category
109{
110public:
111 UsbCategory( DevicesView* parent );
112 virtual ~UsbCategory();
113
114 virtual void populate();
115};
116
117
56#endif 118#endif