//
// 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 "Depot.h"
#include "P4Client.h"
#include <qstringlist.h>
namespace Perforce {
Depot::DepotListCache Depot::_depotListCache;
const DepotList& Depot::getDepots( bool forceFlush )
{
return _depotListCache.getCache( forceFlush );
}
DirEntry* Depot::getDirEntry( const QString& fullPath,
bool forceFlush )
{
return _dirsListCache.getDirEntry( fullPath, forceFlush );
}
DepotPtr Depot::getDepot( const QString& name )
{
DepotList lst = getDepots();
for (Depot* d = lst.first(); d != NULL; d = lst.next()) {
ASSERT( d != NULL );
if (d->getName() == name) {
return d;
}
}
return NULL;
}
void Depot::DepotListCache::HandleError( Error* err )
{
qWarning( "Failed to update the depot list cache." );
}
void Depot::DepotListCache::OutputInfo( char level, char *data )
{
QStringList lst = QStringList::split( " ", QString(data) );
ASSERT( lst[0] == "Depot" );
Depot* d = new Depot();
d->_name = lst[1];
QStringList temp = QStringList::split( "/", lst[2] );
// TODO: set date.
d->_type = lst[3];
d->_address = lst[4];
d->_map = lst[5];
d->_description = lst[6];
_cache.append( d );
}
void Depot::DepotListCache::updateCache()
{
char* p[] = { "" };
RunP4Command( 0, p, "depots", this );
}
const DirEntryList& Depot::getDirEntries( bool forceFlush )
{
return _dirsListCache.getCache( forceFlush );
}
void Depot::DirsListCache::HandleError( Error* err )
{
qWarning( "Failed to update dir list caceh." );
}
void Depot::DirsListCache::updateCache()
{
QString depot = "//" + _parent->getName() + "/*";
char* argv[] = { "-C", const_cast<char *>(depot.latin1()) };
RunP4Command( 2, argv, "dirs", this );
}
DirEntry* Depot::DirsListCache::getDirEntry( const QString& path,
bool forceFlush )
{
qDebug( "looking for: %s", path.latin1() );
for (DirEntry* d = _cache.first(); d != NULL; d = _cache.next()) {
ASSERT( d != NULL );
// qDebug( "Looking at direntry: %s", d->getFullPath().latin1() );
if (path.startsWith(d->getFullPath())) {
// this may be it...
if (d->getFullPath() == path) {
qDebug( "Found match!" );
return d;
}
else {
// traverse...
return d->getDirEntry( path );
}
}
}
return NULL;
}
void Depot::DirsListCache::OutputStat( StrDict *varList )
{
ASSERT( varList != NULL );
char* name = varList->GetVar( "dir" )->Text();
ASSERT( name != NULL );
DirEntry* d = new DirEntry( name );
_cache.append( d );
}
} // end namespace