-rw-r--r-- | noncore/settings/sysinfo/devicesinfo.cpp | 192 | ||||
-rw-r--r-- | noncore/settings/sysinfo/devicesinfo.h | 62 |
2 files changed, 244 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 | |||
@@ -26,49 +26,221 @@ _;:, .> :=|. This program is free software; you can | |||
26 | Boston, MA 02111-1307, USA. | 26 | Boston, MA 02111-1307, USA. |
27 | */ | 27 | */ |
28 | 28 | ||
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> |
36 | using namespace Opie::Core; | ||
37 | using 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 | ||
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 ); |
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 | ||
56 | DevicesView::~DevicesView() | 65 | DevicesView::~DevicesView() |
57 | { | 66 | { |
58 | } | 67 | } |
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 | } |
71 | 79 | ||
72 | DevicesInfo::~DevicesInfo() | 80 | DevicesInfo::~DevicesInfo() |
73 | { | 81 | { |
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 | |||
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 | |||
@@ -30,27 +30,89 @@ _;:, .> :=|. This program is free software; you can | |||
30 | #define DEVICESINFO_H | 30 | #define DEVICESINFO_H |
31 | 31 | ||
32 | #include <qwidget.h> | 32 | #include <qwidget.h> |
33 | #include <opie2/olistview.h> | 33 | #include <opie2/olistview.h> |
34 | using namespace Opie::Ui; | 34 | using namespace Opie::Ui; |
35 | 35 | ||
36 | //================================================================================================= | ||
36 | class DevicesView : public OListView | 37 | class DevicesView : public OListView |
37 | { | 38 | { |
38 | Q_OBJECT | 39 | Q_OBJECT |
39 | public: | 40 | public: |
40 | DevicesView( QWidget* parent = 0, const char* name = 0, WFlags f = 0 ); | 41 | DevicesView( QWidget* parent = 0, const char* name = 0, WFlags f = 0 ); |
41 | ~DevicesView(); | 42 | ~DevicesView(); |
42 | }; | 43 | }; |
43 | 44 | ||
45 | //================================================================================================= | ||
44 | class DevicesInfo : public QWidget | 46 | class DevicesInfo : public QWidget |
45 | { | 47 | { |
46 | Q_OBJECT | 48 | Q_OBJECT |
47 | public: | 49 | public: |
48 | DevicesInfo( QWidget *parent = 0, const char *name = 0, WFlags f = 0 ); | 50 | DevicesInfo( QWidget *parent = 0, const char *name = 0, WFlags f = 0 ); |
49 | ~DevicesInfo(); | 51 | ~DevicesInfo(); |
50 | 52 | ||
51 | private: | 53 | private: |
52 | OListView* view; | 54 | OListView* view; |
53 | 55 | ||
54 | private slots: | 56 | private slots: |
55 | }; | 57 | }; |
58 | |||
59 | //================================================================================================= | ||
60 | class Category : public OListViewItem | ||
61 | { | ||
62 | public: | ||
63 | Category( DevicesView* parent, const QString& name ); | ||
64 | virtual ~Category(); | ||
65 | |||
66 | virtual void populate() = 0; | ||
67 | }; | ||
68 | |||
69 | //================================================================================================= | ||
70 | class Device : public OListViewItem | ||
71 | { | ||
72 | public: | ||
73 | Device( Category* parent, const QString& name ); | ||
74 | ~Device(); | ||
75 | }; | ||
76 | |||
77 | //================================================================================================= | ||
78 | class CpuCategory : public Category | ||
79 | { | ||
80 | public: | ||
81 | CpuCategory( DevicesView* parent ); | ||
82 | virtual ~CpuCategory(); | ||
83 | |||
84 | virtual void populate(); | ||
85 | }; | ||
86 | |||
87 | //================================================================================================= | ||
88 | class InputCategory : public Category | ||
89 | { | ||
90 | public: | ||
91 | InputCategory( DevicesView* parent ); | ||
92 | virtual ~InputCategory(); | ||
93 | |||
94 | virtual void populate(); | ||
95 | }; | ||
96 | |||
97 | //================================================================================================= | ||
98 | class CardsCategory : public Category | ||
99 | { | ||
100 | public: | ||
101 | CardsCategory( DevicesView* parent ); | ||
102 | virtual ~CardsCategory(); | ||
103 | |||
104 | virtual void populate(); | ||
105 | }; | ||
106 | |||
107 | //================================================================================================= | ||
108 | class UsbCategory : public Category | ||
109 | { | ||
110 | public: | ||
111 | UsbCategory( DevicesView* parent ); | ||
112 | virtual ~UsbCategory(); | ||
113 | |||
114 | virtual void populate(); | ||
115 | }; | ||
116 | |||
117 | |||
56 | #endif | 118 | #endif |