#include "DirEntry.h"
#include "error.h"
#include "P4Client.h"
#include <qstringlist.h>
namespace Perforce {
const QString DirEntry::getName()
{
QStringList lst = QStringList::split( "/", _fullPath );
return lst.last();
}
const DirEntryList& DirEntry::getDirs( bool forceFlush )
{
return _dirEntryCache.getCache( forceFlush );
}
const FileEntryList& DirEntry::getFiles( bool forceFlush )
{
return _fileEntryCache.getCache( forceFlush );
}
DirEntry* DirEntry::getDirEntry( const QString& fullPath, bool forceFlush )
{
DirEntryList lst = _dirEntryCache.getCache( forceFlush );
for (DirEntry* d = lst.first(); d != NULL; d = lst.next()) {
if (fullPath.startsWith(d->getFullPath())) {
if (d->getFullPath() == fullPath) {
return d;
}
else {
return d->getDirEntry( fullPath, forceFlush );
}
}
}
return NULL;
}
void DirEntry::DirEntryCache::HandleError( Error* err )
{
qWarning( "Failed to update dir entry cache." );
}
void DirEntry::DirEntryCache::OutputStat( StrDict* varList )
{
ASSERT( varList != NULL );
char* name = varList->GetVar( "dir" )->Text();
ASSERT( name != NULL );
DirEntry* d = new DirEntry( name );
_cache.append( d );
}
void DirEntry::DirEntryCache::updateCache()
{
QString temp = _parent->_fullPath + "/*";
char* p[] = { "-C", const_cast<char *>(temp.latin1()) };
RunP4Command( 2, p, "dirs", this );
}
}