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 #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 #include <kstdguiitem.h>
00024 #include <kdeversion.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 namespace GDBDebugger
00038 {
00039
00040
00041
00042
00043
00044
00045
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
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 #if KDE_IS_VERSION( 3, 2, 90 )
00070 QPushButton *ok = buttonbox->addButton(KStdGuiItem::ok());
00071 buttonbox->addStretch();
00072 QPushButton *cancel = buttonbox->addButton(KStdGuiItem::cancel());
00073 #else
00074 QPushButton *ok = buttonbox->addButton(i18n("OK"));
00075 buttonbox->addStretch();
00076 QPushButton *cancel = buttonbox->addButton(i18n("Cancel"));
00077 #endif
00078 buttonbox->layout();
00079 topLayout->addWidget(buttonbox);
00080
00081 connect(ok, SIGNAL(clicked()), SLOT(accept()));
00082 connect(cancel, SIGNAL(clicked()), SLOT(reject()));
00083
00084 psProc_ = new KShellProcess("/bin/sh");
00085 #ifdef USE_SOLARIS
00086 *psProc_ << "ps";
00087 *psProc_ << "-opid";
00088 *psProc_ << "-otty";
00089 *psProc_ << "-os";
00090 *psProc_ << "-otime";
00091 *psProc_ << "-oargs";
00092 pidCmd_ = "ps -opid -otty -os -otime -oargs";
00093
00094 if (getuid() == 0) {
00095 *psProc_ << "-e";
00096 pidCmd_ += " -e";
00097 }
00098 #else
00099 *psProc_ << "ps";
00100 *psProc_ << "x";
00101 pidCmd_ = "ps x";
00102
00103 if (getuid() == 0) {
00104 *psProc_ << "a";
00105 pidCmd_ += " a";
00106 }
00107 #endif
00108
00109 connect( psProc_, SIGNAL(processExited(KProcess *)), SLOT(slotProcessExited()) );
00110 connect( psProc_, SIGNAL(receivedStdout(KProcess *, char *, int)), SLOT(slotReceivedOutput(KProcess *, char *, int)) );
00111 psProc_->start(KProcess::NotifyOnExit, KProcess::Stdout);
00112
00113
00114 resize( ((KGlobalSettings::fixedFont()).pointSize())*40, height());
00115 topLayout->activate();
00116 }
00117
00118
00119
00120 Dbg_PS_Dialog::~Dbg_PS_Dialog()
00121 {
00122 delete psProc_;
00123 }
00124
00125
00126
00127 int Dbg_PS_Dialog::pidSelected()
00128 {
00129 QString pidText = pids_->text(pids_->currentItem());
00130 if (!pidText.isEmpty())
00131 return atoi(pidText.latin1());
00132
00133 return 0;
00134 }
00135
00136
00137
00138 void Dbg_PS_Dialog::slotReceivedOutput(KProcess *, char *buffer, int buflen)
00139 {
00140 pidLines_ += QString::fromLocal8Bit(buffer, buflen+1);
00141 }
00142
00143
00144
00145 void Dbg_PS_Dialog::slotProcessExited()
00146 {
00147 delete psProc_;
00148 psProc_ = 0;
00149
00150 pidLines_ += '\n';
00151
00152 int start = pidLines_.find('\n', 0);
00153 int pos;
00154 if (start != -1)
00155 heading_->setText(pidLines_.left(start));
00156 while ( (pos = pidLines_.find('\n', start)) != -1) {
00157 QString item = pidLines_.mid(start, pos-start);
00158 if (!item.isEmpty()) {
00159 if (item.find(pidCmd_) == -1)
00160 pids_->insertItem(item);
00161 }
00162
00163 start = pos+1;
00164 }
00165 }
00166
00167 }
00168
00169
00170 #include "dbgpsdlg.moc"
This file is part of the documentation for KDevelop Version 3.1.2.