23 #include <tdeversion.h> 26 #include <tdelocale.h> 28 #include <tqpainter.h> 29 #include <tqapplication.h> 32 ProcessListBoxItem::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);
45 bool ProcessListBoxItem::isCustomItem()
50 static inline unsigned char normalize(
int a)
52 return (a < 0 ? 0 : a > 255 ? 255 : a);
55 static inline double blend1(
double a,
double b,
double k)
57 return a + (b - a) * k;
60 TQColor 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));
72 void 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);
106 ProcessWidget::ProcessWidget(TQWidget *parent,
const char *name)
107 : TDEListBox(parent, name)
109 setFocusPolicy(TQ_NoFocus);
115 childproc =
new TDEProcess();
116 childproc->setUseShell(
true);
120 connect( procLineMaker, TQT_SIGNAL(receivedStdoutLine(
const TQCString&)),
121 this, TQT_SLOT(insertStdoutLine(
const TQCString&) ));
122 connect( procLineMaker, TQT_SIGNAL(receivedStderrLine(
const TQCString&)),
123 this, TQT_SLOT(insertStderrLine(
const TQCString&) ));
124 connect( procLineMaker, TQT_SIGNAL(receivedPartialStdoutLine(
const TQCString&)),
125 this, TQT_SLOT(addPartialStdoutLine(
const TQCString&) ));
126 connect( procLineMaker, TQT_SIGNAL(receivedPartialStderrLine(
const TQCString&)),
127 this, TQT_SLOT(addPartialStderrLine(
const TQCString&) ));
129 connect(childproc, TQT_SIGNAL(processExited(TDEProcess*)),
130 this, TQT_SLOT(slotProcessExited(TDEProcess*) )) ;
134 ProcessWidget::~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();
172 void ProcessWidget::slotProcessExited(TDEProcess *)
174 procLineMaker->flush();
175 if( !stdoutbuf.isEmpty() )
176 insertStdoutLine(
"");
177 if( !stderrbuf.isEmpty() )
178 insertStderrLine(
"");
179 childFinished(childproc->normalExit(), childproc->exitStatus());
180 maybeScrollToBottom();
181 emit processExited(childproc);
187 if( !stdoutbuf.isEmpty() )
191 ProcessListBoxItem::Normal ),
193 stdoutbuf.truncate( 0 );
197 ProcessListBoxItem::Normal) );
199 lastRowStdout = count() - 1;
200 maybeScrollToBottom();
206 if( !stderrbuf.isEmpty() )
210 ProcessListBoxItem::Error ),
212 stderrbuf.truncate( 0 );
216 ProcessListBoxItem::Error) );
218 lastRowStderr = count() - 1;
219 maybeScrollToBottom();
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;
252 TQSize ProcessWidget::minimumSizeHint()
const 257 return TQSize( TQListBox::sizeHint().width(),
258 (fontMetrics().lineSpacing()+2)*4 );
267 if ( verticalScrollBar()->value() == verticalScrollBar()->maxValue() )
269 setBottomItem( count() -1 );
273 void ProcessWidget::addPartialStderrLine(
const TQCString& linepart)
275 stderrbuf += linepart;
278 void ProcessWidget::addPartialStdoutLine(
const TQCString& linepart)
280 stdoutbuf += linepart;
283 #include "processwidget.moc"
Convenience class to catch output of TDEProcess.
Utility objects for process output views.
Listbox item for process widgets.