summaryrefslogtreecommitdiff
path: root/noncore/settings/sysinfo/modulesinfo.cpp
Unidiff
Diffstat (limited to 'noncore/settings/sysinfo/modulesinfo.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/settings/sysinfo/modulesinfo.cpp120
1 files changed, 120 insertions, 0 deletions
diff --git a/noncore/settings/sysinfo/modulesinfo.cpp b/noncore/settings/sysinfo/modulesinfo.cpp
new file mode 100644
index 0000000..7a32c20
--- a/dev/null
+++ b/noncore/settings/sysinfo/modulesinfo.cpp
@@ -0,0 +1,120 @@
1/**********************************************************************
2** ModulesInfo
3**
4** Display Modules information
5**
6** Copyright (C) 2002, Michael Lauer
7** mickey@tm.informatik.uni-frankfurt.de
8** http://www.Vanille.de
9**
10** Based on ProcessInfo by Dan Williams <williamsdr@acm.org>
11**
12** This file may be distributed and/or modified under the terms of the
13** GNU General Public License version 2 as published by the Free Software
14** Foundation and appearing in the file LICENSE.GPL included in the
15** packaging of this file.
16**
17** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
18** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
19**
20**********************************************************************/
21
22#include <qpe/qpeapplication.h>
23
24#include <qheader.h>
25#include <qlistview.h>
26#include <qlayout.h>
27#include <qtimer.h>
28#include <qfile.h>
29
30#include "modulesinfo.h"
31
32ModulesInfo::ModulesInfo( QWidget* parent, const char* name, WFlags fl )
33 : QWidget( parent, name, fl )
34{
35 QVBoxLayout *layout = new QVBoxLayout( this, 5 );
36
37 ModulesView = new QListView( this, "ModulesView" );
38 int colnum = ModulesView->addColumn( tr( "Module" ) );
39 colnum = ModulesView->addColumn( tr( "Size" ) );
40 ModulesView->setColumnAlignment( colnum, Qt::AlignRight );
41 colnum = ModulesView->addColumn( tr( "Use#" ) );
42 ModulesView->setColumnAlignment( colnum, Qt::AlignRight );
43 colnum = ModulesView->addColumn( tr( "Used By" ) );
44 ModulesView->setAllColumnsShowFocus( TRUE );
45 QPEApplication::setStylusOperation( ModulesView->viewport(), QPEApplication::RightOnHold );
46 connect( ModulesView, SIGNAL( rightButtonPressed( QListViewItem *, const QPoint &, int ) ),
47 this, SLOT( viewModules( QListViewItem * ) ) );
48
49 layout->addWidget( ModulesView );
50 QTimer *t = new QTimer( this );
51 connect( t, SIGNAL( timeout() ), this, SLOT( updateData() ) );
52 t->start( 5000 );
53
54 updateData();
55
56 ModulesDtl = new ModulesDetail( 0, 0, 0 );
57 ModulesDtl->ModulesView->setTextFormat( PlainText );
58}
59
60ModulesInfo::~ModulesInfo()
61{
62}
63
64void ModulesInfo::updateData()
65{
66 char modname[64];
67 char usage[200];
68 int modsize, usecount;
69
70 ModulesView->clear();
71
72 FILE *procfile = fopen( ( QString ) ( "/proc/modules"), "r");
73
74 if ( procfile )
75 {
76 while ( true ) {
77 int success = fscanf( procfile, "%s%d%d%[^\n]", modname, &modsize, &usecount, usage );
78
79 if ( success == EOF )
80 break;
81
82 QString qmodname = QString( modname );
83 QString qmodsize = QString::number( modsize ).rightJustify( 6, ' ' );
84 QString qusecount = QString::number( usecount ).rightJustify( 2, ' ' );
85 QString qusage = QString( usage );
86
87 ( void ) new QListViewItem( ModulesView, qmodname, qmodsize, qusecount, qusage );
88 }
89
90 fclose( procfile );
91 }
92}
93
94void ModulesInfo::viewModules( QListViewItem *modules )
95{
96 QString modname = modules->text( 0 );
97 ModulesDtl->setCaption( QString( "Module: " ) + modname );
98 ModulesDtl->modname = modname;
99 QString command = QString( "/sbin/modinfo " ) + modules->text( 0 );
100
101 FILE* modinfo = popen( command, "r" );
102
103 if ( modinfo )
104 {
105 char line[200];
106 ModulesDtl->ModulesView->setText( " Details:\n------------\n" );
107
108 while( true )
109 {
110 int success = fscanf( modinfo, "%[^\n]\n", line );
111 if ( success == EOF )
112 break;
113 ModulesDtl->ModulesView->append( line );
114 }
115
116 pclose( modinfo );
117 }
118
119 ModulesDtl->showMaximized();
120}