#include "FileEntry.h"
#include "DirEntry.h"
#include "ImageManager.h"
#include "P4Client.h"
#include <qstringlist.h>
namespace Perforce
{
QDict< FileEntry::FileEntryCache > FileEntry::_fileEntryCaches;
const FileEntryList& FileEntry::getFileEntries( const QString depotPath )
{
FileEntryCache* cache = _fileEntryCaches.find( depotPath );
if (cache == NULL) {
cache = new FileEntryCache();
cache->_depotPath = depotPath;
_fileEntryCaches.insert( depotPath, cache );
}
cache->updateCacheIfNecessary();
return cache->getCache();
}
QString FileEntry::getGuiLabel() const
{
QString name = getName();
name.append( "#0/" )
.append( QString::number(getRevision()) )
.append( " <" )
.append( getType() )
.append( ">" );
return name;
}
void FileEntry::FileEntryCache::HandleError( Error* err )
{
qWarning( "Failed to update file entry cache." );
}
void FileEntry::FileEntryCache::OutputStat( StrDict* varList )
{
FileEntry* fe = FileEntry::createFileEntry( varList );
if (fe != NULL) {
_cache.append( fe );
}
}
FileEntry* FileEntry::createFileEntry( StrDict* varList )
{
QString temp;
FileEntry* f = new FileEntry();
f->setDepotFile( varList->GetVar("depotFile")->Text() );
StrPtr* fname = varList->GetVar("clientFile");
f->setClient( varList->GetVar("clientFile")->Text() );
StrPtr* p = varList->GetVar( "headRev" );
if (p == NULL) {
// this file has not yet been checked in...
return NULL;
}
temp = varList->GetVar( "headRev" )->Text();
f->setRevision( temp.toInt() );
f->setAction( varList->GetVar("headAction")->Text() );
f->setChange( varList->GetVar("headChange")->Text() );
f->setType( varList->GetVar("headType")->Text() );
QStringList lst = QStringList::split( "/", f->getDepotFile() );
f->setName( lst.last() );
// f->setUser( varList->GetVar("user")->Text() );
// f->setClient( varList->GetVar("client")->Text() );
return f;
}
void FileEntry::FileEntryCache::updateCache()
{
QString temp;
if (_parent == NULL) {
temp = _depotPath + "/*";
}
else {
temp = _parent->_fullPath + "/*";
}
char* p[] = { "-C", const_cast<char *>(temp.latin1()) };
RunP4Command( 2, p, "fstat", this );
}
QPixmap FileEntry::getPixmapForFileType( const QString& e )
{
QPixmap pm;
// covert to lowercase to handle mixed case strings.
QString ext = e.lower();
ImageManager* im = ImageManager::getInstance();
ASSERT( im != NULL );
if (ext == "") {
pm = im->getPixmap( "file_unknown.png" );
} else if (ext == ".c") {
pm = im->getPixmap( "file_c.png" );
} else if (ext == ".cc" || ext == ".cpp" || ext == ".cxx" || ext == ".C") {
pm = im->getPixmap( "file_cpp.png" );
} else if (ext == ".txt") {
pm = im->getPixmap( "file_txt.png" );
} else if (ext == ".h" || ext == ".hxx") {
pm = im->getPixmap( "file_h.png" );
} else if (ext == ".dsw" || ext == ".dsp" || ext == ".mak" ||
ext == "Makefile") {
pm = im->getPixmap( "file_project.png" );
} else if (ext == ".png" || ext == ".bmp" || ext == ".gif" || ext == ".jpg") {
pm = im->getPixmap( "file_binary.png" );
} else if (ext == ".java") {
pm = im->getPixmap( "file_java.png" );
} else if (ext == ".htm" || ext == ".html") {
pm = im->getPixmap( "file_html.png" );
} else if (ext == ".py") {
pm = im->getPixmap( "file_py.png" );
} else if (ext == ".rb") {
pm = im->getPixmap( "file_ruby.png" );
} else {
pm = im->getPixmap( "file_unknown.png" );
}
return pm;
}
}