00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
#include "shellinsertdlg.h"
00013
00014
#include <qcombobox.h>
00015
#include <qlayout.h>
00016
#include <qpushbutton.h>
00017
#include <kconfig.h>
00018
#include <kbuttonbox.h>
00019
#include <kdebug.h>
00020
#include <klocale.h>
00021
#include <kmessagebox.h>
00022
#include <kprocess.h>
00023
#include <klineedit.h>
00024
00025
#include "kdevplugin.h"
00026
#include "domutil.h"
00027
#include "filterpart.h"
00028
00029
00030 ShellInsertDialog::ShellInsertDialog()
00031 :
QDialog(0, "shell filter dialog", true)
00032 {
00033
QVBoxLayout *layout =
new QVBoxLayout(
this, 10, 4);
00034
00035
combo =
new QComboBox(
true,
this);
00036
combo->setDuplicatesEnabled(
false);
00037 layout->addWidget(
combo);
00038
00039
KButtonBox *buttonbox =
new KButtonBox(
this);
00040
start_button = buttonbox->
addButton(i18n(
"&Start"));
00041
start_button->setDefault(
true);
00042
cancel_button = buttonbox->
addButton(i18n(
"Cancel"));
00043 buttonbox->
layout();
00044 layout->addWidget(buttonbox);
00045
00046 connect(
start_button, SIGNAL(clicked()),
00047
this, SLOT(
slotStartClicked()) );
00048 connect(
cancel_button, SIGNAL(clicked()),
00049
this, SLOT(reject()) );
00050 connect(
combo->lineEdit(), SIGNAL(textChanged(
const QString &)),
this, SLOT(
executeTextChanged(
const QString &)));
00051
m_proc = 0;
00052
00053
KConfig *config = FilterFactory::instance()->config();
00054 config->
setGroup(
"General");
00055
QStringList items = config->
readListEntry(
"InsertItems");
00056
combo->insertStringList(items);
00057
executeTextChanged(
combo->lineEdit()->text());
00058
00059 }
00060
00061
00062 ShellInsertDialog::~ShellInsertDialog()
00063 {
00064
kdDebug(9029) <<
"~ShellInsertDialog" <<
endl;
00065
delete m_proc;
00066
00067
00068
QStringList list;
00069
for (
int i=0; i <
combo->count(); ++i)
00070 list <<
combo->text(i);
00071
00072
KConfig *config = FilterFactory::instance()->config();
00073 config->
setGroup(
"General");
00074 config->
writeEntry(
"InsertItems", list);
00075 }
00076
00077
00078 void ShellInsertDialog::executeTextChanged(
const QString &text)
00079 {
00080
start_button->setEnabled(!
text.isEmpty());
00081 }
00082
00083 int ShellInsertDialog::exec()
00084 {
00085
start_button->setEnabled(
true);
00086
return QDialog::exec();
00087 }
00088
00089
00090 void ShellInsertDialog::slotStartClicked()
00091 {
00092
start_button->setEnabled(
false);
00093
m_str =
QCString();
00094
00095
delete m_proc;
00096
m_proc =
new KShellProcess(
"/bin/sh");
00097 (*m_proc) <<
combo->currentText();
00098 connect(
m_proc, SIGNAL(receivedStdout(
KProcess*,
char *,
int)),
00099
this, SLOT(
slotReceivedStdout(
KProcess*,
char *,
int)) );
00100 connect(
m_proc, SIGNAL(processExited(
KProcess*)),
00101
this, SLOT(
slotProcessExited(
KProcess*)) );
00102
m_proc->
start(KProcess::NotifyOnExit, KProcess::AllOutput);
00103 }
00104
00105
00106 void ShellInsertDialog::slotReceivedStdout(
KProcess *,
char *text,
int len)
00107 {
00108
m_str +=
QCString(
text,
len+1);
00109 }
00110
00111
00112 void ShellInsertDialog::slotProcessExited(
KProcess *)
00113 {
00114
if (
m_proc->
normalExit()) {
00115 accept();
00116 }
else {
00117 KMessageBox::error(
this, i18n(
"Process exited with status %1")
00118 .arg(
m_proc->
exitStatus()));
00119 reject();
00120 }
00121 }
00122
00123
#include "shellinsertdlg.moc"