/*
    knetd, KDE Network Daemon

    Copyright (c) 2005 by Engin AYDOGAN		<engin @ bzzzt.biz>

    *************************************************************************
    *                                                                       *
    * 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 "processwrapper.h"

ProcessWrapper::ProcessWrapper()
{
	setEnvironment( "LANG", "C" );
	setEnvironment( "LC_ALL", "C" );
	connect( this, SIGNAL( receivedStdout( KProcess*, char*, int ) ),
		this, SLOT( slotStdout( KProcess*, char*, int ) ) );
	connect( this, SIGNAL( receivedStderr( KProcess*, char*, int ) ),
		this, SLOT( slotStderr( KProcess*, char*, int ) ) );
	connect( this, SIGNAL( processExited( KProcess* ) ),
		this, SLOT( slotExited( KProcess* ) ) );
}

bool
ProcessWrapper::start( RunMode r, Communication c )
{
	return KProcess::start( r, c );
}

void
ProcessWrapper::slotStdout( KProcess*, char* buf, int len )
{
	m_stdoutBuf += QString::fromLatin1( buf, len );
}

void
ProcessWrapper::slotStderr( KProcess*, char* buf, int len )
{
	m_stderrBuf += QString::fromLatin1( buf, len );
}

void
ProcessWrapper::slotExited( KProcess* )
{
	if( !m_stdoutBuf.isNull() )
	{
		emit stdoutReady( m_stdoutBuf );
	}
	if( !m_stderrBuf.isNull() )
	{
		emit stderrReady( m_stderrBuf );
	}
	m_stdoutBuf = QString::null;
	m_stderrBuf = QString::null;
}

#include "processwrapper.moc"
