KDevelop API Documentation

languages/cpp/debugger/dbgpsdlg.cpp

Go to the documentation of this file.
00001 /*************************************************************************** 00002 begin : Mon Sep 20 1999 00003 copyright : (C) 1999 by John Birch 00004 email : jbb@kdevelop.org 00005 ***************************************************************************/ 00006 00007 /*************************************************************************** 00008 * * 00009 * This program is free software; you can redistribute it and/or modify * 00010 * it under the terms of the GNU General Public License as published by * 00011 * the Free Software Foundation; either version 2 of the License, or * 00012 * (at your option) any later version. * 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 // Display a list of processes for the user to select one 00041 // only display processes that they can do something with so if the user 00042 // is root then display all processes 00043 // For use with the internal debugger, but this dialog doesn't know anything 00044 // about why it's doing it. 00045 00046 Dbg_PS_Dialog::Dbg_PS_Dialog(QWidget *parent, const char *name) 00047 : KDialog(parent, name, true), // modal 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 // heading_->setMinimumSize(heading_->sizeHint()); 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 // Default display to 40 chars wide, default height is okay 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 */*proc*/, 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); // Skip the first line (header line) 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"
KDE Logo
This file is part of the documentation for KDevelop Version 3.0.4.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Tue Oct 19 08:01:42 2004 by doxygen 1.3.7 written by Dimitri van Heesch, © 1997-2003