1
/***************************************************************************
2
* Copyright (C) 2002 by Bernd Gehrmann *
5
* This program is free software; you can redistribute it and/or modify *
6
* it under the terms of the GNU General Public License as published by *
7
* the Free Software Foundation; either version 2 of the License, or *
8
* (at your option) any later version. *
10
***************************************************************************/
12
#include "shellinsertdlg.h"
14
#include <qcombobox.h>
16
#include <qpushbutton.h>
18
#include <kbuttonbox.h>
21
#include <kmessagebox.h>
23
#include <klineedit.h>
24
#include <kstdguiitem.h>
25
#include <kdeversion.h>
27
#include "kdevplugin.h"
29
#include "filterpart.h"
32
ShellInsertDialog::ShellInsertDialog()
33
: QDialog(0, "shell filter dialog", true)
35
QVBoxLayout *layout = new QVBoxLayout(this, 10, 4);
37
combo = new QComboBox(true, this);
38
combo->setDuplicatesEnabled(false);
39
layout->addWidget(combo);
41
KButtonBox *buttonbox = new KButtonBox(this);
42
start_button = buttonbox->addButton(i18n("&Start"));
43
start_button->setDefault(true);
44
#if KDE_IS_VERSION( 3, 2, 90 )
45
cancel_button = buttonbox->addButton(KStdGuiItem::cancel());
47
cancel_button = buttonbox->addButton(i18n("Cancel"));
50
layout->addWidget(buttonbox);
52
connect( start_button, SIGNAL(clicked()),
53
this, SLOT(slotStartClicked()) );
54
connect( cancel_button, SIGNAL(clicked()),
55
this, SLOT(reject()) );
56
connect( combo->lineEdit(), SIGNAL(textChanged( const QString &)), this, SLOT(executeTextChanged( const QString &)));
59
KConfig *config = FilterFactory::instance()->config();
60
config->setGroup("General");
61
QStringList items = config->readListEntry("InsertItems");
62
combo->insertStringList(items);
63
executeTextChanged( combo->lineEdit()->text());
68
ShellInsertDialog::~ShellInsertDialog()
70
kdDebug(9029) << "~ShellInsertDialog" << endl;
73
// QComboBox API is a bit incomplete :-(
75
for (int i=0; i < combo->count(); ++i)
76
list << combo->text(i);
78
KConfig *config = FilterFactory::instance()->config();
79
config->setGroup("General");
80
config->writeEntry("InsertItems", list);
84
void ShellInsertDialog::executeTextChanged( const QString &text)
86
start_button->setEnabled(!text.isEmpty());
89
int ShellInsertDialog::exec()
91
start_button->setEnabled(true);
92
return QDialog::exec();
96
void ShellInsertDialog::slotStartClicked()
98
start_button->setEnabled(false);
102
m_proc = new KShellProcess("/bin/sh");
103
(*m_proc) << combo->currentText();
104
connect( m_proc, SIGNAL(receivedStdout(KProcess*, char *, int)),
105
this, SLOT(slotReceivedStdout(KProcess*, char *, int)) );
106
connect( m_proc, SIGNAL(processExited(KProcess*)),
107
this, SLOT(slotProcessExited(KProcess*)) );
108
m_proc->start(KProcess::NotifyOnExit, KProcess::AllOutput);
112
void ShellInsertDialog::slotReceivedStdout(KProcess *, char *text, int len)
114
m_str += QCString(text, len+1);
118
void ShellInsertDialog::slotProcessExited(KProcess *)
120
if (m_proc->normalExit()) {
123
KMessageBox::error(this, i18n("Process exited with status %1")
124
.arg(m_proc->exitStatus()));
129
#include "shellinsertdlg.moc"