Make a branch to make krunner Good Enough For Aaron™.
[kdebase/uwolfer.git] / apps / kinfocenter / info / info_openbsd.cpp
blobcf17f6e78f807c9b11aed5abfe76e81c2659e8b2
1 /*
2 * info_netbsd.cpp is part of the KDE program kcminfo. This displays
3 * various information about the OpenBSD system it's running on.
5 * Originally written by Jaromir Dolecek <dolecek@ics.muni.cz>. CPU info
6 * code has been imported from implementation of processor.cpp for KDE 1.0
7 * by David Brownlee <abs@NetBSD.org> as found in NetBSD packages collection.
8 * Hubert Feyer <hubertf@NetBSD.org> enhanced the sound information printing
9 * quite a lot, too.
11 * The code is placed into public domain. Do whatever you want with it.
14 #define INFO_CPU_AVAILABLE
15 #define INFO_IRQ_AVAILABLE
16 #define INFO_DMA_AVAILABLE
17 #define INFO_PCI_AVAILABLE
18 #define INFO_IOPORTS_AVAILABLE
19 #define INFO_SOUND_AVAILABLE
20 #define INFO_DEVICES_AVAILABLE
21 #define INFO_SCSI_AVAILABLE
22 #define INFO_PARTITIONS_AVAILABLE
23 #define INFO_XSERVER_AVAILABLE
27 * all following functions should return true, when the Information
28 * was filled into the lBox-Widget. Returning false indicates that
29 * information was not available.
32 #include <sys/types.h>
33 #include <sys/param.h>
34 #include <sys/sysctl.h>
35 #include <stdio.h> /* for NULL */
36 #include <stdlib.h> /* for malloc(3) */
38 #include <QFile>
39 #include <QFontMetrics>
40 #include <Q3StrList>
41 #include <QTextStream>
43 #include <kdebug.h>
45 typedef struct
47 int string;
48 int name;
49 const char *title;
50 } hw_info_mib_list_t;
52 bool GetInfo_CPU(Q3ListView *lBox)
54 static hw_info_mib_list_t hw_info_mib_list[]= {
55 { 1, HW_MODEL, "Model" },
56 { 1, HW_MACHINE, "Machine" },
57 { 0, HW_NCPU, "Number of CPUs" },
58 { 0, HW_PAGESIZE, "Pagesize" },
59 { 0,0,0 }
61 hw_info_mib_list_t *hw_info_mib;
63 int mib[2], num;
64 char *buf;
65 size_t len;
66 QString value;
68 lBox->addColumn(i18n("Information"));
69 lBox->addColumn(i18n("Value"));
71 for ( hw_info_mib = hw_info_mib_list ; hw_info_mib->title ; ++hw_info_mib )
73 mib[0] = CTL_HW;
74 mib[1] = hw_info_mib->name;
75 if ( hw_info_mib->string ) {
76 sysctl(mib,2,NULL,&len,NULL,0);
77 if ( (buf = (char*)malloc(len)) ) {
78 sysctl(mib,2,buf,&len,NULL,0);
79 value = QString::fromLocal8Bit(buf);
80 free(buf);
82 else {
83 value = QString("Unknown");
86 else {
87 len = sizeof(num);
88 sysctl(mib,2,&num,&len,NULL,0);
89 value.sprintf("%d", num);
91 new Q3ListViewItem(lBox, hw_info_mib->title, value);
94 return true;
97 // this is used to find out which devices are currently
98 // on system
99 static bool GetDmesgInfo(Q3ListView *lBox, const char *filter,
100 void func(Q3ListView *, QString s, void **, bool))
102 QFile *dmesg = new QFile("/var/run/dmesg.boot");
103 bool usepipe=false;
104 FILE *pipe=NULL;
105 QTextStream *t;
106 bool seencpu=false;
107 void *opaque=NULL;
108 QString s;
109 bool found=false;
111 if (dmesg->exists() && dmesg->open(QIODevice::ReadOnly)) {
112 t = new QTextStream(dmesg);
114 else {
115 delete dmesg;
116 pipe = popen("/sbin/dmesg", "r");
117 if (!pipe) return false;
118 usepipe = true;
119 t = new QTextStream(pipe, QIODevice::ReadOnly);
122 Q3ListViewItem *olditem = NULL;
123 while(!(s = t->readLine()).isNull()) {
124 if (!seencpu) {
125 if (s.contains("cpu"))
126 seencpu = true;
127 else
128 continue;
130 if (s.contains("boot device") ||
131 s.contains("WARNING: old BSD partition ID!"))
132 break;
134 if (!filter || s.contains(filter)) {
135 if (func) {
136 func(lBox, s, &opaque, false);
138 else {
139 olditem = new Q3ListViewItem(lBox, olditem, s);
141 found = true;
144 if (func) {
145 func(lBox, s, &opaque, true);
147 //lBox->triggerUpdate();
149 delete t;
150 if (pipe) {
151 pclose(pipe);
153 else {
154 dmesg->close();
155 delete dmesg;
158 return found;
162 void AddIRQLine(Q3ListView *lBox, QString s, void **opaque, bool ending)
164 Q3StrList *strlist = (Q3StrList *) *opaque;
165 const char *str;
166 int pos, irqnum=0;
167 const char *p;
168 p = s.toLatin1();
170 if (!strlist) {
171 strlist = new Q3StrList();
172 *opaque = (void *) strlist;
174 if (ending) {
175 str = strlist->first();
176 for(;str; str = strlist->next()) {
177 new Q3ListViewItem(lBox, str);
179 delete strlist;
180 return;
183 pos = s.find(" irq ");
184 irqnum = (pos < 0) ? 0 : atoi(&p[pos+5]);
185 if (irqnum) {
186 s.sprintf("%02d%s", irqnum, p);
188 else {
189 s.sprintf("??%s", p);
191 strlist->inSort(s.toLatin1());
194 bool GetInfo_IRQ (Q3ListView *lBox)
196 lBox->addColumn(i18n("IRQ"));
197 lBox->addColumn(i18n("Device"));
198 (void) GetDmesgInfo(lBox, " irq ", AddIRQLine);
199 return true;
202 bool GetInfo_DMA (Q3ListView *)
204 return false;
207 bool GetInfo_PCI (Q3ListView *lbox)
209 if (!GetDmesgInfo(lbox, "at pci", NULL))
210 new Q3ListViewItem(lbox, i18n("No PCI devices found."));
211 return true;
214 bool GetInfo_IO_Ports (Q3ListView *lbox)
216 if (!GetDmesgInfo(lbox, "port 0x", NULL))
217 new Q3ListViewItem(lbox, i18n("No I/O port devices found."));
218 return true;
221 bool GetInfo_Sound (Q3ListView *lbox)
223 if (!GetDmesgInfo(lbox, "audio", NULL))
224 new Q3ListViewItem(lbox, i18n("No audio devices found."));
226 // append information on any audio devices found
227 Q3ListViewItem *lvitem = lbox->firstChild();
228 for(; lvitem; lvitem = lvitem->nextSibling()) {
229 QString s;
230 int pos, len;
231 const char *start, *end;
232 char *dev;
234 s = lvitem->text(0);
235 if ((pos = s.find("at ")) >= 0) {
236 pos += 3; // skip "at "
237 start = end = s.toAscii();
238 for(; *end && (*end!=':') && (*end!='\n'); end++);
239 len = end - start;
240 dev = (char *) malloc(len + 1);
241 strncpy(dev, start, len);
242 dev[len] = '\0';
244 GetDmesgInfo(lbox, dev, NULL);
246 free(dev);
250 return true;
253 bool GetInfo_Devices (Q3ListView *lBox)
255 (void) GetDmesgInfo(lBox, NULL, NULL);
256 return true;
259 bool GetInfo_SCSI (Q3ListView *lbox)
261 if (!GetDmesgInfo(lbox, "scsibus", NULL))
262 new Q3ListViewItem(lbox, i18n("No SCSI devices found."));
263 return true;
266 bool GetInfo_Partitions (Q3ListView *lbox)
268 QString s;
269 char *line, *orig_line;
270 const char *device, *mountpoint, *type, *flags;
271 FILE *pipe = popen("/sbin/mount", "r");
272 QTextStream *t;
274 if (!pipe) {
275 kError(0) << i18n("Unable to run /sbin/mount.") << endl;
276 return false;
278 t = new QTextStream(pipe, QIODevice::ReadOnly);
280 lbox->addColumn(i18n("Device"));
281 lbox->addColumn(i18n("Mount Point"));
282 lbox->addColumn(i18n("FS Type"));
283 lbox->addColumn(i18n("Mount Options"));
285 Q3ListViewItem *olditem = 0;
286 while (!(s = t->readLine()).isNull()) {
287 orig_line = line = strdup(s.toLatin1());
289 device = strsep(&line, " ");
291 (void) strsep(&line, " "); // consume word "on"
292 mountpoint = strsep(&line, " ");
294 (void) strsep(&line, " "); // consume word "type"
295 type = strsep(&line, " ");
297 flags = line;
299 olditem = new Q3ListViewItem(lbox, olditem, device, mountpoint,
300 type, flags);
302 free(orig_line);
305 delete t;
306 pclose(pipe);
307 return true;
310 bool GetInfo_XServer_and_Video (Q3ListView *lBox)
312 return GetInfo_XServer_Generic( lBox );