33 #include "collectingprocess.h"
35 #include <tqvaluelist.h>
41 struct CollectingProcess::Private {
42 Private() : stdoutSize( 0 ), stderrSize( 0 )
46 TQValueList<TQByteArray> stdoutBuffer;
48 TQValueList<TQByteArray> stderrBuffer;
52 CollectingProcess::CollectingProcess( TQObject * parent,
const char * name )
53 : TDEProcess( parent, name )
58 CollectingProcess::~CollectingProcess() {
64 disconnect(
this, TQ_SIGNAL( receivedStdout( TDEProcess *,
char *,
int ) ),
65 this, TQ_SLOT( slotReceivedStdout( TDEProcess *,
char *,
int ) ) );
66 if ( comm & Stdout ) {
67 connect(
this, TQ_SIGNAL( receivedStdout( TDEProcess *,
char *,
int ) ),
68 this, TQ_SLOT( slotReceivedStdout( TDEProcess *,
char *,
int ) ) );
71 disconnect(
this, TQ_SIGNAL( receivedStderr( TDEProcess *,
char *,
int ) ),
72 this, TQ_SLOT( slotReceivedStderr( TDEProcess *,
char *,
int ) ) );
73 if ( comm & Stderr ) {
74 connect(
this, TQ_SIGNAL( receivedStderr( TDEProcess *,
char *,
int ) ),
75 this, TQ_SLOT( slotReceivedStderr( TDEProcess *,
char *,
int ) ) );
77 return TDEProcess::start( runmode, comm );
80 void CollectingProcess::slotReceivedStdout( TDEProcess *,
char *buf,
int len )
83 b.duplicate( buf, len );
84 d->stdoutBuffer.append( b );
88 void CollectingProcess::slotReceivedStderr( TDEProcess *,
char *buf,
int len )
91 b.duplicate( buf, len );
92 d->stderrBuffer.append( b );
98 if ( d->stdoutSize == 0 ) {
103 TQByteArray b( d->stdoutSize );
104 for ( TQValueList<TQByteArray>::const_iterator it = d->stdoutBuffer.begin();
105 it != d->stdoutBuffer.end();
107 memcpy( b.data() + offset, (*it).data(), (*it).size() );
108 offset += (*it).size();
110 d->stdoutBuffer.clear();
118 if ( d->stderrSize == 0 ) {
119 return TQByteArray();
123 TQByteArray b( d->stderrSize );
124 for ( TQValueList<TQByteArray>::const_iterator it = d->stderrBuffer.begin();
125 it != d->stderrBuffer.end();
127 memcpy( b.data() + offset, (*it).data(), (*it).size() );
128 offset += (*it).size();
130 d->stderrBuffer.clear();
136 void CollectingProcess::virtual_hook(
int id,
void * data ) {
137 TDEProcess::virtual_hook(
id, data );
140 #include "collectingprocess.moc"
TQByteArray collectedStderr()
Returns the contents of the stderr buffer and clears it afterwards.
bool start(RunMode runmode, Communication comm)
Starts the process in NotifyOnExit mode and writes in to stdin of the process.
TQByteArray collectedStdout()
Returns the contents of the stdout buffer and clears it afterwards.
TDEPIM classes for drag and drop of mails.