- added some optimization to RequestDirDetails internal functions

- improved sorting/selection in shared files flat mode
*W* Needs full recompilation.



git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@4121 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
csoler 2011-04-03 19:59:12 +00:00
parent f9c896c3ac
commit 6c2bdbe214
12 changed files with 115 additions and 47 deletions

View File

@ -1237,6 +1237,12 @@ int FileIndexMonitor::RequestDirDetails(std::string uid, std::string path, DirDe
return (uid == fi.root->id) ;
}
uint32_t FileIndexMonitor::getType(void *ref) const
{
RsStackMutex mutex(fiMutex) ;
return fi.getType(ref) ;
}
int FileIndexMonitor::RequestDirDetails(void *ref, DirDetails &details, uint32_t flags) const
{
RsStackMutex mutex(fiMutex) ;

View File

@ -135,6 +135,7 @@ class FileIndexMonitor: public CacheSource, public RsThread
// Interface for browsing dir hirarchy
int RequestDirDetails(void*, DirDetails&, uint32_t) const ;
uint32_t getType(void*) const ;
int RequestDirDetails(std::string uid, std::string path, DirDetails &details) const ;
// set/update shared directories

View File

@ -1216,6 +1216,16 @@ int FileIndex::searchBoolExp(Expression * exp, std::list<FileEntry *> &results)
return 0;
}
uint32_t FileIndex::getType(void *ref)
{
if(ref == NULL)
return DIR_TYPE_ROOT ;
if(!isValid(ref))
return DIR_TYPE_ROOT ;
return static_cast<FileEntry*>(ref)->type() ;
}
bool FileIndex::extractData(void *ref,DirDetails& details)
{
if(!isValid(ref))
@ -1227,7 +1237,7 @@ bool FileIndex::extractData(void *ref,DirDetails& details)
}
FileEntry *file = static_cast<FileEntry *>(ref);
DirEntry *dir = dynamic_cast<DirEntry *>(file);
DirEntry *dir = (file->hash.empty())?static_cast<DirEntry *>(file):NULL ; // This is a hack to avoid doing a dynamic_cast
details.children = std::list<DirStub>() ;
time_t now = time(NULL) ;
@ -1304,7 +1314,7 @@ bool FileIndex::extractData(void *ref,DirDetails& details)
FileEntry *f ;
for(f=file;f->parent!=NULL;f=f->parent) ;
details.id = dynamic_cast<PersonEntry*>(f)->id;
details.id = static_cast<PersonEntry*>(f)->id; // The topmost parent is necessarily a personEntrY, so we can avoid a dynamic_cast.
#ifdef FI_DEBUG
assert(details.parent != details.ref) ;

View File

@ -83,7 +83,8 @@ class FileEntry
: size(0), modtime(0), pop(0), updtime(0), parent(NULL), row(0)
{ return; }
virtual ~FileEntry() { return; }
virtual ~FileEntry() { return; }
virtual uint32_t type() const { return DIR_TYPE_FILE ; }
virtual int print(std::ostream &out);
@ -118,6 +119,7 @@ DirEntry * updateDir(const FileEntry& fe, time_t updtime);
FileEntry * updateFile(const FileEntry& fe, time_t updtime);
virtual uint32_t type() const { return DIR_TYPE_DIR ; }
int checkParentPointers();
int updateChildRows();
@ -179,6 +181,7 @@ DirEntry &operator=(DirEntry &src)
(*pdest) = src;
return *this;
}
virtual uint32_t type() const { return DIR_TYPE_PERSON ; }
/* Data */
std::string id;
@ -248,6 +251,7 @@ class FileIndex
/// Fills up details from the data contained in ref.
//
static bool extractData(void *ref,DirDetails& details) ;
static uint32_t getType(void *ref) ;
};

View File

@ -155,6 +155,7 @@ int FileIndexStore::loadCache(const CacheData &data)
return ret;
}
/* Search Interface - For Directory Access */
int FileIndexStore::RequestDirDetails(std::string uid, std::string path, DirDetails &details) const
{
@ -247,7 +248,14 @@ int FileIndexStore::RequestDirDetails(void *ref, DirDetails &details, uint32_t f
unlockData();
return b;
}
uint32_t FileIndexStore::getType(void *ref) const
{
lockData() ;
uint32_t b = FileIndex::getType(ref) ;
unlockData();
return b;
}
int FileIndexStore::SearchHash(std::string hash, std::list<FileDetail> &results) const
{

View File

@ -84,6 +84,7 @@ virtual int loadCache(const CacheData &data); /* actual load, once data availa
/* Search Interface - For Directory Access */
int RequestDirDetails(std::string uid, std::string path, DirDetails &details) const;
int RequestDirDetails(void *ref, DirDetails &details, uint32_t flags) const;
uint32_t getType(void *ref) const ;
private:
int AboutToModify();

View File

@ -502,7 +502,25 @@ int ftServer::RequestDirDetails(void *ref, DirDetails &details, uint32_t flags)
else
return mFiStore->RequestDirDetails(ref, details, flags);
}
uint32_t ftServer::getType(void *ref, uint32_t flags)
{
#ifdef SERVER_DEBUG
std::cerr << "ftServer::RequestDirDetails(ref:" << ref;
std::cerr << ", flags:" << flags << ", ...) -> mFiStore";
std::cerr << std::endl;
if (!mFiStore)
{
std::cerr << "mFiStore not SET yet = FAIL";
std::cerr << std::endl;
}
#endif
if(flags & DIR_FLAGS_LOCAL)
return mFiMon->getType(ref);
else
return mFiStore->getType(ref);
}
/***************************************************************/
/******************** Search Interface *************************/
/***************************************************************/

View File

@ -171,6 +171,7 @@ virtual bool ExtraFileMove(std::string fname, std::string hash, uint64_t size,
***/
virtual int RequestDirDetails(std::string uid, std::string path, DirDetails &details);
virtual int RequestDirDetails(void *ref, DirDetails &details, uint32_t flags);
virtual uint32_t getType(void *ref,uint32_t flags) ;
virtual int SearchKeywords(std::list<std::string> keywords, std::list<DirDetails> &results,uint32_t flags);
virtual int SearchBoolExp(Expression * exp, std::list<DirDetails> &results,uint32_t flags);

View File

@ -159,7 +159,9 @@ class RsFiles
* Directory Listing / Search Interface
*/
virtual int RequestDirDetails(std::string uid, std::string path, DirDetails &details) = 0;
virtual int RequestDirDetails(void *ref, DirDetails &details, uint32_t flags) = 0;
virtual uint32_t getType(void *ref,uint32_t flags) = 0;
virtual int SearchKeywords(std::list<std::string> keywords, std::list<DirDetails> &results,uint32_t flags) = 0;
virtual int SearchBoolExp(Expression * exp, std::list<DirDetails> &results,uint32_t flags) = 0;

View File

@ -83,7 +83,7 @@ bool TreeStyle_RDM::hasChildren(const QModelIndex &parent) const
else
flags |= DIR_FLAGS_LOCAL;
if (!rsFiles->RequestDirDetails(ref, details, flags))
if (!requestDirDetails(ref, details, flags))
{
/* error */
#ifdef RDM_DEBUG
@ -144,7 +144,7 @@ int TreeStyle_RDM::rowCount(const QModelIndex &parent) const
else
flags |= DIR_FLAGS_LOCAL;
if (!rsFiles->RequestDirDetails(ref, details, flags))
if (!requestDirDetails(ref, details, flags))
{
#ifdef RDM_DEBUG
std::cerr << "lookup failed -> 0";
@ -379,8 +379,7 @@ QVariant FlatStyle_RDM::displayRole(const DirDetails& details,int coln) const
return QVariant();
} /* end of DisplayRole */
QVariant RetroshareDirModel::sortRole(const DirDetails& details,int coln) const
QVariant TreeStyle_RDM::sortRole(const DirDetails& details,int coln) const
{
/*
* Person: name, id, 0, 0;
@ -440,6 +439,27 @@ QVariant RetroshareDirModel::sortRole(const DirDetails& details,int coln) const
}
}
return QVariant();
}
QVariant FlatStyle_RDM::sortRole(const DirDetails& details,int coln) const
{
/*
* Person: name, id, 0, 0;
* File : name, size, rank, (0) ts
* Dir : name, (0) count, (0) path, (0) ts
*/
if (details.type == DIR_TYPE_FILE) /* File */
{
switch(coln)
{
case 0: return QString::fromUtf8(details.name.c_str());
case 1: return (qulonglong) details.count;
case 2: return details.age;
case 3: return QString::fromStdString(rsPeers->getPeerName(details.id));
}
}
else
return QVariant();
} /* end of SortRole */
@ -467,7 +487,7 @@ QVariant RetroshareDirModel::data(const QModelIndex &index, int role) const
else
flags |= DIR_FLAGS_LOCAL;
if (!rsFiles->RequestDirDetails(ref, details, flags))
if (!requestDirDetails(ref, details, flags))
return QVariant();
if (role == RetroshareDirModel::FileNameRole) /* end of FileNameRole */
@ -532,7 +552,7 @@ void RetroshareDirModel::getAgeIndicatorRec(DirDetails &details, QString &ret) c
else
flags |= DIR_FLAGS_LOCAL;
if (rsFiles->RequestDirDetails(ref, childDetails, flags) && ret == tr(""))
if (requestDirDetails(ref, childDetails, flags) && ret == tr(""))
getAgeIndicatorRec(childDetails, ret);
}
}
@ -650,7 +670,7 @@ QModelIndex TreeStyle_RDM::index(int row, int column, const QModelIndex & parent
else
flags |= DIR_FLAGS_LOCAL;
if (!rsFiles->RequestDirDetails(ref, details, flags))
if (!requestDirDetails(ref, details, flags))
{
#ifdef RDM_DEBUG
std::cerr << "lookup failed -> invalid";
@ -728,7 +748,7 @@ QModelIndex TreeStyle_RDM::parent( const QModelIndex & index ) const
DirDetails details;
uint32_t flags = (RemoteMode)?DIR_FLAGS_REMOTE:DIR_FLAGS_LOCAL;
if (!rsFiles->RequestDirDetails(ref, details, flags))
if (!requestDirDetails(ref, details, flags))
{
#ifdef RDM_DEBUG
std::cerr << "Failed Lookup -> invalid";
@ -781,7 +801,7 @@ Qt::ItemFlags RetroshareDirModel::flags( const QModelIndex & index ) const
else
flags |= DIR_FLAGS_LOCAL;
if (!rsFiles->RequestDirDetails(ref, details, flags))
if (!requestDirDetails(ref, details, flags))
return Qt::ItemIsSelectable; // Error.
switch(details.type)
@ -829,15 +849,13 @@ Qt::ItemFlags RetroshareDirModel::flags( const QModelIndex & index ) const
#endif
}
bool RetroshareDirModel::requestDirDetails(void *ref,DirDetails& details,uint32_t flags) const
{
// We should use a cache instead of calling RsFiles::RequestDirDetails(), which is very costly
// due to some pointer checking crap.
//void RetroshareDirModel::update (const QModelIndex &index )
//{
//#ifdef RDM_DEBUG
// //std::cerr << "Directory Request(" << id << ") : ";
// //std::cerr << path << std::endl;
//#endif
// //rsFiles -> RequestDirectories(id, path, 1);
//}
return rsFiles->RequestDirDetails(ref, details, flags) ;
}
void RetroshareDirModel::downloadSelected(const QModelIndexList &list)
{
@ -912,7 +930,7 @@ void RetroshareDirModel::downloadDirectory(const DirDetails & dirDetails, int pr
DirDetails subDirDetails;
uint32_t flags = DIR_FLAGS_CHILDREN | DIR_FLAGS_REMOTE;
if (!rsFiles->RequestDirDetails(it->ref, subDirDetails, flags)) continue;
if (!requestDirDetails(it->ref, subDirDetails, flags)) continue;
downloadDirectory(subDirDetails, prefixLen);
}
@ -942,7 +960,7 @@ void RetroshareDirModel::getDirDetailsFromSelect (const QModelIndexList &list, s
flags |= DIR_FLAGS_LOCAL;
}
if (!rsFiles->RequestDirDetails(ref, details, flags))
if (!requestDirDetails(ref, details, flags))
{
continue;
}
@ -987,7 +1005,7 @@ void RetroshareDirModel::getFileInfoFromIndexList(const QModelIndexList& list, s
else
flags |= DIR_FLAGS_LOCAL;
if (!rsFiles->RequestDirDetails(ref, details, flags))
if (!requestDirDetails(ref, details, flags))
continue;
if(details.type == DIR_TYPE_PERSON)
@ -1084,7 +1102,7 @@ void RetroshareDirModel::getFilePaths(const QModelIndexList &list, std::list<std
uint32_t flags = DIR_FLAGS_DETAILS;
flags |= DIR_FLAGS_LOCAL;
if (!rsFiles->RequestDirDetails(ref, details, flags))
if (!requestDirDetails(ref, details, flags))
{
#ifdef RDM_DEBUG
std::cerr << "getFilePaths() Bad Request" << std::endl;
@ -1148,7 +1166,7 @@ QMimeData * RetroshareDirModel::mimeData ( const QModelIndexList & indexes ) con
flags |= DIR_FLAGS_LOCAL;
}
if (!rsFiles->RequestDirDetails(ref, details, flags))
if (!requestDirDetails(ref, details, flags))
{
continue;
}
@ -1232,25 +1250,12 @@ QStringList RetroshareDirModel::mimeTypes () const
int RetroshareDirModel::getType ( const QModelIndex & index ) const
{
//if (RemoteMode) // only local files can be opened
// return ;
void *ref = index.internalPointer();
if (!ref)
return false;
//if (RemoteMode) // only local files can be opened
// return ;
DirDetails details;
uint32_t flags = DIR_FLAGS_DETAILS;
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))
{
return false;//not good, but....
}
return details.type;
return rsFiles->getType(index.internalPointer(),flags);
}
FlatStyle_RDM::~FlatStyle_RDM()
@ -1278,7 +1283,7 @@ void FlatStyle_RDM::postMods()
uint32_t flags = DIR_FLAGS_DETAILS;
DirDetails details ;
if (rsFiles->RequestDirDetails(ref, details, flags))
if (requestDirDetails(ref, details, flags))
{
if(details.type == DIR_TYPE_FILE) // only push files, not directories nor persons.
_ref_entries.push_back(ref);

View File

@ -61,6 +61,7 @@ class RetroshareDirModel : public QAbstractItemModel
void getFilePaths(const QModelIndexList &list, std::list<std::string> &fullpaths);
void changeAgeIndicator(uint32_t indicator) { ageIndicator = indicator; }
bool requestDirDetails(void *ref,DirDetails& details,uint32_t flags) const;
public:
virtual QMimeData * mimeData ( const QModelIndexList & indexes ) const;
@ -75,9 +76,9 @@ class RetroshareDirModel : public QAbstractItemModel
void getAgeIndicatorRec(DirDetails &details, QString &ret) const;
virtual QVariant displayRole(const DirDetails&,int) const = 0 ;
virtual QVariant sortRole(const DirDetails&,int) const =0;
QVariant decorationRole(const DirDetails&,int) const ;
QVariant sortRole(const DirDetails&,int) const ;
uint32_t ageIndicator;
@ -148,6 +149,7 @@ class TreeStyle_RDM: public RetroshareDirModel
virtual QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const;
virtual QVariant displayRole(const DirDetails&,int) const ;
virtual QVariant sortRole(const DirDetails&,int) const ;
virtual QModelIndex index(int row, int column, const QModelIndex & parent = QModelIndex() ) const;
virtual QModelIndex parent ( const QModelIndex & index ) const;
@ -176,6 +178,7 @@ class FlatStyle_RDM: public RetroshareDirModel
virtual QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const;
virtual QVariant displayRole(const DirDetails&,int) const ;
virtual QVariant sortRole(const DirDetails&,int) const ;
virtual QModelIndex index(int row, int column, const QModelIndex & parent = QModelIndex() ) const;
virtual QModelIndex parent ( const QModelIndex & index ) const;

View File

@ -55,6 +55,10 @@
#define IMAGE_OPENFOLDER ":/images/folderopen.png"
#define IMAGE_OPENFILE ":/images/fileopen.png"
// Define to avoid using the search in treeview, because it is really slow for now.
//
#define DONT_USE_SEARCH_IN_TREE_VIEW 1
const QString Image_AddNewAssotiationForFile = ":/images/kcmsystem24.png";
class SFDSortFilterProxyModel : public QSortFilterProxyModel
@ -208,9 +212,6 @@ SharedFilesDialog::SharedFilesDialog(QWidget *parent)
//
changeCurrentViewModel(ui.viewType_CB->currentIndex()) ;
ui.filterStartButton->hide();
ui.filterClearButton->hide();
/* Hide platform specific features */
#ifdef Q_WS_WIN
@ -278,16 +279,22 @@ void SharedFilesDialog::changeCurrentViewModel(int c)
model = tree_model ;
proxyModel = tree_proxyModel ;
ui.remoteDirTreeView->setColumnHidden(3,true) ;
#ifdef DONT_USE_SEARCH_IN_TREE_VIEW
ui.filterLabel->hide();
ui.filterPatternLineEdit->hide();
ui.filterStartButton->hide();
ui.filterClearButton->hide();
#endif
}
else
{
model = flat_model ;
proxyModel = flat_proxyModel ;
ui.remoteDirTreeView->setColumnHidden(3,false) ;
#ifdef DONT_USE_SEARCH_IN_TREE_VIEW
ui.filterLabel->show();
ui.filterPatternLineEdit->show();
#endif
}
model->preMods();
@ -301,7 +308,9 @@ void SharedFilesDialog::changeCurrentViewModel(int c)
ui.remoteDirTreeView->header()->headerDataChanged(Qt::Horizontal,0,4) ;
#ifdef DONT_USE_SEARCH_IN_TREE_VIEW
if(c == 1)
#endif
FilterItems();
}