diff --git a/retroshare-gui/src/gui/FileTransfer/TransfersDialog.cpp b/retroshare-gui/src/gui/FileTransfer/TransfersDialog.cpp index ca4cf5cfa..b9e961457 100644 --- a/retroshare-gui/src/gui/FileTransfer/TransfersDialog.cpp +++ b/retroshare-gui/src/gui/FileTransfer/TransfersDialog.cpp @@ -1640,8 +1640,27 @@ void TransfersDialog::updateDetailsDialog() void TransfersDialog::pasteLink() { - RSLinkClipboard::process(RetroShareLink::TYPE_FILE); - RSLinkClipboard::process(RetroShareLink::TYPE_FILE_TREE); + QList links ; + + // We want to capture and process all links at once here, because we're possibly pasting a large collection of files. So we first + // merge all links into a single RsCollection and then process it. + + RsCollection col ; + RSLinkClipboard::pasteLinks(links,RetroShareLink::TYPE_FILE_TREE); + + for(QList::const_iterator it(links.begin());it!=links.end();++it) + { + FileTree *ft = FileTree::create((*it).radix().toStdString()) ; + + col.merge_in(*ft) ; + } + links.clear(); + RSLinkClipboard::pasteLinks(links,RetroShareLink::TYPE_FILE); + + for(QList::const_iterator it(links.begin());it!=links.end();++it) + col.merge_in((*it).name(),(*it).size(),RsFileHash((*it).hash().toStdString())) ; + + col.downloadFiles(); } void TransfersDialog::getDLSelectedItems(std::set *ids, std::set *rows) diff --git a/retroshare-gui/src/gui/RetroShareLink.cpp b/retroshare-gui/src/gui/RetroShareLink.cpp index 769a6321f..a42d9c104 100644 --- a/retroshare-gui/src/gui/RetroShareLink.cpp +++ b/retroshare-gui/src/gui/RetroShareLink.cpp @@ -1716,17 +1716,17 @@ void RSLinkClipboard::copyLinks(const QList& links) QApplication::clipboard()->setText(res) ; } -void RSLinkClipboard::pasteLinks(QList &links) +void RSLinkClipboard::pasteLinks(QList &links,RetroShareLink::enumType type) { - return parseClipboard(links); + return parseClipboard(links,type); } -void RSLinkClipboard::parseClipboard(QList &links) +void RSLinkClipboard::parseClipboard(QList &links,RetroShareLink::enumType type) { // parse clipboard for links. // QString text = QApplication::clipboard()->text() ; - parseText(text, links); + parseText(text, links,type); } QString RSLinkClipboard::toString() @@ -1771,26 +1771,18 @@ bool RSLinkClipboard::empty(RetroShareLink::enumType type /* = RetroShareLink::T return true; } -/*static*/ int RSLinkClipboard::process(RetroShareLink::enumType type /* = RetroShareLink::TYPE_UNKNOWN*/, uint flag /* = RSLINK_PROCESS_NOTIFY_ALL*/) +int RSLinkClipboard::process(RetroShareLink::enumType type /* = RetroShareLink::TYPE_UNKNOWN*/, uint flag /* = RSLINK_PROCESS_NOTIFY_ALL*/) { QList links; - pasteLinks(links); + pasteLinks(links,type); - QList linksToProcess; - for (int i = 0; i < links.size(); ++i) { - if (links[i].valid() && (type == RetroShareLink::TYPE_UNKNOWN || links[i].type() == type)) { - linksToProcess.append(links[i]); - } - } - - if (linksToProcess.isEmpty()) { + if (links.isEmpty()) return 0; - } - return RetroShareLink::process(linksToProcess, flag); + return RetroShareLink::process(links, flag); } -void RSLinkClipboard::parseText(QString text, QList &links) +void RSLinkClipboard::parseText(QString text, QList &links,RetroShareLink::enumType type ) { links.clear(); @@ -1805,7 +1797,7 @@ void RSLinkClipboard::parseText(QString text, QList &links) QString url(text.mid(pos, rx.matchedLength())); RetroShareLink link(url); - if(link.valid()) + if(link.valid() && (type == RetroShareLink::TYPE_UNKNOWN || type == link.type())) { // check that the link is not already in the list: bool already = false ; diff --git a/retroshare-gui/src/gui/RetroShareLink.h b/retroshare-gui/src/gui/RetroShareLink.h index 11b25b419..43ca67ab0 100644 --- a/retroshare-gui/src/gui/RetroShareLink.h +++ b/retroshare-gui/src/gui/RetroShareLink.h @@ -192,7 +192,7 @@ class RSLinkClipboard // Get the liste of pasted links, either from the internal RS links, or by default // from the clipboard. // - static void pasteLinks(QList &links) ; + static void pasteLinks(QList &links,RetroShareLink::enumType type = RetroShareLink::TYPE_UNKNOWN) ; // Produces a list of links with no html structure. static QString toString() ; @@ -215,10 +215,10 @@ class RSLinkClipboard // static int process(RetroShareLink::enumType type = RetroShareLink::TYPE_UNKNOWN, uint flag = RSLINK_PROCESS_NOTIFY_ALL); - static void parseText(QString text, QList &links) ; + static void parseText(QString text, QList &links, RetroShareLink::enumType type = RetroShareLink::TYPE_UNKNOWN) ; private: - static void parseClipboard(QList &links) ; + static void parseClipboard(QList &links, RetroShareLink::enumType type = RetroShareLink::TYPE_UNKNOWN) ; }; #endif diff --git a/retroshare-gui/src/gui/common/RsCollection.cpp b/retroshare-gui/src/gui/common/RsCollection.cpp index a7ba9637a..a42d34340 100644 --- a/retroshare-gui/src/gui/common/RsCollection.cpp +++ b/retroshare-gui/src/gui/common/RsCollection.cpp @@ -41,25 +41,21 @@ const QString RsCollection::ExtensionString = QString("rscollection") ; RsCollection::RsCollection(QObject *parent) : QObject(parent), _xml_doc("RsCollection") { + _root = _xml_doc.createElement("RsCollection"); + _xml_doc.appendChild(_root); } RsCollection::RsCollection(const FileTree& fr) : _xml_doc("RsCollection") { - QDomElement root = _xml_doc.createElement("RsCollection"); - _xml_doc.appendChild(root); - - recursAddElements(_xml_doc,fr,0,root) ; + recursAddElements(_xml_doc,fr,0,_root) ; } RsCollection::RsCollection(const std::vector& file_infos, QObject *parent) : QObject(parent), _xml_doc("RsCollection") { - QDomElement root = _xml_doc.createElement("RsCollection"); - _xml_doc.appendChild(root); - for(uint32_t i = 0;i& colFileInfos,const QString& current_path, bool bad_chars_in_parent) const { QDomNode n = e.firstChild() ; @@ -235,7 +246,7 @@ void RsCollection::recursAddElements(QDomDocument& doc,const FileTree& ft,uint32 f.setAttribute(QString("sha1"),QString::fromStdString(subfiles[i].hash.toStdString())) ; f.setAttribute(QString("size"),QString::number(subfiles[i].size)) ; - e.appendChild(f) ; + d.appendChild(f) ; } } diff --git a/retroshare-gui/src/gui/common/RsCollection.h b/retroshare-gui/src/gui/common/RsCollection.h index f42b81db0..0a6e1e65f 100644 --- a/retroshare-gui/src/gui/common/RsCollection.h +++ b/retroshare-gui/src/gui/common/RsCollection.h @@ -68,10 +68,11 @@ public: RsCollection(const FileTree& fr); virtual ~RsCollection() ; + void merge_in(const QString& fname,uint64_t size,const RsFileHash& hash) ; + void merge_in(const FileTree& tree) ; + static const QString ExtensionString ; - - // Loads file from disk. bool load(QWidget *parent); bool load(const QString& fileName, bool showError = true); @@ -108,6 +109,7 @@ private: QDomDocument _xml_doc ; QString _fileName ; bool _saved; + QDomElement _root ; friend class RsCollectionDialog ; };