summaryrefslogtreecommitdiff
path: root/noncore/settings/sysinfo/processinfo.cpp
Unidiff
Diffstat (limited to 'noncore/settings/sysinfo/processinfo.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/settings/sysinfo/processinfo.cpp11
1 files changed, 9 insertions, 2 deletions
diff --git a/noncore/settings/sysinfo/processinfo.cpp b/noncore/settings/sysinfo/processinfo.cpp
index dd9a05d..e887267 100644
--- a/noncore/settings/sysinfo/processinfo.cpp
+++ b/noncore/settings/sysinfo/processinfo.cpp
@@ -1,107 +1,108 @@
1/********************************************************************** 1/**********************************************************************
2** ProcessInfo 2** ProcessInfo
3** 3**
4** Display process information 4** Display process information
5** 5**
6** Copyright (C) 2002, Dan Williams 6** Copyright (C) 2002, Dan Williams
7** williamsdr@acm.org 7** williamsdr@acm.org
8** http://draknor.net 8** http://draknor.net
9** 9**
10** This file may be distributed and/or modified under the terms of the 10** This file may be distributed and/or modified under the terms of the
11** GNU General Public License version 2 as published by the Free Software 11** GNU General Public License version 2 as published by the Free Software
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 <opie2/olistview.h>
25#include <qpe/qpeapplication.h> 25#include <qpe/qpeapplication.h>
26 26
27/* QT */ 27/* QT */
28#include <qcombobox.h> 28#include <qcombobox.h>
29#include <qdir.h> 29#include <qdir.h>
30#include <qlayout.h> 30#include <qlayout.h>
31#include <qmessagebox.h> 31#include <qmessagebox.h>
32#include <qpushbutton.h> 32#include <qpushbutton.h>
33#include <qtextview.h> 33#include <qtextview.h>
34#include <qtimer.h> 34#include <qtimer.h>
35#include <qwhatsthis.h> 35#include <qwhatsthis.h>
36 36
37/* STD */ 37/* STD */
38#include <sys/types.h> 38#include <sys/types.h>
39#include <signal.h> 39#include <signal.h>
40 40
41using namespace Opie::Ui;
41ProcessInfo::ProcessInfo( QWidget* parent, const char* name, WFlags fl ) 42ProcessInfo::ProcessInfo( QWidget* parent, const char* name, WFlags fl )
42 : QWidget( parent, name, fl ) 43 : QWidget( parent, name, fl )
43{ 44{
44 QGridLayout *layout = new QGridLayout( this ); 45 QGridLayout *layout = new QGridLayout( this );
45 layout->setSpacing( 4 ); 46 layout->setSpacing( 4 );
46 layout->setMargin( 4 ); 47 layout->setMargin( 4 );
47 48
48 49
49 ProcessView = new OListView( this, "ProcessView" ); 50 ProcessView = new OListView( this, "ProcessView" );
50 int colnum = ProcessView->addColumn( tr( "PID" ) ); 51 int colnum = ProcessView->addColumn( tr( "PID" ) );
51 ProcessView->setColumnAlignment( colnum, Qt::AlignRight ); 52 ProcessView->setColumnAlignment( colnum, Qt::AlignRight );
52 colnum = ProcessView->addColumn( tr( "Command" ),96 ); 53 colnum = ProcessView->addColumn( tr( "Command" ),96 );
53 colnum = ProcessView->addColumn( tr( "Status" ) ); 54 colnum = ProcessView->addColumn( tr( "Status" ) );
54 colnum = ProcessView->addColumn( tr( "Time" ) ); 55 colnum = ProcessView->addColumn( tr( "Time" ) );
55 ProcessView->setColumnAlignment( colnum, Qt::AlignRight ); 56 ProcessView->setColumnAlignment( colnum, Qt::AlignRight );
56 ProcessView->setAllColumnsShowFocus( TRUE ); 57 ProcessView->setAllColumnsShowFocus( TRUE );
57 QPEApplication::setStylusOperation( ProcessView->viewport(), QPEApplication::RightOnHold ); 58 QPEApplication::setStylusOperation( ProcessView->viewport(), QPEApplication::RightOnHold );
58 connect( ProcessView, SIGNAL( rightButtonPressed(OListViewItem*,const QPoint&,int) ), 59 connect( ProcessView, SIGNAL( rightButtonPressed(QListViewItem*,const QPoint&,int) ),
59 this, SLOT( viewProcess(OListViewItem*) ) ); 60 this, SLOT( viewProcess(QListViewItem*) ) );
60 layout->addMultiCellWidget( ProcessView, 0, 0, 0, 1 ); 61 layout->addMultiCellWidget( ProcessView, 0, 0, 0, 1 );
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." ) ); 62 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." ) );
62 63
63 SignalCB = new QComboBox( FALSE, this, "SignalCB" ); 64 SignalCB = new QComboBox( FALSE, this, "SignalCB" );
64 SignalCB->insertItem( " 1: SIGHUP" ); 65 SignalCB->insertItem( " 1: SIGHUP" );
65 SignalCB->insertItem( " 2: SIGINT" ); 66 SignalCB->insertItem( " 2: SIGINT" );
66 SignalCB->insertItem( " 3: SIGQUIT" ); 67 SignalCB->insertItem( " 3: SIGQUIT" );
67 SignalCB->insertItem( " 5: SIGTRAP" ); 68 SignalCB->insertItem( " 5: SIGTRAP" );
68 SignalCB->insertItem( " 6: SIGABRT" ); 69 SignalCB->insertItem( " 6: SIGABRT" );
69 SignalCB->insertItem( " 9: SIGKILL" ); 70 SignalCB->insertItem( " 9: SIGKILL" );
70 SignalCB->insertItem( "14: SIGALRM" ); 71 SignalCB->insertItem( "14: SIGALRM" );
71 SignalCB->insertItem( "15: SIGTERM" ); 72 SignalCB->insertItem( "15: SIGTERM" );
72 SignalCB->insertItem( "18: SIGCONT" ); 73 SignalCB->insertItem( "18: SIGCONT" );
73 SignalCB->insertItem( "19: SIGSTOP" ); 74 SignalCB->insertItem( "19: SIGSTOP" );
74 layout->addWidget( SignalCB, 1, 0 ); 75 layout->addWidget( SignalCB, 1, 0 );
75 QWhatsThis::add( SignalCB, tr( "Select a signal here and then click the Send button to the right to send to this process." ) ); 76 QWhatsThis::add( SignalCB, tr( "Select a signal here and then click the Send button to the right to send to this process." ) );
76 77
77 SendButton = new QPushButton( this, "SendButton" ); 78 SendButton = new QPushButton( this, "SendButton" );
78 SendButton->setMinimumSize( QSize( 50, 24 ) ); 79 SendButton->setMinimumSize( QSize( 50, 24 ) );
79 SendButton->setMaximumSize( QSize( 50, 24 ) ); 80 SendButton->setMaximumSize( QSize( 50, 24 ) );
80 SendButton->setText( tr( "Send" ) ); 81 SendButton->setText( tr( "Send" ) );
81 connect( SendButton, SIGNAL( clicked() ), this, SLOT( slotSendClicked() ) ); 82 connect( SendButton, SIGNAL( clicked() ), this, SLOT( slotSendClicked() ) );
82 layout->addWidget( SendButton, 1, 1 ); 83 layout->addWidget( SendButton, 1, 1 );
83 QWhatsThis::add( SendButton, tr( "Click here to send the selected signal to this process." ) ); 84 QWhatsThis::add( SendButton, tr( "Click here to send the selected signal to this process." ) );
84 85
85 QTimer *t = new QTimer( this ); 86 QTimer *t = new QTimer( this );
86 connect( t, SIGNAL( timeout() ), this, SLOT( updateData() ) ); 87 connect( t, SIGNAL( timeout() ), this, SLOT( updateData() ) );
87 t->start( 5000 ); 88 t->start( 5000 );
88 89
89 updateData(); 90 updateData();
90 91
91 ProcessDtl = new Detail(); 92 ProcessDtl = new Detail();
92 QWhatsThis::add( ProcessDtl->detailView, tr( "This area shows detailed information about this process." ) ); 93 QWhatsThis::add( ProcessDtl->detailView, tr( "This area shows detailed information about this process." ) );
93} 94}
94 95
95ProcessInfo::~ProcessInfo() 96ProcessInfo::~ProcessInfo()
96{} 97{}
97 98
98void ProcessInfo::updateData() 99void ProcessInfo::updateData()
99{ 100{
100 int pid, ppid, pgrp, session, tty, tpgid, utime, stime, cutime, cstime, counter, priority, starttime, 101 int pid, ppid, pgrp, session, tty, tpgid, utime, stime, cutime, cstime, counter, priority, starttime,
101 signal, blocked, sigignore, sigcatch; 102 signal, blocked, sigignore, sigcatch;
102 uint flags, minflt, cminflt, majflt, cmajflt, timeout, itrealvalue, vsize, rss, rlim, startcode, 103 uint flags, minflt, cminflt, majflt, cmajflt, timeout, itrealvalue, vsize, rss, rlim, startcode,
103 endcode, startstack, kstkesp, kstkeip, wchan; 104 endcode, startstack, kstkesp, kstkeip, wchan;
104 char state; 105 char state;
105 char comm[64]; 106 char comm[64];
106 107
107 QString selectedpid; 108 QString selectedpid;
@@ -140,67 +141,73 @@ void ProcessInfo::updateData()
140 processnum = processnum.rightJustify( 5, ' ' ); 141 processnum = processnum.rightJustify( 5, ' ' );
141 QString processcmd = QString( comm ).replace( QRegExp( "[()]" ), "" ); 142 QString processcmd = QString( comm ).replace( QRegExp( "[()]" ), "" );
142 QString processstatus = QChar(state); 143 QString processstatus = QChar(state);
143 QString processtime = QString::number( ( utime + stime ) / 100 ); 144 QString processtime = QString::number( ( utime + stime ) / 100 );
144 processtime = processtime.rightJustify( 9, ' ' ); 145 processtime = processtime.rightJustify( 9, ' ' );
145 fclose( procfile ); 146 fclose( procfile );
146 147
147 newitem = new OListViewItem( ProcessView, processnum, processcmd, processstatus, processtime ); 148 newitem = new OListViewItem( ProcessView, processnum, processcmd, processstatus, processtime );
148 if ( processnum == selectedpid ) 149 if ( processnum == selectedpid )
149 { 150 {
150 selecteditem = newitem; 151 selecteditem = newitem;
151 } 152 }
152 } 153 }
153 } 154 }
154 } 155 }
155 ProcessView->setCurrentItem( selecteditem ); 156 ProcessView->setCurrentItem( selecteditem );
156 } 157 }
157 158
158 delete proclist; 159 delete proclist;
159 delete procdir; 160 delete procdir;
160} 161}
161 162
162void ProcessInfo::slotSendClicked() 163void ProcessInfo::slotSendClicked()
163{ 164{
164 OListViewItem *currprocess = static_cast<OListViewItem*>( ProcessView->currentItem() ); 165 OListViewItem *currprocess = static_cast<OListViewItem*>( ProcessView->currentItem() );
165 if ( !currprocess ) 166 if ( !currprocess )
166 { 167 {
167 return; 168 return;
168 } 169 }
169 170
170 QString capstr = tr( "Really want to send %1\nto this process?" ).arg( SignalCB->currentText() ); 171 QString capstr = tr( "Really want to send %1\nto this process?" ).arg( SignalCB->currentText() );
171 172
172 173
173 if ( QMessageBox::warning( this, currprocess->text( 1 ), capstr, 174 if ( QMessageBox::warning( this, currprocess->text( 1 ), capstr,
174 QMessageBox::Yes | QMessageBox::Default, QMessageBox::No | QMessageBox::Escape ) == QMessageBox::Yes ) 175 QMessageBox::Yes | QMessageBox::Default, QMessageBox::No | QMessageBox::Escape ) == QMessageBox::Yes )
175 { 176 {
176 currprocess = static_cast<OListViewItem*>( ProcessView->currentItem() ); 177 currprocess = static_cast<OListViewItem*>( ProcessView->currentItem() );
177 if ( currprocess ) 178 if ( currprocess )
178 { 179 {
179 QString sigstr = SignalCB->currentText(); 180 QString sigstr = SignalCB->currentText();
180 sigstr.truncate(2); 181 sigstr.truncate(2);
181 int sigid = sigstr.toUInt(); 182 int sigid = sigstr.toUInt();
182 kill( currprocess->text( 0 ).stripWhiteSpace().toUInt(), sigid ); 183 kill( currprocess->text( 0 ).stripWhiteSpace().toUInt(), sigid );
183 } 184 }
184 } 185 }
185 186
186} 187}
187 188
189void ProcessInfo::viewProcess( QListViewItem* process ) {
190 if ( !process )
191 return;
192 viewProcess( static_cast<OListViewItem*>( process ) );
193}
194
188void ProcessInfo::viewProcess( OListViewItem *process ) 195void ProcessInfo::viewProcess( OListViewItem *process )
189{ 196{
190 QString pid= process->text( 0 ).stripWhiteSpace(); 197 QString pid= process->text( 0 ).stripWhiteSpace();
191 QString command = process->text( 1 ); 198 QString command = process->text( 1 );
192 ProcessDtl->setCaption( pid + " - " + command ); 199 ProcessDtl->setCaption( pid + " - " + command );
193 FILE *statfile = fopen( ( QString ) ( "/proc/" + pid + "/status"), "r"); 200 FILE *statfile = fopen( ( QString ) ( "/proc/" + pid + "/status"), "r");
194 if ( statfile ) 201 if ( statfile )
195 { 202 {
196 char line[81]; 203 char line[81];
197 fgets( line, 81, statfile ); 204 fgets( line, 81, statfile );
198 ProcessDtl->detailView->setText( line ); 205 ProcessDtl->detailView->setText( line );
199 while ( fgets( line, 81, statfile ) ) 206 while ( fgets( line, 81, statfile ) )
200 { 207 {
201 ProcessDtl->detailView->append( line ); 208 ProcessDtl->detailView->append( line );
202 } 209 }
203 fclose( statfile ); 210 fclose( statfile );
204 } 211 }
205 QPEApplication::showWidget( ProcessDtl ); 212 QPEApplication::showWidget( ProcessDtl );
206} 213}