// Implementation of QTreeDiffRunner.
#include <qapplication.h>
#include "qtreediffrunner.h"
QTreeDiffRunner::QTreeDiffRunner
( QWidget* parent, const char* diffprog, FileSys* t1, FileSys* t2, QString n1, QString n2 )
: QObject(), temp1( t1 ), temp2( t2 )
{
// Create the process with the temp file arguments.
QString dprog( diffprog );
pro = new QProcess( dprog, parent, "$P4DIFF" );
pro->addArgument( t1->Path().Text() );
pro->addArgument( t2->Path().Text() );
if ( dprog.endsWith( "p4diff.exe" ) || dprog.endsWith( "p4diff")
|| dprog.endsWith( "squid.exe" ) || dprog.endsWith( "squid" ) )
{
pro->addArgument( "-l" );
pro->addArgument( n1 );
pro->addArgument( "-r" );
pro->addArgument( n2 ) ;
}
if ( !( pro->launch( QString::null ) ) ) //failed launch
{
QMessageBox::warning
(
parent,
"Diff Error",
QString( "Could not launch " ) + diffprog,
QMessageBox::Ok,
QMessageBox::NoButton,
QMessageBox::NoButton
);
Cleanup();
}
else
{
// When the process exits, clean up the temp files.
connect( pro, SIGNAL( processExited() ), this, SLOT( Cleanup() ) );
// If this app is about to quit, kill the process.
connect( qApp, SIGNAL( aboutToQuit() ), this, SLOT( Close() ) );
}
}
QTreeDiffRunner::~QTreeDiffRunner()
{
}
void QTreeDiffRunner::Cleanup()
{
temp1->Unlink();
temp2->Unlink();
delete temp1;
delete temp2;
delete this;
}
void QTreeDiffRunner::Close()
{
pro->kill();
Cleanup();
}