mirror of
https://github.com/RetroShare/RetroShare.git
synced 2024-10-01 02:35:48 -04:00
added copy links from file hierarchy
This commit is contained in:
parent
f98edd400e
commit
e1d5014288
@ -30,15 +30,63 @@ FileTree *FileTree::create(const std::string& radix64_string)
|
|||||||
return ft ;
|
return ft ;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void recurs_buildFileTree(FileTreeImpl& ft,uint32_t index,void *ref)
|
void FileTreeImpl::recurs_buildFileTree(FileTreeImpl& ft,uint32_t index,const DirDetails& dd,bool remote)
|
||||||
{
|
{
|
||||||
|
if(ft.mDirs.size() <= index)
|
||||||
|
ft.mDirs.resize(index+1) ;
|
||||||
|
|
||||||
|
ft.mDirs[index].name = dd.name ;
|
||||||
|
ft.mDirs[index].subfiles.clear();
|
||||||
|
ft.mDirs[index].subdirs.clear();
|
||||||
|
|
||||||
|
DirDetails dd2 ;
|
||||||
|
|
||||||
|
FileSearchFlags flags = remote?RS_FILE_HINTS_REMOTE:RS_FILE_HINTS_LOCAL ;
|
||||||
|
|
||||||
|
for(uint32_t i=0;i<dd.children.size();++i)
|
||||||
|
if(rsFiles->RequestDirDetails(dd.children[i].ref,dd2,flags))
|
||||||
|
{
|
||||||
|
if(dd.children[i].type == DIR_TYPE_FILE)
|
||||||
|
{
|
||||||
|
FileTree::FileData f ;
|
||||||
|
f.name = dd2.name ;
|
||||||
|
f.size = dd2.count ;
|
||||||
|
f.hash = dd2.hash ;
|
||||||
|
|
||||||
|
ft.mDirs[index].subfiles.push_back(ft.mFiles.size()) ;
|
||||||
|
ft.mFiles.push_back(f) ;
|
||||||
|
}
|
||||||
|
else if(dd.children[i].type == DIR_TYPE_DIR)
|
||||||
|
{
|
||||||
|
ft.mDirs[index].subdirs.push_back(ft.mDirs.size());
|
||||||
|
recurs_buildFileTree(ft,ft.mDirs.size(),dd2,remote) ;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
std::cerr << "(EE) Unsupported DirDetails type." << std::endl;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
std::cerr << "(EE) Cannot request dir details for pointer " << dd.children[i].ref << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
FileTree *FileTree::create(void *ref)
|
bool FileTreeImpl::getDirectoryContent(uint32_t index,std::vector<uint32_t>& subdirs,std::vector<FileData>& subfiles) const
|
||||||
|
{
|
||||||
|
if(index >= mDirs.size())
|
||||||
|
return false ;
|
||||||
|
|
||||||
|
subdirs = mDirs[index].subdirs ;
|
||||||
|
|
||||||
|
subfiles.clear() ;
|
||||||
|
for(uint32_t i=0;i<mDirs[index].subfiles.size();++i)
|
||||||
|
subfiles.push_back(mFiles[mDirs[index].subfiles[i]]);
|
||||||
|
|
||||||
|
return true ;
|
||||||
|
}
|
||||||
|
|
||||||
|
FileTree *FileTree::create(const DirDetails& dd, bool remote)
|
||||||
{
|
{
|
||||||
FileTreeImpl *ft = new FileTreeImpl ;
|
FileTreeImpl *ft = new FileTreeImpl ;
|
||||||
|
|
||||||
recurs_buildFileTree(*ft,0,ref) ;
|
FileTreeImpl::recurs_buildFileTree(*ft,0,dd,remote) ;
|
||||||
|
|
||||||
return ft ;
|
return ft ;
|
||||||
}
|
}
|
||||||
@ -81,16 +129,12 @@ bool FileTreeImpl::deserialise(unsigned char *buffer,uint32_t buffer_size)
|
|||||||
|
|
||||||
if(FileListIO::readField(buffer,buffer_size,buffer_offset,FILE_LIST_IO_TAG_LOCAL_FILE_ENTRY,node_section_data,node_section_size))
|
if(FileListIO::readField(buffer,buffer_size,buffer_offset,FILE_LIST_IO_TAG_LOCAL_FILE_ENTRY,node_section_data,node_section_size))
|
||||||
{
|
{
|
||||||
std::string file_name ;
|
|
||||||
uint64_t file_size ;
|
|
||||||
RsFileHash file_hash ;
|
|
||||||
|
|
||||||
if(!FileListIO::readField(node_section_data,node_section_size,node_section_offset,FILE_LIST_IO_TAG_FILE_NAME ,mFiles[i].name )) throw read_error(node_section_data,node_section_size,node_section_offset,FILE_LIST_IO_TAG_FILE_NAME ) ;
|
if(!FileListIO::readField(node_section_data,node_section_size,node_section_offset,FILE_LIST_IO_TAG_FILE_NAME ,mFiles[i].name )) throw read_error(node_section_data,node_section_size,node_section_offset,FILE_LIST_IO_TAG_FILE_NAME ) ;
|
||||||
if(!FileListIO::readField(node_section_data,node_section_size,node_section_offset,FILE_LIST_IO_TAG_FILE_SIZE ,mFiles[i].size )) throw read_error(node_section_data,node_section_size,node_section_offset,FILE_LIST_IO_TAG_FILE_SIZE ) ;
|
if(!FileListIO::readField(node_section_data,node_section_size,node_section_offset,FILE_LIST_IO_TAG_FILE_SIZE ,mFiles[i].size )) throw read_error(node_section_data,node_section_size,node_section_offset,FILE_LIST_IO_TAG_FILE_SIZE ) ;
|
||||||
if(!FileListIO::readField(node_section_data,node_section_size,node_section_offset,FILE_LIST_IO_TAG_FILE_SHA1_HASH,mFiles[i].hash )) throw read_error(node_section_data,node_section_size,node_section_offset,FILE_LIST_IO_TAG_FILE_SHA1_HASH) ;
|
if(!FileListIO::readField(node_section_data,node_section_size,node_section_offset,FILE_LIST_IO_TAG_FILE_SHA1_HASH,mFiles[i].hash )) throw read_error(node_section_data,node_section_size,node_section_offset,FILE_LIST_IO_TAG_FILE_SHA1_HASH) ;
|
||||||
|
|
||||||
mTotalFiles++ ;
|
mTotalFiles++ ;
|
||||||
mTotalSize += file_size ;
|
mTotalSize += mFiles[i].size ;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
throw read_error(buffer,buffer_size,buffer_offset,FILE_LIST_IO_TAG_LOCAL_FILE_ENTRY) ;
|
throw read_error(buffer,buffer_size,buffer_offset,FILE_LIST_IO_TAG_LOCAL_FILE_ENTRY) ;
|
||||||
|
@ -15,6 +15,8 @@ public:
|
|||||||
protected:
|
protected:
|
||||||
void recurs_print(uint32_t index,const std::string& indent) const;
|
void recurs_print(uint32_t index,const std::string& indent) const;
|
||||||
|
|
||||||
|
static void recurs_buildFileTree(FileTreeImpl& ft,uint32_t index,const DirDetails& dd,bool remote);
|
||||||
|
|
||||||
struct DirData {
|
struct DirData {
|
||||||
std::string name;
|
std::string name;
|
||||||
std::vector<uint32_t> subdirs ;
|
std::vector<uint32_t> subdirs ;
|
||||||
@ -22,4 +24,6 @@ protected:
|
|||||||
};
|
};
|
||||||
std::vector<FileData> mFiles ;
|
std::vector<FileData> mFiles ;
|
||||||
std::vector<DirData> mDirs ;
|
std::vector<DirData> mDirs ;
|
||||||
|
|
||||||
|
friend class FileTree ;
|
||||||
};
|
};
|
||||||
|
@ -144,7 +144,7 @@ class FileTree
|
|||||||
public:
|
public:
|
||||||
virtual ~FileTree() {}
|
virtual ~FileTree() {}
|
||||||
|
|
||||||
static FileTree *create(void *ref) ;
|
static FileTree *create(const DirDetails& dd, bool remote) ;
|
||||||
static FileTree *create(const std::string& radix64_string) ;
|
static FileTree *create(const std::string& radix64_string) ;
|
||||||
|
|
||||||
virtual std::string toRadix64() const =0 ;
|
virtual std::string toRadix64() const =0 ;
|
||||||
@ -160,6 +160,8 @@ public:
|
|||||||
virtual uint32_t root() const { return 0;}
|
virtual uint32_t root() const { return 0;}
|
||||||
virtual bool getDirectoryContent(uint32_t index,std::vector<uint32_t>& subdirs,std::vector<FileData>& subfiles) const = 0;
|
virtual bool getDirectoryContent(uint32_t index,std::vector<uint32_t>& subdirs,std::vector<FileData>& subfiles) const = 0;
|
||||||
|
|
||||||
|
virtual void print() const=0;
|
||||||
|
|
||||||
uint32_t mTotalFiles ;
|
uint32_t mTotalFiles ;
|
||||||
uint64_t mTotalSize ;
|
uint64_t mTotalSize ;
|
||||||
};
|
};
|
||||||
|
@ -511,7 +511,8 @@ void RemoteSharedFilesDialog::spawnCustomPopupMenu( QPoint point )
|
|||||||
connect( downloadAct , SIGNAL( triggered() ), this, SLOT( downloadRemoteSelected() ) ) ;
|
connect( downloadAct , SIGNAL( triggered() ), this, SLOT( downloadRemoteSelected() ) ) ;
|
||||||
contextMnu.addAction( downloadAct) ;
|
contextMnu.addAction( downloadAct) ;
|
||||||
|
|
||||||
if ( type == DIR_TYPE_FILE ) {
|
//if ( type == DIR_TYPE_FILE )
|
||||||
|
{
|
||||||
contextMnu.addSeparator() ;//------------------------------------
|
contextMnu.addSeparator() ;//------------------------------------
|
||||||
contextMnu.addAction( copylinkAct) ;
|
contextMnu.addAction( copylinkAct) ;
|
||||||
contextMnu.addAction( sendlinkAct) ;
|
contextMnu.addAction( sendlinkAct) ;
|
||||||
@ -572,6 +573,18 @@ void SharedFilesDialog::copyLink (const QModelIndexList& lst, bool remote)
|
|||||||
|
|
||||||
if (details.type == DIR_TYPE_DIR)
|
if (details.type == DIR_TYPE_DIR)
|
||||||
{
|
{
|
||||||
|
FileTree *ft = FileTree::create(details,remote) ;
|
||||||
|
|
||||||
|
std::cerr << "Created collection file tree:" << std::endl;
|
||||||
|
ft->print();
|
||||||
|
|
||||||
|
RetroShareLink link = RetroShareLink::createCollection(QString::fromUtf8(details.name.c_str()), details.count,QString::fromStdString(ft->toRadix64())) ;
|
||||||
|
|
||||||
|
if(link.valid())
|
||||||
|
urls.push_back(link) ;
|
||||||
|
|
||||||
|
delete ft ;
|
||||||
|
#ifdef TO_REMOVE
|
||||||
for(uint32_t j=0;j<details.children.size();++j)
|
for(uint32_t j=0;j<details.children.size();++j)
|
||||||
{
|
{
|
||||||
const DirStub& dirStub = details.children[j];
|
const DirStub& dirStub = details.children[j];
|
||||||
@ -594,6 +607,7 @@ void SharedFilesDialog::copyLink (const QModelIndexList& lst, bool remote)
|
|||||||
urls.push_back(link) ;
|
urls.push_back(link) ;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user