made the age indicator functional, by recursively changing color of directory/files

git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@2244 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
csoler 2010-02-08 22:32:00 +00:00
parent 38b0c578bb
commit 024e7f4b44
10 changed files with 114 additions and 62 deletions

View file

@ -195,31 +195,34 @@ bool FileIndexMonitor::loadLocalCache(const CacheData &data) /* called with sto
{
bool ok = false;
fiMutex.lock(); { /* LOCKED DIRS */
fiMutex.lock();
{ /* LOCKED DIRS */
//fi.root->name = data.pid;
//fi.root->name = data.pid;
/* More error checking needed here! */
/* More error checking needed here! */
std::string name = data.name ; // this trick allows to load the complete file. Not the one being shared.
name[name.length()-1] = 'c' ;
std::string name = data.name ; // this trick allows to load the complete file. Not the one being shared.
name[name.length()-1] = 'c' ;
if ((ok = fi.loadIndex(data.path + '/' + name, "", data.size)))
{
if ((ok = fi.loadIndex(data.path + '/' + name, "", data.size)))
{
#ifdef FIM_DEBUG
std::cerr << "FileIndexMonitor::loadCache() Success!";
std::cerr << std::endl;
std::cerr << "FileIndexMonitor::loadCache() Success!";
std::cerr << std::endl;
#endif
fi.root->row = 0;
fi.root->name = data.pname ;
}
else
{
fi.root->row = 0;
fi.root->name = data.pname ;
}
else
{
#ifdef FIM_DEBUG
std::cerr << "FileIndexMonitor::loadCache() Failed!";
std::cerr << std::endl;
std::cerr << "FileIndexMonitor::loadCache() Failed!";
std::cerr << std::endl;
#endif
}
}
fi.updateMaxModTime() ;
} fiMutex.unlock(); /* UNLOCKED DIRS */
@ -1026,6 +1029,7 @@ int FileIndexMonitor::RequestDirDetails(void *ref, DirDetails &details, uint32_t
details.path = "root";
details.age = 0;
details.flags = 0;
details.min_age = 0 ;
return true ;
}

View file

@ -559,6 +559,24 @@ int FileIndex::setRootDirectories(std::list<std::string> inlist, time_t updtime)
return 1;
}
void FileIndex::updateMaxModTime()
{
RecursUpdateMaxModTime(root) ;
}
void FileIndex::RecursUpdateMaxModTime(DirEntry *dir)
{
time_t max_mod_t = 0 ;
for(std::map<std::string,DirEntry*>::iterator it(dir->subdirs.begin());it!=dir->subdirs.end();++it)
{
RecursUpdateMaxModTime(it->second) ;
max_mod_t = std::max(max_mod_t, it->second->most_recent_time) ;
}
for(std::map<std::string,FileEntry*>::iterator it(dir->files.begin());it!=dir->files.end();++it)
max_mod_t = std::max(max_mod_t, it->second->modtime) ;
dir->most_recent_time = max_mod_t ;
}
int FileIndex::getRootDirectories(std::list<std::string> &outlist)
{
@ -571,7 +589,7 @@ int FileIndex::getRootDirectories(std::list<std::string> &outlist)
return 1;
}
/* update (index building) */
/* update (index building) */
DirEntry *FileIndex::updateDirEntry(std::string fpath, FileEntry fe, time_t utime)
{
/* path is to parent */
@ -1183,7 +1201,7 @@ bool FileIndex::extractData(void *ref,DirDetails& details)
if(!isValid(ref))
{
#ifdef FI_DEBUG
std::cerr << "FileIndex::RequestDirDetails() asked for an invalid pointer " << (void*)ref << std::endl;
std::cerr << "FileIndex::extractData() asked for an invalid pointer " << (void*)ref << std::endl;
#endif
return false ;
}
@ -1192,11 +1210,12 @@ bool FileIndex::extractData(void *ref,DirDetails& details)
DirEntry *dir = dynamic_cast<DirEntry *>(file);
details.children = std::list<DirStub>() ;
time_t now = time(NULL) ;
if (dir!=NULL) /* has children --- fill */
{
#ifdef FI_DEBUG
std::cerr << "FileIndex::RequestDirDetails() ref=dir" << std::endl;
std::cerr << "FileIndex::extractData() ref=dir" << std::endl;
#endif
/* extract all the entries */
for(std::map<std::string,DirEntry*>::const_iterator dit(dir->subdirs.begin()); dit != dir->subdirs.end(); ++dit)
@ -1225,22 +1244,24 @@ bool FileIndex::extractData(void *ref,DirDetails& details)
details.type = DIR_TYPE_DIR;
details.hash = "";
details.count = dir->subdirs.size() + dir->files.size();
details.min_age = now - dir->most_recent_time ;
}
else
{
#ifdef FI_DEBUG
std::cerr << "FileIndexStore::RequestDirDetails() ref=file" << std::endl;
std::cerr << "FileIndexStore::extractData() ref=file" << std::endl;
#endif
details.type = DIR_TYPE_FILE;
details.count = file->size;
details.min_age = now - file->modtime ;
}
#ifdef FI_DEBUG
std::cerr << "FileIndexStore::RequestDirDetails() name: " << file->name << std::endl;
std::cerr << "FileIndexStore::extractData() name: " << file->name << std::endl;
#endif
details.ref = file;
details.hash = file->hash;
details.age = time(NULL) - file->modtime;
details.age = now - file->modtime;
details.flags = 0;//file->pop;
/* find parent pointer, and row */

View file

@ -144,6 +144,8 @@ void writeFileInfo(std::ostringstream&);
std::map<std::string, DirEntry *> subdirs;
std::map<std::string, FileEntry *> files;
time_t most_recent_time; /* last updated */
/* Inherited members from FileEntry:
int size - count for dirs
std::string name; - directory name
@ -226,6 +228,12 @@ class FileIndex
int searchHash(std::string hash, std::list<FileEntry *> &results) const;
int searchBoolExp(Expression * exp, std::list<FileEntry *> &results) const;
/// Recursively compute the maximum modification time of children.
/// Used to easily retrieve mose recent files.
//
void updateMaxModTime() ;
void RecursUpdateMaxModTime(DirEntry *) ;
PersonEntry *root;
static std::set<void*> _pointers ;

View file

@ -126,10 +126,12 @@ int FileIndexStore::loadCache(const CacheData &data)
for(it = indices.begin(); it != indices.end(); it++)
{
(it->second)->root->row = i++;
it->second->FileIndex::updateMaxModTime() ;
}
if (localindex)
{
localindex->root->row = 0;
localindex->updateMaxModTime() ;
}
unlockData();
@ -220,6 +222,7 @@ int FileIndexStore::RequestDirDetails(void *ref, DirDetails &details, uint32_t f
details.count = indices.size();
details.age = 0;
details.flags = 0;
details.min_age = 0;
unlockData();
return true ;

View file

@ -244,6 +244,7 @@ class DirDetails
uint64_t count;
uint32_t age;
uint32_t flags;
uint32_t min_age ; // minimum age of files in this subtree
std::list<DirStub> children;
};