//
// 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
//
//
#include "Change.h"
#include "P4Client.h"
#include <qpixmap.h>
#include <qstringlist.h>
namespace Perforce {
Change::ChangesCache Change::_changesCache;
Change::PendingChangesCache Change::_pendingChangesCache;
//========================================================================
//
// static factory method
//
Change* Change::create_change( StrDict* varList )
{
Change* cl = new Change();
QString temp = varList->GetVar( "time" )->Text();
cl->_date.setTime_t( temp.toInt() );
cl->_description = varList->GetVar( "desc" )->Text();
IUpdateable< Change* >::replaceNewlinesWithSpaces( cl->_description );
cl->_name = varList->GetVar( "change" )->Text();
cl->_user = varList->GetVar( "user" )->Text();
cl->_client = varList->GetVar( "client" )->Text();
return cl;
}
const ChangesList& Change::getChanges()
{
_changesCache.updateCacheIfNecessary();
return _changesCache.getCache();
}
const ChangesList& Change::getPendingChanges()
{
_pendingChangesCache.updateCacheIfNecessary();
return _pendingChangesCache.getCache();
}
void Change::ChangesCache::updateCache()
{
char* p[] = { "-m", "100", "-l", "-s", "submitted" };
RunP4Command( 5, p, "changes", this );
}
void Change::PendingChangesCache::updateCache()
{
// add the default change explicitly
Change* def = new Change();
def->_name = "default";
def->_description = "This is the default changelist dude";
_cache.append( def );
char* p[] = { "-s", "pending" };
RunP4Command( 2, p, "changes", this );
OpenedFilesUI* ui = new OpenedFilesUI();
ui->_changes = &this->_cache;
RunP4Command( 0, NULL, "opened", ui );
delete ui;
}
void Change::ChangesCache::OutputStat( StrDict* varList )
{
// sanity check
QString temp = varList->GetVar( "status" )->Text();
ASSERT( temp.lower() == "submitted" );
Change*cl = create_change( varList );
_cache.append( cl );
}
void Change::PendingChangesCache::OutputStat( StrDict* varList )
{
ASSERT( varList != NULL );
// sanity check
QString temp = varList->GetVar( "status" )->Text();
ASSERT( temp.lower() == "pending" );
Change* cl = create_change( varList );
_cache.append( cl );
}
void Change::ChangesCache::HandleError( Error* err )
{
ASSERT( 0 && "ERROR" );
}
void Change::PendingChangesCache::HandleError( Error* err )
{
ASSERT( 0 && "Error" );
}
void Change::OpenedFilesUI::HandleError( Error* err )
{
ASSERT( 0 && "Error Getting opened files" );
}
void Change::OpenedFilesUI::OutputStat( StrDict* varList )
{
ASSERT( varList != NULL );
QString temp;
FileEntry* f = new FileEntry();
f->setDepotFile( varList->GetVar("depotFile")->Text() );
f->setClient( varList->GetVar("clientFile")->Text() );
temp = varList->GetVar( "rev" )->Text();
f->setRevision( temp.toInt() );
f->setAction( varList->GetVar("action")->Text() );
f->setChange( varList->GetVar("change")->Text() );
f->setType( varList->GetVar("type")->Text() );
f->setUser( varList->GetVar("user")->Text() );
f->setClient( varList->GetVar("client")->Text() );
// add this file entry to the proper change
bool foundHome = false;
for (Change* c = _changes->first(); c != NULL; c = _changes->next()) {
ASSERT( c != NULL );
if (c->getName() == f->getChange()) {
c->_openedFiles.append( f );
foundHome = true;
}
}
if (!foundHome) {
qDebug( "FileEntry doesn't have matching change cached!" );
qDebug( "FileEntry.change: %s", f->getChange().latin1() );
qDebug( "Cached changes" );
for (Change* c = _changes->first(); c != NULL; c = _changes->next()) {
ASSERT( c != NULL );
qDebug( "Change.Name=%s", c->getName().latin1() );
}
qDebug( "End cached changes" );
}
}
} // end namespace