-rw-r--r-- | noncore/settings/sysinfo/modulesinfo.cpp | 2 |
1 files changed, 2 insertions, 0 deletions
diff --git a/noncore/settings/sysinfo/modulesinfo.cpp b/noncore/settings/sysinfo/modulesinfo.cpp index 8def0d6..0bf51e8 100644 --- a/noncore/settings/sysinfo/modulesinfo.cpp +++ b/noncore/settings/sysinfo/modulesinfo.cpp | |||
@@ -19,173 +19,175 @@ | |||
19 | ** | 19 | ** |
20 | **********************************************************************/ | 20 | **********************************************************************/ |
21 | 21 | ||
22 | #include <qpe/qpeapplication.h> | 22 | #include <qpe/qpeapplication.h> |
23 | 23 | ||
24 | #include <qcombobox.h> | 24 | #include <qcombobox.h> |
25 | #include <qfile.h> | 25 | #include <qfile.h> |
26 | #include <qheader.h> | 26 | #include <qheader.h> |
27 | #include <qlayout.h> | 27 | #include <qlayout.h> |
28 | #include <qlistview.h> | 28 | #include <qlistview.h> |
29 | #include <qmessagebox.h> | 29 | #include <qmessagebox.h> |
30 | #include <qpushbutton.h> | 30 | #include <qpushbutton.h> |
31 | #include <qstring.h> | 31 | #include <qstring.h> |
32 | #include <qtimer.h> | 32 | #include <qtimer.h> |
33 | #include <qwhatsthis.h> | 33 | #include <qwhatsthis.h> |
34 | 34 | ||
35 | #include "modulesinfo.h" | 35 | #include "modulesinfo.h" |
36 | #include "detail.h" | 36 | #include "detail.h" |
37 | 37 | ||
38 | ModulesInfo::ModulesInfo( QWidget* parent, const char* name, WFlags fl ) | 38 | ModulesInfo::ModulesInfo( QWidget* parent, const char* name, WFlags fl ) |
39 | : QWidget( parent, name, fl ) | 39 | : QWidget( parent, name, fl ) |
40 | { | 40 | { |
41 | QGridLayout *layout = new QGridLayout( this ); | 41 | QGridLayout *layout = new QGridLayout( this ); |
42 | layout->setSpacing( 4 ); | 42 | layout->setSpacing( 4 ); |
43 | layout->setMargin( 4 ); | 43 | layout->setMargin( 4 ); |
44 | 44 | ||
45 | ModulesView = new QListView( this ); | 45 | ModulesView = new QListView( this ); |
46 | int colnum = ModulesView->addColumn( tr( "Module" ) ); | 46 | int colnum = ModulesView->addColumn( tr( "Module" ) ); |
47 | colnum = ModulesView->addColumn( tr( "Size" ) ); | 47 | colnum = ModulesView->addColumn( tr( "Size" ) ); |
48 | ModulesView->setColumnAlignment( colnum, Qt::AlignRight ); | 48 | ModulesView->setColumnAlignment( colnum, Qt::AlignRight ); |
49 | colnum = ModulesView->addColumn( tr( "Use#" ) ); | 49 | colnum = ModulesView->addColumn( tr( "Use#" ) ); |
50 | ModulesView->setColumnAlignment( colnum, Qt::AlignRight ); | 50 | ModulesView->setColumnAlignment( colnum, Qt::AlignRight ); |
51 | colnum = ModulesView->addColumn( tr( "Used by" ) ); | 51 | colnum = ModulesView->addColumn( tr( "Used by" ) ); |
52 | ModulesView->setAllColumnsShowFocus( TRUE ); | 52 | ModulesView->setAllColumnsShowFocus( TRUE ); |
53 | layout->addMultiCellWidget( ModulesView, 0, 0, 0, 1 ); | 53 | layout->addMultiCellWidget( ModulesView, 0, 0, 0, 1 ); |
54 | 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." ) ); | 54 | 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 | 55 | ||
56 | // Test if we have /sbin/modinfo, and if so, allow module detail window | 56 | // Test if we have /sbin/modinfo, and if so, allow module detail window |
57 | if ( QFile::exists( "/sbin/modinfo" ) ) | 57 | if ( QFile::exists( "/sbin/modinfo" ) ) |
58 | { | 58 | { |
59 | QPEApplication::setStylusOperation( ModulesView->viewport(), QPEApplication::RightOnHold ); | 59 | QPEApplication::setStylusOperation( ModulesView->viewport(), QPEApplication::RightOnHold ); |
60 | connect( ModulesView, SIGNAL( rightButtonPressed( QListViewItem *, const QPoint &, int ) ), | 60 | connect( ModulesView, SIGNAL( rightButtonPressed( QListViewItem *, const QPoint &, int ) ), |
61 | this, SLOT( viewModules( QListViewItem * ) ) ); | 61 | this, SLOT( viewModules( QListViewItem * ) ) ); |
62 | } | 62 | } |
63 | 63 | ||
64 | CommandCB = new QComboBox( FALSE, this ); | 64 | CommandCB = new QComboBox( FALSE, this ); |
65 | CommandCB->insertItem( "modprobe -r" ); | 65 | CommandCB->insertItem( "modprobe -r" ); |
66 | CommandCB->insertItem( "rmmod" ); | 66 | CommandCB->insertItem( "rmmod" ); |
67 | // I can't think of other useful commands yet. Anyone? | 67 | // I can't think of other useful commands yet. Anyone? |
68 | layout->addWidget( CommandCB, 1, 0 ); | 68 | layout->addWidget( CommandCB, 1, 0 ); |
69 | 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." ) ); | 69 | 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 | 70 | ||
71 | QPushButton *btn = new QPushButton( this ); | 71 | QPushButton *btn = new QPushButton( this ); |
72 | btn->setMinimumSize( QSize( 50, 24 ) ); | 72 | btn->setMinimumSize( QSize( 50, 24 ) ); |
73 | btn->setMaximumSize( QSize( 50, 24 ) ); | 73 | btn->setMaximumSize( QSize( 50, 24 ) ); |
74 | btn->setText( tr( "Send" ) ); | 74 | btn->setText( tr( "Send" ) ); |
75 | connect( btn, SIGNAL( clicked() ), this, SLOT( slotSendClicked() ) ); | 75 | connect( btn, SIGNAL( clicked() ), this, SLOT( slotSendClicked() ) ); |
76 | layout->addWidget( btn, 1, 1 ); | 76 | layout->addWidget( btn, 1, 1 ); |
77 | QWhatsThis::add( btn, tr( "Click here to send the selected command to the module selected above." ) ); | 77 | QWhatsThis::add( btn, tr( "Click here to send the selected command to the module selected above." ) ); |
78 | 78 | ||
79 | QTimer *t = new QTimer( this ); | 79 | QTimer *t = new QTimer( this ); |
80 | connect( t, SIGNAL( timeout() ), this, SLOT( updateData() ) ); | 80 | connect( t, SIGNAL( timeout() ), this, SLOT( updateData() ) ); |
81 | t->start( 5000 ); | 81 | t->start( 5000 ); |
82 | 82 | ||
83 | updateData(); | 83 | updateData(); |
84 | 84 | ||
85 | ModulesDtl = new Detail(); | 85 | ModulesDtl = new Detail(); |
86 | QWhatsThis::add( ModulesDtl->detailView, tr( "This area shows detailed information about this module." ) ); | 86 | QWhatsThis::add( ModulesDtl->detailView, tr( "This area shows detailed information about this module." ) ); |
87 | } | 87 | } |
88 | 88 | ||
89 | ModulesInfo::~ModulesInfo() | 89 | ModulesInfo::~ModulesInfo() |
90 | { | 90 | { |
91 | } | 91 | } |
92 | 92 | ||
93 | void ModulesInfo::updateData() | 93 | void ModulesInfo::updateData() |
94 | { | 94 | { |
95 | char modname[64]; | 95 | char modname[64]; |
96 | char usage[200]; | 96 | char usage[200]; |
97 | int modsize, usecount; | 97 | int modsize, usecount; |
98 | 98 | ||
99 | QString selectedmod; | 99 | QString selectedmod; |
100 | QListViewItem *curritem = ModulesView->currentItem(); | 100 | QListViewItem *curritem = ModulesView->currentItem(); |
101 | if ( curritem ) | 101 | if ( curritem ) |
102 | { | 102 | { |
103 | selectedmod = curritem->text( 0 ); | 103 | selectedmod = curritem->text( 0 ); |
104 | } | 104 | } |
105 | 105 | ||
106 | ModulesView->clear(); | 106 | ModulesView->clear(); |
107 | 107 | ||
108 | FILE *procfile = fopen( ( QString ) ( "/proc/modules"), "r"); | 108 | FILE *procfile = fopen( ( QString ) ( "/proc/modules"), "r"); |
109 | 109 | ||
110 | if ( procfile ) | 110 | if ( procfile ) |
111 | { | 111 | { |
112 | QListViewItem *newitem; | 112 | QListViewItem *newitem; |
113 | QListViewItem *selecteditem = 0x0; | 113 | QListViewItem *selecteditem = 0x0; |
114 | while ( true ) { | 114 | while ( true ) { |
115 | modname[0] = '\0'; | ||
116 | usage[0] = '\0'; | ||
115 | int success = fscanf( procfile, "%s%d%d%[^\n]", modname, &modsize, &usecount, usage ); | 117 | int success = fscanf( procfile, "%s%d%d%[^\n]", modname, &modsize, &usecount, usage ); |
116 | 118 | ||
117 | if ( success == EOF ) | 119 | if ( success == EOF ) |
118 | break; | 120 | break; |
119 | 121 | ||
120 | QString qmodname = QString( modname ); | 122 | QString qmodname = QString( modname ); |
121 | QString qmodsize = QString::number( modsize ).rightJustify( 6, ' ' ); | 123 | QString qmodsize = QString::number( modsize ).rightJustify( 6, ' ' ); |
122 | QString qusecount = QString::number( usecount ).rightJustify( 2, ' ' ); | 124 | QString qusecount = QString::number( usecount ).rightJustify( 2, ' ' ); |
123 | QString qusage = QString( usage ); | 125 | QString qusage = QString( usage ); |
124 | 126 | ||
125 | newitem = new QListViewItem( ModulesView, qmodname, qmodsize, qusecount, qusage ); | 127 | newitem = new QListViewItem( ModulesView, qmodname, qmodsize, qusecount, qusage ); |
126 | if ( qmodname == selectedmod ) | 128 | if ( qmodname == selectedmod ) |
127 | { | 129 | { |
128 | selecteditem = newitem; | 130 | selecteditem = newitem; |
129 | } | 131 | } |
130 | } | 132 | } |
131 | ModulesView->setCurrentItem( selecteditem ); | 133 | ModulesView->setCurrentItem( selecteditem ); |
132 | 134 | ||
133 | fclose( procfile ); | 135 | fclose( procfile ); |
134 | } | 136 | } |
135 | } | 137 | } |
136 | 138 | ||
137 | void ModulesInfo::slotSendClicked() | 139 | void ModulesInfo::slotSendClicked() |
138 | { | 140 | { |
139 | if ( !ModulesView->currentItem() ) | 141 | if ( !ModulesView->currentItem() ) |
140 | { | 142 | { |
141 | return; | 143 | return; |
142 | } | 144 | } |
143 | 145 | ||
144 | QString capstr = tr( "You really want to execute %1 for this module?" ).arg( CommandCB->currentText() ); | 146 | QString capstr = tr( "You really want to execute %1 for this module?" ).arg( CommandCB->currentText() ); |
145 | 147 | ||
146 | QString modname = ModulesView->currentItem()->text( 0 ); | 148 | QString modname = ModulesView->currentItem()->text( 0 ); |
147 | 149 | ||
148 | if ( QMessageBox::warning( this, modname, capstr, | 150 | if ( QMessageBox::warning( this, modname, capstr, |
149 | QMessageBox::Yes | QMessageBox::Default, QMessageBox::No | QMessageBox::Escape ) == QMessageBox::Yes ) | 151 | QMessageBox::Yes | QMessageBox::Default, QMessageBox::No | QMessageBox::Escape ) == QMessageBox::Yes ) |
150 | { | 152 | { |
151 | QString command = "/sbin/"; | 153 | QString command = "/sbin/"; |
152 | command.append( CommandCB->currentText() ); | 154 | command.append( CommandCB->currentText() ); |
153 | command.append( " " ); | 155 | command.append( " " ); |
154 | command.append( modname ); | 156 | command.append( modname ); |
155 | 157 | ||
156 | FILE* stream = popen( command, "r" ); | 158 | FILE* stream = popen( command, "r" ); |
157 | if ( stream ) | 159 | if ( stream ) |
158 | pclose( stream ); | 160 | pclose( stream ); |
159 | } | 161 | } |
160 | 162 | ||
161 | } | 163 | } |
162 | 164 | ||
163 | void ModulesInfo::viewModules( QListViewItem *modules ) | 165 | void ModulesInfo::viewModules( QListViewItem *modules ) |
164 | { | 166 | { |
165 | QString modname = modules->text( 0 ); | 167 | QString modname = modules->text( 0 ); |
166 | QString capstr = "Module: "; | 168 | QString capstr = "Module: "; |
167 | capstr.append( modname ); | 169 | capstr.append( modname ); |
168 | ModulesDtl->setCaption( capstr ); | 170 | ModulesDtl->setCaption( capstr ); |
169 | QString command = "/sbin/modinfo "; | 171 | QString command = "/sbin/modinfo "; |
170 | command.append( modname ); | 172 | command.append( modname ); |
171 | FILE* modinfo = popen( command, "r" ); | 173 | FILE* modinfo = popen( command, "r" ); |
172 | 174 | ||
173 | if ( modinfo ) | 175 | if ( modinfo ) |
174 | { | 176 | { |
175 | char line[200]; | 177 | char line[200]; |
176 | ModulesDtl->detailView->setText( " Details:\n------------\n" ); | 178 | ModulesDtl->detailView->setText( " Details:\n------------\n" ); |
177 | 179 | ||
178 | while( true ) | 180 | while( true ) |
179 | { | 181 | { |
180 | int success = fscanf( modinfo, "%[^\n]\n", line ); | 182 | int success = fscanf( modinfo, "%[^\n]\n", line ); |
181 | if ( success == EOF ) | 183 | if ( success == EOF ) |
182 | break; | 184 | break; |
183 | ModulesDtl->detailView->append( line ); | 185 | ModulesDtl->detailView->append( line ); |
184 | } | 186 | } |
185 | 187 | ||
186 | pclose( modinfo ); | 188 | pclose( modinfo ); |
187 | } | 189 | } |
188 | 190 | ||
189 | ModulesDtl->showMaximized(); | 191 | ModulesDtl->showMaximized(); |
190 | } | 192 | } |
191 | 193 | ||