-rw-r--r-- | noncore/settings/sysinfo/processdetail.cpp | 22 | ||||
-rw-r--r-- | noncore/settings/sysinfo/processdetail.h | 6 | ||||
-rw-r--r-- | noncore/settings/sysinfo/processinfo.cpp | 41 | ||||
-rw-r--r-- | noncore/settings/sysinfo/processinfo.h | 3 |
4 files changed, 32 insertions, 40 deletions
diff --git a/noncore/settings/sysinfo/processdetail.cpp b/noncore/settings/sysinfo/processdetail.cpp index 06e5c0d..ef612e6 100644 --- a/noncore/settings/sysinfo/processdetail.cpp +++ b/noncore/settings/sysinfo/processdetail.cpp @@ -8,81 +8,77 @@ ** http://draknor.net ** ** This file may be distributed and/or modified under the terms of the ** GNU General Public License version 2 as published by the Free Software ** Foundation and appearing in the file LICENSE.GPL included in the ** packaging of this file. ** ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. ** **********************************************************************/ #include "processdetail.h" #include <sys/types.h> #include <signal.h> #include <qcombobox.h> #include <qpushbutton.h> #include <qtextview.h> #include <qlayout.h> #include <qlistview.h> #include <qmessagebox.h> -ProcessDetail::ProcessDetail( QWidget* parent, const char* name, bool modal, WFlags fl ) - : QDialog( parent, name, modal, fl ) +ProcessDetail::ProcessDetail( QWidget* parent, const char* name, WFlags fl ) + : QWidget( parent, name, fl ) { pid = 0; QGridLayout *layout = new QGridLayout( this ); - layout->setSpacing( 6 ); - layout->setMargin( 11 ); + layout->setSpacing( 4 ); + layout->setMargin( 4 ); SignalCB = new QComboBox( FALSE, this, "SignalCB" ); - SignalCB->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)1, (QSizePolicy::SizeType)7, SignalCB->sizePolicy().hasHeightForWidth() ) ); - SignalCB->setMinimumSize( QSize( 50, 24 ) ); - SignalCB->setMaximumSize( QSize( 600, 24 ) ); SignalCB->insertItem( " 1: SIGHUP" ); SignalCB->insertItem( " 2: SIGINT" ); SignalCB->insertItem( " 9: SIGKILL" ); SignalCB->insertItem( "15: SIGTERM" ); SignalCB->insertItem( "18: SIGCONT" ); SignalCB->insertItem( "19: SIGSTOP" ); layout->addWidget( SignalCB, 1, 0 ); ProcessView = new QTextView( this, "ProcessView" ); - ProcessView->setFrameShadow( QTextView::Plain ); layout->addMultiCellWidget( ProcessView, 0, 0, 0, 1 ); SendButton = new QPushButton( this, "SendButton" ); - SendButton->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)0, (QSizePolicy::SizeType)0, SendButton->sizePolicy().hasHeightForWidth() ) ); SendButton->setMinimumSize( QSize( 50, 24 ) ); SendButton->setMaximumSize( QSize( 50, 24 ) ); SendButton->setText( tr( "Send" ) ); connect( SendButton, SIGNAL( clicked() ), this, SLOT( slotSendClicked() ) ); layout->addWidget( SendButton, 1, 1 ); } ProcessDetail::~ProcessDetail() { } void ProcessDetail::slotSendClicked() { QString sigstr = SignalCB->currentText(); sigstr.truncate(2); int sigid = sigstr.toUInt(); - if ( !QMessageBox::information( this, caption(), - ( tr( "You really want to send\n" + SignalCB->currentText() + "\nto this process?") ), - ( tr( "Yes" ) ), ( tr( "No" ) ), 0 ) ) + if ( QMessageBox::warning( this, caption(), + tr( "You really want to send\n" + SignalCB->currentText() + "\nto this process?"), + QMessageBox::Yes | QMessageBox::Default, QMessageBox::No | QMessageBox::Escape ) + == QMessageBox::Yes ) { if ( kill( pid, sigid ) == 0 ) { - accept(); + hide(); } } } diff --git a/noncore/settings/sysinfo/processdetail.h b/noncore/settings/sysinfo/processdetail.h index 5d418ac..22e196f 100644 --- a/noncore/settings/sysinfo/processdetail.h +++ b/noncore/settings/sysinfo/processdetail.h @@ -1,47 +1,47 @@ /********************************************************************** ** ProcessDetail ** ** Display process information ** ** Copyright (C) 2002, Dan Williams ** williamsdr@acm.org ** http://draknor.net ** ** This file may be distributed and/or modified under the terms of the ** GNU General Public License version 2 as published by the Free Software ** Foundation and appearing in the file LICENSE.GPL included in the ** packaging of this file. ** ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. ** **********************************************************************/ #ifndef PROCESSDETAIL_H #define PROCESSDETAIL_H -#include <qdialog.h> +#include <qwidget.h> #include <qcombo.h> #include <qtextview.h> #include <qpushbutton.h> #include <qlistview.h> -class ProcessDetail : public QDialog +class ProcessDetail : public QWidget { Q_OBJECT public: - ProcessDetail( QWidget* parent, const char* name, bool modal, WFlags fl ); + ProcessDetail( QWidget* parent, const char* name, WFlags fl ); ~ProcessDetail(); QComboBox* SignalCB; QTextView* ProcessView; QPushButton* SendButton; int pid; private slots: void slotSendClicked(); }; #endif // PROCESSDETAIL_H diff --git a/noncore/settings/sysinfo/processinfo.cpp b/noncore/settings/sysinfo/processinfo.cpp index 225da63..ad81d7b 100644 --- a/noncore/settings/sysinfo/processinfo.cpp +++ b/noncore/settings/sysinfo/processinfo.cpp @@ -4,134 +4,127 @@ ** Display process information ** ** Copyright (C) 2002, Dan Williams ** williamsdr@acm.org ** http://draknor.net ** ** This file may be distributed and/or modified under the terms of the ** GNU General Public License version 2 as published by the Free Software ** Foundation and appearing in the file LICENSE.GPL included in the ** packaging of this file. ** ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. ** **********************************************************************/ #include <qheader.h> #include <qlistview.h> #include <qlayout.h> #include <qtimer.h> #include <qfile.h> #include <qdir.h> #include "processinfo.h" -#include "processdetail.h" ProcessInfo::ProcessInfo( QWidget* parent, const char* name, WFlags fl ) : QWidget( parent, name, fl ) { QVBoxLayout *layout = new QVBoxLayout( this, 5 ); ProcessView = new QListView( this, "ProcessView" ); int colnum = ProcessView->addColumn( tr( "PID" ) ); ProcessView->setColumnAlignment( colnum, Qt::AlignRight ); colnum = ProcessView->addColumn( tr( "Command" ),96 ); colnum = ProcessView->addColumn( tr( "Status" ) ); colnum = ProcessView->addColumn( tr( "Time" ) ); ProcessView->setColumnAlignment( colnum, Qt::AlignRight ); ProcessView->setAllColumnsShowFocus( TRUE ); connect( ProcessView, SIGNAL( doubleClicked(QListViewItem *) ), this, SLOT( viewProcess(QListViewItem *) ) ); layout->addWidget( ProcessView ); QTimer *t = new QTimer( this ); connect( t, SIGNAL( timeout() ), this, SLOT( updateData() ) ); t->start( 5000 ); updateData(); + + ProcessDtl = new ProcessDetail( 0, 0, 0 ); + ProcessDtl->ProcessView->setTextFormat( RichText ); } ProcessInfo::~ProcessInfo() { } void ProcessInfo::updateData() { - QString processnum(""); - QString processcmd(""); - QString processstatus(""); - QString processtime(""); int pid, ppid, pgrp, session, tty, tpgid, utime, stime, cutime, cstime, counter, priority, starttime, signal, blocked, sigignore, sigcatch; uint flags, minflt, cminflt, majflt, cmajflt, timeout, itrealvalue, vsize, rss, rlim, startcode, endcode, startstack, kstkesp, kstkeip, wchan; char state; - char comm[255]; + char comm[64]; ProcessView->clear(); - QDir *procdir = new QDir("/proc"); - procdir->setFilter(QDir::Dirs); - procdir->setSorting(QDir::Name); + QDir *procdir = new QDir("/proc", 0, QDir::Name, QDir::Dirs); QFileInfoList *proclist = new QFileInfoList(*(procdir->entryInfoList())); if ( proclist ) { QFileInfoListIterator it(*proclist); QFileInfo *f; while ( ( f = it.current() ) != 0 ) { ++it; - processnum = f->fileName(); - if ( processnum >= "0" && processnum <= "99999" ) + QString processnum = f->fileName(); + if ( processnum >= "1" && processnum <= "99999" ) { FILE *procfile = fopen( ( QString ) ( "/proc/" + processnum + "/stat"), "r"); if ( procfile ) { fscanf( procfile, "%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", &pid, comm, &state, &ppid, &pgrp, &session,&tty, &tpgid, &flags, &minflt, &cminflt, &majflt, &cmajflt, &utime, &stime, &cutime, &cstime, &counter, &priority, &timeout, &itrealvalue, &starttime, &vsize, &rss, &rlim, &startcode, &endcode, &startstack, &kstkesp, &kstkeip, &signal, &blocked, &sigignore, &sigcatch, &wchan ); processnum = processnum.rightJustify( 5, ' ' ); - processcmd = QString( comm ).replace( QRegExp( "(" ), "" ); - processcmd = processcmd.replace( QRegExp( ")" ), "" ); - processstatus = state; - processtime.setNum( ( utime + stime ) / 100 ); + QString processcmd = QString( comm ).replace( QRegExp( "[()]" ), "" ); + QString processstatus = QChar(state); + QString processtime = QString::number( ( utime + stime ) / 100 ); processtime = processtime.rightJustify( 9, ' ' ); fclose( procfile ); ( void ) new QListViewItem( ProcessView, processnum, processcmd, processstatus, processtime ); } } } } delete proclist; delete procdir; } void ProcessInfo::viewProcess(QListViewItem *process) { - QString pid= process->text(0).stripWhiteSpace(); - QString command = process->text(1); - ProcessDetail *processdtl = new ProcessDetail( this, 0, TRUE, 0); - processdtl->setCaption( pid + " - " + command ); - processdtl->pid = pid.toUInt(); - processdtl->ProcessView->setTextFormat( RichText ); + QString pid= process->text( 0 ).stripWhiteSpace(); + QString command = process->text( 1 ); + ProcessDtl->setCaption( pid + " - " + command ); + ProcessDtl->pid = pid.toUInt(); FILE *statfile = fopen( ( QString ) ( "/proc/" + pid + "/status"), "r"); if ( statfile ) { char line[81]; fgets( line, 81, statfile ); - processdtl->ProcessView->setText( line ); + ProcessDtl->ProcessView->setText( line ); while ( fgets( line, 81, statfile ) ) { - processdtl->ProcessView->append( line ); + ProcessDtl->ProcessView->append( line ); } fclose( statfile ); } - processdtl->showMaximized(); + ProcessDtl->showMaximized(); } diff --git a/noncore/settings/sysinfo/processinfo.h b/noncore/settings/sysinfo/processinfo.h index e5bacca..89d1a93 100644 --- a/noncore/settings/sysinfo/processinfo.h +++ b/noncore/settings/sysinfo/processinfo.h @@ -2,40 +2,43 @@ ** ProcessInfo ** ** Display process information ** ** Copyright (C) 2002, Dan Williams ** williamsdr@acm.org ** http://draknor.net ** ** This file may be distributed and/or modified under the terms of the ** GNU General Public License version 2 as published by the Free Software ** Foundation and appearing in the file LICENSE.GPL included in the ** packaging of this file. ** ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. ** **********************************************************************/ #ifndef PROCESSINFO_H #define PROCESSINFO_H #include <qwidget.h> #include <qlistview.h> +#include "processdetail.h" + class ProcessInfo : public QWidget { Q_OBJECT public: ProcessInfo( QWidget *parent = 0, const char *name = 0, WFlags f = 0 ); ~ProcessInfo(); private slots: void updateData(); void viewProcess(QListViewItem *); private: QListView* ProcessView; + ProcessDetail *ProcessDtl; }; #endif |