1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
|
/***************************************************************************
* Copyright (C) 2002 by Bernd Gehrmann *
* [email protected] *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#include "shellfilterdlg.h"
#include <tqcombobox.h>
#include <tqlayout.h>
#include <tqpushbutton.h>
#include <kbuttonbox.h>
#include <kconfig.h>
#include <kdebug.h>
#include <klocale.h>
#include <kmessagebox.h>
#include <kprocess.h>
#include <kstdguiitem.h>
#include <kdeversion.h>
#include "kdevplugin.h"
#include "domutil.h"
#include "filterpart.h"
ShellFilterDialog::ShellFilterDialog()
: TQDialog(0, "shell filter dialog", true)
{
TQVBoxLayout *tqlayout = new TQVBoxLayout(this, 10, 4);
combo = new TQComboBox(true, this);
combo->setDuplicatesEnabled(false);
tqlayout->addWidget(combo);
KButtonBox *buttonbox = new KButtonBox(this);
start_button = buttonbox->addButton(i18n("&Start"));
start_button->setDefault(true);
cancel_button = buttonbox->addButton(KStdGuiItem::cancel());
buttonbox->tqlayout();
tqlayout->addWidget(buttonbox);
connect( start_button, TQT_SIGNAL(clicked()),
this, TQT_SLOT(slotStartClicked()) );
connect( cancel_button, TQT_SIGNAL(clicked()),
this, TQT_SLOT(reject()) );
m_proc = 0;
KConfig *config = FilterFactory::instance()->config();
config->setGroup("General");
combo->insertStringList(config->readListEntry("filteritems"));
}
ShellFilterDialog::~ShellFilterDialog()
{
kdDebug(9029) << "~ShellFilterDialog" << endl;
delete m_proc;
// TQComboBox API is a bit incomplete :-(
TQStringList list;
for (int i=0; i < combo->count(); ++i)
list << combo->text(i);
KConfig *config = FilterFactory::instance()->config();
config->setGroup("General");
config->writeEntry("filteritems", list);
}
void ShellFilterDialog::slotStartClicked()
{
start_button->setEnabled(false);
m_outstr = TQCString();
delete m_proc;
m_proc = new KShellProcess("/bin/sh");
(*m_proc) << combo->currentText();
connect( m_proc, TQT_SIGNAL(receivedStdout(KProcess*, char *, int)),
this, TQT_SLOT(slotReceivedStdout(KProcess*, char *, int)) );
connect( m_proc, TQT_SIGNAL(wroteStdin(KProcess*)),
this, TQT_SLOT(slotWroteStdin(KProcess*)) );
connect( m_proc, TQT_SIGNAL(processExited(KProcess*)),
this, TQT_SLOT(slotProcessExited(KProcess*)) );
m_proc->start(KProcess::NotifyOnExit, KProcess::All);
m_proc->writeStdin(m_instr, m_instr.length());
}
int ShellFilterDialog::exec()
{
start_button->setEnabled(true);
return TQDialog::exec();
}
void ShellFilterDialog::slotReceivedStdout(KProcess *, char *text, int len)
{
m_outstr += TQString::fromLocal8Bit(text, len+1);
kdDebug(9029) << "outstr " << m_outstr << endl;
}
void ShellFilterDialog::slotWroteStdin(KProcess *)
{
m_proc->closeStdin();
kdDebug(9029) << "close stdin " << m_outstr << endl;
}
void ShellFilterDialog::slotProcessExited(KProcess *)
{
kdDebug(9029) << "process exit " << m_proc->normalExit() << endl;
if (m_proc->normalExit()) {
accept();
} else {
KMessageBox::error(this, i18n("Process exited with status %1")
.tqarg(m_proc->exitStatus()));
reject();
}
}
#include "shellfilterdlg.moc"
|