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