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/processinfo.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/processinfo.cpp') (more/less context) (show whitespace changes)
-rw-r--r-- | noncore/settings/sysinfo/processinfo.cpp | 24 |
1 files changed, 14 insertions, 10 deletions
diff --git a/noncore/settings/sysinfo/processinfo.cpp b/noncore/settings/sysinfo/processinfo.cpp index 69b4ab5..dd9a05d 100644 --- a/noncore/settings/sysinfo/processinfo.cpp +++ b/noncore/settings/sysinfo/processinfo.cpp | |||
@@ -12,56 +12,60 @@ | |||
12 | ** Foundation and appearing in the file LICENSE.GPL included in the | 12 | ** Foundation and appearing in the file LICENSE.GPL included in the |
13 | ** packaging of this file. | 13 | ** packaging of this file. |
14 | ** | 14 | ** |
15 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | 15 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE |
16 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | 16 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
17 | ** | 17 | ** |
18 | **********************************************************************/ | 18 | **********************************************************************/ |
19 | 19 | ||
20 | #include "processinfo.h" | 20 | #include "processinfo.h" |
21 | #include "detail.h" | 21 | #include "detail.h" |
22 | 22 | ||
23 | /* OPIE */ | 23 | /* OPIE */ |
24 | #include <opie2/olistview.h> | ||
24 | #include <qpe/qpeapplication.h> | 25 | #include <qpe/qpeapplication.h> |
25 | 26 | ||
26 | /* QT */ | 27 | /* QT */ |
28 | #include <qcombobox.h> | ||
27 | #include <qdir.h> | 29 | #include <qdir.h> |
28 | #include <qlayout.h> | 30 | #include <qlayout.h> |
29 | #include <qmessagebox.h> | 31 | #include <qmessagebox.h> |
32 | #include <qpushbutton.h> | ||
33 | #include <qtextview.h> | ||
30 | #include <qtimer.h> | 34 | #include <qtimer.h> |
31 | #include <qwhatsthis.h> | 35 | #include <qwhatsthis.h> |
32 | 36 | ||
33 | /* STD */ | 37 | /* STD */ |
34 | #include <sys/types.h> | 38 | #include <sys/types.h> |
35 | #include <signal.h> | 39 | #include <signal.h> |
36 | 40 | ||
37 | ProcessInfo::ProcessInfo( QWidget* parent, const char* name, WFlags fl ) | 41 | ProcessInfo::ProcessInfo( QWidget* parent, const char* name, WFlags fl ) |
38 | : QWidget( parent, name, fl ) | 42 | : QWidget( parent, name, fl ) |
39 | { | 43 | { |
40 | QGridLayout *layout = new QGridLayout( this ); | 44 | QGridLayout *layout = new QGridLayout( this ); |
41 | layout->setSpacing( 4 ); | 45 | layout->setSpacing( 4 ); |
42 | layout->setMargin( 4 ); | 46 | layout->setMargin( 4 ); |
43 | 47 | ||
44 | 48 | ||
45 | ProcessView = new QListView( this, "ProcessView" ); | 49 | ProcessView = new OListView( this, "ProcessView" ); |
46 | int colnum = ProcessView->addColumn( tr( "PID" ) ); | 50 | int colnum = ProcessView->addColumn( tr( "PID" ) ); |
47 | ProcessView->setColumnAlignment( colnum, Qt::AlignRight ); | 51 | ProcessView->setColumnAlignment( colnum, Qt::AlignRight ); |
48 | colnum = ProcessView->addColumn( tr( "Command" ),96 ); | 52 | colnum = ProcessView->addColumn( tr( "Command" ),96 ); |
49 | colnum = ProcessView->addColumn( tr( "Status" ) ); | 53 | colnum = ProcessView->addColumn( tr( "Status" ) ); |
50 | colnum = ProcessView->addColumn( tr( "Time" ) ); | 54 | colnum = ProcessView->addColumn( tr( "Time" ) ); |
51 | ProcessView->setColumnAlignment( colnum, Qt::AlignRight ); | 55 | ProcessView->setColumnAlignment( colnum, Qt::AlignRight ); |
52 | ProcessView->setAllColumnsShowFocus( TRUE ); | 56 | ProcessView->setAllColumnsShowFocus( TRUE ); |
53 | QPEApplication::setStylusOperation( ProcessView->viewport(), QPEApplication::RightOnHold ); | 57 | QPEApplication::setStylusOperation( ProcessView->viewport(), QPEApplication::RightOnHold ); |
54 | connect( ProcessView, SIGNAL( rightButtonPressed(QListViewItem*,const QPoint&,int) ), | 58 | connect( ProcessView, SIGNAL( rightButtonPressed(OListViewItem*,const QPoint&,int) ), |
55 | this, SLOT( viewProcess(QListViewItem*) ) ); | 59 | this, SLOT( viewProcess(OListViewItem*) ) ); |
56 | layout->addMultiCellWidget( ProcessView, 0, 0, 0, 1 ); | 60 | layout->addMultiCellWidget( ProcessView, 0, 0, 0, 1 ); |
57 | QWhatsThis::add( ProcessView, tr( "This is a list of all the processes on this handheld device.\n\nClick and hold on a process to see additional information about the process, or to send a signal to it." ) ); | 61 | QWhatsThis::add( ProcessView, tr( "This is a list of all the processes on this handheld device.\n\nClick and hold on a process to see additional information about the process, or to send a signal to it." ) ); |
58 | 62 | ||
59 | SignalCB = new QComboBox( FALSE, this, "SignalCB" ); | 63 | SignalCB = new QComboBox( FALSE, this, "SignalCB" ); |
60 | SignalCB->insertItem( " 1: SIGHUP" ); | 64 | SignalCB->insertItem( " 1: SIGHUP" ); |
61 | SignalCB->insertItem( " 2: SIGINT" ); | 65 | SignalCB->insertItem( " 2: SIGINT" ); |
62 | SignalCB->insertItem( " 3: SIGQUIT" ); | 66 | SignalCB->insertItem( " 3: SIGQUIT" ); |
63 | SignalCB->insertItem( " 5: SIGTRAP" ); | 67 | SignalCB->insertItem( " 5: SIGTRAP" ); |
64 | SignalCB->insertItem( " 6: SIGABRT" ); | 68 | SignalCB->insertItem( " 6: SIGABRT" ); |
65 | SignalCB->insertItem( " 9: SIGKILL" ); | 69 | SignalCB->insertItem( " 9: SIGKILL" ); |
66 | SignalCB->insertItem( "14: SIGALRM" ); | 70 | SignalCB->insertItem( "14: SIGALRM" ); |
67 | SignalCB->insertItem( "15: SIGTERM" ); | 71 | SignalCB->insertItem( "15: SIGTERM" ); |
@@ -92,34 +96,34 @@ ProcessInfo::~ProcessInfo() | |||
92 | {} | 96 | {} |
93 | 97 | ||
94 | void ProcessInfo::updateData() | 98 | void ProcessInfo::updateData() |
95 | { | 99 | { |
96 | int pid, ppid, pgrp, session, tty, tpgid, utime, stime, cutime, cstime, counter, priority, starttime, | 100 | int pid, ppid, pgrp, session, tty, tpgid, utime, stime, cutime, cstime, counter, priority, starttime, |
97 | signal, blocked, sigignore, sigcatch; | 101 | signal, blocked, sigignore, sigcatch; |
98 | uint flags, minflt, cminflt, majflt, cmajflt, timeout, itrealvalue, vsize, rss, rlim, startcode, | 102 | uint flags, minflt, cminflt, majflt, cmajflt, timeout, itrealvalue, vsize, rss, rlim, startcode, |
99 | endcode, startstack, kstkesp, kstkeip, wchan; | 103 | endcode, startstack, kstkesp, kstkeip, wchan; |
100 | char state; | 104 | char state; |
101 | char comm[64]; | 105 | char comm[64]; |
102 | 106 | ||
103 | QString selectedpid; | 107 | QString selectedpid; |
104 | QListViewItem *curritem = ProcessView->currentItem(); | 108 | OListViewItem *curritem = static_cast<OListViewItem*>( ProcessView->currentItem() ); |
105 | if ( curritem ) | 109 | if ( curritem ) |
106 | { | 110 | { |
107 | selectedpid = curritem->text( 0 ); | 111 | selectedpid = curritem->text( 0 ); |
108 | } | 112 | } |
109 | 113 | ||
110 | ProcessView->clear(); | 114 | ProcessView->clear(); |
111 | 115 | ||
112 | QListViewItem *newitem; | 116 | OListViewItem *newitem; |
113 | QListViewItem *selecteditem = 0x0; | 117 | OListViewItem *selecteditem = 0x0; |
114 | QDir *procdir = new QDir("/proc", 0, QDir::Name, QDir::Dirs); | 118 | QDir *procdir = new QDir("/proc", 0, QDir::Name, QDir::Dirs); |
115 | QFileInfoList *proclist = new QFileInfoList(*(procdir->entryInfoList())); | 119 | QFileInfoList *proclist = new QFileInfoList(*(procdir->entryInfoList())); |
116 | if ( proclist ) | 120 | if ( proclist ) |
117 | { | 121 | { |
118 | QFileInfoListIterator it(*proclist); | 122 | QFileInfoListIterator it(*proclist); |
119 | QFileInfo *f; | 123 | QFileInfo *f; |
120 | while ( ( f = it.current() ) != 0 ) | 124 | while ( ( f = it.current() ) != 0 ) |
121 | { | 125 | { |
122 | ++it; | 126 | ++it; |
123 | QString processnum = f->fileName(); | 127 | QString processnum = f->fileName(); |
124 | if ( processnum >= "1" && processnum <= "99999" ) | 128 | if ( processnum >= "1" && processnum <= "99999" ) |
125 | { | 129 | { |
@@ -131,66 +135,66 @@ void ProcessInfo::updateData() | |||
131 | "%d %s %c %d %d %d %d %d %u %u %u %u %u %d %d %d %d %d %d %u %u %d %u %u %u %u %u %u %u %u %d %d %d %d %u", | 135 | "%d %s %c %d %d %d %d %d %u %u %u %u %u %d %d %d %d %d %d %u %u %d %u %u %u %u %u %u %u %u %d %d %d %d %u", |
132 | &pid, comm, &state, &ppid, &pgrp, &session,&tty, &tpgid, &flags, &minflt, &cminflt, | 136 | &pid, comm, &state, &ppid, &pgrp, &session,&tty, &tpgid, &flags, &minflt, &cminflt, |
133 | &majflt, &cmajflt, &utime, &stime, &cutime, &cstime, &counter, &priority, &timeout, | 137 | &majflt, &cmajflt, &utime, &stime, &cutime, &cstime, &counter, &priority, &timeout, |
134 | &itrealvalue, &starttime, &vsize, &rss, &rlim, &startcode, &endcode, &startstack, | 138 | &itrealvalue, &starttime, &vsize, &rss, &rlim, &startcode, &endcode, &startstack, |
135 | &kstkesp, &kstkeip, &signal, &blocked, &sigignore, &sigcatch, &wchan ); | 139 | &kstkesp, &kstkeip, &signal, &blocked, &sigignore, &sigcatch, &wchan ); |
136 | processnum = processnum.rightJustify( 5, ' ' ); | 140 | processnum = processnum.rightJustify( 5, ' ' ); |
137 | QString processcmd = QString( comm ).replace( QRegExp( "[()]" ), "" ); | 141 | QString processcmd = QString( comm ).replace( QRegExp( "[()]" ), "" ); |
138 | QString processstatus = QChar(state); | 142 | QString processstatus = QChar(state); |
139 | QString processtime = QString::number( ( utime + stime ) / 100 ); | 143 | QString processtime = QString::number( ( utime + stime ) / 100 ); |
140 | processtime = processtime.rightJustify( 9, ' ' ); | 144 | processtime = processtime.rightJustify( 9, ' ' ); |
141 | fclose( procfile ); | 145 | fclose( procfile ); |
142 | 146 | ||
143 | newitem = new QListViewItem( ProcessView, processnum, processcmd, processstatus, processtime ); | 147 | newitem = new OListViewItem( ProcessView, processnum, processcmd, processstatus, processtime ); |
144 | if ( processnum == selectedpid ) | 148 | if ( processnum == selectedpid ) |
145 | { | 149 | { |
146 | selecteditem = newitem; | 150 | selecteditem = newitem; |
147 | } | 151 | } |
148 | } | 152 | } |
149 | } | 153 | } |
150 | } | 154 | } |
151 | ProcessView->setCurrentItem( selecteditem ); | 155 | ProcessView->setCurrentItem( selecteditem ); |
152 | } | 156 | } |
153 | 157 | ||
154 | delete proclist; | 158 | delete proclist; |
155 | delete procdir; | 159 | delete procdir; |
156 | } | 160 | } |
157 | 161 | ||
158 | void ProcessInfo::slotSendClicked() | 162 | void ProcessInfo::slotSendClicked() |
159 | { | 163 | { |
160 | QListViewItem *currprocess = ProcessView->currentItem(); | 164 | OListViewItem *currprocess = static_cast<OListViewItem*>( ProcessView->currentItem() ); |
161 | if ( !currprocess ) | 165 | if ( !currprocess ) |
162 | { | 166 | { |
163 | return; | 167 | return; |
164 | } | 168 | } |
165 | 169 | ||
166 | QString capstr = tr( "Really want to send %1\nto this process?" ).arg( SignalCB->currentText() ); | 170 | QString capstr = tr( "Really want to send %1\nto this process?" ).arg( SignalCB->currentText() ); |
167 | 171 | ||
168 | 172 | ||
169 | if ( QMessageBox::warning( this, currprocess->text( 1 ), capstr, | 173 | if ( QMessageBox::warning( this, currprocess->text( 1 ), capstr, |
170 | QMessageBox::Yes | QMessageBox::Default, QMessageBox::No | QMessageBox::Escape ) == QMessageBox::Yes ) | 174 | QMessageBox::Yes | QMessageBox::Default, QMessageBox::No | QMessageBox::Escape ) == QMessageBox::Yes ) |
171 | { | 175 | { |
172 | currprocess = ProcessView->currentItem(); | 176 | currprocess = static_cast<OListViewItem*>( ProcessView->currentItem() ); |
173 | if ( currprocess ) | 177 | if ( currprocess ) |
174 | { | 178 | { |
175 | QString sigstr = SignalCB->currentText(); | 179 | QString sigstr = SignalCB->currentText(); |
176 | sigstr.truncate(2); | 180 | sigstr.truncate(2); |
177 | int sigid = sigstr.toUInt(); | 181 | int sigid = sigstr.toUInt(); |
178 | kill( currprocess->text( 0 ).stripWhiteSpace().toUInt(), sigid ); | 182 | kill( currprocess->text( 0 ).stripWhiteSpace().toUInt(), sigid ); |
179 | } | 183 | } |
180 | } | 184 | } |
181 | 185 | ||
182 | } | 186 | } |
183 | 187 | ||
184 | void ProcessInfo::viewProcess( QListViewItem *process ) | 188 | void ProcessInfo::viewProcess( OListViewItem *process ) |
185 | { | 189 | { |
186 | QString pid= process->text( 0 ).stripWhiteSpace(); | 190 | QString pid= process->text( 0 ).stripWhiteSpace(); |
187 | QString command = process->text( 1 ); | 191 | QString command = process->text( 1 ); |
188 | ProcessDtl->setCaption( pid + " - " + command ); | 192 | ProcessDtl->setCaption( pid + " - " + command ); |
189 | FILE *statfile = fopen( ( QString ) ( "/proc/" + pid + "/status"), "r"); | 193 | FILE *statfile = fopen( ( QString ) ( "/proc/" + pid + "/status"), "r"); |
190 | if ( statfile ) | 194 | if ( statfile ) |
191 | { | 195 | { |
192 | char line[81]; | 196 | char line[81]; |
193 | fgets( line, 81, statfile ); | 197 | fgets( line, 81, statfile ); |
194 | ProcessDtl->detailView->setText( line ); | 198 | ProcessDtl->detailView->setText( line ); |
195 | while ( fgets( line, 81, statfile ) ) | 199 | while ( fgets( line, 81, statfile ) ) |
196 | { | 200 | { |