Diffstat (limited to 'noncore/settings/sysinfo/modulesinfo.cpp') (more/less context) (show whitespace changes)
-rw-r--r-- | noncore/settings/sysinfo/modulesinfo.cpp | 22 |
1 files changed, 13 insertions, 9 deletions
diff --git a/noncore/settings/sysinfo/modulesinfo.cpp b/noncore/settings/sysinfo/modulesinfo.cpp index e688a29..dfe48e1 100644 --- a/noncore/settings/sysinfo/modulesinfo.cpp +++ b/noncore/settings/sysinfo/modulesinfo.cpp | |||
@@ -2,185 +2,189 @@ | |||
2 | ** ModulesInfo | 2 | ** ModulesInfo |
3 | ** | 3 | ** |
4 | ** Display Modules information | 4 | ** Display Modules information |
5 | ** | 5 | ** |
6 | ** Copyright (C) 2002, Michael Lauer | 6 | ** Copyright (C) 2002, Michael Lauer |
7 | ** mickey@tm.informatik.uni-frankfurt.de | 7 | ** mickey@tm.informatik.uni-frankfurt.de |
8 | ** http://www.Vanille.de | 8 | ** http://www.Vanille.de |
9 | ** | 9 | ** |
10 | ** Based on ProcessInfo by Dan Williams <williamsdr@acm.org> | 10 | ** Based on ProcessInfo by Dan Williams <williamsdr@acm.org> |
11 | ** | 11 | ** |
12 | ** This file may be distributed and/or modified under the terms of the | 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 | 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 | 14 | ** Foundation and appearing in the file LICENSE.GPL included in the |
15 | ** packaging of this file. | 15 | ** packaging of this file. |
16 | ** | 16 | ** |
17 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | 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. | 18 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
19 | ** | 19 | ** |
20 | **********************************************************************/ | 20 | **********************************************************************/ |
21 | 21 | ||
22 | #include "modulesinfo.h" | 22 | #include "modulesinfo.h" |
23 | #include "detail.h" | 23 | #include "detail.h" |
24 | 24 | ||
25 | /* OPIE */ | 25 | /* OPIE */ |
26 | #include <opie2/olistview.h> | ||
26 | #include <qpe/qpeapplication.h> | 27 | #include <qpe/qpeapplication.h> |
27 | 28 | ||
28 | /* QT */ | 29 | /* QT */ |
30 | #include <qcombobox.h> | ||
29 | #include <qfile.h> | 31 | #include <qfile.h> |
30 | #include <qlayout.h> | 32 | #include <qlayout.h> |
31 | #include <qmessagebox.h> | 33 | #include <qmessagebox.h> |
34 | #include <qpushbutton.h> | ||
35 | #include <qtextview.h> | ||
32 | #include <qtimer.h> | 36 | #include <qtimer.h> |
33 | #include <qwhatsthis.h> | 37 | #include <qwhatsthis.h> |
34 | 38 | ||
35 | ModulesInfo::ModulesInfo( QWidget* parent, const char* name, WFlags fl ) | 39 | ModulesInfo::ModulesInfo( QWidget* parent, const char* name, WFlags fl ) |
36 | : QWidget( parent, name, fl ) | 40 | : QWidget( parent, name, fl ) |
37 | { | 41 | { |
38 | QGridLayout *layout = new QGridLayout( this ); | 42 | QGridLayout *layout = new QGridLayout( this ); |
39 | layout->setSpacing( 4 ); | 43 | layout->setSpacing( 4 ); |
40 | layout->setMargin( 4 ); | 44 | layout->setMargin( 4 ); |
41 | 45 | ||
42 | ModulesView = new QListView( this ); | 46 | ModulesView = new OListView( this ); |
43 | int colnum = ModulesView->addColumn( tr( "Module" ) ); | 47 | int colnum = ModulesView->addColumn( tr( "Module" ) ); |
44 | colnum = ModulesView->addColumn( tr( "Size" ) ); | 48 | colnum = ModulesView->addColumn( tr( "Size" ) ); |
45 | ModulesView->setColumnAlignment( colnum, Qt::AlignRight ); | 49 | ModulesView->setColumnAlignment( colnum, Qt::AlignRight ); |
46 | colnum = ModulesView->addColumn( tr( "Use#" ) ); | 50 | colnum = ModulesView->addColumn( tr( "Use#" ) ); |
47 | ModulesView->setColumnAlignment( colnum, Qt::AlignRight ); | 51 | ModulesView->setColumnAlignment( colnum, Qt::AlignRight ); |
48 | colnum = ModulesView->addColumn( tr( "Used by" ) ); | 52 | colnum = ModulesView->addColumn( tr( "Used by" ) ); |
49 | ModulesView->setAllColumnsShowFocus( TRUE ); | 53 | ModulesView->setAllColumnsShowFocus( TRUE ); |
50 | layout->addMultiCellWidget( ModulesView, 0, 0, 0, 1 ); | 54 | layout->addMultiCellWidget( ModulesView, 0, 0, 0, 1 ); |
51 | QWhatsThis::add( ModulesView, tr( "This is a list of all the kernel modules currently loaded on this handheld device.\n\nClick and hold on a module to see additional information about the module, or to unload it." ) ); | 55 | QWhatsThis::add( ModulesView, tr( "This is a list of all the kernel modules currently loaded on this handheld device.\n\nClick and hold on a module to see additional information about the module, or to unload it." ) ); |
52 | 56 | ||
53 | // Test if we have /sbin/modinfo, and if so, allow module detail window | 57 | // Test if we have /sbin/modinfo, and if so, allow module detail window |
54 | if ( QFile::exists( "/sbin/modinfo" ) ) | 58 | if ( QFile::exists( "/sbin/modinfo" ) ) |
55 | { | 59 | { |
56 | QPEApplication::setStylusOperation( ModulesView->viewport(), QPEApplication::RightOnHold ); | 60 | QPEApplication::setStylusOperation( ModulesView->viewport(), QPEApplication::RightOnHold ); |
57 | connect( ModulesView, SIGNAL( rightButtonPressed(QListViewItem*,const QPoint&,int) ), | 61 | connect( ModulesView, SIGNAL( rightButtonPressed(OListViewItem*,const QPoint&,int) ), |
58 | this, SLOT( viewModules(QListViewItem*) ) ); | 62 | this, SLOT( viewModules(OListViewItem*) ) ); |
59 | } | 63 | } |
60 | 64 | ||
61 | CommandCB = new QComboBox( FALSE, this ); | 65 | CommandCB = new QComboBox( FALSE, this ); |
62 | CommandCB->insertItem( "modprobe -r" ); | 66 | CommandCB->insertItem( "modprobe -r" ); |
63 | CommandCB->insertItem( "rmmod" ); | 67 | CommandCB->insertItem( "rmmod" ); |
64 | // I can't think of other useful commands yet. Anyone? | 68 | // I can't think of other useful commands yet. Anyone? |
65 | layout->addWidget( CommandCB, 1, 0 ); | 69 | layout->addWidget( CommandCB, 1, 0 ); |
66 | QWhatsThis::add( CommandCB, tr( "Select a command here and then click the Send button to the right to send the command to module selected above." ) ); | 70 | QWhatsThis::add( CommandCB, tr( "Select a command here and then click the Send button to the right to send the command to module selected above." ) ); |
67 | 71 | ||
68 | QPushButton *btn = new QPushButton( this ); | 72 | QPushButton *btn = new QPushButton( this ); |
69 | btn->setMinimumSize( QSize( 50, 24 ) ); | 73 | btn->setMinimumSize( QSize( 50, 24 ) ); |
70 | btn->setMaximumSize( QSize( 50, 24 ) ); | 74 | btn->setMaximumSize( QSize( 50, 24 ) ); |
71 | btn->setText( tr( "Send" ) ); | 75 | btn->setText( tr( "Send" ) ); |
72 | connect( btn, SIGNAL( clicked() ), this, SLOT( slotSendClicked() ) ); | 76 | connect( btn, SIGNAL( clicked() ), this, SLOT( slotSendClicked() ) ); |
73 | layout->addWidget( btn, 1, 1 ); | 77 | layout->addWidget( btn, 1, 1 ); |
74 | QWhatsThis::add( btn, tr( "Click here to send the selected command to the module selected above." ) ); | 78 | QWhatsThis::add( btn, tr( "Click here to send the selected command to the module selected above." ) ); |
75 | 79 | ||
76 | QTimer *t = new QTimer( this ); | 80 | QTimer *t = new QTimer( this ); |
77 | connect( t, SIGNAL( timeout() ), this, SLOT( updateData() ) ); | 81 | connect( t, SIGNAL( timeout() ), this, SLOT( updateData() ) ); |
78 | t->start( 5000 ); | 82 | t->start( 5000 ); |
79 | 83 | ||
80 | updateData(); | 84 | updateData(); |
81 | 85 | ||
82 | ModulesDtl = new Detail(); | 86 | ModulesDtl = new Detail(); |
83 | QWhatsThis::add( ModulesDtl->detailView, tr( "This area shows detailed information about this module." ) ); | 87 | QWhatsThis::add( ModulesDtl->detailView, tr( "This area shows detailed information about this module." ) ); |
84 | } | 88 | } |
85 | 89 | ||
86 | ModulesInfo::~ModulesInfo() | 90 | ModulesInfo::~ModulesInfo() |
87 | {} | 91 | {} |
88 | 92 | ||
89 | void ModulesInfo::updateData() | 93 | void ModulesInfo::updateData() |
90 | { | 94 | { |
91 | char modname[64]; | 95 | char modname[64]; |
92 | char usage[200]; | 96 | char usage[200]; |
93 | int modsize, usecount; | 97 | int modsize, usecount; |
94 | 98 | ||
95 | QString selectedmod; | 99 | QString selectedmod; |
96 | QListViewItem *curritem = ModulesView->currentItem(); | 100 | OListViewItem *curritem = static_cast<OListViewItem*>( ModulesView->currentItem() ); |
97 | if ( curritem ) | 101 | if ( curritem ) |
98 | { | 102 | { |
99 | selectedmod = curritem->text( 0 ); | 103 | selectedmod = curritem->text( 0 ); |
100 | } | 104 | } |
101 | 105 | ||
102 | ModulesView->clear(); | 106 | ModulesView->clear(); |
103 | 107 | ||
104 | FILE *procfile = fopen( ( QString ) ( "/proc/modules"), "r"); | 108 | FILE *procfile = fopen( ( QString ) ( "/proc/modules"), "r"); |
105 | 109 | ||
106 | if ( procfile ) | 110 | if ( procfile ) |
107 | { | 111 | { |
108 | QListViewItem *newitem; | 112 | OListViewItem *newitem; |
109 | QListViewItem *selecteditem = 0x0; | 113 | OListViewItem *selecteditem = 0x0; |
110 | while ( true ) | 114 | while ( true ) |
111 | { | 115 | { |
112 | modname[0] = '\0'; | 116 | modname[0] = '\0'; |
113 | usage[0] = '\0'; | 117 | usage[0] = '\0'; |
114 | int success = fscanf( procfile, "%s%d%d%[^\n]", modname, &modsize, &usecount, usage ); | 118 | int success = fscanf( procfile, "%s%d%d%[^\n]", modname, &modsize, &usecount, usage ); |
115 | 119 | ||
116 | if ( success == EOF ) | 120 | if ( success == EOF ) |
117 | break; | 121 | break; |
118 | 122 | ||
119 | QString qmodname = QString( modname ); | 123 | QString qmodname = QString( modname ); |
120 | QString qmodsize = QString::number( modsize ).rightJustify( 6, ' ' ); | 124 | QString qmodsize = QString::number( modsize ).rightJustify( 6, ' ' ); |
121 | QString qusecount = QString::number( usecount ).rightJustify( 2, ' ' ); | 125 | QString qusecount = QString::number( usecount ).rightJustify( 2, ' ' ); |
122 | QString qusage = QString( usage ); | 126 | QString qusage = QString( usage ); |
123 | 127 | ||
124 | newitem = new QListViewItem( ModulesView, qmodname, qmodsize, qusecount, qusage ); | 128 | newitem = new OListViewItem( ModulesView, qmodname, qmodsize, qusecount, qusage ); |
125 | if ( qmodname == selectedmod ) | 129 | if ( qmodname == selectedmod ) |
126 | { | 130 | { |
127 | selecteditem = newitem; | 131 | selecteditem = newitem; |
128 | } | 132 | } |
129 | } | 133 | } |
130 | ModulesView->setCurrentItem( selecteditem ); | 134 | ModulesView->setCurrentItem( selecteditem ); |
131 | 135 | ||
132 | fclose( procfile ); | 136 | fclose( procfile ); |
133 | } | 137 | } |
134 | } | 138 | } |
135 | 139 | ||
136 | void ModulesInfo::slotSendClicked() | 140 | void ModulesInfo::slotSendClicked() |
137 | { | 141 | { |
138 | if ( !ModulesView->currentItem() ) | 142 | if ( !ModulesView->currentItem() ) |
139 | { | 143 | { |
140 | return; | 144 | return; |
141 | } | 145 | } |
142 | 146 | ||
143 | QString capstr = tr( "You really want to execute %1 for this module?" ).arg( CommandCB->currentText() ); | 147 | QString capstr = tr( "You really want to execute\n%1 for this module?" ).arg( CommandCB->currentText() ); |
144 | 148 | ||
145 | QString modname = ModulesView->currentItem()->text( 0 ); | 149 | QString modname = ModulesView->currentItem()->text( 0 ); |
146 | 150 | ||
147 | if ( QMessageBox::warning( this, modname, capstr, | 151 | if ( QMessageBox::warning( this, modname, capstr, |
148 | QMessageBox::Yes | QMessageBox::Default, QMessageBox::No | QMessageBox::Escape ) == QMessageBox::Yes ) | 152 | QMessageBox::Yes | QMessageBox::Default, QMessageBox::No | QMessageBox::Escape ) == QMessageBox::Yes ) |
149 | { | 153 | { |
150 | QString command = "/sbin/"; | 154 | QString command = "/sbin/"; |
151 | command.append( CommandCB->currentText() ); | 155 | command.append( CommandCB->currentText() ); |
152 | command.append( " " ); | 156 | command.append( " " ); |
153 | command.append( modname ); | 157 | command.append( modname ); |
154 | 158 | ||
155 | FILE* stream = popen( command, "r" ); | 159 | FILE* stream = popen( command, "r" ); |
156 | if ( stream ) | 160 | if ( stream ) |
157 | pclose( stream ); | 161 | pclose( stream ); |
158 | } | 162 | } |
159 | 163 | ||
160 | } | 164 | } |
161 | 165 | ||
162 | void ModulesInfo::viewModules( QListViewItem *modules ) | 166 | void ModulesInfo::viewModules( OListViewItem *modules ) |
163 | { | 167 | { |
164 | QString modname = modules->text( 0 ); | 168 | QString modname = modules->text( 0 ); |
165 | QString capstr = "Module: "; | 169 | QString capstr = "Module: "; |
166 | capstr.append( modname ); | 170 | capstr.append( modname ); |
167 | ModulesDtl->setCaption( capstr ); | 171 | ModulesDtl->setCaption( capstr ); |
168 | QString command = "/sbin/modinfo "; | 172 | QString command = "/sbin/modinfo "; |
169 | command.append( modname ); | 173 | command.append( modname ); |
170 | FILE* modinfo = popen( command, "r" ); | 174 | FILE* modinfo = popen( command, "r" ); |
171 | 175 | ||
172 | if ( modinfo ) | 176 | if ( modinfo ) |
173 | { | 177 | { |
174 | char line[200]; | 178 | char line[200]; |
175 | ModulesDtl->detailView->setText( " Details:\n------------\n" ); | 179 | ModulesDtl->detailView->setText( " Details:\n------------\n" ); |
176 | 180 | ||
177 | while( true ) | 181 | while( true ) |
178 | { | 182 | { |
179 | int success = fscanf( modinfo, "%[^\n]\n", line ); | 183 | int success = fscanf( modinfo, "%[^\n]\n", line ); |
180 | if ( success == EOF ) | 184 | if ( success == EOF ) |
181 | break; | 185 | break; |
182 | ModulesDtl->detailView->append( line ); | 186 | ModulesDtl->detailView->append( line ); |
183 | } | 187 | } |
184 | 188 | ||
185 | pclose( modinfo ); | 189 | pclose( modinfo ); |
186 | } | 190 | } |