diff --git a/libretroshare/src/file_sharing/file_tree.cc b/libretroshare/src/file_sharing/file_tree.cc index 65eacbcef..8a1f11fc5 100644 --- a/libretroshare/src/file_sharing/file_tree.cc +++ b/libretroshare/src/file_sharing/file_tree.cc @@ -71,11 +71,12 @@ void FileTreeImpl::recurs_buildFileTree(FileTreeImpl& ft,uint32_t index,const Di std::cerr << "(EE) Cannot request dir details for pointer " << dd.children[i].ref << std::endl; } -bool FileTreeImpl::getDirectoryContent(uint32_t index,std::vector& subdirs,std::vector& subfiles) const +bool FileTreeImpl::getDirectoryContent(uint32_t index,std::string& name,std::vector& subdirs,std::vector& subfiles) const { if(index >= mDirs.size()) return false ; + name = mDirs[index].name; subdirs = mDirs[index].subdirs ; subfiles.clear() ; diff --git a/libretroshare/src/file_sharing/file_tree.h b/libretroshare/src/file_sharing/file_tree.h index 942414e67..5f94bdf48 100644 --- a/libretroshare/src/file_sharing/file_tree.h +++ b/libretroshare/src/file_sharing/file_tree.h @@ -10,7 +10,7 @@ public: } virtual std::string toRadix64() const ; - virtual bool getDirectoryContent(uint32_t index,std::vector& subdirs,std::vector& subfiles) const ; + virtual bool getDirectoryContent(uint32_t index,std::string& name,std::vector& subdirs,std::vector& subfiles) const ; virtual void print() const ; bool serialise(unsigned char *& data,uint32_t& data_size) const ; diff --git a/libretroshare/src/retroshare/rsfiles.h b/libretroshare/src/retroshare/rsfiles.h index 422b1e9fd..64af23885 100644 --- a/libretroshare/src/retroshare/rsfiles.h +++ b/libretroshare/src/retroshare/rsfiles.h @@ -158,7 +158,7 @@ public: }; virtual uint32_t root() const { return 0;} - virtual bool getDirectoryContent(uint32_t index,std::vector& subdirs,std::vector& subfiles) const = 0; + virtual bool getDirectoryContent(uint32_t index,std::string& name,std::vector& subdirs,std::vector& subfiles) const = 0; virtual void print() const=0; diff --git a/retroshare-gui/src/gui/FileTransfer/SharedFilesDialog.cpp b/retroshare-gui/src/gui/FileTransfer/SharedFilesDialog.cpp index 3a437c9cf..0f0244818 100644 --- a/retroshare-gui/src/gui/FileTransfer/SharedFilesDialog.cpp +++ b/retroshare-gui/src/gui/FileTransfer/SharedFilesDialog.cpp @@ -1014,6 +1014,7 @@ void LocalSharedFilesDialog::spawnCustomPopupMenu( QPoint point ) switch (type) { case DIR_TYPE_DIR : contextMnu.addAction(openfolderAct) ; + contextMnu.addAction(copylinkAct) ; contextMnu.addSeparator() ;//------------------------------------ contextMnu.addMenu(&collectionMenu) ; break ; diff --git a/retroshare-gui/src/gui/RetroShareLink.cpp b/retroshare-gui/src/gui/RetroShareLink.cpp index d141422f1..5a417cc37 100644 --- a/retroshare-gui/src/gui/RetroShareLink.cpp +++ b/retroshare-gui/src/gui/RetroShareLink.cpp @@ -1393,10 +1393,12 @@ static void processList(const QStringList &list, const QString &textSingular, co case TYPE_COLLECTION: { - //FileHierarchy fh ; - //fh.initFromRadix(_radix); + FileTree *ft = FileTree::create(_radix.toStdString()) ; - QMessageBox::information(NULL,"Unimplemented code","File collection links not handled yet.") ; + RsCollectionEditor colled(*ft,NULL) ; + colled.exec(); + + delete ft; } break; diff --git a/retroshare-gui/src/gui/common/RsCollectionEditor.cpp b/retroshare-gui/src/gui/common/RsCollectionEditor.cpp index 7abfe3f92..ea76231bd 100644 --- a/retroshare-gui/src/gui/common/RsCollectionEditor.cpp +++ b/retroshare-gui/src/gui/common/RsCollectionEditor.cpp @@ -43,6 +43,15 @@ RsCollectionEditor::RsCollectionEditor(QObject *parent) { } +RsCollectionEditor::RsCollectionEditor(const FileTree& fr, QObject *parent) + : QObject(parent), _xml_doc("RsCollection") +{ + QDomElement root = _xml_doc.createElement("RsCollection"); + _xml_doc.appendChild(root); + + recursAddElements(_xml_doc,fr,0,root) ; +} + RsCollectionEditor::RsCollectionEditor(const std::vector& file_infos, QObject *parent) : QObject(parent), _xml_doc("RsCollection") { @@ -186,7 +195,7 @@ void RsCollectionEditor::recursAddElements(QDomDocument& doc,const ColFileInfo& f.setAttribute(QString("size"),QString::number(colFileInfo.size)) ; e.appendChild(f) ; -} + } else if (colFileInfo.type == DIR_TYPE_DIR) { QDomElement d = doc.createElement("Directory") ; @@ -194,7 +203,7 @@ void RsCollectionEditor::recursAddElements(QDomDocument& doc,const ColFileInfo& d.setAttribute(QString("name"),colFileInfo.name) ; for (std::vector::const_iterator it = colFileInfo.children.begin(); it != colFileInfo.children.end(); ++it) -{ + { recursAddElements(doc,(*it),d) ; } @@ -202,6 +211,34 @@ void RsCollectionEditor::recursAddElements(QDomDocument& doc,const ColFileInfo& } } +void RsCollectionEditor::recursAddElements(QDomDocument& doc,const FileTree& ft,uint32_t index,QDomElement& e) const +{ + std::vector subdirs ; + std::vector subfiles ; + std::string name; + + if(!ft.getDirectoryContent(index,name,subdirs,subfiles)) + return ; + + QDomElement d = doc.createElement("Directory") ; + d.setAttribute(QString::fromUtf8()("name"),QString::fromUtf8(name.c_str())) ; + e.appendChild(d) ; + + for (uint32_t i=0;i& file_entries, QObject *parent = 0) ; + RsCollectionEditor(const FileTree& fr, QObject *parent); virtual ~RsCollectionEditor() ; static const QString ExtensionString ; - // Loads file from disk. - bool load(QWidget *parent); + // Loads file from disk. + bool load(QWidget *parent); bool load(const QString& fileName, bool showError = true); - // Save to disk - bool save(QWidget *parent) const ; + // Loads from FileTree + bool load(const FileTree& f); + + // Save to disk + bool save(QWidget *parent) const ; bool save(const QString& fileName) const ; // Open new collection @@ -84,28 +88,28 @@ public: // Open existing collection bool openColl(const QString& fileName, bool readOnly = false, bool showError = true); - // Download the content. - void downloadFiles() const ; + // Download the content. + void downloadFiles() const ; - qulonglong size(); + qulonglong size(); static bool isCollectionFile(const QString& fileName); private slots: void saveColl(std::vector colFileInfos, const QString& fileName); - private: +private: - void recursAddElements(QDomDocument&,const DirDetails&,QDomElement&) const ; + void recursAddElements(QDomDocument&,const DirDetails&,QDomElement&) const ; void recursAddElements(QDomDocument&,const ColFileInfo&,QDomElement&) const; void recursCollectColFileInfos(const QDomElement&,std::vector& colFileInfos,const QString& current_dir,bool bad_chars_in_parent) const ; // check that the file is a valid rscollection file, and not a lol bomb or some shit like this static bool checkFile(const QString &fileName, bool showError); - QDomDocument _xml_doc ; + QDomDocument _xml_doc ; QString _fileName ; bool _saved; - friend class RsCollectionDialog ; + friend class RsCollectionDialog ; };