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