added extra list view in own files.

This commit is contained in:
csoler 2018-09-27 13:42:49 +02:00
parent 359e11433b
commit 1383846364
No known key found for this signature in database
GPG key ID: 7BCA522266C0804C
9 changed files with 149 additions and 24 deletions

View file

@ -38,6 +38,7 @@
//#define DEBUG_P3FILELISTS 1
#define DEBUG_CONTENT_FILTERING 1
#define DEBUG_FILE_HIERARCHY 1
static const uint32_t P3FILELISTS_UPDATE_FLAG_NOTHING_CHANGED = 0x0000 ;
static const uint32_t P3FILELISTS_UPDATE_FLAG_REMOTE_MAP_CHANGED = 0x0001 ;
@ -71,6 +72,7 @@ p3FileDatabase::p3FileDatabase(p3ServiceControl *mpeers)
mUpdateFlags = P3FILELISTS_UPDATE_FLAG_NOTHING_CHANGED ;
mLastRemoteDirSweepTS = 0 ;
mLastExtraFilesCacheUpdate = 0;
mLastCleanupTime = 0 ;
mLastDataRecvTS = 0 ;
mTrustFriendNodesForBannedFiles = TRUST_FRIEND_NODES_FOR_BANNED_FILES_DEFAULT;
@ -884,6 +886,8 @@ void p3FileDatabase::requestDirUpdate(void *ref)
}
}
// Finds the pointer to the sub-element #row under element ref.
bool p3FileDatabase::findChildPointer( void *ref, int row, void *& result,
FileSearchFlags flags ) const
{
@ -891,10 +895,10 @@ bool p3FileDatabase::findChildPointer( void *ref, int row, void *& result,
{
if(flags & RS_FILE_HINTS_LOCAL)
{
if(row != 0)
if(row != 0 && row != 1)
return false ;
convertEntryIndexToPointer<sizeof(void*)>(0,0,result);
convertEntryIndexToPointer<sizeof(void*)>(0,row,result);
return true ;
}
@ -913,12 +917,18 @@ bool p3FileDatabase::findChildPointer( void *ref, int row, void *& result,
convertPointerToEntryIndex<sizeof(void*)>(ref,e,fi);
// check consistency
if( (fi == 0 && !(flags & RS_FILE_HINTS_LOCAL)) || (fi > 0 && (flags & RS_FILE_HINTS_LOCAL)))
if( (fi == 0 && !(flags & RS_FILE_HINTS_LOCAL)) || (fi > 1 && (flags & RS_FILE_HINTS_LOCAL)))
{
P3FILELISTS_ERROR() << "(EE) remote request on local index or local request on remote index. This should not happen." << std::endl;
return false ;
}
DirectoryStorage *storage = (fi==0)? ((DirectoryStorage*)mLocalSharedDirs) : ((DirectoryStorage*)mRemoteDirectories[fi-1]);
if(fi==1 && (flags & RS_FILE_HINTS_LOCAL)) // extra list
{
convertEntryIndexToPointer<sizeof(void*)>(row+1,1,result);
return true;
}
DirectoryStorage *storage = (flags & RS_FILE_HINTS_LOCAL)? ((DirectoryStorage*)mLocalSharedDirs) : ((DirectoryStorage*)mRemoteDirectories[fi-1]);
// Case where the index is the top of a single person. Can be us, or a friend.
@ -950,6 +960,65 @@ int p3FileDatabase::getSharedDirStatistics(const RsPeerId& pid,SharedDirStats& s
}
}
void p3FileDatabase::getExtraFilesDirDetails(void *ref,DirectoryStorage::EntryIndex e,DirDetails& d) const
{
// update the cache of extra files if last requested too long ago
time_t now = time(NULL);
if(mLastExtraFilesCacheUpdate + DELAY_BETWEEN_EXTRA_FILES_CACHE_UPDATES <= now)
{
mExtraFiles->getExtraFileList(mExtraFilesCache);
mLastExtraFilesCacheUpdate = now;
}
//
if(e == 0) // "virtual extra files directory" => create a dir with as many child as they are extra files
{
d.parent = NULL ;
d.prow = 0;//fi-1 ;
d.type = DIR_TYPE_DIR;
d.hash.clear() ;
d.count = mExtraFilesCache.size();
d.max_mtime = time(NULL);
d.mtime = time(NULL);
d.name = "Temporary shared files";
d.path = "/";
d.ref = ref ;
for(uint32_t i=0;i<mExtraFilesCache.size();++i)
{
DirStub stub;
stub.type = DIR_TYPE_FILE;
stub.name = mExtraFilesCache[i].fname;
convertEntryIndexToPointer<sizeof(void*)>(i,1,stub.ref); // local shared files from extra list
d.children.push_back(stub);
}
}
else // extra file. Just query the corresponding data from ftExtra
{
d.prow = 1;//fi-1 ;
d.type = DIR_TYPE_FILE;
FileInfo& f(mExtraFilesCache[(int)e-1]) ;
d.hash = f.hash;
d.count = 0;
d.max_mtime = time(NULL);
d.mtime = time(NULL);
d.name = f.fname;
d.path = "/";
d.ref = ref ;
convertEntryIndexToPointer<sizeof(void*)>(0,1,d.parent) ;
}
d.id = RsPeerId();
}
// This function converts a pointer into directory details, to be used by the AbstractItemModel for browsing the files.
int p3FileDatabase::RequestDirDetails(void *ref, DirDetails& d, FileSearchFlags flags) const
{
@ -975,10 +1044,8 @@ int p3FileDatabase::RequestDirDetails(void *ref, DirDetails& d, FileSearchFlags
{
d.ref = NULL ;
d.type = DIR_TYPE_ROOT;
d.count = 1;
d.parent = NULL;
d.prow = -1;
d.ref = NULL;
d.name = "root";
d.hash.clear() ;
d.path = "";
@ -989,13 +1056,26 @@ int p3FileDatabase::RequestDirDetails(void *ref, DirDetails& d, FileSearchFlags
if(flags & RS_FILE_HINTS_LOCAL)
{
void *p;
convertEntryIndexToPointer<sizeof(void*)>(0,0,p);
{
convertEntryIndexToPointer<sizeof(void*)>(0,0,p); // root of own directories
DirStub stub;
stub.type = DIR_TYPE_PERSON;
stub.name = mServCtrl->getOwnId().toStdString();
stub.ref = p;
d.children.push_back(stub);
}
{
convertEntryIndexToPointer<sizeof(void*)>(0,1,p); // local shared files from extra list
DirStub stub;
stub.type = DIR_TYPE_PERSON;
stub.name = "Temporary shared files";
stub.ref = p;
d.children.push_back(stub);
}
}
else for(uint32_t i=0;i<mRemoteDirectories.size();++i)
if(mRemoteDirectories[i] != NULL)
@ -1014,6 +1094,7 @@ int p3FileDatabase::RequestDirDetails(void *ref, DirDetails& d, FileSearchFlags
#ifdef DEBUG_FILE_HIERARCHY
P3FILELISTS_DEBUG() << "ExtractData: ref=" << ref << ", flags=" << flags << " : returning this: " << std::endl;
P3FILELISTS_DEBUG() << d << std::endl;
#endif
return true ;
@ -1025,12 +1106,25 @@ int p3FileDatabase::RequestDirDetails(void *ref, DirDetails& d, FileSearchFlags
convertPointerToEntryIndex<sizeof(void*)>(ref,e,fi);
// check consistency
if( (fi == 0 && !(flags & RS_FILE_HINTS_LOCAL)) || (fi > 0 && (flags & RS_FILE_HINTS_LOCAL)))
if( (fi == 0 && !(flags & RS_FILE_HINTS_LOCAL)) || (fi > 1 && (flags & RS_FILE_HINTS_LOCAL)))
{
P3FILELISTS_ERROR() << "(EE) remote request on local index or local request on remote index. This should not happen." << std::endl;
return false ;
}
DirectoryStorage *storage = (fi==0)? ((DirectoryStorage*)mLocalSharedDirs) : ((DirectoryStorage*)mRemoteDirectories[fi-1]);
if((flags & RS_FILE_HINTS_LOCAL) && fi == 1) // extra list
{
getExtraFilesDirDetails(ref,e,d);
#ifdef DEBUG_FILE_HIERARCHY
P3FILELISTS_DEBUG() << "ExtractData: ref=" << ref << ", flags=" << flags << " : returning this: " << std::endl;
P3FILELISTS_DEBUG() << d << std::endl;
#endif
return true;
}
DirectoryStorage *storage = (flags & RS_FILE_HINTS_LOCAL)? ((DirectoryStorage*)mLocalSharedDirs) : ((DirectoryStorage*)mRemoteDirectories[fi-1]);
// Case where the index is the top of a single person. Can be us, or a friend.