author | mickeyl <mickeyl> | 2005-05-02 17:32:08 (UTC) |
---|---|---|
committer | mickeyl <mickeyl> | 2005-05-02 17:32:08 (UTC) |
commit | 8bd13e6ac069f9d58ec10e61a4dc174837c6b5ee (patch) (unidiff) | |
tree | 81d80182a1aee3e71ccf21a2bcb1a1e107d8d72d /noncore/settings/sysinfo/devicesinfo.cpp | |
parent | c3d0da09d6c49061efc43ce9707c5952ebefdae3 (diff) | |
download | opie-8bd13e6ac069f9d58ec10e61a4dc174837c6b5ee.zip opie-8bd13e6ac069f9d58ec10e61a4dc174837c6b5ee.tar.gz opie-8bd13e6ac069f9d58ec10e61a4dc174837c6b5ee.tar.bz2 |
first stab at populating device nodes
Diffstat (limited to 'noncore/settings/sysinfo/devicesinfo.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/settings/sysinfo/devicesinfo.cpp | 192 |
1 files changed, 182 insertions, 10 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 | |||
@@ -31,4 +31,8 @@ _;:, .> :=|. This program is free software; you can | |||
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> |
36 | using namespace Opie::Core; | ||
37 | using namespace Opie::Ui; | ||
34 | 38 | ||
@@ -38,4 +42,4 @@ _;:, .> :=|. This program is free software; you can | |||
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> |
@@ -44,8 +48,7 @@ _;:, .> :=|. This program is free software; you can | |||
44 | 48 | ||
45 | using namespace Opie::Ui; | 49 | //================================================================================================= |
46 | |||
47 | DevicesView::DevicesView( QWidget* parent, const char* name, WFlags fl ) | 50 | DevicesView::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 ); |
@@ -53,2 +56,8 @@ DevicesView::DevicesView( QWidget* parent, const char* name, WFlags fl ) | |||
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 | } |
@@ -59,12 +68,11 @@ DevicesView::~DevicesView() | |||
59 | 68 | ||
69 | //================================================================================================= | ||
60 | DevicesInfo::DevicesInfo( QWidget* parent, const char* name, WFlags fl ) | 70 | DevicesInfo::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 | } |
@@ -74 +82,165 @@ DevicesInfo::~DevicesInfo() | |||
74 | } | 82 | } |
83 | |||
84 | |||
85 | Category::Category( DevicesView* parent, const QString& name ) | ||
86 | :OListViewItem( parent, name ) | ||
87 | { | ||
88 | odebug << "Category '" << name << "' inserted. Scanning for devices..." << oendl; | ||
89 | } | ||
90 | |||
91 | Category::~Category() | ||
92 | { | ||
93 | } | ||
94 | |||
95 | //================================================================================================= | ||
96 | Device::Device( Category* parent, const QString& name ) | ||
97 | :OListViewItem( parent, name ) | ||
98 | { | ||
99 | } | ||
100 | |||
101 | Device::~Device() | ||
102 | { | ||
103 | } | ||
104 | |||
105 | //================================================================================================= | ||
106 | CpuCategory::CpuCategory( DevicesView* parent ) | ||
107 | :Category( parent, "1. Central Processing Unit" ) | ||
108 | { | ||
109 | } | ||
110 | |||
111 | CpuCategory::~CpuCategory() | ||
112 | { | ||
113 | } | ||
114 | |||
115 | void 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 | //================================================================================================= | ||
143 | InputCategory::InputCategory( DevicesView* parent ) | ||
144 | :Category( parent, "2. Input Subsystem" ) | ||
145 | { | ||
146 | } | ||
147 | |||
148 | InputCategory::~InputCategory() | ||
149 | { | ||
150 | } | ||
151 | |||
152 | void 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 | //================================================================================================= | ||
166 | CardsCategory::CardsCategory( DevicesView* parent ) | ||
167 | :Category( parent, "3. Removable Cards" ) | ||
168 | { | ||
169 | } | ||
170 | |||
171 | CardsCategory::~CardsCategory() | ||
172 | { | ||
173 | } | ||
174 | |||
175 | void 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 | //================================================================================================= | ||
205 | UsbCategory::UsbCategory( DevicesView* parent ) | ||
206 | :Category( parent, "4. Universal Serial Bus" ) | ||
207 | { | ||
208 | } | ||
209 | |||
210 | UsbCategory::~UsbCategory() | ||
211 | { | ||
212 | } | ||
213 | |||
214 | void 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 | |||