KDevelop API Documentation

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 #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 // Display a list of processes for the user to select one
00043 // only display processes that they can do something with so if the user
00044 // is root then display all processes
00045 // For use with the internal debugger, but this dialog doesn't know anything
00046 // about why it's doing it.
00047 
00048 Dbg_PS_Dialog::Dbg_PS_Dialog(QWidget *parent, const char *name)
00049     : KDialog(parent, name, true),      // modal
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 #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     // Default display to 40 chars wide, default height is okay
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 */*proc*/, 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);  // Skip the first line (header line)
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"
KDE Logo
This file is part of the documentation for KDevelop Version 3.1.2.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Wed Mar 23 00:03:46 2005 by doxygen 1.3.9.1 written by Dimitri van Heesch, © 1997-2003