23#include <tdeversion.h>
29#include <tqapplication.h>
32ProcessListBoxItem::ProcessListBoxItem(
const TQString &s, Type type)
33 : TQListBoxText(s), t(type)
36 clean.replace( TQChar(
'\t'), TQString(
" ") );
37 clean.replace( TQChar(
'\n'), TQString() );
38 clean.replace( TQChar(
'\r'), TQString() );
41 setCustomHighlighting(
true);
45bool ProcessListBoxItem::isCustomItem()
50static inline unsigned char normalize(
int a)
52 return (a < 0 ? 0 : a > 255 ? 255 : a);
55static inline double blend1(
double a,
double b,
double k)
57 return a + (b - a) * k;
60TQColor ProcessListBoxItem::blend(
const TQColor &c1,
const TQColor &c2,
double k)
const
62 if (k < 0.0)
return c1;
63 if (k > 1.0)
return c2;
65 int r = normalize((
int)blend1((
double)c1.red(), (
double)c2.red(), k));
66 int g = normalize((
int)blend1((
double)c1.green(), (
double)c2.green(), k));
67 int b = normalize((
int)blend1((
double)c1.blue(), (
double)c2.blue(), k));
69 return TQColor(tqRgb(r, g, b));
72void ProcessListBoxItem::paint(TQPainter *p)
74 TQColor dim, warn, err, back;
76 const TQColorGroup& group = listBox()->palette().active();
78 back = group.button();
79 warn = group.buttonText();
86 err = group.linkVisited();
87 dim = blend(warn, back);
95 back = TQt::lightGray;
99 p->fillRect(p->window(), TQBrush(back));
100 p->setPen((t==Error)? err :
101 (t==Diagnostic)? warn : dim);
102 TQListBoxText::paint(p);
106ProcessWidget::ProcessWidget(TQWidget *parent,
const char *name)
107 : TDEListBox(parent, name)
109 setFocusPolicy(TQWidget::NoFocus);
115 childproc =
new TDEProcess();
116 childproc->setUseShell(
true);
120 connect( procLineMaker, TQ_SIGNAL(receivedStdoutLine(
const TQCString&)),
121 this, TQ_SLOT(insertStdoutLine(
const TQCString&) ));
122 connect( procLineMaker, TQ_SIGNAL(receivedStderrLine(
const TQCString&)),
123 this, TQ_SLOT(insertStderrLine(
const TQCString&) ));
124 connect( procLineMaker, TQ_SIGNAL(receivedPartialStdoutLine(
const TQCString&)),
125 this, TQ_SLOT(addPartialStdoutLine(
const TQCString&) ));
126 connect( procLineMaker, TQ_SIGNAL(receivedPartialStderrLine(
const TQCString&)),
127 this, TQ_SLOT(addPartialStderrLine(
const TQCString&) ));
129 connect(childproc, TQ_SIGNAL(processExited(TDEProcess*)),
130 this, TQ_SLOT(slotProcessExited(TDEProcess*) )) ;
134ProcessWidget::~ProcessWidget()
137 delete procLineMaker;
143 procLineMaker->clearBuffers();
144 procLineMaker->blockSignals(
false );
148 childproc->clearArguments();
150 childproc->setWorkingDirectory( dir );
153 *childproc << command;
154 childproc->start(TDEProcess::OwnGroup, TDEProcess::AllOutput);
160 procLineMaker->blockSignals(
true );
162 childproc->kill( signo );
168 return childproc->isRunning();
172void ProcessWidget::slotProcessExited(TDEProcess *)
174 procLineMaker->flush();
175 if( !stdoutbuf.isEmpty() )
177 if( !stderrbuf.isEmpty() )
179 childFinished(childproc->normalExit(), childproc->exitStatus());
181 emit processExited(childproc);
187 if( !stdoutbuf.isEmpty() )
191 ProcessListBoxItem::Normal ),
193 stdoutbuf.truncate( 0 );
197 ProcessListBoxItem::Normal) );
199 lastRowStdout = count() - 1;
206 if( !stderrbuf.isEmpty() )
210 ProcessListBoxItem::Error ),
212 stderrbuf.truncate( 0 );
216 ProcessListBoxItem::Error) );
218 lastRowStderr = count() - 1;
226 ProcessListBoxItem::Type t;
230 s = i18n(
"*** Exited with status: %1 ***").arg(status);
231 t = ProcessListBoxItem::Error;
233 s = i18n(
"*** Exited normally ***");
234 t = ProcessListBoxItem::Diagnostic;
237 if ( childproc->signalled() && childproc->exitSignal() == SIGSEGV )
239 s = i18n(
"*** Process aborted. Segmentation fault ***");
243 s = i18n(
"*** Process aborted ***");
245 t = ProcessListBoxItem::Error;
252TQSize ProcessWidget::minimumSizeHint()
const
257 return TQSize( TQListBox::sizeHint().width(),
258 (fontMetrics().lineSpacing()+2)*4 );
267 if ( verticalScrollBar()->value() == verticalScrollBar()->maxValue() )
269 setBottomItem( count() -1 );
273void ProcessWidget::addPartialStderrLine(
const TQCString& linepart)
275 stderrbuf += linepart;
278void ProcessWidget::addPartialStdoutLine(
const TQCString& linepart)
280 stdoutbuf += linepart;
283#include "processwidget.moc"
Convenience class to catch output of TDEProcess.
Listbox item for process widgets.
Utility objects for process output views.