From 5997c104952ec56422dad892e3cdaf51ea5ff996 Mon Sep 17 00:00:00 2001 From: csoler Date: Sun, 12 Nov 2017 22:46:29 +0100 Subject: [PATCH] fixed bug causing RsCollection to fail on remote files. Now using RsCollectionDialog when downloading directories from friend shared files --- .../src/gui/FileTransfer/SearchDialog.cpp | 6 +- .../gui/FileTransfer/SharedFilesDialog.cpp | 26 ++++++-- .../src/gui/FileTransfer/SharedFilesDialog.h | 1 + .../src/gui/FileTransfer/TransfersDialog.cpp | 7 ++- retroshare-gui/src/gui/MainWindow.cpp | 12 ++-- retroshare-gui/src/gui/MainWindow.h | 2 +- retroshare-gui/src/gui/RemoteDirModel.cpp | 61 ++++++++++--------- retroshare-gui/src/gui/RemoteDirModel.h | 2 +- .../src/gui/common/RsCollection.cpp | 15 +++-- retroshare-gui/src/gui/common/RsCollection.h | 4 +- 10 files changed, 83 insertions(+), 53 deletions(-) diff --git a/retroshare-gui/src/gui/FileTransfer/SearchDialog.cpp b/retroshare-gui/src/gui/FileTransfer/SearchDialog.cpp index d55f78e99..2fd0558ef 100644 --- a/retroshare-gui/src/gui/FileTransfer/SearchDialog.cpp +++ b/retroshare-gui/src/gui/FileTransfer/SearchDialog.cpp @@ -445,10 +445,10 @@ void SearchDialog::collCreate() details.type = DIR_TYPE_FILE; dirVec.push_back(details); - }//if (!item->text(SR_HASH_COL).isEmpty()) - }//for (int i = 0; i < numdls; ++i) + } + } - RsCollection(dirVec).openNewColl(this); + RsCollection(dirVec,RS_FILE_HINTS_LOCAL).openNewColl(this); } void SearchDialog::collModif() diff --git a/retroshare-gui/src/gui/FileTransfer/SharedFilesDialog.cpp b/retroshare-gui/src/gui/FileTransfer/SharedFilesDialog.cpp index bf3e1c92b..92fd34857 100644 --- a/retroshare-gui/src/gui/FileTransfer/SharedFilesDialog.cpp +++ b/retroshare-gui/src/gui/FileTransfer/SharedFilesDialog.cpp @@ -509,9 +509,18 @@ void RemoteSharedFilesDialog::spawnCustomPopupMenu( QPoint point ) collectionMenu.addAction(collCreateAct); collectionMenu.addAction(collOpenAct); - QAction *downloadAct = new QAction(QIcon(IMAGE_DOWNLOAD), tr( "Download" ), &contextMnu ) ; - connect( downloadAct , SIGNAL( triggered() ), this, SLOT( downloadRemoteSelected() ) ) ; - contextMnu.addAction( downloadAct) ; + if(type == DIR_TYPE_DIR) + { + QAction *downloadActI = new QAction(QIcon(IMAGE_DOWNLOAD), tr( "Download..." ), &contextMnu ) ; + connect( downloadActI , SIGNAL( triggered() ), this, SLOT( downloadRemoteSelectedInteractive() ) ) ; + contextMnu.addAction( downloadActI) ; + } + else + { + QAction *downloadAct = new QAction(QIcon(IMAGE_DOWNLOAD), tr( "Download" ), &contextMnu ) ; + connect( downloadAct , SIGNAL( triggered() ), this, SLOT( downloadRemoteSelected() ) ) ; + contextMnu.addAction( downloadAct) ; + } contextMnu.addSeparator() ;//------------------------------------ contextMnu.addAction( copylinkAct) ; @@ -545,7 +554,16 @@ void RemoteSharedFilesDialog::expanded(const QModelIndex& indx) model->updateRef(proxyModel->mapToSource(indx)) ; } +void RemoteSharedFilesDialog::downloadRemoteSelectedInteractive() +{ + /* call back to the model (which does all the interfacing? */ + std::cerr << "Downloading Files" ; + std::cerr << std::endl ; + + QModelIndexList lst = getSelected() ; + model -> downloadSelected(lst,true) ; +} void RemoteSharedFilesDialog::downloadRemoteSelected() { /* call back to the model (which does all the interfacing? */ @@ -554,7 +572,7 @@ void RemoteSharedFilesDialog::downloadRemoteSelected() std::cerr << std::endl ; QModelIndexList lst = getSelected() ; - model -> downloadSelected(lst) ; + model -> downloadSelected(lst,false) ; } void SharedFilesDialog::copyLinks(const QModelIndexList& lst, bool remote,QList& urls,bool& has_unhashed_files) diff --git a/retroshare-gui/src/gui/FileTransfer/SharedFilesDialog.h b/retroshare-gui/src/gui/FileTransfer/SharedFilesDialog.h index 8e242a0a6..4fb18ab0c 100644 --- a/retroshare-gui/src/gui/FileTransfer/SharedFilesDialog.h +++ b/retroshare-gui/src/gui/FileTransfer/SharedFilesDialog.h @@ -187,6 +187,7 @@ class RemoteSharedFilesDialog : public SharedFilesDialog private slots: void downloadRemoteSelected(); + void downloadRemoteSelectedInteractive(); void expanded(const QModelIndex& indx); }; diff --git a/retroshare-gui/src/gui/FileTransfer/TransfersDialog.cpp b/retroshare-gui/src/gui/FileTransfer/TransfersDialog.cpp index ea06b598b..196bc90ac 100644 --- a/retroshare-gui/src/gui/FileTransfer/TransfersDialog.cpp +++ b/retroshare-gui/src/gui/FileTransfer/TransfersDialog.cpp @@ -2133,7 +2133,8 @@ void TransfersDialog::collCreate() std::set::iterator it ; getDLSelectedItems(&items, NULL); - for (it = items.begin(); it != items.end(); ++it) { + for (it = items.begin(); it != items.end(); ++it) + { FileInfo info; if (!rsFiles->FileDetails(*it, RS_FILE_HINTS_DOWNLOAD, info)) continue; @@ -2144,9 +2145,9 @@ void TransfersDialog::collCreate() details.type = DIR_TYPE_FILE; dirVec.push_back(details); - }//for (it = items.begin(); + } - RsCollection(dirVec).openNewColl(this); + RsCollection(dirVec,RS_FILE_HINTS_LOCAL).openNewColl(this); } void TransfersDialog::collModif() diff --git a/retroshare-gui/src/gui/MainWindow.cpp b/retroshare-gui/src/gui/MainWindow.cpp index cc08d4954..35399146a 100644 --- a/retroshare-gui/src/gui/MainWindow.cpp +++ b/retroshare-gui/src/gui/MainWindow.cpp @@ -1027,12 +1027,12 @@ void MainWindow::addFriend() } /** New RSCollection ShortCut */ -void MainWindow::newRsCollection() -{ - std::vector dirVec; - - RsCollection(dirVec).openNewColl(this); -} +// void MainWindow::newRsCollection() +// { +// std::vector dirVec; +// +// RsCollection(dirVec).openNewColl(this); +// } /** Shows Share Manager */ void MainWindow::openShareManager() diff --git a/retroshare-gui/src/gui/MainWindow.h b/retroshare-gui/src/gui/MainWindow.h index b3fc246dc..a52bf0073 100644 --- a/retroshare-gui/src/gui/MainWindow.h +++ b/retroshare-gui/src/gui/MainWindow.h @@ -223,7 +223,7 @@ private slots: /** Toolbar fns. */ void addFriend(); - void newRsCollection(); + //void newRsCollection(); void showMessengerWindow(); void showStatisticsWindow(); #ifdef ENABLE_WEBUI diff --git a/retroshare-gui/src/gui/RemoteDirModel.cpp b/retroshare-gui/src/gui/RemoteDirModel.cpp index 7ffbcf5bd..4f6109ff5 100644 --- a/retroshare-gui/src/gui/RemoteDirModel.cpp +++ b/retroshare-gui/src/gui/RemoteDirModel.cpp @@ -1065,10 +1065,12 @@ void RetroshareDirModel::createCollectionFile(QWidget *parent, const QModelIndex std::vector dirVec; getDirDetailsFromSelect(list, dirVec); - RsCollection(dirVec).openNewColl(parent); + FileSearchFlags f = RemoteMode?RS_FILE_HINTS_REMOTE:RS_FILE_HINTS_LOCAL ; + + RsCollection(dirVec,f).openNewColl(parent); } -void RetroshareDirModel::downloadSelected(const QModelIndexList &list) +void RetroshareDirModel::downloadSelected(const QModelIndexList &list,bool interactive) { if (!RemoteMode) { @@ -1085,35 +1087,38 @@ void RetroshareDirModel::downloadSelected(const QModelIndexList &list) std::vector dirVec; getDirDetailsFromSelect(list, dirVec); + FileSearchFlags f = RemoteMode?RS_FILE_HINTS_REMOTE:RS_FILE_HINTS_LOCAL ; - /* Fire off requests */ - for (int i = 0, n = dirVec.size(); i < n; ++i) - { - if (!RemoteMode) - { - continue; /* don't try to download local stuff */ - } + if(interactive) + RsCollection(dirVec,f).downloadFiles() ; + else /* Fire off requests */ + for (int i = 0, n = dirVec.size(); i < n; ++i) + { + if (!RemoteMode) + { + continue; /* don't try to download local stuff */ + } - const DirDetails& details = dirVec[i]; + const DirDetails& details = dirVec[i]; - /* if it is a file */ - if (details.type == DIR_TYPE_FILE) - { - std::cerr << "RetroshareDirModel::downloadSelected() Calling File Request"; - std::cerr << std::endl; - std::list srcIds; - srcIds.push_back(details.id); - rsFiles -> FileRequest(details.name, details.hash, - details.count, "", RS_FILE_REQ_ANONYMOUS_ROUTING, srcIds); - } - /* if it is a dir, copy all files included*/ - else if (details.type == DIR_TYPE_DIR) - { - int prefixLen = details.path.rfind(details.name); - if (prefixLen < 0) continue; - downloadDirectory(details, prefixLen); - } - } + /* if it is a file */ + if (details.type == DIR_TYPE_FILE) + { + std::cerr << "RetroshareDirModel::downloadSelected() Calling File Request"; + std::cerr << std::endl; + std::list srcIds; + srcIds.push_back(details.id); + rsFiles -> FileRequest(details.name, details.hash, + details.count, "", RS_FILE_REQ_ANONYMOUS_ROUTING, srcIds); + } + /* if it is a dir, copy all files included*/ + else if (details.type == DIR_TYPE_DIR) + { + int prefixLen = details.path.rfind(details.name); + if (prefixLen < 0) continue; + downloadDirectory(details, prefixLen); + } + } } /* recursively download a directory */ diff --git a/retroshare-gui/src/gui/RemoteDirModel.h b/retroshare-gui/src/gui/RemoteDirModel.h index 73642dda4..ed394b795 100644 --- a/retroshare-gui/src/gui/RemoteDirModel.h +++ b/retroshare-gui/src/gui/RemoteDirModel.h @@ -63,7 +63,7 @@ class RetroshareDirModel : public QAbstractItemModel bool visible() { return _visible ;} /* Callback from GUI */ - void downloadSelected(const QModelIndexList &list); + void downloadSelected(const QModelIndexList &list, bool interactive); void createCollectionFile(QWidget *parent, const QModelIndexList &list); void getDirDetailsFromSelect (const QModelIndexList &list, std::vector & dirVec); diff --git a/retroshare-gui/src/gui/common/RsCollection.cpp b/retroshare-gui/src/gui/common/RsCollection.cpp index f92598137..d6ae71fc8 100644 --- a/retroshare-gui/src/gui/common/RsCollection.cpp +++ b/retroshare-gui/src/gui/common/RsCollection.cpp @@ -56,14 +56,20 @@ RsCollection::RsCollection(const FileTree& fr) recursAddElements(_xml_doc,fr,0,_root) ; } -RsCollection::RsCollection(const std::vector& file_infos, QObject *parent) +RsCollection::RsCollection(const std::vector& file_infos,FileSearchFlags flags, QObject *parent) : QObject(parent), _xml_doc("RsCollection") { _root = _xml_doc.createElement("RsCollection"); _xml_doc.appendChild(_root); + if(! ( (flags & RS_FILE_HINTS_LOCAL) || (flags & RS_FILE_HINTS_REMOTE))) + { + std::cerr << "(EE) Wrong flags passed to RsCollection constructor. Please fix the code!" << std::endl; + return ; + } + for(uint32_t i = 0;iRequestDirDetails(details.children[i].ref, subDirDetails, flags)) continue; - recursAddElements(doc,subDirDetails,d) ; + recursAddElements(doc,subDirDetails,d,flags) ; } e.appendChild(d) ; diff --git a/retroshare-gui/src/gui/common/RsCollection.h b/retroshare-gui/src/gui/common/RsCollection.h index 0a6e1e65f..cbd9c28e6 100644 --- a/retroshare-gui/src/gui/common/RsCollection.h +++ b/retroshare-gui/src/gui/common/RsCollection.h @@ -64,7 +64,7 @@ public: RsCollection(QObject *parent = 0) ; // create from list of files and directories - RsCollection(const std::vector& file_entries, QObject *parent = 0) ; + RsCollection(const std::vector& file_entries, FileSearchFlags flags, QObject *parent = 0) ; RsCollection(const FileTree& fr); virtual ~RsCollection() ; @@ -98,7 +98,7 @@ private slots: private: - void recursAddElements(QDomDocument&,const DirDetails&,QDomElement&) const ; + void recursAddElements(QDomDocument&, const DirDetails&, QDomElement&, FileSearchFlags flags) const ; void recursAddElements(QDomDocument&,const ColFileInfo&,QDomElement&) const; void recursAddElements(QDomDocument& doc,const FileTree& ft,uint32_t index,QDomElement& e) const;