KDevelop API Documentation

parts/filter/shellfilterdlg.cpp

Go to the documentation of this file.
00001 /*************************************************************************** 00002 * Copyright (C) 2002 by Bernd Gehrmann * 00003 * bernd@kdevelop.org * 00004 * * 00005 * This program is free software; you can redistribute it and/or modify * 00006 * it under the terms of the GNU General Public License as published by * 00007 * the Free Software Foundation; either version 2 of the License, or * 00008 * (at your option) any later version. * 00009 * * 00010 ***************************************************************************/ 00011 00012 #include "shellfilterdlg.h" 00013 00014 #include <qcombobox.h> 00015 #include <qlayout.h> 00016 #include <qpushbutton.h> 00017 #include <kbuttonbox.h> 00018 #include <kconfig.h> 00019 #include <kdebug.h> 00020 #include <klocale.h> 00021 #include <kmessagebox.h> 00022 #include <kprocess.h> 00023 00024 #include "kdevplugin.h" 00025 #include "domutil.h" 00026 #include "filterpart.h" 00027 00028 00029 ShellFilterDialog::ShellFilterDialog() 00030 : QDialog(0, "shell filter dialog", true) 00031 { 00032 QVBoxLayout *layout = new QVBoxLayout(this, 10, 4); 00033 00034 combo = new QComboBox(true, this); 00035 combo->setDuplicatesEnabled(false); 00036 layout->addWidget(combo); 00037 00038 KButtonBox *buttonbox = new KButtonBox(this); 00039 start_button = buttonbox->addButton(i18n("&Start")); 00040 start_button->setDefault(true); 00041 cancel_button = buttonbox->addButton(i18n("Cancel")); 00042 buttonbox->layout(); 00043 layout->addWidget(buttonbox); 00044 00045 connect( start_button, SIGNAL(clicked()), 00046 this, SLOT(slotStartClicked()) ); 00047 connect( cancel_button, SIGNAL(clicked()), 00048 this, SLOT(reject()) ); 00049 00050 m_proc = 0; 00051 00052 KConfig *config = FilterFactory::instance()->config(); 00053 config->setGroup("General"); 00054 combo->insertStringList(config->readListEntry("filteritems")); 00055 } 00056 00057 00058 ShellFilterDialog::~ShellFilterDialog() 00059 { 00060 kdDebug(9029) << "~ShellFilterDialog" << endl; 00061 delete m_proc; 00062 00063 // QComboBox API is a bit incomplete :-( 00064 QStringList list; 00065 for (int i=0; i < combo->count(); ++i) 00066 list << combo->text(i); 00067 00068 KConfig *config = FilterFactory::instance()->config(); 00069 config->setGroup("General"); 00070 config->writeEntry("filteritems", list); 00071 } 00072 00073 00074 void ShellFilterDialog::slotStartClicked() 00075 { 00076 start_button->setEnabled(false); 00077 m_outstr = QCString(); 00078 00079 delete m_proc; 00080 m_proc = new KShellProcess("/bin/sh"); 00081 (*m_proc) << combo->currentText(); 00082 connect( m_proc, SIGNAL(receivedStdout(KProcess*, char *, int)), 00083 this, SLOT(slotReceivedStdout(KProcess*, char *, int)) ); 00084 connect( m_proc, SIGNAL(wroteStdin(KProcess*)), 00085 this, SLOT(slotWroteStdin(KProcess*)) ); 00086 connect( m_proc, SIGNAL(processExited(KProcess*)), 00087 this, SLOT(slotProcessExited(KProcess*)) ); 00088 m_proc->start(KProcess::NotifyOnExit, KProcess::All); 00089 m_proc->writeStdin(m_instr, m_instr.length()); 00090 } 00091 00092 00093 int ShellFilterDialog::exec() 00094 { 00095 start_button->setEnabled(true); 00096 return QDialog::exec(); 00097 } 00098 00099 00100 void ShellFilterDialog::slotReceivedStdout(KProcess *, char *text, int len) 00101 { 00102 m_outstr += QString::fromLocal8Bit(text, len+1); 00103 kdDebug(9029) << "outstr " << m_outstr << endl; 00104 } 00105 00106 00107 void ShellFilterDialog::slotWroteStdin(KProcess *) 00108 { 00109 m_proc->closeStdin(); 00110 kdDebug(9029) << "close stdin " << m_outstr << endl; 00111 } 00112 00113 00114 void ShellFilterDialog::slotProcessExited(KProcess *) 00115 { 00116 kdDebug(9029) << "process exit " << m_proc->normalExit() << endl; 00117 if (m_proc->normalExit()) { 00118 accept(); 00119 } else { 00120 KMessageBox::error(this, i18n("Process exited with status %1") 00121 .arg(m_proc->exitStatus())); 00122 reject(); 00123 } 00124 } 00125 00126 #include "shellfilterdlg.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 Wed Oct 6 17:39:12 2004 by doxygen 1.3.7 written by Dimitri van Heesch, © 1997-2003