mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-06-08 22:52:54 -04:00
factorized and cleaned the common code between fistore.cc and fimonitor.cc, improved the stability of FileIndex, improved the display in RemoteDirModel
git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@2158 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
parent
dd5e058173
commit
8e5b1dca64
6 changed files with 321 additions and 358 deletions
|
@ -261,10 +261,18 @@ void FileIndexMonitor::run()
|
|||
{
|
||||
break;
|
||||
}
|
||||
|
||||
#ifdef FIM_DEBUG
|
||||
RsStackMutex mtx(fiMutex) ;
|
||||
std::cerr <<"*********** FileIndex **************" << std::endl ;
|
||||
fi.printFileIndex(std::cerr) ;
|
||||
std::cerr <<"************** END *****************" << std::endl ;
|
||||
std::cerr << std::endl ;
|
||||
#endif
|
||||
}
|
||||
|
||||
// updateCycle(current_job);
|
||||
updateCycle();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -987,17 +995,45 @@ int FileIndexMonitor::RequestDirDetails(void *ref, DirDetails &details, uint32_t
|
|||
fi.root->checkParentPointers();
|
||||
#endif
|
||||
|
||||
// return details as reported by the FileIndex
|
||||
// If ref is NULL, we build a root node
|
||||
|
||||
bool b = fi.RequestDirDetails(ref,details,flags) ;
|
||||
if (ref == NULL)
|
||||
{
|
||||
#ifdef FI_DEBUG
|
||||
std::cerr << "FileIndex::RequestDirDetails() ref=NULL (root)" << std::endl;
|
||||
#endif
|
||||
/* local only */
|
||||
DirStub stub;
|
||||
stub.type = DIR_TYPE_PERSON;
|
||||
stub.name = fi.root->name;
|
||||
stub.ref = fi.root;
|
||||
details.children.push_back(stub);
|
||||
details.count = 1;
|
||||
|
||||
details.parent = NULL;
|
||||
details.prow = -1;
|
||||
details.ref = NULL;
|
||||
details.type = DIR_TYPE_ROOT;
|
||||
details.name = "root";
|
||||
details.hash = "";
|
||||
details.path = "root";
|
||||
details.age = 0;
|
||||
details.flags = 0;
|
||||
|
||||
return true ;
|
||||
}
|
||||
|
||||
bool b = FileIndex::extractData(ref,details) ;
|
||||
|
||||
if(!b)
|
||||
return false ;
|
||||
|
||||
// look for the top level and setup flags accordingly
|
||||
|
||||
if(ref != NULL)
|
||||
{
|
||||
FileEntry *file = (FileEntry *) ref;
|
||||
DirEntry *dir = dynamic_cast<DirEntry *>(file);
|
||||
DirEntry *dir = dynamic_cast<DirEntry*>(file->parent) ;
|
||||
DirEntry *last_dir = NULL ;
|
||||
|
||||
if(dir != NULL)
|
||||
|
@ -1025,8 +1061,9 @@ int FileIndexMonitor::RequestDirDetails(void *ref, DirDetails &details, uint32_t
|
|||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return b ;
|
||||
return true ;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -26,6 +26,7 @@
|
|||
#include "rsiface/rsexpr.h"
|
||||
#include "util/rsdir.h"
|
||||
|
||||
#include <assert.h>
|
||||
#include <stdlib.h>
|
||||
#include <algorithm>
|
||||
#include <iostream>
|
||||
|
@ -1177,50 +1178,28 @@ int FileIndex::searchBoolExp(Expression * exp, std::list<FileEntry *> &results)
|
|||
return 0;
|
||||
}
|
||||
|
||||
int FileIndex::RequestDirDetails(void *ref, DirDetails &details, uint32_t flags) const
|
||||
bool FileIndex::extractData(void *ref,DirDetails& details)
|
||||
{
|
||||
/* so cast *ref to a DirEntry */
|
||||
|
||||
if(ref != NULL && !isValid(ref))
|
||||
return false ;
|
||||
|
||||
FileEntry *file = (FileEntry *) ref;
|
||||
DirEntry *dir = dynamic_cast<DirEntry *>(file);
|
||||
|
||||
if (!ref)
|
||||
if(!isValid(ref))
|
||||
{
|
||||
#ifdef FI_DEBUG
|
||||
std::cerr << "FileIndex::RequestDirDetails() ref=NULL (root)" << std::endl;
|
||||
std::cerr << "FileIndex::RequestDirDetails() asked for an invalid pointer " << (void*)ref << std::endl;
|
||||
#endif
|
||||
/* local only */
|
||||
DirStub stub;
|
||||
stub.type = DIR_TYPE_PERSON;
|
||||
stub.name = root->name;
|
||||
stub.ref = root;
|
||||
details.children.push_back(stub);
|
||||
details.count = 1;
|
||||
|
||||
details.parent = NULL;
|
||||
details.prow = 0;
|
||||
details.ref = NULL;
|
||||
details.type = DIR_TYPE_ROOT;
|
||||
details.name = "";
|
||||
details.hash = "";
|
||||
details.path = "";
|
||||
details.age = 0;
|
||||
details.flags = 0;
|
||||
return false ;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (dir) /* has children --- fill */
|
||||
|
||||
FileEntry *file = static_cast<FileEntry *>(ref);
|
||||
DirEntry *dir = dynamic_cast<DirEntry *>(file);
|
||||
|
||||
details.children = std::list<DirStub>() ;
|
||||
|
||||
if (dir!=NULL) /* has children --- fill */
|
||||
{
|
||||
#ifdef FI_DEBUG
|
||||
std::cerr << "FileIndex::RequestDirDetails() ref=dir" << std::endl;
|
||||
#endif
|
||||
std::map<std::string, FileEntry *>::iterator fit;
|
||||
std::map<std::string, DirEntry *>::iterator dit;
|
||||
/* extract all the entries */
|
||||
for(dit = dir->subdirs.begin(); dit != dir->subdirs.end(); dit++)
|
||||
for(std::map<std::string,DirEntry*>::const_iterator dit(dir->subdirs.begin()); dit != dir->subdirs.end(); ++dit)
|
||||
{
|
||||
DirStub stub;
|
||||
stub.type = DIR_TYPE_DIR;
|
||||
|
@ -1230,7 +1209,7 @@ int FileIndex::RequestDirDetails(void *ref, DirDetails &details, uint32_t flags)
|
|||
details.children.push_back(stub);
|
||||
}
|
||||
|
||||
for(fit = dir->files.begin(); fit != dir->files.end(); fit++)
|
||||
for(std::map<std::string,FileEntry*>::const_iterator fit(dir->files.begin()); fit != dir->files.end(); ++fit)
|
||||
{
|
||||
DirStub stub;
|
||||
stub.type = DIR_TYPE_FILE;
|
||||
|
@ -1240,6 +1219,9 @@ int FileIndex::RequestDirDetails(void *ref, DirDetails &details, uint32_t flags)
|
|||
details.children.push_back(stub);
|
||||
}
|
||||
|
||||
if(dir->parent == NULL)
|
||||
details.type = DIR_TYPE_PERSON ;
|
||||
else
|
||||
details.type = DIR_TYPE_DIR;
|
||||
details.hash = "";
|
||||
details.count = dir->subdirs.size() + dir->files.size();
|
||||
|
@ -1263,53 +1245,24 @@ int FileIndex::RequestDirDetails(void *ref, DirDetails &details, uint32_t flags)
|
|||
details.flags = 0;//file->pop;
|
||||
|
||||
/* find parent pointer, and row */
|
||||
DirEntry *parent = file->parent;
|
||||
if (!parent) /* then must be root */
|
||||
{
|
||||
details.parent = NULL;
|
||||
details.prow = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
details.parent = parent;
|
||||
details.prow = parent->row;
|
||||
}
|
||||
details.parent = file->parent ;
|
||||
|
||||
details.prow = (file->parent==NULL)?0:file->parent->row ;
|
||||
details.path = (file->parent==NULL)?"":file->parent->path;
|
||||
|
||||
/* find peer id */
|
||||
parent = dir;
|
||||
if (!dir) /* cannot be null -> no files at root level */
|
||||
parent=file->parent;
|
||||
FileEntry *f ;
|
||||
for(f=file;f->parent!=NULL;f=f->parent) ;
|
||||
|
||||
// Well, yes, it can be null, beleive me. In such a case it may be that
|
||||
// file is a person entry.
|
||||
details.id = dynamic_cast<PersonEntry*>(f)->id;
|
||||
|
||||
PersonEntry *person;
|
||||
|
||||
if(parent==NULL)
|
||||
{
|
||||
if(NULL == (person = dynamic_cast<PersonEntry *>(file)))
|
||||
{
|
||||
std::cerr << "Major Error- Not PersonEntry!";
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/* NEW add path (to dir - if dir, or parent dir - if file? */
|
||||
details.path = parent->path;
|
||||
|
||||
while(parent->parent)
|
||||
parent = parent->parent;
|
||||
|
||||
/* we should end up on the PersonEntry */
|
||||
if (NULL == (person = dynamic_cast<PersonEntry *>(parent)))
|
||||
{
|
||||
std::cerr << "Major Error- Not PersonEntry!";
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
details.id = person->id;
|
||||
}
|
||||
#ifdef FI_DEBUG
|
||||
assert(details.parent != details.ref) ;
|
||||
std::cout << "details: ref=" << (void*)ref << ", prow=" << details.prow << ", parent=" << (void*)details.parent << ", children=" ;
|
||||
for(std::list<DirStub>::iterator it(details.children.begin());it!=details.children.end();++it)
|
||||
std::cout << " " << (void*)it->ref ;
|
||||
std::cout << std::endl ;
|
||||
#endif
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -79,7 +79,7 @@ class DirEntry;
|
|||
class FileEntry
|
||||
{
|
||||
public:
|
||||
FileEntry() :parent(NULL), row(-1) { return; }
|
||||
FileEntry() :parent(NULL), row(0) { return; }
|
||||
virtual ~FileEntry() { return; }
|
||||
|
||||
virtual int print(std::ostream &out);
|
||||
|
@ -226,14 +226,16 @@ class FileIndex
|
|||
int searchHash(std::string hash, std::list<FileEntry *> &results) const;
|
||||
int searchBoolExp(Expression * exp, std::list<FileEntry *> &results) const;
|
||||
|
||||
/* browse thru directories */
|
||||
int RequestDirDetails(void *ref, DirDetails &details, uint32_t flags) const;
|
||||
PersonEntry *root;
|
||||
|
||||
static std::set<void*> _pointers ;
|
||||
static void registerEntry(void*p) ;
|
||||
static void unregisterEntry(void*p) ;
|
||||
static bool isValid(void*p) ;
|
||||
|
||||
/// Fills up details from the data contained in ref.
|
||||
//
|
||||
static bool extractData(void *ref,DirDetails& details) ;
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -233,7 +233,7 @@ class DirDetails
|
|||
{
|
||||
public:
|
||||
void *parent;
|
||||
uint32_t prow; /* parent row */
|
||||
int prow; /* parent row */
|
||||
|
||||
void *ref;
|
||||
uint8_t type;
|
||||
|
|
|
@ -34,6 +34,7 @@
|
|||
#include <algorithm>
|
||||
#include "util/misc.h"
|
||||
|
||||
#define RDM_DEBUG
|
||||
/*****
|
||||
* #define RDM_DEBUG
|
||||
****/
|
||||
|
@ -116,11 +117,7 @@ void RemoteDirModel::treeStyle()
|
|||
std::cerr << ": ";
|
||||
#endif
|
||||
|
||||
void *ref = NULL;
|
||||
if (parent.isValid())
|
||||
{
|
||||
ref = parent.internalPointer();
|
||||
}
|
||||
void *ref = (parent.isValid())? parent.internalPointer() : NULL ;
|
||||
|
||||
DirDetails details;
|
||||
uint32_t flags = DIR_FLAGS_CHILDREN;
|
||||
|
@ -450,12 +447,10 @@ QString RemoteDirModel::getAgeIndicatorString(const DirDetails &details) const
|
|||
return QString::fromStdString(details.name);
|
||||
break;
|
||||
case 1:
|
||||
//return QString("");
|
||||
return QString::fromStdString(details.id);
|
||||
return QString() ;
|
||||
break;
|
||||
default:
|
||||
//return QString("");
|
||||
return QString::fromStdString("P");
|
||||
return QString() ;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -520,21 +515,21 @@ QString RemoteDirModel::getAgeIndicatorString(const DirDetails &details) const
|
|||
case 3:
|
||||
return QString::fromUtf8("Folder");
|
||||
break;
|
||||
case 4:
|
||||
{
|
||||
if (ageIndicator == IND_DEFAULT)
|
||||
return QString("");
|
||||
QModelIndex pidx = parent(index);
|
||||
QModelIndex pidxs = pidx.sibling(pidx.row(), 4);
|
||||
if (pidxs.isValid() && pidxs.data() != tr(""))
|
||||
return pidxs.data();
|
||||
else {
|
||||
QString ind("");
|
||||
getAgeIndicatorRec(details, ind);
|
||||
return ind;
|
||||
}
|
||||
}
|
||||
break;
|
||||
// case 4:
|
||||
// {
|
||||
// if (ageIndicator == IND_DEFAULT)
|
||||
// return QString("");
|
||||
// QModelIndex pidx = parent(index);
|
||||
// QModelIndex pidxs = pidx.sibling(pidx.row(), 4);
|
||||
// if (pidxs.isValid() && pidxs.data() != tr(""))
|
||||
// return pidxs.data();
|
||||
// else {
|
||||
// QString ind("");
|
||||
// getAgeIndicatorRec(details, ind);
|
||||
// return ind;
|
||||
// }
|
||||
// }
|
||||
// break;
|
||||
default:
|
||||
return QString(tr("DIR"));
|
||||
break;
|
||||
|
@ -627,20 +622,17 @@ void RemoteDirModel::getAgeIndicatorRec(DirDetails &details, QString &ret) const
|
|||
return QString("Row %1").arg(section);
|
||||
}
|
||||
|
||||
QModelIndex RemoteDirModel::index(int row, int column,
|
||||
const QModelIndex & parent) const
|
||||
QModelIndex RemoteDirModel::index(int row, int column, const QModelIndex & parent) const
|
||||
{
|
||||
#ifdef RDM_DEBUG
|
||||
std::cerr << "RemoteDirModel::index(): " << parent.internalPointer();
|
||||
std::cerr << ": row:" << row << " col:" << column << " ";
|
||||
#endif
|
||||
|
||||
void *ref = NULL;
|
||||
if(row < 0)
|
||||
return QModelIndex() ;
|
||||
|
||||
if (parent.isValid())
|
||||
{
|
||||
ref = parent.internalPointer();
|
||||
}
|
||||
void *ref = (parent.isValid()) ? parent.internalPointer() : NULL;
|
||||
|
||||
/********
|
||||
if (!RemoteMode)
|
||||
|
@ -671,8 +663,7 @@ void RemoteDirModel::getAgeIndicatorRec(DirDetails &details, QString &ret) const
|
|||
|
||||
std::list<DirStub>::iterator it;
|
||||
int i = 0;
|
||||
for(it = details.children.begin();
|
||||
((i < row) && (it != details.children.end())); it++, i++) ;
|
||||
for(it = details.children.begin(); ((i < row) && (it != details.children.end())); ++it, ++i) ;
|
||||
|
||||
if (it == details.children.end())
|
||||
{
|
||||
|
@ -689,8 +680,8 @@ void RemoteDirModel::getAgeIndicatorRec(DirDetails &details, QString &ret) const
|
|||
#endif
|
||||
|
||||
/* we can just grab the reference now */
|
||||
QModelIndex qmi = createIndex(row, column, it->ref);
|
||||
return qmi;
|
||||
|
||||
return createIndex(row, column, it->ref);
|
||||
}
|
||||
|
||||
|
||||
|
@ -714,11 +705,7 @@ void RemoteDirModel::getAgeIndicatorRec(DirDetails &details, QString &ret) const
|
|||
void *ref = index.internalPointer();
|
||||
|
||||
DirDetails details;
|
||||
uint32_t flags = DIR_FLAGS_PARENT;
|
||||
if (RemoteMode)
|
||||
flags |= DIR_FLAGS_REMOTE;
|
||||
else
|
||||
flags |= DIR_FLAGS_LOCAL;
|
||||
uint32_t flags = (RemoteMode)?DIR_FLAGS_REMOTE:DIR_FLAGS_LOCAL;
|
||||
|
||||
if (!rsFiles->RequestDirDetails(ref, details, flags))
|
||||
{
|
||||
|
@ -766,30 +753,14 @@ void RemoteDirModel::getAgeIndicatorRec(DirDetails &details, QString &ret) const
|
|||
flags |= DIR_FLAGS_LOCAL;
|
||||
|
||||
if (!rsFiles->RequestDirDetails(ref, details, flags))
|
||||
return Qt::ItemIsSelectable; // Error.
|
||||
|
||||
switch(details.type)
|
||||
{
|
||||
return (Qt::ItemIsSelectable); // Error.
|
||||
}
|
||||
|
||||
if (details.type == DIR_TYPE_PERSON)
|
||||
{
|
||||
return (Qt::ItemIsEnabled);
|
||||
}
|
||||
else if (details.type == DIR_TYPE_DIR)
|
||||
{
|
||||
return ( Qt::ItemIsSelectable |
|
||||
Qt::ItemIsEnabled);
|
||||
|
||||
// Qt::ItemIsDragEnabled |
|
||||
// Qt::ItemIsDropEnabled |
|
||||
|
||||
}
|
||||
else // (details.type == DIR_TYPE_FILE)
|
||||
{
|
||||
return ( Qt::ItemIsSelectable |
|
||||
Qt::ItemIsDragEnabled |
|
||||
Qt::ItemIsEnabled);
|
||||
|
||||
|
||||
case DIR_TYPE_PERSON: return Qt::ItemIsEnabled;
|
||||
case DIR_TYPE_DIR: return Qt::ItemIsSelectable | Qt::ItemIsEnabled;
|
||||
default: ;
|
||||
case DIR_TYPE_FILE: return Qt::ItemIsSelectable | Qt::ItemIsDragEnabled | Qt::ItemIsEnabled;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue