mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-06-10 07:32:42 -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;
|
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();
|
updateCycle();
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -987,46 +995,75 @@ int FileIndexMonitor::RequestDirDetails(void *ref, DirDetails &details, uint32_t
|
||||||
fi.root->checkParentPointers();
|
fi.root->checkParentPointers();
|
||||||
#endif
|
#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)
|
if(!b)
|
||||||
return false ;
|
return false ;
|
||||||
|
|
||||||
// look for the top level and setup flags accordingly
|
// look for the top level and setup flags accordingly
|
||||||
|
|
||||||
FileEntry *file = (FileEntry *) ref;
|
if(ref != NULL)
|
||||||
DirEntry *dir = dynamic_cast<DirEntry *>(file);
|
|
||||||
DirEntry *last_dir = NULL ;
|
|
||||||
|
|
||||||
if(dir != NULL)
|
|
||||||
while(dir->parent != NULL)
|
|
||||||
{
|
|
||||||
last_dir = dir ;
|
|
||||||
dir = dir->parent ;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(last_dir != NULL)
|
|
||||||
{
|
{
|
||||||
#ifdef FIM_DEBUG
|
FileEntry *file = (FileEntry *) ref;
|
||||||
std::cerr << "FileIndexMonitor::RequestDirDetails: parent->name=" << last_dir->name << std::endl ;
|
DirEntry *dir = dynamic_cast<DirEntry*>(file->parent) ;
|
||||||
#endif
|
DirEntry *last_dir = NULL ;
|
||||||
std::map<std::string,SharedDirInfo>::const_iterator it = directoryMap.find(last_dir->name) ;
|
|
||||||
|
|
||||||
if(it == directoryMap.end())
|
if(dir != NULL)
|
||||||
std::cerr << "*********** ERROR *********** In " << __PRETTY_FUNCTION__ << std::endl ;
|
while(dir->parent != NULL)
|
||||||
else
|
{
|
||||||
|
last_dir = dir ;
|
||||||
|
dir = dir->parent ;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(last_dir != NULL)
|
||||||
{
|
{
|
||||||
details.flags |= (( (it->second.shareflags & RS_FILE_HINTS_BROWSABLE)>0)?DIR_FLAGS_BROWSABLE:0) ;
|
|
||||||
details.flags |= (( (it->second.shareflags & RS_FILE_HINTS_NETWORK_WIDE)>0)?DIR_FLAGS_NETWORK_WIDE:0) ;
|
|
||||||
#ifdef FIM_DEBUG
|
#ifdef FIM_DEBUG
|
||||||
std::cerr << "flags = " << details.flags << std::endl ;
|
std::cerr << "FileIndexMonitor::RequestDirDetails: parent->name=" << last_dir->name << std::endl ;
|
||||||
#endif
|
#endif
|
||||||
|
std::map<std::string,SharedDirInfo>::const_iterator it = directoryMap.find(last_dir->name) ;
|
||||||
|
|
||||||
|
if(it == directoryMap.end())
|
||||||
|
std::cerr << "*********** ERROR *********** In " << __PRETTY_FUNCTION__ << std::endl ;
|
||||||
|
else
|
||||||
|
{
|
||||||
|
details.flags |= (( (it->second.shareflags & RS_FILE_HINTS_BROWSABLE)>0)?DIR_FLAGS_BROWSABLE:0) ;
|
||||||
|
details.flags |= (( (it->second.shareflags & RS_FILE_HINTS_NETWORK_WIDE)>0)?DIR_FLAGS_NETWORK_WIDE:0) ;
|
||||||
|
#ifdef FIM_DEBUG
|
||||||
|
std::cerr << "flags = " << details.flags << std::endl ;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return b ;
|
return true ;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -26,6 +26,7 @@
|
||||||
#include "rsiface/rsexpr.h"
|
#include "rsiface/rsexpr.h"
|
||||||
#include "util/rsdir.h"
|
#include "util/rsdir.h"
|
||||||
|
|
||||||
|
#include <assert.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
@ -1177,140 +1178,92 @@ int FileIndex::searchBoolExp(Expression * exp, std::list<FileEntry *> &results)
|
||||||
return 0;
|
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(!isValid(ref))
|
||||||
|
|
||||||
if(ref != NULL && !isValid(ref))
|
|
||||||
return false ;
|
|
||||||
|
|
||||||
FileEntry *file = (FileEntry *) ref;
|
|
||||||
DirEntry *dir = dynamic_cast<DirEntry *>(file);
|
|
||||||
|
|
||||||
if (!ref)
|
|
||||||
{
|
{
|
||||||
#ifdef FI_DEBUG
|
#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
|
#endif
|
||||||
/* local only */
|
return false ;
|
||||||
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;
|
FileEntry *file = static_cast<FileEntry *>(ref);
|
||||||
details.prow = 0;
|
DirEntry *dir = dynamic_cast<DirEntry *>(file);
|
||||||
details.ref = NULL;
|
|
||||||
details.type = DIR_TYPE_ROOT;
|
details.children = std::list<DirStub>() ;
|
||||||
details.name = "";
|
|
||||||
|
if (dir!=NULL) /* has children --- fill */
|
||||||
|
{
|
||||||
|
#ifdef FI_DEBUG
|
||||||
|
std::cerr << "FileIndex::RequestDirDetails() 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)
|
||||||
|
{
|
||||||
|
DirStub stub;
|
||||||
|
stub.type = DIR_TYPE_DIR;
|
||||||
|
stub.name = (dit->second) -> name;
|
||||||
|
stub.ref = (dit->second);
|
||||||
|
|
||||||
|
details.children.push_back(stub);
|
||||||
|
}
|
||||||
|
|
||||||
|
for(std::map<std::string,FileEntry*>::const_iterator fit(dir->files.begin()); fit != dir->files.end(); ++fit)
|
||||||
|
{
|
||||||
|
DirStub stub;
|
||||||
|
stub.type = DIR_TYPE_FILE;
|
||||||
|
stub.name = (fit->second) -> name;
|
||||||
|
stub.ref = (fit->second);
|
||||||
|
|
||||||
|
details.children.push_back(stub);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(dir->parent == NULL)
|
||||||
|
details.type = DIR_TYPE_PERSON ;
|
||||||
|
else
|
||||||
|
details.type = DIR_TYPE_DIR;
|
||||||
details.hash = "";
|
details.hash = "";
|
||||||
details.path = "";
|
details.count = dir->subdirs.size() + dir->files.size();
|
||||||
details.age = 0;
|
|
||||||
details.flags = 0;
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (dir) /* has children --- fill */
|
|
||||||
{
|
|
||||||
#ifdef FI_DEBUG
|
#ifdef FI_DEBUG
|
||||||
std::cerr << "FileIndex::RequestDirDetails() ref=dir" << std::endl;
|
std::cerr << "FileIndexStore::RequestDirDetails() ref=file" << std::endl;
|
||||||
#endif
|
#endif
|
||||||
std::map<std::string, FileEntry *>::iterator fit;
|
details.type = DIR_TYPE_FILE;
|
||||||
std::map<std::string, DirEntry *>::iterator dit;
|
details.count = file->size;
|
||||||
/* extract all the entries */
|
|
||||||
for(dit = dir->subdirs.begin(); dit != dir->subdirs.end(); dit++)
|
|
||||||
{
|
|
||||||
DirStub stub;
|
|
||||||
stub.type = DIR_TYPE_DIR;
|
|
||||||
stub.name = (dit->second) -> name;
|
|
||||||
stub.ref = (dit->second);
|
|
||||||
|
|
||||||
details.children.push_back(stub);
|
|
||||||
}
|
|
||||||
|
|
||||||
for(fit = dir->files.begin(); fit != dir->files.end(); fit++)
|
|
||||||
{
|
|
||||||
DirStub stub;
|
|
||||||
stub.type = DIR_TYPE_FILE;
|
|
||||||
stub.name = (fit->second) -> name;
|
|
||||||
stub.ref = (fit->second);
|
|
||||||
|
|
||||||
details.children.push_back(stub);
|
|
||||||
}
|
|
||||||
|
|
||||||
details.type = DIR_TYPE_DIR;
|
|
||||||
details.hash = "";
|
|
||||||
details.count = dir->subdirs.size() + dir->files.size();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
#ifdef FI_DEBUG
|
|
||||||
std::cerr << "FileIndexStore::RequestDirDetails() ref=file" << std::endl;
|
|
||||||
#endif
|
|
||||||
details.type = DIR_TYPE_FILE;
|
|
||||||
details.count = file->size;
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifdef FI_DEBUG
|
|
||||||
std::cerr << "FileIndexStore::RequestDirDetails() name: " << file->name << std::endl;
|
|
||||||
#endif
|
|
||||||
details.ref = file;
|
|
||||||
details.name = file->name;
|
|
||||||
details.hash = file->hash;
|
|
||||||
details.age = time(NULL) - file->modtime;
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* find peer id */
|
|
||||||
parent = dir;
|
|
||||||
if (!dir) /* cannot be null -> no files at root level */
|
|
||||||
parent=file->parent;
|
|
||||||
|
|
||||||
// Well, yes, it can be null, beleive me. In such a case it may be that
|
|
||||||
// file is a person entry.
|
|
||||||
|
|
||||||
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
|
||||||
|
std::cerr << "FileIndexStore::RequestDirDetails() name: " << file->name << std::endl;
|
||||||
|
#endif
|
||||||
|
details.ref = file;
|
||||||
|
details.name = file->name;
|
||||||
|
details.hash = file->hash;
|
||||||
|
details.age = time(NULL) - file->modtime;
|
||||||
|
details.flags = 0;//file->pop;
|
||||||
|
|
||||||
|
/* find parent pointer, and 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 */
|
||||||
|
FileEntry *f ;
|
||||||
|
for(f=file;f->parent!=NULL;f=f->parent) ;
|
||||||
|
|
||||||
|
details.id = dynamic_cast<PersonEntry*>(f)->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;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -79,7 +79,7 @@ class DirEntry;
|
||||||
class FileEntry
|
class FileEntry
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
FileEntry() :parent(NULL), row(-1) { return; }
|
FileEntry() :parent(NULL), row(0) { return; }
|
||||||
virtual ~FileEntry() { return; }
|
virtual ~FileEntry() { return; }
|
||||||
|
|
||||||
virtual int print(std::ostream &out);
|
virtual int print(std::ostream &out);
|
||||||
|
@ -226,14 +226,16 @@ class FileIndex
|
||||||
int searchHash(std::string hash, std::list<FileEntry *> &results) const;
|
int searchHash(std::string hash, std::list<FileEntry *> &results) const;
|
||||||
int searchBoolExp(Expression * exp, 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;
|
PersonEntry *root;
|
||||||
|
|
||||||
static std::set<void*> _pointers ;
|
static std::set<void*> _pointers ;
|
||||||
static void registerEntry(void*p) ;
|
static void registerEntry(void*p) ;
|
||||||
static void unregisterEntry(void*p) ;
|
static void unregisterEntry(void*p) ;
|
||||||
static bool isValid(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:
|
public:
|
||||||
void *parent;
|
void *parent;
|
||||||
uint32_t prow; /* parent row */
|
int prow; /* parent row */
|
||||||
|
|
||||||
void *ref;
|
void *ref;
|
||||||
uint8_t type;
|
uint8_t type;
|
||||||
|
|
|
@ -34,6 +34,7 @@
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include "util/misc.h"
|
#include "util/misc.h"
|
||||||
|
|
||||||
|
#define RDM_DEBUG
|
||||||
/*****
|
/*****
|
||||||
* #define RDM_DEBUG
|
* #define RDM_DEBUG
|
||||||
****/
|
****/
|
||||||
|
@ -116,11 +117,7 @@ void RemoteDirModel::treeStyle()
|
||||||
std::cerr << ": ";
|
std::cerr << ": ";
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void *ref = NULL;
|
void *ref = (parent.isValid())? parent.internalPointer() : NULL ;
|
||||||
if (parent.isValid())
|
|
||||||
{
|
|
||||||
ref = parent.internalPointer();
|
|
||||||
}
|
|
||||||
|
|
||||||
DirDetails details;
|
DirDetails details;
|
||||||
uint32_t flags = DIR_FLAGS_CHILDREN;
|
uint32_t flags = DIR_FLAGS_CHILDREN;
|
||||||
|
@ -447,16 +444,14 @@ QString RemoteDirModel::getAgeIndicatorString(const DirDetails &details) const
|
||||||
switch(coln)
|
switch(coln)
|
||||||
{
|
{
|
||||||
case 0:
|
case 0:
|
||||||
return QString::fromStdString(details.name);
|
return QString::fromStdString(details.name);
|
||||||
break;
|
break;
|
||||||
case 1:
|
case 1:
|
||||||
//return QString("");
|
return QString() ;
|
||||||
return QString::fromStdString(details.id);
|
break;
|
||||||
break;
|
|
||||||
default:
|
default:
|
||||||
//return QString("");
|
return QString() ;
|
||||||
return QString::fromStdString("P");
|
break;
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (details.type == DIR_TYPE_FILE) /* File */
|
else if (details.type == DIR_TYPE_FILE) /* File */
|
||||||
|
@ -464,13 +459,13 @@ QString RemoteDirModel::getAgeIndicatorString(const DirDetails &details) const
|
||||||
switch(coln)
|
switch(coln)
|
||||||
{
|
{
|
||||||
case 0:
|
case 0:
|
||||||
return QString::fromUtf8(details.name.c_str());
|
return QString::fromUtf8(details.name.c_str());
|
||||||
break;
|
break;
|
||||||
case 1:
|
case 1:
|
||||||
{
|
{
|
||||||
std::ostringstream out;
|
std::ostringstream out;
|
||||||
//out << details.count;
|
//out << details.count;
|
||||||
//return QString::fromStdString(out.str());
|
//return QString::fromStdString(out.str());
|
||||||
return misc::friendlyUnit(details.count);
|
return misc::friendlyUnit(details.count);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@ -520,21 +515,21 @@ QString RemoteDirModel::getAgeIndicatorString(const DirDetails &details) const
|
||||||
case 3:
|
case 3:
|
||||||
return QString::fromUtf8("Folder");
|
return QString::fromUtf8("Folder");
|
||||||
break;
|
break;
|
||||||
case 4:
|
// case 4:
|
||||||
{
|
// {
|
||||||
if (ageIndicator == IND_DEFAULT)
|
// if (ageIndicator == IND_DEFAULT)
|
||||||
return QString("");
|
// return QString("");
|
||||||
QModelIndex pidx = parent(index);
|
// QModelIndex pidx = parent(index);
|
||||||
QModelIndex pidxs = pidx.sibling(pidx.row(), 4);
|
// QModelIndex pidxs = pidx.sibling(pidx.row(), 4);
|
||||||
if (pidxs.isValid() && pidxs.data() != tr(""))
|
// if (pidxs.isValid() && pidxs.data() != tr(""))
|
||||||
return pidxs.data();
|
// return pidxs.data();
|
||||||
else {
|
// else {
|
||||||
QString ind("");
|
// QString ind("");
|
||||||
getAgeIndicatorRec(details, ind);
|
// getAgeIndicatorRec(details, ind);
|
||||||
return ind;
|
// return ind;
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
break;
|
// break;
|
||||||
default:
|
default:
|
||||||
return QString(tr("DIR"));
|
return QString(tr("DIR"));
|
||||||
break;
|
break;
|
||||||
|
@ -627,43 +622,40 @@ void RemoteDirModel::getAgeIndicatorRec(DirDetails &details, QString &ret) const
|
||||||
return QString("Row %1").arg(section);
|
return QString("Row %1").arg(section);
|
||||||
}
|
}
|
||||||
|
|
||||||
QModelIndex RemoteDirModel::index(int row, int column,
|
QModelIndex RemoteDirModel::index(int row, int column, const QModelIndex & parent) const
|
||||||
const QModelIndex & parent) const
|
{
|
||||||
{
|
|
||||||
#ifdef RDM_DEBUG
|
#ifdef RDM_DEBUG
|
||||||
std::cerr << "RemoteDirModel::index(): " << parent.internalPointer();
|
std::cerr << "RemoteDirModel::index(): " << parent.internalPointer();
|
||||||
std::cerr << ": row:" << row << " col:" << column << " ";
|
std::cerr << ": row:" << row << " col:" << column << " ";
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void *ref = NULL;
|
if(row < 0)
|
||||||
|
return QModelIndex() ;
|
||||||
|
|
||||||
if (parent.isValid())
|
void *ref = (parent.isValid()) ? parent.internalPointer() : NULL;
|
||||||
{
|
|
||||||
ref = parent.internalPointer();
|
|
||||||
}
|
|
||||||
|
|
||||||
/********
|
/********
|
||||||
if (!RemoteMode)
|
if (!RemoteMode)
|
||||||
{
|
{
|
||||||
remote = &(rsiface->getLocalDirectoryList());
|
remote = &(rsiface->getLocalDirectoryList());
|
||||||
}
|
}
|
||||||
********/
|
********/
|
||||||
|
|
||||||
DirDetails details;
|
DirDetails details;
|
||||||
uint32_t flags = DIR_FLAGS_CHILDREN;
|
uint32_t flags = DIR_FLAGS_CHILDREN;
|
||||||
if (RemoteMode)
|
if (RemoteMode)
|
||||||
flags |= DIR_FLAGS_REMOTE;
|
flags |= DIR_FLAGS_REMOTE;
|
||||||
else
|
else
|
||||||
flags |= DIR_FLAGS_LOCAL;
|
flags |= DIR_FLAGS_LOCAL;
|
||||||
|
|
||||||
if (!rsFiles->RequestDirDetails(ref, details, flags))
|
if (!rsFiles->RequestDirDetails(ref, details, flags))
|
||||||
{
|
{
|
||||||
#ifdef RDM_DEBUG
|
#ifdef RDM_DEBUG
|
||||||
std::cerr << "lookup failed -> invalid";
|
std::cerr << "lookup failed -> invalid";
|
||||||
std::cerr << std::endl;
|
std::cerr << std::endl;
|
||||||
#endif
|
#endif
|
||||||
return QModelIndex();
|
return QModelIndex();
|
||||||
}
|
}
|
||||||
|
|
||||||
/* now iterate through the details to
|
/* now iterate through the details to
|
||||||
* get the reference number
|
* get the reference number
|
||||||
|
@ -671,125 +663,104 @@ void RemoteDirModel::getAgeIndicatorRec(DirDetails &details, QString &ret) const
|
||||||
|
|
||||||
std::list<DirStub>::iterator it;
|
std::list<DirStub>::iterator it;
|
||||||
int i = 0;
|
int i = 0;
|
||||||
for(it = details.children.begin();
|
for(it = details.children.begin(); ((i < row) && (it != details.children.end())); ++it, ++i) ;
|
||||||
((i < row) && (it != details.children.end())); it++, i++) ;
|
|
||||||
|
|
||||||
if (it == details.children.end())
|
if (it == details.children.end())
|
||||||
{
|
{
|
||||||
#ifdef RDM_DEBUG
|
#ifdef RDM_DEBUG
|
||||||
std::cerr << "wrong number of children -> invalid";
|
std::cerr << "wrong number of children -> invalid";
|
||||||
std::cerr << std::endl;
|
std::cerr << std::endl;
|
||||||
#endif
|
#endif
|
||||||
return QModelIndex();
|
return QModelIndex();
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef RDM_DEBUG
|
#ifdef RDM_DEBUG
|
||||||
std::cerr << "success index(" << row << "," << column << "," << it->ref << ")";
|
std::cerr << "success index(" << row << "," << column << "," << it->ref << ")";
|
||||||
std::cerr << std::endl;
|
std::cerr << std::endl;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* we can just grab the reference now */
|
/* we can just grab the reference now */
|
||||||
QModelIndex qmi = createIndex(row, column, it->ref);
|
|
||||||
return qmi;
|
return createIndex(row, column, it->ref);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
QModelIndex RemoteDirModel::parent( const QModelIndex & index ) const
|
QModelIndex RemoteDirModel::parent( const QModelIndex & index ) const
|
||||||
{
|
{
|
||||||
#ifdef RDM_DEBUG
|
#ifdef RDM_DEBUG
|
||||||
std::cerr << "RemoteDirModel::parent(): " << index.internalPointer();
|
std::cerr << "RemoteDirModel::parent(): " << index.internalPointer();
|
||||||
std::cerr << ": ";
|
std::cerr << ": ";
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* create the index */
|
/* create the index */
|
||||||
if (!index.isValid())
|
if (!index.isValid())
|
||||||
{
|
{
|
||||||
#ifdef RDM_DEBUG
|
#ifdef RDM_DEBUG
|
||||||
std::cerr << "Invalid Index -> invalid";
|
std::cerr << "Invalid Index -> invalid";
|
||||||
std::cerr << std::endl;
|
std::cerr << std::endl;
|
||||||
#endif
|
#endif
|
||||||
/* Parent is invalid too */
|
/* Parent is invalid too */
|
||||||
return QModelIndex();
|
return QModelIndex();
|
||||||
}
|
}
|
||||||
void *ref = index.internalPointer();
|
void *ref = index.internalPointer();
|
||||||
|
|
||||||
DirDetails details;
|
DirDetails details;
|
||||||
uint32_t flags = DIR_FLAGS_PARENT;
|
uint32_t flags = (RemoteMode)?DIR_FLAGS_REMOTE:DIR_FLAGS_LOCAL;
|
||||||
if (RemoteMode)
|
|
||||||
flags |= DIR_FLAGS_REMOTE;
|
|
||||||
else
|
|
||||||
flags |= DIR_FLAGS_LOCAL;
|
|
||||||
|
|
||||||
if (!rsFiles->RequestDirDetails(ref, details, flags))
|
if (!rsFiles->RequestDirDetails(ref, details, flags))
|
||||||
{
|
{
|
||||||
#ifdef RDM_DEBUG
|
#ifdef RDM_DEBUG
|
||||||
std::cerr << "Failed Lookup -> invalid";
|
std::cerr << "Failed Lookup -> invalid";
|
||||||
std::cerr << std::endl;
|
std::cerr << std::endl;
|
||||||
#endif
|
#endif
|
||||||
return QModelIndex();
|
return QModelIndex();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!(details.parent))
|
if (!(details.parent))
|
||||||
{
|
{
|
||||||
#ifdef RDM_DEBUG
|
#ifdef RDM_DEBUG
|
||||||
std::cerr << "success. parent is Root/NULL --> invalid";
|
std::cerr << "success. parent is Root/NULL --> invalid";
|
||||||
std::cerr << std::endl;
|
std::cerr << std::endl;
|
||||||
#endif
|
#endif
|
||||||
return QModelIndex();
|
return QModelIndex();
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef RDM_DEBUG
|
#ifdef RDM_DEBUG
|
||||||
std::cerr << "success index(" << details.prow << ",0," << details.parent << ")";
|
std::cerr << "success index(" << details.prow << ",0," << details.parent << ")";
|
||||||
std::cerr << std::endl;
|
std::cerr << std::endl;
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
return createIndex(details.prow, 0, details.parent);
|
return createIndex(details.prow, 0, details.parent);
|
||||||
}
|
}
|
||||||
|
|
||||||
Qt::ItemFlags RemoteDirModel::flags( const QModelIndex & index ) const
|
Qt::ItemFlags RemoteDirModel::flags( const QModelIndex & index ) const
|
||||||
{
|
{
|
||||||
#ifdef RDM_DEBUG
|
#ifdef RDM_DEBUG
|
||||||
std::cerr << "RemoteDirModel::flags()";
|
std::cerr << "RemoteDirModel::flags()";
|
||||||
std::cerr << std::endl;
|
std::cerr << std::endl;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (!index.isValid())
|
if (!index.isValid())
|
||||||
return (Qt::ItemIsSelectable); // Error.
|
return (Qt::ItemIsSelectable); // Error.
|
||||||
|
|
||||||
void *ref = index.internalPointer();
|
void *ref = index.internalPointer();
|
||||||
|
|
||||||
DirDetails details;
|
DirDetails details;
|
||||||
uint32_t flags = DIR_FLAGS_DETAILS;
|
uint32_t flags = DIR_FLAGS_DETAILS;
|
||||||
if (RemoteMode)
|
if (RemoteMode)
|
||||||
flags |= DIR_FLAGS_REMOTE;
|
flags |= DIR_FLAGS_REMOTE;
|
||||||
else
|
else
|
||||||
flags |= DIR_FLAGS_LOCAL;
|
flags |= DIR_FLAGS_LOCAL;
|
||||||
|
|
||||||
if (!rsFiles->RequestDirDetails(ref, details, flags))
|
if (!rsFiles->RequestDirDetails(ref, details, flags))
|
||||||
{
|
return Qt::ItemIsSelectable; // Error.
|
||||||
return (Qt::ItemIsSelectable); // Error.
|
|
||||||
}
|
|
||||||
|
|
||||||
if (details.type == DIR_TYPE_PERSON)
|
switch(details.type)
|
||||||
{
|
{
|
||||||
return (Qt::ItemIsEnabled);
|
case DIR_TYPE_PERSON: return Qt::ItemIsEnabled;
|
||||||
}
|
case DIR_TYPE_DIR: return Qt::ItemIsSelectable | Qt::ItemIsEnabled;
|
||||||
else if (details.type == DIR_TYPE_DIR)
|
default: ;
|
||||||
{
|
case DIR_TYPE_FILE: return Qt::ItemIsSelectable | Qt::ItemIsDragEnabled | Qt::ItemIsEnabled;
|
||||||
return ( Qt::ItemIsSelectable |
|
|
||||||
Qt::ItemIsEnabled);
|
|
||||||
|
|
||||||
// Qt::ItemIsDragEnabled |
|
|
||||||
// Qt::ItemIsDropEnabled |
|
|
||||||
|
|
||||||
}
|
|
||||||
else // (details.type == DIR_TYPE_FILE)
|
|
||||||
{
|
|
||||||
return ( Qt::ItemIsSelectable |
|
|
||||||
Qt::ItemIsDragEnabled |
|
|
||||||
Qt::ItemIsEnabled);
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -38,118 +38,118 @@
|
||||||
|
|
||||||
class RemoteDirModel : public QAbstractItemModel
|
class RemoteDirModel : public QAbstractItemModel
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
enum Roles{ FileNameRole = Qt::UserRole+1 };
|
enum Roles{ FileNameRole = Qt::UserRole+1 };
|
||||||
|
|
||||||
RemoteDirModel(bool mode, QObject *parent = 0);
|
RemoteDirModel(bool mode, QObject *parent = 0);
|
||||||
|
|
||||||
/* These are all overloaded Virtual Functions */
|
/* These are all overloaded Virtual Functions */
|
||||||
int rowCount(const QModelIndex &parent = QModelIndex()) const;
|
int rowCount(const QModelIndex &parent = QModelIndex()) const;
|
||||||
int columnCount(const QModelIndex &parent = QModelIndex()) const;
|
int columnCount(const QModelIndex &parent = QModelIndex()) const;
|
||||||
|
|
||||||
QVariant data(const QModelIndex &index, int role) const;
|
QVariant data(const QModelIndex &index, int role) const;
|
||||||
QVariant headerData(int section, Qt::Orientation orientation,
|
QVariant headerData(int section, Qt::Orientation orientation,
|
||||||
int role = Qt::DisplayRole) const;
|
int role = Qt::DisplayRole) const;
|
||||||
|
|
||||||
QModelIndex index(int row, int column,
|
QModelIndex index(int row, int column,
|
||||||
const QModelIndex & parent = QModelIndex() ) const;
|
const QModelIndex & parent = QModelIndex() ) const;
|
||||||
QModelIndex parent ( const QModelIndex & index ) const;
|
QModelIndex parent ( const QModelIndex & index ) const;
|
||||||
|
|
||||||
Qt::ItemFlags flags ( const QModelIndex & index ) const;
|
Qt::ItemFlags flags ( const QModelIndex & index ) const;
|
||||||
bool hasChildren(const QModelIndex & parent = QModelIndex()) const;
|
bool hasChildren(const QModelIndex & parent = QModelIndex()) const;
|
||||||
|
|
||||||
/* Callback from Core */
|
/* Callback from Core */
|
||||||
void preMods();
|
void preMods();
|
||||||
void postMods();
|
void postMods();
|
||||||
|
|
||||||
/* Callback from GUI */
|
/* Callback from GUI */
|
||||||
void downloadSelected(QModelIndexList list);
|
void downloadSelected(QModelIndexList list);
|
||||||
|
|
||||||
void getDirDetailsFromSelect (QModelIndexList list, std::vector <DirDetails>& dirVec);
|
void getDirDetailsFromSelect (QModelIndexList list, std::vector <DirDetails>& dirVec);
|
||||||
|
|
||||||
bool isDir ( const QModelIndex & index ) const ;
|
bool isDir ( const QModelIndex & index ) const ;
|
||||||
//void openFile(QModelIndex fileIndex, const QString command);
|
//void openFile(QModelIndex fileIndex, const QString command);
|
||||||
|
|
||||||
//#if 0 /****** REMOVED ******/
|
//#if 0 /****** REMOVED ******/
|
||||||
// void recommendSelected(QModelIndexList list);
|
// void recommendSelected(QModelIndexList list);
|
||||||
// void recommendSelectedOnly(QModelIndexList list);
|
// void recommendSelectedOnly(QModelIndexList list);
|
||||||
//#endif
|
//#endif
|
||||||
void getFileInfoFromIndexList(const QModelIndexList& list, std::list<DirDetails>& files_info) ;
|
void getFileInfoFromIndexList(const QModelIndexList& list, std::list<DirDetails>& files_info) ;
|
||||||
|
|
||||||
void openSelected(QModelIndexList list, bool openFolder);
|
void openSelected(QModelIndexList list, bool openFolder);
|
||||||
|
|
||||||
void getFilePaths(QModelIndexList list, std::list<std::string> &fullpaths);
|
void getFilePaths(QModelIndexList list, std::list<std::string> &fullpaths);
|
||||||
|
|
||||||
void changeAgeIndicator(int indicator) { ageIndicator = indicator; }
|
void changeAgeIndicator(int indicator) { ageIndicator = indicator; }
|
||||||
|
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
|
|
||||||
void collapsed ( const QModelIndex & index ) { update(index); }
|
void collapsed ( const QModelIndex & index ) { update(index); }
|
||||||
void expanded ( const QModelIndex & index ) { update(index); }
|
void expanded ( const QModelIndex & index ) { update(index); }
|
||||||
|
|
||||||
/* Drag and Drop Functionality */
|
/* Drag and Drop Functionality */
|
||||||
public:
|
public:
|
||||||
|
|
||||||
virtual QMimeData * mimeData ( const QModelIndexList & indexes ) const;
|
virtual QMimeData * mimeData ( const QModelIndexList & indexes ) const;
|
||||||
virtual QStringList mimeTypes () const;
|
virtual QStringList mimeTypes () const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void update (const QModelIndex &index );
|
void update (const QModelIndex &index );
|
||||||
void treeStyle();
|
void treeStyle();
|
||||||
void downloadDirectory(const DirDetails & details, int prefixLen);
|
void downloadDirectory(const DirDetails & details, int prefixLen);
|
||||||
static QString getFlagsString(uint32_t) ;
|
static QString getFlagsString(uint32_t) ;
|
||||||
QString getAgeIndicatorString(const DirDetails &) const;
|
QString getAgeIndicatorString(const DirDetails &) const;
|
||||||
void getAgeIndicatorRec(DirDetails &details, QString &ret) const;
|
void getAgeIndicatorRec(DirDetails &details, QString &ret) const;
|
||||||
|
|
||||||
int ageIndicator;
|
int ageIndicator;
|
||||||
|
|
||||||
QIcon categoryIcon;
|
QIcon categoryIcon;
|
||||||
QIcon peerIcon;
|
QIcon peerIcon;
|
||||||
|
|
||||||
class RemoteIndex
|
class RemoteIndex
|
||||||
{
|
|
||||||
public:
|
|
||||||
RemoteIndex() {}
|
|
||||||
RemoteIndex(std::string in_person,
|
|
||||||
std::string in_path,
|
|
||||||
int in_idx,
|
|
||||||
int in_row,
|
|
||||||
int in_column,
|
|
||||||
std::string in_name,
|
|
||||||
int in_size,
|
|
||||||
int in_type,
|
|
||||||
int in_ts, int in_rank)
|
|
||||||
:id(in_person), path(in_path), parent(in_idx),
|
|
||||||
row(in_row), column(in_column),
|
|
||||||
name(in_name), size(in_size),
|
|
||||||
type(in_type), timestamp(in_ts), rank(in_rank)
|
|
||||||
{
|
{
|
||||||
return;
|
public:
|
||||||
}
|
RemoteIndex() {}
|
||||||
|
RemoteIndex(std::string in_person,
|
||||||
|
std::string in_path,
|
||||||
|
int in_idx,
|
||||||
|
int in_row,
|
||||||
|
int in_column,
|
||||||
|
std::string in_name,
|
||||||
|
int in_size,
|
||||||
|
int in_type,
|
||||||
|
int in_ts, int in_rank)
|
||||||
|
:id(in_person), path(in_path), parent(in_idx),
|
||||||
|
row(in_row), column(in_column),
|
||||||
|
name(in_name), size(in_size),
|
||||||
|
type(in_type), timestamp(in_ts), rank(in_rank)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
std::string id;
|
std::string id;
|
||||||
std::string path;
|
std::string path;
|
||||||
int parent;
|
int parent;
|
||||||
int row;
|
int row;
|
||||||
int column;
|
int column;
|
||||||
|
|
||||||
/* display info */
|
/* display info */
|
||||||
std::string name;
|
std::string name;
|
||||||
int size;
|
int size;
|
||||||
int type;
|
int type;
|
||||||
int timestamp;
|
int timestamp;
|
||||||
int rank;
|
int rank;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
bool RemoteMode;
|
bool RemoteMode;
|
||||||
|
|
||||||
mutable int nIndex;
|
mutable int nIndex;
|
||||||
mutable std::vector<RemoteIndex> indexSet;
|
mutable std::vector<RemoteIndex> indexSet;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue