//
//
// QPerforce is a gui interface to the perforce revision control
// system. It is based on the qt library, and should be easily portable
// across any platform that has this toolkit available.
//
// Copyright (C) 2002 Jacob Gladish
//
// TODO: find legit copyright.
//
#include "P4Process.h"
#include "BranchSpec.h"
#include "ConfigOptions.h"
#include "qperforceWindow.h"
#include "SubmittedChangeList.h"
#include <qstring.h>
#include <qapplication.h>
static const QString ROOT_COMMAND = "p4";
P4Process::P4Process()
{
}
P4Process::~P4Process()
{
}
void P4Process::exec( const QString& args, bool forceSupressOutput )
{
// print to status pane of configuration is set.
ConfigOptions* opts = ConfigOptions::getInstance();
if (opts->showP4Commands() && !forceSupressOutput) {
QString msg;
msg.sprintf( "<img src=\"img.exec\" height=12 width=12/> <b>Executing:</b> "
" <code>%s</code>", args.latin1() );
qperforceWindow* win = qperforceWindow::getInstance();
win->appendUserMessage( msg );
}
qDebug( "Setting wait cursor." );
QApplication::setOverrideCursor( Qt::waitCursor );
#ifdef WIN32
_win32Exec( args );
#else
// other platofrm code here.
// use QProcess if we get qt > 3.x
#endif
qDebug( "Setting arrow cursor." );
QApplication::restoreOverrideCursor();
}
const Perforce::UserList P4Process::getUsers()
{
Perforce::UserList l;
// l.setAutoDelete( true );
// blocks here until command completes...
exec( "p4 users" );
// qDebug( "Number of lines: %d", _cmdStdOutput.count() );
// qDebug( "First Entry: %s", _cmdStdOutput[0].latin1() );
// qDebug( "Last Entry: %s", _cmdStdOutput[_cmdStdOutput.count()-1].latin1() );
// parse returned data, and construct list.
QStringList::Iterator iter;
for (iter = _cmdStdOutput.begin(); iter != _cmdStdOutput.end(); ++iter) {
Perforce::User* u = Perforce::User::createNewUser( *iter );
l.append( u );
}
return l;
}
const Perforce::SubmittedChangeListList P4Process::getSubmittedChangeLists()
{
Perforce::SubmittedChangeListList l;
exec( "p4 changes -m 100 -s submitted" );
QStringList::Iterator iter;
for (iter = _cmdStdOutput.begin(); iter != _cmdStdOutput.end(); ++iter) {
Perforce::SubmittedChangeList* scl =
Perforce::SubmittedChangeList::createNewChangeList( *iter );
l.append( scl );
}
return l;
}
const Perforce::BranchSpecList P4Process::getBranchSpecs()
{
exec( "p4 branches" );
Perforce::BranchSpecList l;
QStringList::Iterator iter;
for (iter = _cmdStdOutput.begin(); iter != _cmdStdOutput.end(); ++iter) {
Perforce::BranchSpec* bs = Perforce::BranchSpec::createBranchSpec( *iter );
l.append( bs );
}
return l;
}
const Perforce::JobList P4Process::getJobs()
{
exec( "p4 jobs" );
Perforce::JobList l;
QStringList::Iterator iter;
for (iter = _cmdStdOutput.begin(); iter != _cmdStdOutput.end(); ++iter) {
Perforce::Job* j = Perforce::Job::createJob( (*iter) );
l.append( j );
}
return l;
}
// template <class T1, class T2>
// const T2 execute_perforce( const QString& cmdline )
// {
// T2 t;
// execute( cmdLine );
//
// QStringList::Iterator iter;
// for (iter = _cmdStdOutput.begin(); iter != _cmdStdOutput.end(); ++iter) {
// T1* bs = T1::createNewObject( *iter );
// T2.append( bs );
// }
//
// return T2;
// }