From 885eb640dc381f73ea0cfa15954dc90978b695a6 Mon Sep 17 00:00:00 2001 From: csoler Date: Tue, 27 Feb 2024 22:10:49 +0100 Subject: [PATCH] starting fixing RsCollection with the new model --- .../gui/FileTransfer/SharedFilesDialog.cpp | 5 ++- .../src/gui/common/RsCollection.cpp | 37 +++++++++---------- retroshare-gui/src/gui/common/RsCollection.h | 4 +- .../src/gui/common/RsCollectionDialog.cpp | 2 +- 4 files changed, 25 insertions(+), 23 deletions(-) diff --git a/retroshare-gui/src/gui/FileTransfer/SharedFilesDialog.cpp b/retroshare-gui/src/gui/FileTransfer/SharedFilesDialog.cpp index 7321486fe..8c7e460c2 100644 --- a/retroshare-gui/src/gui/FileTransfer/SharedFilesDialog.cpp +++ b/retroshare-gui/src/gui/FileTransfer/SharedFilesDialog.cpp @@ -733,7 +733,7 @@ void SharedFilesDialog::sendLinkTo() void SharedFilesDialog::collCreate() { -#ifdef TODO +#ifdef TODO_COLLECTION QModelIndexList lst = getSelected(); std::vector dirVec; @@ -831,6 +831,8 @@ void SharedFilesDialog::collOpen() if (qinfo.exists()) { if (qinfo.absoluteFilePath().endsWith(RsCollection::ExtensionString)) { + RsCollectionDialog::openExistingCollection(qinfo.absoluteFilePath(),true); +#ifdef TO_REMOVE RsCollection::RsCollectionErrorCode err; RsCollection collection(qinfo.absoluteFilePath(),err); @@ -839,6 +841,7 @@ void SharedFilesDialog::collOpen() collection.downloadFiles(); return; } +#endif } } } diff --git a/retroshare-gui/src/gui/common/RsCollection.cpp b/retroshare-gui/src/gui/common/RsCollection.cpp index bc76fff00..e7e329604 100644 --- a/retroshare-gui/src/gui/common/RsCollection.cpp +++ b/retroshare-gui/src/gui/common/RsCollection.cpp @@ -38,19 +38,17 @@ const QString RsCollection::ExtensionString = QString("rscollection") ; RsCollection::RsCollection(QObject *parent) - : QObject(parent) + : QObject(parent), mFileTree(new RsFileTree) { -// _root = _xml_doc.createElement("RsCollection"); -// _xml_doc.appendChild(_root); } RsCollection::RsCollection(const RsFileTree& ft) - : mFileTree(ft) { + mFileTree = std::unique_ptr(new RsFileTree(ft)); } RsCollection::RsCollection(const std::vector& file_infos,FileSearchFlags flags, QObject *parent) - : QObject(parent) + : QObject(parent), mFileTree(new RsFileTree) { if(! ( (flags & RS_FILE_HINTS_LOCAL) || (flags & RS_FILE_HINTS_REMOTE))) { @@ -59,7 +57,7 @@ RsCollection::RsCollection(const std::vector& file_infos,FileSearchF } for(uint32_t i = 0;iroot(),file_infos[i],flags) ; } RsCollection::~RsCollection() @@ -142,7 +140,7 @@ static QString purifyFileName(const QString& input,bool& bad) void RsCollection::merge_in(const QString& fname,uint64_t size,const RsFileHash& hash) { - mFileTree.addFile(mFileTree.root(),fname.toStdString(),hash,size); + mFileTree->addFile(mFileTree->root(),fname.toStdString(),hash,size); #ifdef TO_REMOVE ColFileInfo info ; info.type = DIR_TYPE_FILE ; @@ -155,7 +153,7 @@ void RsCollection::merge_in(const QString& fname,uint64_t size,const RsFileHash& } void RsCollection::merge_in(const RsFileTree& tree) { - recursMergeTree(mFileTree.root(),tree,tree.directoryData(tree.root())) ; + recursMergeTree(mFileTree->root(),tree,tree.directoryData(tree.root())) ; } void RsCollection::recursMergeTree(RsFileTree::DirIndex parent,const RsFileTree& tree,const RsFileTree::DirData& dd) @@ -163,13 +161,13 @@ void RsCollection::recursMergeTree(RsFileTree::DirIndex parent,const RsFileTree& for(uint32_t i=0;iaddFile(parent,fd.name,fd.hash,fd.size); } for(uint32_t i=0;iaddDirectory(parent,ld.name); recursMergeTree(new_dir_index,tree,ld); } } @@ -234,10 +232,10 @@ void RsCollection::recursCollectColFileInfos(const QDomElement& e,std::vectoraddFile(parent,dd.name,dd.hash,dd.size); else if (dd.type == DIR_TYPE_DIR) { - RsFileTree::DirIndex new_dir_index = mFileTree.addDirectory(parent,dd.name); + RsFileTree::DirIndex new_dir_index = mFileTree->addDirectory(parent,dd.name); for(uint32_t i=0;idirectoryData(mFileTree->root())); if(!recursExportToXml(xml_doc,root,root_data)) return false; @@ -504,7 +503,7 @@ bool RsCollection::recursParseXml(QDomDocument& doc,const QDomNode& e,const RsFi std::string name = purifyFileName(ee.attribute(QString("name")), bad_chars_detected).toUtf8().constData() ; uint64_t size = ee.attribute(QString("size")).toULongLong() ; - mFileTree.addFile(parent,name,hash,size); + mFileTree->addFile(parent,name,hash,size); #ifdef TO_REMOVE mFileTree.addFile(parent,) ColFileInfo newChild ; @@ -522,7 +521,7 @@ bool RsCollection::recursParseXml(QDomDocument& doc,const QDomNode& e,const RsFi bool bad_chars_detected = false ; std::string cleanDirName = purifyFileName(ee.attribute(QString("name")),bad_chars_detected).toUtf8().constData() ; - RsFileTree::DirIndex new_dir_index = mFileTree.addDirectory(parent,cleanDirName); + RsFileTree::DirIndex new_dir_index = mFileTree->addDirectory(parent,cleanDirName); recursParseXml(doc,ee,new_dir_index); #ifdef TO_REMOVE @@ -554,7 +553,7 @@ bool RsCollection::recursExportToXml(QDomDocument& doc,QDomElement& e,const RsFi { QDomElement f = doc.createElement("File") ; - const RsFileTree::FileData& fd(mFileTree.fileData(dd.subfiles[i])); + const RsFileTree::FileData& fd(mFileTree->fileData(dd.subfiles[i])); f.setAttribute(QString("name"),QString::fromUtf8(fd.name.c_str())) ; f.setAttribute(QString("sha1"),QString::fromStdString(fd.hash.toStdString())) ; @@ -565,7 +564,7 @@ bool RsCollection::recursExportToXml(QDomDocument& doc,QDomElement& e,const RsFi for(uint32_t i=0;idirectoryData(dd.subdirs[i])); QDomElement d = doc.createElement("Directory") ; d.setAttribute(QString("name"),QString::fromUtf8(di.name.c_str())) ; @@ -600,11 +599,11 @@ bool RsCollection::save(QWidget *parent) const qulonglong RsCollection::count() const { - return mFileTree.numFiles(); + return mFileTree->numFiles(); } qulonglong RsCollection::size() { - return mFileTree.totalFileSize(); + return mFileTree->totalFileSize(); #ifdef TO_REMOVE QDomElement docElem = _xml_doc.documentElement(); diff --git a/retroshare-gui/src/gui/common/RsCollection.h b/retroshare-gui/src/gui/common/RsCollection.h index 47fdee5d6..745a4c764 100644 --- a/retroshare-gui/src/gui/common/RsCollection.h +++ b/retroshare-gui/src/gui/common/RsCollection.h @@ -90,7 +90,7 @@ public: bool save(const QString& fileName) const ; // returns the file tree - const RsFileTree& fileTree() const { return mFileTree; } + const RsFileTree& fileTree() const { return *mFileTree; } // total size of files in the collection qulonglong size(); // total number of files in the collection @@ -129,7 +129,7 @@ private: // Auto Download recursively. void autoDownloadFiles(ColFileInfo colFileInfo, QString dlDir) const ; - RsFileTree mFileTree; + std::unique_ptr mFileTree; #ifdef TO_REMOVE QDomDocument _xml_doc ; QString _fileName ; diff --git a/retroshare-gui/src/gui/common/RsCollectionDialog.cpp b/retroshare-gui/src/gui/common/RsCollectionDialog.cpp index 52583c4f7..c6f22ceb7 100644 --- a/retroshare-gui/src/gui/common/RsCollectionDialog.cpp +++ b/retroshare-gui/src/gui/common/RsCollectionDialog.cpp @@ -1456,7 +1456,7 @@ void RsCollectionDialog::saveChild(QTreeWidgetItem *parentItem, ColFileInfo *par bool RsCollectionDialog::openExistingCollection(const QString& fileName, bool readOnly /* = false */, bool showError /* = true*/) { - return RsCollectionDialog(fileName,readOnly,showError).exec(); + return RsCollectionDialog(fileName,false,readOnly).exec(); } bool RsCollectionDialog::openNewCollection(const RsFileTree& tree,const QString& proposed_file_name)