28#include <tqapplication.h>
31ProcessListBoxItem::ProcessListBoxItem(
const TQString &s, Type type)
32 : TQListBoxText(s), t(type)
35 clean.replace( TQChar(
'\t'), TQString(
" ") );
36 clean.replace( TQChar(
'\n'), TQString() );
37 clean.replace( TQChar(
'\r'), TQString() );
40 setCustomHighlighting(
true);
44bool ProcessListBoxItem::isCustomItem()
49static inline unsigned char normalize(
int a)
51 return (a < 0 ? 0 : a > 255 ? 255 : a);
54static inline double blend1(
double a,
double b,
double k)
56 return a + (b - a) * k;
59TQColor ProcessListBoxItem::blend(
const TQColor &c1,
const TQColor &c2,
double k)
const
61 if (k < 0.0)
return c1;
62 if (k > 1.0)
return c2;
64 int r = normalize((
int)blend1((
double)c1.red(), (
double)c2.red(), k));
65 int g = normalize((
int)blend1((
double)c1.green(), (
double)c2.green(), k));
66 int b = normalize((
int)blend1((
double)c1.blue(), (
double)c2.blue(), k));
68 return TQColor(tqRgb(r, g, b));
71void ProcessListBoxItem::paint(TQPainter *p)
73 TQColor dim, warn, err, back;
75 const TQColorGroup& group = listBox()->palette().active();
77 back = group.button();
78 warn = group.buttonText();
85 err = group.linkVisited();
86 dim = blend(warn, back);
94 back = TQt::lightGray;
98 p->fillRect(p->window(), TQBrush(back));
99 p->setPen((t==Error)? err :
100 (t==Diagnostic)? warn : dim);
101 TQListBoxText::paint(p);
105ProcessWidget::ProcessWidget(TQWidget *parent,
const char *name)
106 : TDEListBox(parent, name)
108 setFocusPolicy(TQWidget::NoFocus);
114 childproc =
new TDEProcess();
115 childproc->setUseShell(
true);
119 connect( procLineMaker, TQ_SIGNAL(receivedStdoutLine(
const TQCString&)),
120 this, TQ_SLOT(insertStdoutLine(
const TQCString&) ));
121 connect( procLineMaker, TQ_SIGNAL(receivedStderrLine(
const TQCString&)),
122 this, TQ_SLOT(insertStderrLine(
const TQCString&) ));
123 connect( procLineMaker, TQ_SIGNAL(receivedPartialStdoutLine(
const TQCString&)),
124 this, TQ_SLOT(addPartialStdoutLine(
const TQCString&) ));
125 connect( procLineMaker, TQ_SIGNAL(receivedPartialStderrLine(
const TQCString&)),
126 this, TQ_SLOT(addPartialStderrLine(
const TQCString&) ));
128 connect(childproc, TQ_SIGNAL(processExited(TDEProcess*)),
129 this, TQ_SLOT(slotProcessExited(TDEProcess*) )) ;
133ProcessWidget::~ProcessWidget()
136 delete procLineMaker;
142 procLineMaker->clearBuffers();
143 procLineMaker->blockSignals(
false );
147 childproc->clearArguments();
149 childproc->setWorkingDirectory( dir );
152 *childproc << command;
153 childproc->start(TDEProcess::OwnGroup, TDEProcess::AllOutput);
159 procLineMaker->blockSignals(
true );
161 childproc->kill( signo );
167 return childproc->isRunning();
171void ProcessWidget::slotProcessExited(TDEProcess *)
173 procLineMaker->flush();
174 if( !stdoutbuf.isEmpty() )
176 if( !stderrbuf.isEmpty() )
178 childFinished(childproc->normalExit(), childproc->exitStatus());
180 emit processExited(childproc);
186 if( !stdoutbuf.isEmpty() )
190 ProcessListBoxItem::Normal ),
192 stdoutbuf.truncate( 0 );
196 ProcessListBoxItem::Normal) );
198 lastRowStdout = count() - 1;
205 if( !stderrbuf.isEmpty() )
209 ProcessListBoxItem::Error ),
211 stderrbuf.truncate( 0 );
215 ProcessListBoxItem::Error) );
217 lastRowStderr = count() - 1;
225 ProcessListBoxItem::Type t;
229 s = i18n(
"*** Exited with status: %1 ***").arg(status);
230 t = ProcessListBoxItem::Error;
232 s = i18n(
"*** Exited normally ***");
233 t = ProcessListBoxItem::Diagnostic;
236 if ( childproc->signalled() && childproc->exitSignal() == SIGSEGV )
238 s = i18n(
"*** Process aborted. Segmentation fault ***");
242 s = i18n(
"*** Process aborted ***");
244 t = ProcessListBoxItem::Error;
251TQSize ProcessWidget::minimumSizeHint()
const
256 return TQSize( TQListBox::sizeHint().width(),
257 (fontMetrics().lineSpacing()+2)*4 );
266 if ( verticalScrollBar()->value() == verticalScrollBar()->maxValue() )
268 setBottomItem( count() -1 );
272void ProcessWidget::addPartialStderrLine(
const TQCString& linepart)
274 stderrbuf += linepart;
277void ProcessWidget::addPartialStdoutLine(
const TQCString& linepart)
279 stdoutbuf += linepart;
282#include "processwidget.moc"
Convenience class to catch output of TDEProcess.
Listbox item for process widgets.
Utility objects for process output views.