shellfilterdlg.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
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 #include <kstdguiitem.h>
00024 #include <kdeversion.h>
00025
00026 #include "kdevplugin.h"
00027 #include "domutil.h"
00028 #include "filterpart.h"
00029
00030
00031 ShellFilterDialog::ShellFilterDialog()
00032 : QDialog(0, "shell filter dialog", true)
00033 {
00034 QVBoxLayout *layout = new QVBoxLayout(this, 10, 4);
00035
00036 combo = new QComboBox(true, this);
00037 combo->setDuplicatesEnabled(false);
00038 layout->addWidget(combo);
00039
00040 KButtonBox *buttonbox = new KButtonBox(this);
00041 start_button = buttonbox->addButton(i18n("&Start"));
00042 start_button->setDefault(true);
00043 #if KDE_IS_VERSION( 3, 2, 90 )
00044 cancel_button = buttonbox->addButton(KStdGuiItem::cancel());
00045 #else
00046 cancel_button = buttonbox->addButton(i18n("Cancel"));
00047 #endif
00048 buttonbox->layout();
00049 layout->addWidget(buttonbox);
00050
00051 connect( start_button, SIGNAL(clicked()),
00052 this, SLOT(slotStartClicked()) );
00053 connect( cancel_button, SIGNAL(clicked()),
00054 this, SLOT(reject()) );
00055
00056 m_proc = 0;
00057
00058 KConfig *config = FilterFactory::instance()->config();
00059 config->setGroup("General");
00060 combo->insertStringList(config->readListEntry("filteritems"));
00061 }
00062
00063
00064 ShellFilterDialog::~ShellFilterDialog()
00065 {
00066 kdDebug(9029) << "~ShellFilterDialog" << endl;
00067 delete m_proc;
00068
00069
00070 QStringList list;
00071 for (int i=0; i < combo->count(); ++i)
00072 list << combo->text(i);
00073
00074 KConfig *config = FilterFactory::instance()->config();
00075 config->setGroup("General");
00076 config->writeEntry("filteritems", list);
00077 }
00078
00079
00080 void ShellFilterDialog::slotStartClicked()
00081 {
00082 start_button->setEnabled(false);
00083 m_outstr = QCString();
00084
00085 delete m_proc;
00086 m_proc = new KShellProcess("/bin/sh");
00087 (*m_proc) << combo->currentText();
00088 connect( m_proc, SIGNAL(receivedStdout(KProcess*, char *, int)),
00089 this, SLOT(slotReceivedStdout(KProcess*, char *, int)) );
00090 connect( m_proc, SIGNAL(wroteStdin(KProcess*)),
00091 this, SLOT(slotWroteStdin(KProcess*)) );
00092 connect( m_proc, SIGNAL(processExited(KProcess*)),
00093 this, SLOT(slotProcessExited(KProcess*)) );
00094 m_proc->start(KProcess::NotifyOnExit, KProcess::All);
00095 m_proc->writeStdin(m_instr, m_instr.length());
00096 }
00097
00098
00099 int ShellFilterDialog::exec()
00100 {
00101 start_button->setEnabled(true);
00102 return QDialog::exec();
00103 }
00104
00105
00106 void ShellFilterDialog::slotReceivedStdout(KProcess *, char *text, int len)
00107 {
00108 m_outstr += QString::fromLocal8Bit(text, len+1);
00109 kdDebug(9029) << "outstr " << m_outstr << endl;
00110 }
00111
00112
00113 void ShellFilterDialog::slotWroteStdin(KProcess *)
00114 {
00115 m_proc->closeStdin();
00116 kdDebug(9029) << "close stdin " << m_outstr << endl;
00117 }
00118
00119
00120 void ShellFilterDialog::slotProcessExited(KProcess *)
00121 {
00122 kdDebug(9029) << "process exit " << m_proc->normalExit() << endl;
00123 if (m_proc->normalExit()) {
00124 accept();
00125 } else {
00126 KMessageBox::error(this, i18n("Process exited with status %1")
00127 .arg(m_proc->exitStatus()));
00128 reject();
00129 }
00130 }
00131
00132 #include "shellfilterdlg.moc"
This file is part of the documentation for KDevelop Version 3.1.2.