author | mickeyl <mickeyl> | 2004-03-05 21:37:50 (UTC) |
---|---|---|
committer | mickeyl <mickeyl> | 2004-03-05 21:37:50 (UTC) |
commit | 8851dc992ab535bde6cb417cafc44658953f495d (patch) (unidiff) | |
tree | 0a70bd4a768880e61c5af1ab142508c2bb81ecd0 /noncore/settings/sysinfo/modulesinfo.cpp | |
parent | b9d58b616102970872129b5bc2f55569910f5c03 (diff) | |
download | opie-8851dc992ab535bde6cb417cafc44658953f495d.zip opie-8851dc992ab535bde6cb417cafc44658953f495d.tar.gz opie-8851dc992ab535bde6cb417cafc44658953f495d.tar.bz2 |
use listview stuff from libopie2
miscellaneous cleanups
Diffstat (limited to 'noncore/settings/sysinfo/modulesinfo.cpp') (more/less context) (ignore 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 | |||
@@ -14,57 +14,61 @@ | |||
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 ) ); |
@@ -84,91 +88,91 @@ ModulesInfo::ModulesInfo( QWidget* parent, const char* name, WFlags fl ) | |||
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]; |