00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
#include "dbgpsdlg.h"
00019
00020
#include <kbuttonbox.h>
00021
#include <kdialog.h>
00022
#include <kglobalsettings.h>
00023
#include <klocale.h>
00024
#include <kprocess.h>
00025
00026
#include <qframe.h>
00027
#include <qlabel.h>
00028
#include <qlayout.h>
00029
#include <qlistbox.h>
00030
#include <qtoolbutton.h>
00031
#include <qpushbutton.h>
00032
00033
#include <stdlib.h>
00034
#include <unistd.h>
00035
#include <sys/types.h>
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
namespace JAVADebugger
00046 {
00047
00048 Dbg_PS_Dialog::Dbg_PS_Dialog(
QWidget *parent,
const char *name)
00049 :
KDialog(parent, name, true),
00050 psProc_(0),
00051 pids_(new
QListBox(this)),
00052 heading_(new
QLabel(" ", this)),
00053 pidLines_(
QString())
00054 {
00055 setCaption(i18n(
"Attach to Process"));
00056
00057
QBoxLayout *topLayout =
new QVBoxLayout(
this, 5);
00058
00059
heading_->setFont(KGlobalSettings::fixedFont());
00060
heading_->setFrameStyle(QFrame::Panel|QFrame::Sunken);
00061
heading_->setMaximumHeight(
heading_->sizeHint().height());
00062
heading_->setMinimumSize(
heading_->sizeHint());
00063 topLayout->
addWidget(
heading_, 5);
00064
00065 topLayout->
addWidget(
pids_, 5);
00066
pids_->setFont(KGlobalSettings::fixedFont());
00067
00068
KButtonBox *buttonbox =
new KButtonBox(
this, Qt::Horizontal, 5);
00069
QPushButton *ok = buttonbox->
addButton(i18n(
"OK"));
00070 buttonbox->
addStretch();
00071
QPushButton *cancel = buttonbox->
addButton(i18n(
"Cancel"));
00072 buttonbox->
layout();
00073 topLayout->
addWidget(buttonbox);
00074
00075 connect(ok, SIGNAL(clicked()), SLOT(accept()));
00076 connect(cancel, SIGNAL(clicked()), SLOT(reject()));
00077
00078
psProc_ =
new KShellProcess(
"/bin/sh");
00079 *
psProc_ <<
"ps";
00080 *
psProc_ <<
"x";
00081
pidCmd_ =
"ps x";
00082
00083
if (getuid() == 0) {
00084 *
psProc_ <<
"a";
00085
pidCmd_ +=
" a";
00086 }
00087
00088 connect(
psProc_, SIGNAL(processExited(
KProcess *)), SLOT(
slotProcessExited()) );
00089 connect(
psProc_, SIGNAL(receivedStdout(
KProcess *,
char *,
int)), SLOT(
slotReceivedOutput(
KProcess *,
char *,
int)) );
00090
psProc_->
start(KProcess::NotifyOnExit, KProcess::Stdout);
00091
00092
00093 resize( ((KGlobalSettings::fixedFont()).pointSize())*40, height());
00094 topLayout->activate();
00095 }
00096
00097
00098
00099 Dbg_PS_Dialog::~Dbg_PS_Dialog()
00100 {
00101
delete psProc_;
00102 }
00103
00104
00105
00106 int Dbg_PS_Dialog::pidSelected()
00107 {
00108
QString pidText =
pids_->text(
pids_->currentItem());
00109
if (!pidText.isEmpty())
00110
return atoi(pidText.latin1());
00111
00112
return 0;
00113 }
00114
00115
00116
00117 void Dbg_PS_Dialog::slotReceivedOutput(
KProcess *,
char *buffer,
int buflen)
00118 {
00119
pidLines_ += QString::fromLocal8Bit(buffer, buflen+1);
00120 }
00121
00122
00123
00124 void Dbg_PS_Dialog::slotProcessExited()
00125 {
00126
delete psProc_;
00127
psProc_ = 0;
00128
00129
pidLines_ +=
'\n';
00130
00131
int start =
pidLines_.find(
'\n', 0);
00132
int pos;
00133
if (start != -1)
00134
heading_->setText(
pidLines_.left(start));
00135
while ( (pos =
pidLines_.find(
'\n', start)) != -1) {
00136
QString item =
pidLines_.mid(start, pos-start);
00137
if (!item.isEmpty()) {
00138
if (item.find(
pidCmd_) == -1)
00139
pids_->insertItem(item);
00140 }
00141
00142 start = pos+1;
00143 }
00144 }
00145
00146
00147 }
00148
00149
#include "dbgpsdlg.moc"